/* * Gxl2TouchGraph.java * * Copyright (C) 2003 Miika Nurminen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ import java.io.*; import org.w3c.dom.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; import javax.xml.transform.dom.*; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.awt.image.BufferedImage; class NodeAction { public void doAction(Element src,Element target) { } } /** * Conversion program from GXL to TouchGraph 1.20 * Converted to standard filter 19.9.2003 * * @version 0.1 - 2003-8-6 * @author minurmin */ public class Gxl2TouchGraph { // Global value so it can be ref'd by the tree-adapter Document document; Document outDoc; String workDir = ""; private String getAbsoluteFileName(String fname) { return StringLib.catOnce(workDir,File.separator)+fname; } /** * Creates a DOM representation of an XML document given in filename. * * @param filename input file */ public void fromFile( InputStream is,String workDir) throws SAXException,ParserConfigurationException,IOException { this.workDir = workDir; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse( is/*new File(filename)*/ ); } // add content action class here... private void addSubNode(Element src, Element target, String name, NodeAction action) { Element e = outDoc.createElement(name); action.doAction(src,e); target.appendChild(e); } private void transformNodes(Element root) { NodeList nl = document.getElementsByTagName("node"); for (int i=0; i"); try { BufferedImage b = ImgLib.readImage(getAbsoluteFileName(imgname)); if ((b.getWidth()+20)>minWidth) minWidth=b.getWidth()+20; } catch (IOException e) { // if image cannot be read, it is simply skipped. System.err.println(e.getMessage()); e.printStackTrace(); } } else { // normal links, concept map handling. to do: if more prefixes/postfixes occur, generalize! String targetFrame = "_blank"; if (StringLib.testEndStr(imgname,".cmap")) { // removing path, changing extension // file.separator account only separator of current system imgname = "map.php?map="+imgname.substring(Math.max(imgname.lastIndexOf('/'),imgname.lastIndexOf('\\'))+1,imgname.length()-5)/*+".html"*/; targetFrame="_self"; // concept maps are opened on same frame } else if (StringLib.testEndStr(imgname,".url")) { try { BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(getAbsoluteFileName(imgname)))); imgname = r.readLine(); } catch (IOException e) { System.err.println(e.getMessage()); e.printStackTrace(); } } hintValue.append(""+m.get("desc").toString()+""); } hintValue.append("
"); } } target.setAttribute("hint",hintValue.toString()); target.setAttribute("width", Integer.toString(minWidth)/*"300"*/); target.setAttribute("height","-1"); target.setAttribute("isHTML","true"); } }); } } private void transformEdges(Element root) { NodeList nl = document.getElementsByTagName("edge"); for (int i=0; i output.xml"); System.out.println(" java -dir ../mydir/ -i input.xml -o output.xml\n"); return; } m.openStreams(); Gxl2TouchGraph t = new Gxl2TouchGraph(); t.fromFile(m.getInput(),workDir); t.doTransform(); t.toStream(m.getOutput()); // takes outfilename without extension } catch (Exception e) { /* Potential Exception types (omitted for clarity): -SAXException -ParserConfigurationException -TransformerException -IOException */ ErrorLib.errorReport(e); } try { m.getInput().close(); m.getOutput().close(); } catch (IOException e) { ErrorLib.errorReport(e); } } }