Commits

tbrugz committed 0199e65

AbstractDump: added 'graphml.footer' & 'gxl.footer' snippets ; + changes in properties loading

  • Participants
  • Parent commits a27f3b2

Comments (0)

Files changed (5)

File src/graphml-snippets.properties

         </y:PolyLineEdge>\
       </data>
 
-footer=</graph></graphml>
+#gxl.footer=</graph></gxl>
+
+#graphml.footer=</graph></graphml>
+

File src/tbrugz/graphml/DumpDotModel.java

  * see:
  * http://en.wikipedia.org/wiki/DOT_language
  * http://en.wikipedia.org/wiki/Graphviz
+ * 
+ * TODO: dump first nodes then labels
  */
 public class DumpDotModel extends AbstractDump {
 

File src/tbrugz/graphml/DumpGXLModel.java

 package tbrugz.graphml;
 
-import java.io.PrintStream;
-import java.util.Properties;
+import java.io.File;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import tbrugz.graphml.model.Edge;
 import tbrugz.graphml.model.Root;
 
 public class DumpGXLModel extends AbstractDump {
 
-	Properties snippets = new Properties();
-	
+	static Log log = LogFactory.getLog(DumpGXLModel.class);
+
 	//List<Link> links = new ArrayList<Link>();
-	
-	@Override
-	public void dumpModel(Element root, PrintStream out) {
-		loadSnippets("snippets.properties");
-		super.dumpModel(root, out);
+
+	void loadDefaultSnipets() {
+		loadSnippets(DumpGraphMLModel.DEFAULT_SNIPPETS_FILE);
+		log.info("loaded default snippets file: "+new File(DumpGraphMLModel.DEFAULT_SNIPPETS_FILE).getAbsolutePath());
 	}
 
 	@Override
 	public void dumpModel(Element root) {
+		if(snippets.size()==0) { loadDefaultSnipets(); }
 		dumpModel(root, 0);
 	}
 	
 		}
 		else if(elem instanceof Node) {
 			Node t = (Node) elem;
-		    out("<node id=\""+t.getId()+"\">", level);
-		    out("  <type xlink:href=\"http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Proc\" xlink:type=\"simple\"/>", level);
-		    out("</node>", level);
-		    /*List<Link> ll = t.getProx();
-		    for(Link l: ll) {
-		    	l.setSource(t.getId());
-		    }
-		    links.addAll(ll);*/
+			out("<node id=\""+t.getId()+"\">", level);
+			out("  <type xlink:href=\"http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Proc\" xlink:type=\"simple\"/>", level);
+			out("</node>", level);
+			/*List<Link> ll = t.getProx();
+			for(Link l: ll) {
+				l.setSource(t.getId());
+			}
+			links.addAll(ll);*/
 		}
 		else if(elem instanceof Edge) {
 			Edge myl = (Edge) elem;
-			out("<edge id=\""+myl.getSource()+"_"+myl.getTarget()+"\" to=\""+myl.getTarget()+"\" from=\""+myl.getSource()+"\">", level+1);
-			out("  <type xlink:href=\"http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Call\" xlink:type=\" simple\"/>", level+1);
-			out("</edge>", level+1);
+			out("<edge id=\""+myl.getSource()+"_"+myl.getTarget()+"\" to=\""+myl.getTarget()+"\" from=\""+myl.getSource()+"\">", level);
+			out("  <type xlink:href=\"http://www.gupro.de/GXL/examples/schema/gxl/simpleExample/simpleExampleSchema.gxl#Call\" xlink:type=\"simple\"/>", level);
+			out("</edge>", level);
 		}
 		else {
-			out(">> unknown element: "+elem.getClass().getName(), level);
+			log.warn("unknown element: "+elem.getClass().getName()+" , level = "+level);
 		}
 		
 		if(elem instanceof Composite) {
 			}
 		}
 
+		//end of processing
 		if(elem instanceof Root) {
 			/*for(Link myl: links) {
 				out("<edge id=\""+myl.getSource()+"_"+myl.getsTarget()+"\" to=\""+myl.getsTarget()+"\" from=\""+myl.getSource()+"\">", level+1);
 				out("</edge>", level+1);
 			}*/
 			
-			out("</graph></gxl>", level);
+			if(hasSnippet("gxl.footer")) {
+				outSnippet("gxl.footer", level);
+			}
+			else {
+				out("</graph></gxl>", level);
+			}
 		}
 	}
 	

File src/tbrugz/graphml/DumpGraphMLModel.java

 
 	Set<String> nodeNames = new TreeSet<String>();
 	
-	{
+	void loadDefaultSnipets() {
 		loadSnippets(DEFAULT_SNIPPETS_FILE);
-		log.debug("loading default snippets file: "+new File(DEFAULT_SNIPPETS_FILE).getAbsolutePath());
+		log.info("loaded default snippets file: "+new File(DEFAULT_SNIPPETS_FILE).getAbsolutePath());
 	}
 	
 	@Override
 	public void dumpModel(Element root) {
+		if(snippets.size()==0) { loadDefaultSnipets(); }
 		dumpModel(root, 0);
 	}
 	
 
 		//end of processing
 		if(elem instanceof Root) {
-			if(hasSnippet("footer")) {
-				outSnippet("footer", level);
+			if(hasSnippet("graphml.footer")) {
+				outSnippet("graphml.footer", level);
 			}
 			else {
 				out("</graph></graphml>", level);
 		}
 		return s;
 	}
-	
-	@Deprecated
-	public void oldOutNodeContents(Node t, int level) {
-		outSnippet(getSnippetId(t, "node"), level, t.getLabel());
-	}
 
 	public void outEdgeContents(Edge l, int level) {
 		outSnippet(getSnippetId(l, "edge"), level, l.getName());

File src/tbrugz/xml/AbstractDump.java

 
 import java.io.FileInputStream;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
 
 public abstract class AbstractDump {
 
-	static String levelStr = "  "; //"\t";
+	static final String levelStr = "  "; //"\t";
 	
-	static Log log = LogFactory.getLog(AbstractDump.class);
+	static final Log log = LogFactory.getLog(AbstractDump.class);
 
-	protected Properties snippets = new FileReaderProperties();
+	protected final Properties snippets = new FileReaderProperties();
 	
 	PrintStream output = null;
 	
 	}
 	
 	public void loadProp(Properties prop, String fileName) {
+		Properties ptemp = new Properties();
 		try {
-			prop.load(new FileInputStream(fileName));
-			log.info("loaded prop file: "+fileName);
+			File f = new File(fileName);
+			ptemp.load(new FileInputStream(f));
+			prop.putAll(ptemp);
+			log.info("loaded prop file: "+f.getAbsolutePath());
 		}
 		catch(IOException ioe) {
 			try {
 				String resource = "/"+fileName;
 				InputStream is = AbstractDump.class.getResourceAsStream(resource);
 				if(is==null) { log.warn("resource not found: "+resource); return; }
-				prop.load(is);
-				log.info("loaded prop resource: "+resource);
+				ptemp.load(is);
+				prop.putAll(ptemp);
+				//log.info("loaded prop resource: "+resource);
+				log.info("loaded prop resource: "+resource, new Throwable());
 			}
 			catch(IOException e) {
 				log.warn("error loading file: "+ioe);
 			}
-		} 
+		}
 	}
 	
 	public abstract void dumpModel(Element root);
 	
+	//XXX add: public abstract String getDefaultFileFormat();
+	
 	//public abstract void dumpModel(Element elem, int level);
 	
 	final static Pattern paramPattern = Pattern.compile("(\\{(.)+?})");