[Jiemamy-notify] commit [2055] DataWriter#emptyElement で改行がおこらないバグ修正。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 10月 27日 (月) 22:10:01 JST


Revision: 2055
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=2055
Author:   daisuke_m
Date:     2008-10-27 22:10:01 +0900 (Mon, 27 Oct 2008)

Log Message:
-----------
DataWriter#emptyElement で改行がおこらないバグ修正。

Modified Paths:
--------------
    artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/DataWriter.java
    artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/XMLWriter.java


-------------- next part --------------
Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/DataWriter.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/DataWriter.java	2008-10-27 12:42:57 UTC (rev 2054)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/DataWriter.java	2008-10-27 13:10:01 UTC (rev 2055)
@@ -68,16 +68,10 @@
  */
 public class DataWriter extends XMLWriter {
 	
-	private final static Object SEEN_NOTHING = new Object();
+	private SeenState state = SeenState.NOTHING;
 	
-	private final static Object SEEN_ELEMENT = new Object();
+	private Stack<SeenState> stateStack = new Stack<SeenState>();
 	
-	private final static Object SEEN_DATA = new Object();
-	
-	private Object state = SEEN_NOTHING;
-	
-	private Stack<Object> stateStack = new Stack<Object>();
-	
 	private int indentStep = 0;
 	
 	private int depth = 0;
@@ -135,8 +129,8 @@
 	 * @see XMLWriter#characters(char[], int, int)
 	 */
 	@Override
-	public void characters(char ch[], int start, int length) throws SAXException {
-		state = SEEN_DATA;
+	public void characters(char[] ch, int start, int length) throws SAXException {
+		state = SeenState.DATA;
 		super.characters(ch, start, length);
 	}
 	
@@ -161,12 +155,13 @@
 	 */
 	@Override
 	public void emptyElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
-		state = SEEN_ELEMENT;
+		state = SeenState.ELEMENT;
 		if (depth > 0) {
 			super.characters(getLineSeparator());
 		}
 		doIndent();
 		super.emptyElement(uri, localName, qName, atts);
+		state = SeenState.ELEMENT;
 	}
 	
 	/**
@@ -190,7 +185,7 @@
 	@Override
 	public void endElement(String uri, String localName, String qName) throws SAXException {
 		depth--;
-		if (state == SEEN_ELEMENT) {
+		if (state == SeenState.ELEMENT) {
 			super.characters(getLineSeparator());
 			doIndent();
 		}
@@ -224,8 +219,8 @@
 	@Override
 	public void reset() {
 		depth = 0;
-		state = SEEN_NOTHING;
-		stateStack = (new Stack<Object>());
+		state = SeenState.NOTHING;
+		stateStack = (new Stack<SeenState>());
 		super.reset();
 	}
 	
@@ -261,8 +256,8 @@
 	 */
 	@Override
 	public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
-		stateStack.push(SEEN_ELEMENT);
-		state = SEEN_NOTHING;
+		stateStack.push(SeenState.ELEMENT);
+		state = SeenState.NOTHING;
 		if (depth > 0) {
 			super.characters(getLineSeparator());
 		}
@@ -281,7 +276,7 @@
 	private void doIndent() throws SAXException {
 		if (indentStep > 0 && depth > 0) {
 			int n = indentStep * depth;
-			char ch[] = new char[n];
+			char[] ch = new char[n];
 			for (int i = 0; i < n; i++) {
 				ch[i] = ' ';
 			}
@@ -289,4 +284,9 @@
 		}
 	}
 	
+
+	private enum SeenState {
+		NOTHING, ELEMENT, DATA
+	}
+	
 }

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/XMLWriter.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/XMLWriter.java	2008-10-27 12:42:57 UTC (rev 2054)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/com/megginson/sax/XMLWriter.java	2008-10-27 13:10:01 UTC (rev 2055)
@@ -326,7 +326,7 @@
 	 * @see org.xml.sax.ContentHandler#characters
 	 */
 	@Override
