Author: remi
Date: 2008-07-31 15:49:27 +0200 (Thu, 31 Jul 2008)
New Revision: 1435
Modified:
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
Log:
* added the attitune hashtable object to xml file functions.
Modified:
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
===================================================================
---
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
2008-07-31 11:38:00 UTC (rev 1434)
+++
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
2008-07-31 13:49:27 UTC (rev 1435)
@@ -43,6 +43,7 @@
private String wavsPath = "";
private Hashtable<String,Object> xmlStruct;
private Hashtable<String,Object> blocksStruct;
+ private Hashtable<String,Object> headerStruct;
/*
*
@@ -103,6 +104,9 @@
blocksStruct = (Hashtable)blocksStruct.get("script");
blocksStruct = (Hashtable)blocksStruct.get("timeline");
+ /* Get the header structure */
+ headerStruct = (Hashtable)xmlStruct.get("header");
+
return true;
}
@@ -177,6 +181,15 @@
/**
*
+ * @return
+ */
+ public Hashtable<String,Object> getHeaderStruct()
+ {
+ return headerStruct;
+ }
+
+ /**
+ *
* @param waveName
* @return
*/
Modified:
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
===================================================================
---
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
2008-07-31 11:38:00 UTC (rev 1434)
+++
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
2008-07-31 13:49:27 UTC (rev 1435)
@@ -5,8 +5,10 @@
import java.io.FileInputStream;
import java.util.*;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.stream.*;
+import javax.xml.transform.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
@@ -19,9 +21,153 @@
*/
public class ATTXmlParser
{
+ /* Global xml struct for the xml write */
+ private static Document doc;
+
/*
- *
+ * Insert a leaf in the xml structure
*/
+ private static void insertLeaf(Node parentNode, String textID, Object
textValue)
+ {
+ Node leafNode;
+ String typeString;
+ Element element;
+ Node text;
+
+ leafNode = doc.createElement(textID);
+
+ if (textValue.getClass().toString().equals("class
java.lang.String"))
+ {
+ if (textValue == "")
+ {
+ textValue = " ";
+ }
+ typeString = "str";
+ }
+ else if (textValue.getClass().toString().equals("class
java.lang.Double"))
+ {
+ typeString = "float";
+ }
+ else if (textValue.getClass().toString().equals("class
java.lang.Float"))
+ {
+ typeString = "float";
+ }
+ else if (textValue.getClass().toString().equals("class
java.lang.Integer"))
+ {
+ typeString = "int";
+ }
+ else
+ {
+ typeString = "str";
+ }
+
+ element = (Element)leafNode;
+ element.setAttribute("type", typeString);
+ text = doc.createTextNode(textValue.toString());
+ leafNode.appendChild(text);
+ parentNode.appendChild(leafNode);
+ }
+
+ /*
+ * Insert a node in the xml structure
+ */
+ private static Node insertNode(Node parentNode, String nodeID)
+ {
+ Node newNode;
+
+ newNode = doc.createElement(nodeID);
+ parentNode.appendChild(newNode);
+
+ return newNode;
+ }
+
+ /*
+ * Xml node constructor
+ */
+ @SuppressWarnings("unchecked")
+ private static void nodeStructToNXML(Node parentNode,
+ Hashtable<String,Object> nodeStruct)
+ {
+ String key;
+ Node newNode;
+ Iterator<String> it = (Iterator<String>)nodeStruct.keys();
+
+ while (it.hasNext())
+ {
+ key = (String)it.next();
+
+ if
(!nodeStruct.get(key).getClass().toString().equals("class java.util.Hashtable"))
+ {
+ insertLeaf(parentNode, key,
nodeStruct.get(key));
+ }
+ else
+ {
+ newNode = insertNode(parentNode, key);
+ nodeStructToNXML(newNode,
(Hashtable<String,Object>)nodeStruct.get(key));
+ }
+ }
+ }
+
+ /*
+ * Write a xml document object to a xml file
+ */
+ private static void writeXML(Document xmldoc, StreamResult out)
+ throws TransformerConfigurationException, TransformerException
+ {
+ DOMSource domSource = new DOMSource(xmldoc);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.setOutputProperty
+ (OutputKeys.OMIT_XML_DECLARATION, "no");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
+ transformer.transform(domSource, out);
+ }
+
+ /**
+ * Convert a hashtable structure to a xml file
+ */
+ public static boolean structToXml(Hashtable<String,Object> struct,
String path)
+ {
+ DocumentBuilderFactory xmlObj;
+ DocumentBuilder db = null;
+ Node rootNode;
+ StreamResult out;
+
+ xmlObj = DocumentBuilderFactory.newInstance();
+
+ try
+ {
+ db = xmlObj.newDocumentBuilder();
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+
+ doc = db.newDocument();
+ rootNode = doc.createElement("scene");
+ doc.appendChild(rootNode);
+
+ nodeStructToNXML(rootNode, struct);
+
+ out = new StreamResult(path);
+
+ try
+ {
+ writeXML(doc, out);
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /*
+ * Xml node to hashtable constructor
+ */
private static void nodeXMLToStruct(Node parentNode,
Hashtable<String,Object> nodeStruct)
{
int i;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn