ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1198542 - in /webservices/commons/trunk/modules/axiom: modules/axiom-samples/ modules/axiom-samples/src/test/java/org/apache/axiom/samples/ modules/axiom-samples/src/test/resources/org/apache/axiom/samples/ src/site/apt/
Date Sun, 06 Nov 2011 19:56:28 GMT
Author: veithen
Date: Sun Nov  6 19:56:28 2011
New Revision: 1198542

URL: http://svn.apache.org/viewvc?rev=1198542&view=rev
Log:
Added another quick start sample.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/resources/org/apache/axiom/samples/fragments.xml
  (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-samples/pom.xml
    webservices/commons/trunk/modules/axiom/src/site/apt/quickstart-samples.apt

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-samples/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-samples/pom.xml?rev=1198542&r1=1198541&r2=1198542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-samples/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-samples/pom.xml Sun Nov  6 19:56:28
2011
@@ -57,4 +57,16 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <includes>
+                        <include>**/*Sample.java</include>
+                    </includes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

Added: webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java?rev=1198542&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java
Sun Nov  6 19:56:28 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.samples;
+
+import java.io.InputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+
+public class FragmentsSample extends TestCase {
+    // START SNIPPET: main
+    public void processFragments(InputStream in) throws XMLStreamException {
+        // Create an XMLStreamReader without building the object model
+        XMLStreamReader reader =
+            OMXMLBuilderFactory.createOMBuilder(in).getDocument().getXMLStreamReader(false);
+        while (reader.hasNext()) {
+            if (reader.getEventType() == XMLStreamReader.START_ELEMENT &&
+                    reader.getName().equals(new QName("tag"))) {
+                // A matching START_ELEMENT event was found. Build a corresponding OMElement.
+                OMElement element = 
+                    OMXMLBuilderFactory.createStAXOMBuilder(reader).getDocumentElement();
+                // Make sure that all events belonging to the element are consumed so that
+                // that the XMLStreamReader points to a well defined location (namely the
+                // event immediately following the END_ELEMENT event).
+                element.build();
+                // Now process the element.
+                processFragment(element);
+            } else {
+                reader.next();
+            }
+        }
+    }
+    // END SNIPPET: main
+    
+    public void processFragment(OMElement element) {
+        System.out.println(element.toString());
+    }
+    
+    public void test() throws XMLStreamException {
+        processFragments(FragmentsSample.class.getResourceAsStream("fragments.xml"));
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/resources/org/apache/axiom/samples/fragments.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/resources/org/apache/axiom/samples/fragments.xml?rev=1198542&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/resources/org/apache/axiom/samples/fragments.xml
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/resources/org/apache/axiom/samples/fragments.xml
Sun Nov  6 19:56:28 2011
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<root>
+    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua. Ut enim
+    ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea <tag>commodo</tag>
consequat. Duis aute irure dolor in
+    reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat <tag>cupidatat</tag> non proident,
+    sunt in culpa qui officia deserunt mollit anim id est laborum.
+</root>
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-samples/src/test/resources/org/apache/axiom/samples/fragments.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/src/site/apt/quickstart-samples.apt
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/site/apt/quickstart-samples.apt?rev=1198542&r1=1198541&r2=1198542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/site/apt/quickstart-samples.apt (original)
+++ webservices/commons/trunk/modules/axiom/src/site/apt/quickstart-samples.apt Sun Nov  6
19:56:28 2011
@@ -28,3 +28,25 @@ Schema validation using javax.xml.valida
 
   It leverages the fact that Axiom is capable of constructing a <<<SAXSource>>>
from an <<<OMDocument>>>
   or <<<OMElement>>>.
+
+Loading local chunks from a large XML document
+
+  Here the goal is to process a large XML document "by chunks", i.e.
+  
+    [[1]] Parse the file and find a relevant element (e.g. by name)
+    
+    [[2]] Load this element into memory as an <<<OMElement>>>.
+    
+    [[3]] Process the <<<OMElement>>> (the "chunk").
+  
+  The process is repeated until the end of the document is reached.
+  
+  This can be achieved without loading the entire document into memory (and without loading
all the
+  chunks in memory) by scanning the document using the StAX API and switching to Axiom when
a
+  matching element is found:
+
+%{snippet|id=main|file=modules/axiom-samples/src/test/java/org/apache/axiom/samples/FragmentsSample.java}
+
+  The code leverages the fact that <<<createStAXOMBuilder>>> can be used
to build a fragment
+  (corresponding to a given element) from a StAX stream reader, simply by passing an
+  <<<XMLStreamReader>>> that is positioned on a <<<START_ELEMENT>>>
event.



Mime
View raw message