From 9ea83fdd1a140a8e7cb66d005243854892776780 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Mon, 8 Apr 2013 22:31:11 +0200 Subject: [PATCH] Done swixml two sided binding handlers methods and small things in xml writer. --- .../java/org/x4o/xml/io/XMLConstants.java | 1 - .../java/org/x4o/xml/io/sax/XMLWriter.java | 411 +++++++++--------- .../org/x4o/xml/lang/X4OLanguageProperty.java | 7 +- .../META-INF/swixml/swixml-lang-2.0.eld | 10 +- .../META-INF/swixml/swixml-lang-3.0.eld | 10 +- 5 files changed, 217 insertions(+), 222 deletions(-) diff --git a/x4o-core/src/main/java/org/x4o/xml/io/XMLConstants.java b/x4o-core/src/main/java/org/x4o/xml/io/XMLConstants.java index d42c6ff..d831cad 100644 --- a/x4o-core/src/main/java/org/x4o/xml/io/XMLConstants.java +++ b/x4o-core/src/main/java/org/x4o/xml/io/XMLConstants.java @@ -123,7 +123,6 @@ public final class XMLConstants { public static final String CHAR_NEWLINE = "\r\n"; - static public String getDocumentDeclaration(String encoding) { return getDocumentDeclaration(encoding,null); diff --git a/x4o-core/src/main/java/org/x4o/xml/io/sax/XMLWriter.java b/x4o-core/src/main/java/org/x4o/xml/io/sax/XMLWriter.java index 9f1909a..fc34c88 100644 --- a/x4o-core/src/main/java/org/x4o/xml/io/sax/XMLWriter.java +++ b/x4o-core/src/main/java/org/x4o/xml/io/sax/XMLWriter.java @@ -48,11 +48,6 @@ import org.xml.sax.ext.DefaultHandler2; * @version 1.0 17/04/2005 */ public class XMLWriter extends DefaultHandler2 { - - private final static String ENCODING = "http://writer.x4o.org/xml/properties/encoding"; - private final static String CHAR_NEWLINE = "http://writer.x4o.org/xml/properties/char/newline"; - private final static String CHAR_TAB = "http://writer.x4o.org/xml/properties/char/tab"; - private final static String URI_PREFX = "http://writer.x4o.org/xml/properties/char/"; private String encoding = null; private String charNewline = null; @@ -123,19 +118,13 @@ public class XMLWriter extends DefaultHandler2 { this(new OutputStreamWriter(out, XMLConstants.XML_DEFAULT_ENCODING),XMLConstants.XML_DEFAULT_ENCODING); } - - /** * @see org.xml.sax.ContentHandler#startDocument() */ @Override public void startDocument() throws SAXException { indent = 0; - try { - out.write(XMLConstants.getDocumentDeclaration(encoding)); - } catch (IOException e) { - throw new SAXException(e); - } + write(XMLConstants.getDocumentDeclaration(encoding)); } /** @@ -143,11 +132,7 @@ public class XMLWriter extends DefaultHandler2 { */ @Override public void endDocument() throws SAXException { - try { - out.flush(); - } catch (IOException e) { - throw new SAXException(e); - } + writeFlush(); } /** @@ -159,112 +144,107 @@ public class XMLWriter extends DefaultHandler2 { */ @Override public void startElement(String uri, String localName, String name,Attributes atts) throws SAXException { - try { - if (startElement!=null) { - out.write(startElement.toString()); - startElement=null; - } - startElement = new StringBuffer(200); - - if (printedReturn==false) { - startElement.append(charNewline); - } - printedReturn=false; - - for (int i = 0; i < indent; i++) { - startElement.append(charTab); - } - startElement.append(XMLConstants.TAG_OPEN); - - if (localName==null) { - localName = "null"; - } - - if (XMLConstants.NULL_NS_URI.equals(uri) | uri==null) { - startElement.append(localName); - } else { - String prefix = prefixMapping.get(uri); - if (prefix==null) { - throw new SAXException("preFixUri: "+uri+" is not started."); - } - if (XMLConstants.NULL_NS_URI.equals(prefix)==false) { - startElement.append(prefix); - startElement.append(XMLConstants.XMLNS_ASSIGN); - } - startElement.append(localName); - } - - if ((uri!=null & XMLConstants.NULL_NS_URI.equals(uri)==false) && printedMappings.contains(uri)==false) { - String prefix = prefixMapping.get(uri); - if (prefix==null) { - throw new SAXException("preFixUri: "+uri+" is not started."); - } - printedMappings.add(uri); - - startElement.append(' '); - startElement.append(XMLConstants.XMLNS_ATTRIBUTE); - if ("".equals(prefix)==false) { - startElement.append(':'); - startElement.append(prefix); - } - startElement.append("=\""); - startElement.append(uri); - startElement.append('"'); - - boolean first = true; - for (String uri2:prefixMapping.keySet()) { - if (printedMappings.contains(uri2)==false) { - prefix = prefixMapping.get(uri2); - if (prefix==null) { - throw new SAXException("preFixUri: "+uri+" is not started."); - } - printedMappings.add(uri2); - - if (first) { - startElement.append(charNewline); - first = false; - } - - startElement.append(' '); - startElement.append(XMLConstants.XMLNS_ATTRIBUTE); - if ("".equals(prefix)==false) { - startElement.append(XMLConstants.XMLNS_ASSIGN); - startElement.append(prefix); - } - startElement.append("=\""); - startElement.append(uri2); - startElement.append('"'); - startElement.append(charNewline); - } - } - } - - for (int i=0;i - - - - - + + + + + diff --git a/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld b/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld index 00f4d65..ab2cd2b 100644 --- a/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld +++ b/x4o-core/src/test/resources/META-INF/swixml/swixml-lang-3.0.eld @@ -38,11 +38,11 @@ - - - - - + + + + +