/* * OrderGxl.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.*; /** * Reorders contents of GXL file such that nodes are before edges. * (potential use case: importing gxl file to jgraph) * @author Miika Nurminen */ class GxlOrderer extends XmlTransformFramework { public GxlOrderer(InputStream in, PrintStream out) { super(in,out); } protected void doTransform() { /* ks. gxl2touchgraph: luo uusi dokumentti (/lataa pohja) ja kopioi siihen toisen dokumentin solmut */ try { Document outDoc = this.newDocument(null); Element e = doc.getDocumentElement(); e.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"); DomLib.copyNodes(e, outDoc, outDoc, 1); Node n = (outDoc.getElementsByTagName("graph")).item(0); DomLib.copyNodeList(doc.getElementsByTagName("node"), n, outDoc, true); DomLib.copyNodeList(doc.getElementsByTagName("edge"), n, outDoc, true); doc = outDoc; } catch (Exception e) { // on exceptions no changes are done to the document ErrorLib.errorReport(e); } this.setDoctype("http://www.gupro.de/GXL/gxl-1.0.dtd",null); } } /** * * @author Miika Nurminen */ public class OrderGxl { /** Creates a new instance of OrderGxl */ public OrderGxl() { } /** * @param args the command line arguments */ public static void main(String[] args) { FileArgumentScheme m = new FileArgumentScheme(args); try { m.openStreams(); GxlOrderer o = new GxlOrderer(m.getInput(),m.getOutput()); o.performTransform(); } catch (FileNotFoundException e) { ErrorLib.errorReport(e); } try { m.getInput().close(); m.getOutput().close(); } catch (IOException e) { ErrorLib.errorReport(e); } } }