View Javadoc
1 package com.bonevich.erj.app; 2 3 import com.bonevich.erj.xml.SVGReader; 4 import com.bonevich.erj.diagram.ERDiagram; 5 6 import org.tigris.gef.ocl.*; 7 8 import java.io.File; 9 import java.io.InputStream; 10 import java.io.OutputStream; 11 import java.io.OutputStreamWriter; 12 import java.io.IOException; 13 import java.util.Hashtable; 14 15 import org.xml.sax.InputSource; 16 17 public final class ProjectDiagram extends ProjectComponent 18 { 19 ////////////////////////////////////////////////////////// 20 // Constants 21 public static final String DIAGRAM_EXTENSION = "." + SVG; 22 public static final String DIAGRAM_TEE = "/com/bonevich/erj/xml/dtd/svg-erj.tee"; 23 24 ////////////////////////////////////////////////////////// 25 // Attributes 26 private ERDiagram _diagram; 27 28 private static Hashtable _templates = TemplateReader.readFile(DIAGRAM_TEE); 29 private static OCLExpander _expander = new OCLExpander(_templates); 30 31 ////////////////////////////////////////////////////////// 32 // Constructors 33 public ProjectDiagram(Project project, ERDiagram d) 34 { 35 super(project); 36 _diagram = d; 37 setType(SVG); 38 } 39 40 public ERDiagram getDiagram() 41 { 42 return _diagram; 43 } 44 45 public String getEntryExtension() 46 { 47 return DIAGRAM_EXTENSION; 48 } 49 50 public void initEntryFilename() 51 { 52 if (_diagram != null) 53 { 54 _entryFilename = _project.getName() + "_" + _diagram.getName() + DIAGRAM_EXTENSION; 55 } 56 } 57 58 public void load(InputStream in) throws IOException 59 { 60 // We need to use an InputSource so that DOCTYPE and other 61 // entities are properly resolved. Furthermore, it needs to 62 // have its SystemId set with an URL path. 63 InputSource src = new InputSource(in); 64 File path = new File(_project.getFilepath() + "$" + getEntryFilename()); 65 src.setSystemId(path.toURL().toString()); 66 67 SVGReader reader = SVGReader.getInstance(); 68 reader.setOwnerRegistry(_project.getModelRegistry()); 69 _diagram = (ERDiagram) reader.readDiagram(src); 70 71 _diagram.setSchema(_project.getModel()); 72 _project.addDiagram(_diagram); 73 initEntryFilename(); 74 } 75 76 public void save(OutputStream out) throws IOException 77 { 78 OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8"); 79 _expander.expand(writer, _diagram, "", ""); 80 // DO NOT CLOSE THE WRITER - this messes with out and can cause problems 81 writer.flush(); 82 } 83 84 } /*** end class ProjectDiagram */

This page was automatically generated by Maven