Return-Path: Delivered-To: apmail-forrest-svn-archive@www.apache.org Received: (qmail 892 invoked from network); 29 Sep 2008 08:00:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Sep 2008 08:00:40 -0000 Received: (qmail 12842 invoked by uid 500); 29 Sep 2008 08:00:38 -0000 Delivered-To: apmail-forrest-svn-archive@forrest.apache.org Received: (qmail 12812 invoked by uid 500); 29 Sep 2008 08:00:38 -0000 Mailing-List: contact svn-help@forrest.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Forrest Developers List" List-Id: Delivered-To: mailing list svn@forrest.apache.org Received: (qmail 12803 invoked by uid 99); 29 Sep 2008 08:00:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Sep 2008 01:00:38 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Sep 2008 07:59:44 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1F59B238889D; Mon, 29 Sep 2008 00:59:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r700017 - in /forrest/trunk/whiteboard/dispatcher/java/org/apache/forrest/dispatcher/impl: XMLStructurer.java XMLStructurerAxiom.java helper/StAX.java Date: Mon, 29 Sep 2008 07:59:48 -0000 To: svn@forrest.apache.org From: thorsten@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080929075949.1F59B238889D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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)); + } + } }