Author: thorsten
Date: Mon Sep 29 00:59:48 2008
New Revision: 700017
URL: http://svn.apache.org/viewvc?rev=700017&view=rev
Log:
Extracting common method that can be used in both implementations
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurerAxiom.java
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StAX.java
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java?rev=700017&r1=700016&r2=700017&view=diff
==============================================================================
---
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
(original)
+++
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurer.java
Mon Sep 29 00:59:48 2008
@@ -363,44 +363,7 @@
propertyValue = reader.getAttributeValue(i);
}
}
- if (allowXmlProperties) {
- param.put(propertyName, recordXmlProperies(reader));
- } else if (null != propertyValue && null != propertyName) {
- param.put(propertyName, propertyValue);
- }
-
- }
-
- private InputSource recordXmlProperies(XMLStreamReader reader)
- throws XMLStreamException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- XMLEventWriter writerProperty = getWriter(out);
- XMLEventAllocator allocator = getEventAllocator();
- XMLEvent currentEvent = allocator.allocate(reader);
- writerProperty.add(currentEvent);
- boolean process = true;
- while (process) {
- int event = reader.next();
- currentEvent = allocator.allocate(reader);
- switch (event) {
- case XMLStreamConstants.END_ELEMENT:
- if (reader.getLocalName().equals(Captions.PROPERTY_ELEMENT)) {
- writerProperty.add(currentEvent);
- writerProperty.flush();
- writerProperty.close();
- process = false;
- } else {
- writerProperty.add(currentEvent);
- }
- break;
-
- default:
- writerProperty.add(currentEvent);
- break;
- }
- }
- InputSource value = new InputSource(StreamHelper.switchStream(out));
- return value;
+ addProperties(reader, param, propertyName,
propertyValue,allowXmlProperties);
}
private void openPaths(XMLEventWriter writer, String[] tokenizer)
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurerAxiom.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurerAxiom.java?rev=700017&r1=700016&r2=700017&view=diff
==============================================================================
---
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurerAxiom.java
(original)
+++
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/XMLStructurerAxiom.java
Mon Sep 29 00:59:48 2008
@@ -1,7 +1,6 @@
package org.apache.forrest.dispatcher.impl;
import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -12,12 +11,8 @@
import java.util.LinkedHashSet;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.events.XMLEvent;
-import javax.xml.stream.util.XMLEventAllocator;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMAttribute;
@@ -340,49 +335,8 @@
String propertyName = null, propertyValue = null;
propertyName = properties.getAttributeValue(qIt(Captions.NAME_ATT));
propertyValue = properties.getAttributeValue(qIt(Captions.VALUE_ATT));
- if (allowXmlProperties) {
- param.put(propertyName, recordXmlProperies(properties
- .getXMLStreamReader()));
- } else if (null != propertyValue && null != propertyName) {
- param.put(propertyName, propertyValue);
- }
+ addProperties(properties.getXMLStreamReader(), param, propertyName,
propertyValue, allowXmlProperties);
}
- /**
- * @param reader
- * @return
- * @throws XMLStreamException
- */
- private InputSource recordXmlProperies(XMLStreamReader reader)
- throws XMLStreamException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- XMLEventWriter writerProperty = getWriter(out);
- XMLEventAllocator allocator = getEventAllocator();
- XMLEvent currentEvent = allocator.allocate(reader);
- writerProperty.add(currentEvent);
- boolean process = true;
- while (process) {
- int event = reader.next();
- currentEvent = allocator.allocate(reader);
- switch (event) {
- case XMLStreamConstants.END_ELEMENT:
- if (reader.getLocalName().equals(Captions.PROPERTY_ELEMENT)) {
- writerProperty.add(currentEvent);
- writerProperty.flush();
- writerProperty.close();
- process = false;
- } else {
- writerProperty.add(currentEvent);
- }
- break;
-
- default:
- writerProperty.add(currentEvent);
- break;
- }
- }
- InputSource value = new InputSource(new ByteArrayInputStream(out
- .toByteArray()));
- return value;
- }
+
}
Modified:
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StAX.java
URL:
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StAX.java?rev=700017&r1=700016&r2=700017&view=diff
==============================================================================
---
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StAX.java
(original)
+++
forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl/helper/StAX.java
Mon Sep 29 00:59:48 2008
@@ -16,19 +16,26 @@
*/
package org.apache.forrest.dispatcher.impl.helper;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.HashMap;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.XMLEvent;
import javax.xml.stream.util.XMLEventAllocator;
+import org.xml.sax.InputSource;
+
import com.ctc.wstx.evt.DefaultEventAllocator;
@@ -126,4 +133,83 @@
public XMLEventAllocator getEventAllocator() {
return inputFactory.getEventAllocator();
}
+
+ /**
+ * @param reader
+ * @return
+ * @throws XMLStreamException
+ */
+ protected InputSource recordXmlProperies(XMLStreamReader reader) throws
XMLStreamException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ XMLEventWriter writerProperty = getWriter(out);
+ XMLEventAllocator allocator = getEventAllocator();
+ XMLEvent currentEvent = allocator.allocate(reader);
+ writerProperty.add(currentEvent);
+ boolean process = true;
+ boolean hadChilds = false;
+ while (process) {
+ int event = reader.next();
+ currentEvent = allocator.allocate(reader);
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ if (!reader.getLocalName().equals(Captions.PROPERTY_ELEMENT)){
+ hadChilds=true;
+ }
+ writerProperty.add(currentEvent);
+ break;
+
+ case XMLStreamConstants.END_ELEMENT:
+ if (reader.getLocalName().equals(Captions.PROPERTY_ELEMENT)) {
+ writerProperty.add(currentEvent);
+ writerProperty.flush();
+ writerProperty.close();
+ process = false;
+ } else {
+ writerProperty.add(currentEvent);
+ }
+ break;
+
+ default:
+ writerProperty.add(currentEvent);
+ break;
+ }
+ }
+ InputSource value = null;
+ if(hadChilds){
+ value = new InputSource(new ByteArrayInputStream(out.toByteArray()));
+ }
+ return value;
+ }
+
+ /**
+ * @param properties
+ * @param param
+ * @param propertyName
+ * @param propertyValue
+ * @throws XMLStreamException
+ */
+ protected void addProperties(XMLStreamReader reader, HashMap param,
+ String propertyName, String propertyValue,boolean allowXmlProperties)
throws XMLStreamException {
+ /*
+ * if we are in allowXmlProperties mode then
+ * we need to see whether we have an input stream meaning child
+ * elements of the property element.
+ */
+ if (allowXmlProperties ) {
+ InputSource recordXmlProperies = recordXmlProperies(reader);
+ if(null != recordXmlProperies){
+ param.put(propertyName, recordXmlProperies);
+ return;
+ }
+ }
+ /*
+ * Add resolved properties that are not null.
+ * If we are in allowXmlProperties and come up to here
+ * this means the property had no child elements. We
+ * assume then that it had a @value attribute.
+ */
+ if (null != propertyValue && null != propertyName){
+ param.put(propertyName, new String(propertyValue));
+ }
+ }
}