summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1506fcd)
raw | patch | inline | side by side (parent: 1506fcd)
author | ishmal <ishmal@users.sourceforge.net> | |
Wed, 2 Apr 2008 21:57:44 +0000 (21:57 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Wed, 2 Apr 2008 21:57:44 +0000 (21:57 +0000) |
src/bind/java/org/inkscape/cmn/Gateway.java | patch | blob | history | |
src/bind/java/org/inkscape/script/ScriptConsole.java | patch | blob | history |
diff --git a/src/bind/java/org/inkscape/cmn/Gateway.java b/src/bind/java/org/inkscape/cmn/Gateway.java
index bba9cdf0b2d1f7b7df3242a054a91c524154f59e..d1fa47a2b9efb15e2436ac0830291d9bb9061ab3 100644 (file)
import java.io.IOException;
import javax.swing.JOptionPane;
-//for xml
+//####for xml
+//read
import org.w3c.dom.Document;
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+//write
+import java.io.ByteArrayOutputStream;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import org.inkscape.script.ScriptConsole;
//########################################################################
//# MESSSAGES
//########################################################################
-static void err(String message)
+void err(String message)
{
- System.err.println("Gateway err:" + message);
+ ScriptConsole console = ScriptConsole.getInstance();
+ if (console != null)
+ console.err("Gateway err:" + message);
+ else
+ log("Gateway err:" + message);
}
-static void msg(String message)
+void msg(String message)
{
- System.out.println("Gateway:" + message);
+ ScriptConsole console = ScriptConsole.getInstance();
+ if (console != null)
+ console.msg("Gateway err:" + message);
+ else
+ log("Gateway:" + message);
}
-
+void trace(String message)
+{
+ ScriptConsole console = ScriptConsole.getInstance();
+ if (console != null)
+ console.trace("Gateway:" + message);
+ else
+ log("Gateway:" + message);
+}
//########################################################################
-//# R E P R (inkscape's xml tree)
+//# U T I L I T Y
//########################################################################
-private native String documentGet(long backPtr);
-
-public String documentGet()
-{
- return documentGet(backPtr);
-}
-
-public Document documentGetXml()
+/**
+ * Parse a String to an XML Document
+ */
+public Document stringToDoc(String xmlStr)
{
- String xmlStr = documentGet();
if (xmlStr == null || xmlStr.length()==0)
return null;
Document doc = null;
}
catch (java.io.IOException e)
{
- err("getReprXml:" + e);
+ err("stringToDoc:" + e);
+ return null;
}
catch (javax.xml.parsers.ParserConfigurationException e)
{
- err("getReprXml:" + e);
+ err("stringToDoc:" + e);
+ return null;
}
catch (org.xml.sax.SAXException e)
{
- err("getReprXml:" + e);
+ err("stringToDoc:" + e);
+ return null;
}
return doc;
}
+
+
+/**
+ * Serialize an XML Document to a string
+ */
+String docToString(Document doc)
+{
+ if (doc == null)
+ return "";
+ String buf = "";
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer tf = factory.newTransformer();
+ tf.transform(new DOMSource(doc), new StreamResult(baos));
+ baos.close();
+ buf = baos.toString();
+ }
+ catch (java.io.IOException e)
+ {
+ err("docToString:" + e);
+ return null;
+ }
+ catch (javax.xml.transform.TransformerConfigurationException e)
+ {
+ err("docToString:" + e);
+ return null;
+ }
+ catch (javax.xml.transform.TransformerException e)
+ {
+ err("docToString:" + e);
+ return null;
+ }
+ return buf;
+}
+
+
+//########################################################################
+//# R E P R (inkscape's xml tree)
+//########################################################################
+
+private native String documentGet(long backPtr);
+
+public String documentGet()
+{
+ return documentGet(backPtr);
+}
+
+
+public Document documentGetXml()
+{
+ String xmlStr = documentGet();
+ return stringToDoc(xmlStr);
+}
+
private native boolean documentSet(long backPtr, String xmlStr);
public boolean documentSet(String xmlStr)
return documentSet(backPtr, xmlStr);
}
+public boolean documentSetXml(Document doc)
+{
+ String xmlStr = docToString(doc);
+ return documentSet(xmlStr);
+}
+
+
//########################################################################
//# LOGGING STREAM
//########################################################################
diff --git a/src/bind/java/org/inkscape/script/ScriptConsole.java b/src/bind/java/org/inkscape/script/ScriptConsole.java
index c7d71b5756c0b2a3c5b351a1bf1e9b710f841eec..8241e2797e7522b292c1151ae1994803b46479b4 100644 (file)
//########################################################################
//# MESSSAGES
//########################################################################
-void err(String fmt, Object... arguments)
+public void err(String fmt, Object... arguments)
{
terminal.errorf("ScriptConsole err:" + fmt + "\n", arguments);
}
-void msg(String fmt, Object... arguments)
+public void msg(String fmt, Object... arguments)
{
terminal.outputf("ScriptConsole:" + fmt, arguments);
}
-void trace(String fmt, Object... arguments)
+public void trace(String fmt, Object... arguments)
{
terminal.outputf("ScriptConsole:" + fmt + "\n", arguments);
}