-	public void characters(char ch[], int start, int len) throws SAXException {
+	public void characters(char[] ch, int start, int len) throws SAXException {
 		writeEsc(ch, start, len, false);
 		super.characters(ch, start, len);
 	}
@@ -345,7 +345,7 @@
 	 * @see #characters(char[], int, int)
 	 */
 	public void characters(String data) throws SAXException {
-		char ch[] = data.toCharArray();
+		char[] ch = data.toCharArray();
 		characters(ch, 0, ch.length);
 	}
 	
@@ -479,8 +479,8 @@
 	 * Write an empty element.
 	 *
 	 * This method writes an empty element tag rather than a start tag
-	 * followed by an end tag.  Both a {@link #startElement
-	 * startElement} and an {@link #endElement endElement} event will
+	 * followed by an end tag.  Both a {@link #startElement(String, String, String, Attributes)
+	 * startElement} and an {@link #endElement(String, String, String) endElement} event will
 	 * be passed on down the filter chain.
 	 *
 	 * @param uri The element's Namespace URI, or the empty string
@@ -496,8 +496,8 @@
 	 * @exception org.xml.sax.SAXException If there is an error
 	 *            writing the empty tag, or if a handler further down
 	 *            the filter chain raises an exception.
-	 * @see #startElement
-	 * @see #endElement 
+	 * @see #startElement(String, String, String, Attributes)
+	 * @see #endElement(String, String, String)
 	 */
 	public void emptyElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
 		nsSupport.pushContext();
@@ -511,6 +511,7 @@
 		write("/>");
 		super.startElement(uri, localName, qName, atts);
 		super.endElement(uri, localName, qName);
+//		nsSupport.popContext();
 	}
 	
 	/**
@@ -785,17 +786,17 @@
 		}
 		prefix = doneDeclTable.get(uri);
 		if (prefix != null
-				&& ((!isElement || defaultNS != null) && "".equals(prefix) || nsSupport.getURI(prefix) != null)) {
+				&& ((isElement == false || defaultNS != null) && "".equals(prefix) || nsSupport.getURI(prefix) != null)) {
 			prefix = null;
 		}
 		if (prefix == null) {
 			prefix = prefixTable.get(uri);
 			if (prefix != null
-					&& ((!isElement || defaultNS != null) && "".equals(prefix) || nsSupport.getURI(prefix) != null)) {
+					&& ((isElement == false || defaultNS != null) && "".equals(prefix) || nsSupport.getURI(prefix) != null)) {
 				prefix = null;
 			}
 		}
-		if (prefix == null && qName != null && !"".equals(qName)) {
+		if (prefix == null && qName != null && "".equals(qName) == false) {
 			int i = qName.indexOf(':');
 			if (i == -1) {
 				if (isElement && defaultNS == null) {
@@ -869,7 +870,7 @@
 	private void writeAttributes(Attributes atts) throws SAXException {
 		int len = atts.getLength();
 		for (int i = 0; i < len; i++) {
-			char ch[] = atts.getValue(i).toCharArray();
+			char[] ch = atts.getValue(i).toCharArray();
 			write(' ');
 			writeName(atts.getURI(i), atts.getLocalName(i), atts.getQName(i), false);
 			write("=\"");
@@ -886,7 +887,7 @@
 	 * @param isAttVal  true if this is an attribute value literal.
 	 * @throws SAXException  If there is an error writing the characters, this method will throw an IOException wrapped in a SAXException.
 	 */
-	private void writeEsc(char ch[], int start, int length, boolean isAttVal) throws SAXException {
+	private void writeEsc(char[] ch, int start, int length, boolean isAttVal) throws SAXException {
 		for (int i = start; i < start + length; i++) {
 			switch (ch[i]) {
 				case '&':
@@ -927,7 +928,7 @@
 	 */
 	private void writeName(String uri, String localName, String qName, boolean isElement) throws SAXException {
 		String prefix = doPrefix(uri, qName, isElement);
-		if (prefix != null && !"".equals(prefix)) {
+		if (prefix != null && "".equals(prefix) == false) {
 			write(prefix);
 			write(':');
 		}
@@ -947,7 +948,7 @@
 			if (uri == null) {
 				uri = "";
 			}
-			char ch[] = uri.toCharArray();
+			char[] ch = uri.toCharArray();
 			write(' ');
 			if ("".equals(prefix)) {
 				write("xmlns=\"");


Jiemamy-notify メーリングリストの案内
Back to archive index