You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/02/04 02:13:32 UTC
svn commit: r740557 [1/2] - in /cocoon/cocoon3/trunk:
cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/ cocoon-stax/
cocoon-stax/src/main/java/org/apache/cocoon/stax/
cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/
cocoon-stax/src/...
Author: reinhard
Date: Wed Feb 4 01:13:31 2009
New Revision: 740557
URL: http://svn.apache.org/viewvc?rev=740557&view=rev
Log:
COCOON3-19
StAX to SAX conversions
Added:
cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/
cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java (with props)
cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLEventToContentHandler.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/XMLFilterImplEx.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapperTest.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapterTest.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/
cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/converter/complex-stax-test-document.xml (with props)
Modified:
cocoon/cocoon3/trunk/cocoon-stax/LICENSE.txt
cocoon/cocoon3/trunk/cocoon-stax/NOTICE.txt
cocoon/cocoon3/trunk/cocoon-stax/pom.xml
cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/StAXCleaningTransformer.java
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/CleaningTransformerTest.java
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/StAXPipelineTest.java
cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
Added: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,103 @@
+/*
+ * 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.cocoon.sample.rest;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.sun.jersey.api.core.DefaultResourceConfig;
+import com.sun.jersey.api.core.ResourceConfig;
+import com.sun.jersey.spi.container.WebApplication;
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+import com.sun.jersey.spi.spring.container.SpringComponentProviderFactory;
+import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+
+public class CocoonRESTContainer extends ServletContainer implements ApplicationContextAware {
+
+ private static final Logger LOGGER = Logger.getLogger(SpringServlet.class.getName());
+ private static final long serialVersionUID = -8658985429213333769L;
+ private boolean lazyInit;
+ private ResourceConfig rc;
+ private WebApplication wa;
+
+ public void afterPropertiesSet() throws Exception {
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ if (!this.lazyInit) {
+ this.lazyInitiate();
+ this.lazyInit = true;
+ }
+ super.service(request, response);
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ if (applicationContext instanceof ConfigurableApplicationContext) {
+ System.out.println("is a configur....");
+ ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
+ context.addApplicationListener(new ApplicationListener() {
+
+ public void onApplicationEvent(ApplicationEvent event) {
+ System.out.println(event + " (" + event.getClass() + ")");
+ }
+ });
+ }
+ }
+
+ @Override
+ protected ResourceConfig getDefaultResourceConfig(Map<String, Object> props, ServletConfig servletConfig)
+ throws ServletException {
+ DefaultResourceConfig rc = new DefaultResourceConfig();
+ rc.setPropertiesAndFeatures(props);
+ return rc;
+ }
+
+ @Override
+ protected void initiate(ResourceConfig rc, WebApplication wa) {
+ this.rc = rc;
+ this.wa = wa;
+ }
+
+ private void lazyInitiate() {
+ try {
+ final WebApplicationContext springWebContext = WebAppContextUtils.getCurrentWebApplicationContext();
+ final ConfigurableApplicationContext springContext = (ConfigurableApplicationContext) springWebContext;
+
+ this.wa.initiate(this.rc, new SpringComponentProviderFactory(this.rc, springContext));
+ } catch (RuntimeException e) {
+ LOGGER.log(Level.SEVERE, "Exception occurred when intialization", e);
+ throw e;
+ }
+ }
+}
\ No newline at end of file
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/CocoonRESTContainer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,68 @@
+/*
+ * 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.cocoon.sample.rest;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.cocoon.callstack.environment.CallFrameHelper;
+import org.apache.cocoon.servlet.controller.ControllerContextHelper;
+import org.apache.commons.io.IOUtils;
+
+@Path("/test")
+public class SampleRestResource {
+
+ @GET
+ @Produces("text/plain")
+ public String getSample() {
+ return "hello, world";
+ }
+
+ @GET
+ @Path("/1/{id}")
+ public Response getURLService(@PathParam("id")
+ String id) {
+ ResponseBuilder builder = Response.status(Status.OK);
+ builder.type("text/plain");
+ try {
+ HttpServletRequest request = CallFrameHelper.getRequest();
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("name", "reinhard");
+ params.put("id", "28");
+ System.out.println("request=" + request);
+ System.out.println("type=" + request.getClass().getName());
+
+ ControllerContextHelper.storeContext(params, request);
+
+ URL u = new URL("servlet:sample:/controller/screen");
+ builder.entity(IOUtils.toString(u.openStream()));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return builder.build();
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/rest/SampleRestResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cocoon/cocoon3/trunk/cocoon-stax/LICENSE.txt
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/LICENSE.txt?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/LICENSE.txt (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/LICENSE.txt Wed Feb 4 01:13:31 2009
@@ -199,3 +199,36 @@
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.
+
+
+StAX-Utils
+...........................................................................
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of the listed copyright holders nor the names
+ of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
Modified: cocoon/cocoon3/trunk/cocoon-stax/NOTICE.txt
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/NOTICE.txt?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/NOTICE.txt (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/NOTICE.txt Wed Feb 4 01:13:31 2009
@@ -3,3 +3,10 @@
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+
+
+This software contains code derived from Stax-Utils:
+Copyright (c) 2004, Christian Niles, unit12.net
+Copyright (c) 2004, Sun Microsystems, Inc.
+Copyright (c) 2006, John Kristian
+All rights reserved.
Modified: cocoon/cocoon3/trunk/cocoon-stax/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/pom.xml?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/pom.xml Wed Feb 4 01:13:31 2009
@@ -87,4 +87,31 @@
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>it</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/main/java/org/apache/cocoon/stax/converter/util/*.java</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
Modified: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/StAXCleaningTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/StAXCleaningTransformer.java?rev=740557&r1=740556&r2=740557&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/StAXCleaningTransformer.java (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/StAXCleaningTransformer.java Wed Feb 4 01:13:31 2009
@@ -21,7 +21,7 @@
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
-import org.apache.cocoon.pipeline.component.sax.CleaningTransformer;
+import org.apache.cocoon.sax.component.CleaningTransformer;
/**
* Transformer which is used to clean a xml document from all whitespaces,
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.cocoon.stax.converter;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+import javax.xml.stream.util.XMLEventConsumer;
+
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.pipeline.component.Consumer;
+import org.apache.cocoon.pipeline.component.PipelineComponent;
+import org.apache.cocoon.pipeline.component.Producer;
+import org.apache.cocoon.sax.SAXConsumer;
+import org.apache.cocoon.sax.SAXProducer;
+import org.apache.cocoon.stax.AbstractStAXTransformer;
+import org.apache.cocoon.stax.StAXConsumer;
+import org.apache.cocoon.stax.StAXProducer;
+import org.apache.cocoon.stax.converter.util.StAXEventContentHandler;
+import org.apache.cocoon.stax.converter.util.XMLEventToContentHandler;
+import org.apache.cocoon.stax.converter.util.XMLFilterImplEx;
+
+/**
+ * This class could be seen as the default implementation to use SAX components in StAX pipelines.
+ * <p>
+ * If an {@link XMLEvent} is pulled from the {@link SAXForStAXPipelineWrapper} by an
+ * {@link StAXConsumer} the {@link SAXForStAXPipelineWrapper} retrieves an {@link XMLEvent} from its
+ * {@link StAXConsumer} and translate it to an SAXEvent. Each event produced during calling the
+ * SAX-component are transformed to {@link XMLEvent}s and are stored internally. If the
+ * SAX-component produced at least one {@link XMLEvent} all produced {@link XMLEvent}s are
+ * returned. Otherwise the next event is pulled from the {@link StAXProducer} and the process is
+ * repeated.
+ */
+public class SAXForStAXPipelineWrapper extends AbstractStAXTransformer implements XMLEventConsumer {
+
+ private SAXProducer saxTransformer;
+ private XMLEventToContentHandler staxToSaxHandler;
+ private StAXEventContentHandler saxToStaxHandler;
+
+ /**
+ * Constructs an Wrapper around an SAXTransformer and made it available to add it to an
+ * {@link Pipeline} only containing StAX- {@link PipelineComponent}s.
+ *
+ * @param The Transformer which should be wrapped. As an SAXTransformer it have to implement the
+ * {@link SAXProducer} and the {@link SAXConsumer} interface. Since no transformer
+ * interface exists at the moment at the cocoon-sax project this way is chosen. But
+ * this may be changed later.
+ */
+ public SAXForStAXPipelineWrapper(SAXProducer saxTransformer) {
+ // check if component is the right one
+ if (!(saxTransformer instanceof SAXConsumer)) {
+ throw new SetupException("SAX component does not fulfill all preconditions.");
+ }
+
+ this.saxTransformer = saxTransformer;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Producer#setConsumer(Consumer)
+ */
+ @Override
+ public void setConsumer(Consumer consumer) {
+ // call the super method to set the consumer internal
+ super.setConsumer(consumer);
+
+ // setup first component to stax part
+ XMLFilterImplEx filter = new XMLFilterImplEx();
+ filter.setContentHandler((SAXConsumer) this.saxTransformer);
+ filter.setLexicalHandler((SAXConsumer) this.saxTransformer);
+ this.staxToSaxHandler = new XMLEventToContentHandler(filter);
+
+ // setup last component to stax part
+ this.saxToStaxHandler = new StAXEventContentHandler(this);
+ this.saxTransformer.setConsumer(this.saxToStaxHandler);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see XMLEventConsumer#add(XMLEvent)
+ */
+ @Override
+ public void add(XMLEvent event) throws XMLStreamException {
+ this.addEventToQueue(event);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see AbstractStAXTransformer#produceEvents()
+ */
+ @Override
+ protected void produceEvents() throws XMLStreamException {
+ while (this.isQueueEmpty() && this.getParent().hasNext()) {
+ this.staxToSaxHandler.convertEvent(this.getParent().nextEvent());
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/SAXForStAXPipelineWrapper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,85 @@
+/*
+ * 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.cocoon.stax.converter;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.pipeline.component.AbstractPipelineComponent;
+import org.apache.cocoon.pipeline.component.Consumer;
+import org.apache.cocoon.pipeline.component.Producer;
+import org.apache.cocoon.sax.SAXConsumer;
+import org.apache.cocoon.sax.SAXProducer;
+import org.apache.cocoon.stax.StAXConsumer;
+import org.apache.cocoon.stax.StAXProducer;
+import org.apache.cocoon.stax.converter.util.XMLEventToContentHandler;
+import org.apache.cocoon.stax.converter.util.XMLFilterImplEx;
+
+/**
+ * A transformer which transforms between a StAX-only pipeline and a SAX-only pipeline. The first
+ * part of the pipeline have to be out of StAX-Components, where the second part have to be out of
+ * SAX-components.
+ */
+public class StAXToSAXPipelineAdapter extends AbstractPipelineComponent implements StAXConsumer, SAXProducer {
+
+ private XMLEventToContentHandler staxToSaxHandler;
+ private StAXProducer parent;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Producer#setConsumer(Consumer)
+ */
+ @Override
+ public void setConsumer(Consumer consumer) {
+ if (!(consumer instanceof SAXConsumer)) {
+ throw new SetupException("SAXProducer requires an SAXConsumer.");
+ }
+
+ XMLFilterImplEx filter = new XMLFilterImplEx();
+ filter.setContentHandler((SAXConsumer) consumer);
+ filter.setLexicalHandler((SAXConsumer) consumer);
+ this.staxToSaxHandler = new XMLEventToContentHandler(filter);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see StAXProducer#setConsumer(Consumer)
+ */
+ @Override
+ public void initiatePullProcessing() {
+ try {
+ while (this.parent.hasNext()) {
+ this.staxToSaxHandler.convertEvent(this.parent.nextEvent());
+ }
+ } catch (XMLStreamException e) {
+ throw new ProcessingException("Error during retrieving StAXEvents.", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see StAXConsumer#setParent(StAXProducer)
+ */
+ @Override
+ public void setParent(StAXProducer parent) {
+ this.parent = parent;
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/StAXToSAXPipelineAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,131 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import org.xml.sax.Locator;
+
+/**
+ * A dummy locator that returns -1 and null from all methods to indicate that location info is not
+ * available.
+ *
+ * @author Ryan.Shoemaker@Sun.COM
+ */
+public class DummyLocator implements Locator {
+
+ /**
+ * Return the column number where the current document event ends. <p/>
+ * <p>
+ * <strong>Warning:</strong> The return value from the method is intended only as an
+ * approximation for the sake of error reporting; it is not intended to provide sufficient
+ * information to edit the character content of the original XML document.
+ * </p>
+ * <p/>
+ * <p>
+ * The return value is an approximation of the column number in the document entity or external
+ * parsed entity where the markup triggering the event appears.
+ * </p>
+ * <p/>
+ * <p>
+ * If possible, the SAX driver should provide the line position of the first character after the
+ * text associated with the document event.
+ * </p>
+ * <p/>
+ * <p>
+ * If possible, the SAX driver should provide the line position of the first character after the
+ * text associated with the document event. The first column in each line is column 1.
+ * </p>
+ *
+ * @return The column number, or -1 if none is available.
+ * @see #getLineNumber
+ */
+ public int getColumnNumber() {
+ return -1;
+ }
+
+ /**
+ * Return the line number where the current document event ends. <p/>
+ * <p>
+ * <strong>Warning:</strong> The return value from the method is intended only as an
+ * approximation for the sake of error reporting; it is not intended to provide sufficient
+ * information to edit the character content of the original XML document.
+ * </p>
+ * <p/>
+ * <p>
+ * The return value is an approximation of the line number in the document entity or external
+ * parsed entity where the markup triggering the event appears.
+ * </p>
+ * <p/>
+ * <p>
+ * If possible, the SAX driver should provide the line position of the first character after the
+ * text associated with the document event. The first line in the document is line 1.
+ * </p>
+ *
+ * @return The line number, or -1 if none is available.
+ * @see #getColumnNumber
+ */
+ public int getLineNumber() {
+ return -1;
+ }
+
+ /**
+ * Return the public identifier for the current document event. <p/>
+ * <p>
+ * The return value is the public identifier of the document entity or of the external parsed
+ * entity in which the markup triggering the event appears.
+ * </p>
+ *
+ * @return A string containing the public identifier, or null if none is available.
+ * @see #getSystemId
+ */
+ public String getPublicId() {
+ return null;
+ }
+
+ /**
+ * Return the system identifier for the current document event. <p/>
+ * <p>
+ * The return value is the system identifier of the document entity or of the external parsed
+ * entity in which the markup triggering the event appears.
+ * </p>
+ * <p/>
+ * <p>
+ * If the system identifier is a URL, the parser must resolve it fully before passing it to the
+ * application.
+ * </p>
+ *
+ * @return A string containing the system identifier, or null if none is available.
+ * @see #getPublicId
+ */
+ public String getSystemId() {
+ return null;
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/DummyLocator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,79 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * Extended namespace context interface that allows the context tree to be navigated and to list all
+ * known prefixes.
+ *
+ * @author Christian Niles
+ * @version $Revision: 1.1 $
+ */
+public interface ExtendedNamespaceContext extends NamespaceContext {
+
+ /**
+ * Returns a reference to the parent of this context.
+ *
+ * @return The parent context, or <code>null</code> if this is a root context.
+ */
+ public NamespaceContext getParent();
+
+ /**
+ * Determines if the specified prefix is declared within this context, irrespective of any
+ * ancestor contexts.
+ *
+ * @param prefix The prefix to check.
+ * @return <code>true</code> if the prefix is declared in this context, <code>false</code>
+ * otherwise.
+ */
+ public boolean isPrefixDeclared(String prefix);
+
+ /**
+ * Returns an {@link Iterator} of all namespace prefixes in scope within this context, including
+ * those inherited from ancestor contexts.
+ *
+ * @return An {@link Iterator} of prefix {@link String}s.
+ */
+ public Iterator<?> getPrefixes();
+
+ /**
+ * Returns an {@link Iterator} of all namespace prefixes declared within this context,
+ * irrespective of any ancestor contexts.
+ *
+ * @return An {@link Iterator} of prefix {@link String}s.
+ */
+ public Iterator<?> getDeclaredPrefixes();
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/ExtendedNamespaceContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,460 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * Simple NamespaceContext implementation backed by a HashMap.
+ *
+ * @author Christian Niles
+ * @version $Revision: 1.7 $
+ */
+public class SimpleNamespaceContext implements ExtendedNamespaceContext, StaticNamespaceContext {
+
+ /**
+ * The parent context, which may be <code>null</code>
+ */
+ protected NamespaceContext parent;
+
+ /**
+ * map containing bound namespaces, keyed by their prefix. A LinkedHashMap is used to ensure
+ * that {@link #getPrefix(String)} always returns the same prefix, unless that prefix is
+ * removed.
+ */
+ @SuppressWarnings("unchecked")
+ protected Map namespaces = new LinkedHashMap();
+
+ /**
+ * Constructs a SimpleNamespaceContext with no parent context or namespace declarations.
+ */
+ public SimpleNamespaceContext() {
+
+ }
+
+ /**
+ * Constructs a SimpleNamespaceContext with no parent context that contains the specified
+ * prefixes.
+ *
+ * @param namespaces A Map of namespace URIs, keyed by their prefixes.
+ */
+ @SuppressWarnings("unchecked")
+ public SimpleNamespaceContext(Map namespaces) {
+
+ if (namespaces != null) {
+
+ this.namespaces.putAll(namespaces);
+
+ }
+
+ }
+
+ /**
+ * Constructs an empty SimpleNamespaceContext with the given parent. The parent context will be
+ * forwarded any requests for namespaces not declared in this context.
+ *
+ * @param parent The parent context.
+ */
+ public SimpleNamespaceContext(NamespaceContext parent) {
+
+ this.parent = parent;
+
+ }
+
+ /**
+ * Constructs an empty SimpleNamespaceContext with the given parent. The parent context will be
+ * forwarded any requests for namespaces not declared in this context.
+ *
+ * @param parent The parent context.
+ * @param namespaces A Map of namespace URIs, keyed by their prefixes.
+ */
+ @SuppressWarnings("unchecked")
+ public SimpleNamespaceContext(NamespaceContext parent, Map namespaces) {
+
+ this.parent = parent;
+
+ if (namespaces != null) {
+
+ this.namespaces.putAll(namespaces);
+
+ }
+
+ }
+
+ /**
+ * Returns a reference to the parent of this context.
+ *
+ * @return The parent context, or <code>null</code> if this is a root context.
+ */
+ public NamespaceContext getParent() {
+
+ return this.parent;
+
+ }
+
+ /**
+ * Sets the parent context used to inherit namespace bindings.
+ *
+ * @param parent The new parent context.
+ */
+ public void setParent(NamespaceContext parent) {
+
+ this.parent = parent;
+
+ }
+
+ /**
+ * Determines if this is a root context.
+ *
+ * @return <code>true</code> if this is a root context, <code>false</code> otherwise.
+ */
+ public boolean isRootContext() {
+
+ return this.parent == null;
+
+ }
+
+ public String getNamespaceURI(String prefix) {
+
+ if (prefix == null) {
+
+ throw new IllegalArgumentException("prefix argument was null");
+
+ } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
+
+ return XMLConstants.XML_NS_URI;
+
+ } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+
+ return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+
+ } else if (this.namespaces.containsKey(prefix)) {
+
+ // The StAX spec says to return null for any undefined prefix. To
+ // support
+ // undefining a prefix as specified in the Namespaces spec, we store
+ // undefined prefixes as the empty string.
+
+ String uri = (String) this.namespaces.get(prefix);
+ if (uri.length() == 0) {
+
+ return null;
+
+ } else {
+
+ return uri;
+
+ }
+
+ } else if (this.parent != null) {
+
+ return this.parent.getNamespaceURI(prefix);
+
+ } else {
+
+ return null;
+
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getPrefix(String nsURI) {
+
+ if (nsURI == null) {
+
+ throw new IllegalArgumentException("nsURI was null");
+
+ } else if (nsURI.length() == 0) {
+
+ throw new IllegalArgumentException("nsURI was empty");
+
+ } else if (nsURI.equals(XMLConstants.XML_NS_URI)) {
+
+ return XMLConstants.XML_NS_PREFIX;
+
+ } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+
+ return XMLConstants.XMLNS_ATTRIBUTE;
+
+ }
+
+ Iterator iter = this.namespaces.entrySet().iterator();
+ while (iter.hasNext()) {
+
+ Map.Entry entry = (Map.Entry) iter.next();
+ String uri = (String) entry.getValue();
+
+ if (uri.equals(nsURI)) {
+
+ return (String) entry.getKey();
+
+ }
+
+ }
+
+ if (this.parent != null) {
+
+ return this.parent.getPrefix(nsURI);
+
+ } else if (nsURI.length() == 0) {
+
+ return "";
+
+ } else {
+
+ return null;
+
+ }
+
+ }
+
+ /**
+ * Determines if the specified prefix is declared within this context, irrespective of any
+ * ancestor contexts.
+ *
+ * @param prefix The prefix to check.
+ * @return <code>true</code> if the prefix is declared in this context, <code>false</code>
+ * otherwise.
+ */
+ public boolean isPrefixDeclared(String prefix) {
+
+ return this.namespaces.containsKey(prefix);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Iterator getDeclaredPrefixes() {
+
+ return Collections.unmodifiableCollection(this.namespaces.keySet()).iterator();
+
+ }
+
+ /**
+ * Returns the number of namespace prefixes declared in this context.
+ *
+ * @return The number of namespace prefixes declared in this context.
+ */
+ public int getDeclaredPrefixCount() {
+
+ return this.namespaces.size();
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Iterator getPrefixes() {
+
+ if (this.parent == null || !(this.parent instanceof ExtendedNamespaceContext)) {
+
+ return this.getDeclaredPrefixes();
+
+ } else {
+
+ Set prefixes = new HashSet(this.namespaces.keySet());
+
+ ExtendedNamespaceContext superCtx = (ExtendedNamespaceContext) this.parent;
+ for (Iterator i = superCtx.getPrefixes(); i.hasNext();) {
+
+ String prefix = (String) i.next();
+ prefixes.add(prefix);
+
+ }
+
+ return prefixes.iterator();
+
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Iterator getPrefixes(String nsURI) {
+
+ if (nsURI == null) {
+
+ throw new IllegalArgumentException("nsURI was null");
+
+ } else if (nsURI.equals(XMLConstants.XML_NS_URI)) {
+
+ return Collections.singleton(XMLConstants.XML_NS_PREFIX).iterator();
+
+ } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+
+ return Collections.singleton(XMLConstants.XMLNS_ATTRIBUTE).iterator();
+
+ }
+
+ Set prefixes = null;
+ Iterator iter = this.namespaces.entrySet().iterator();
+ while (iter.hasNext()) {
+
+ Map.Entry entry = (Map.Entry) iter.next();
+ String uri = (String) entry.getValue();
+ if (uri.equals(nsURI)) {
+
+ if (prefixes == null) {
+
+ prefixes = new HashSet();
+
+ }
+ prefixes.add(entry.getKey());
+
+ }
+
+ }
+
+ if (this.parent != null) {
+
+ for (Iterator i = this.parent.getPrefixes(nsURI); i.hasNext();) {
+
+ String prefix = (String) i.next();
+
+ if (prefixes == null) {
+
+ prefixes = new HashSet();
+
+ }
+ prefixes.add(prefix);
+
+ }
+
+ }
+
+ if (prefixes != null) {
+
+ return Collections.unmodifiableSet(prefixes).iterator();
+
+ } else if (nsURI.length() == 0) {
+
+ return Collections.singleton("").iterator();
+
+ } else {
+
+ return Collections.EMPTY_LIST.iterator();
+
+ }
+
+ }
+
+ /**
+ * Sets the default namespace in this context.
+ *
+ * @param nsURI The default namespace URI.
+ * @return The previously declared namespace uri, or <code>null</code> if the default prefix
+ * wasn't previously declared in this context.
+ */
+ @SuppressWarnings("unchecked")
+ public String setDefaultNamespace(String nsURI) {
+
+ if (nsURI != null) {
+
+ if (nsURI.equals(XMLConstants.XML_NS_URI)) {
+
+ throw new IllegalArgumentException("Attempt to map 'xml' uri");
+
+ } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+
+ throw new IllegalArgumentException("Attempt to map 'xmlns' uri");
+
+ }
+
+ return (String) this.namespaces.put(XMLConstants.DEFAULT_NS_PREFIX, nsURI);
+
+ } else {
+
+ // put the empty string to record an undefined prefix
+ return (String) this.namespaces.put(XMLConstants.DEFAULT_NS_PREFIX, "");
+
+ }
+
+ }
+
+ /**
+ * Declares a namespace binding in this context.
+ *
+ * @param prefix The namespace prefix.
+ * @param nsURI The namespace URI.
+ * @return The previously declared namespace uri, or <code>null</code> if the prefix wasn't
+ * previously declared in this context.
+ */
+ @SuppressWarnings("unchecked")
+ public String setPrefix(String prefix, String nsURI) {
+
+ if (prefix == null) {
+
+ throw new NullPointerException("Namespace Prefix was null");
+
+ } else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
+
+ return this.setDefaultNamespace(nsURI);
+
+ } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
+
+ throw new IllegalArgumentException("Attempt to map 'xml' prefix");
+
+ } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+
+ throw new IllegalArgumentException("Attempt to map 'xmlns' prefix");
+
+ } else if (nsURI != null) {
+
+ if (nsURI.equals(XMLConstants.XML_NS_URI)) {
+
+ throw new IllegalArgumentException("Attempt to map 'xml' uri");
+
+ } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+
+ throw new IllegalArgumentException("Attempt to map 'xmlns' uri");
+
+ } else {
+
+ return (String) this.namespaces.put(prefix, nsURI);
+
+ }
+
+ } else {
+
+ // put the empty string to record an undefined prefix
+ return (String) this.namespaces.put(prefix, "");
+
+ }
+
+ }
+
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/SimpleNamespaceContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,568 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLReporter;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.Namespace;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.util.XMLEventConsumer;
+
+import org.apache.cocoon.sax.SAXConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * SAX ContentHandler that writes events to a StAX {@link XMLEventConsumer}.
+ *
+ * @author Christian Niles
+ * @version $Revision: 1.5 $
+ */
+public class StAXEventContentHandler extends DefaultHandler implements SAXConsumer {
+
+ /**
+ * Whether the parser is currently within a CDATA section.
+ */
+ private boolean isCDATA;
+
+ /**
+ * Buffer containing text read within the current CDATA section.
+ */
+ private StringBuffer CDATABuffer;
+
+ /**
+ * Stack used to store declared namespaces.
+ */
+ private SimpleNamespaceContext namespaces;
+
+ /**
+ * The SAX {@link Locator}provided to the handler.
+ */
+ private Locator docLocator;
+
+ /**
+ * The STAX {@link XMLReporter}registered to receive notifications.
+ */
+ private XMLReporter reporter;
+
+ /** The consumer to which events will be written. */
+ private XMLEventConsumer consumer;
+
+ /** The factory used to construct events. */
+ private XMLEventFactory eventFactory;
+
+ /**
+ * A stack of {@link List}s, each containing {@link Namespace}events constructed from a
+ * {@link StartElement}event. It is necessary to keep these namespaces so we can report them to
+ * the {@link EndElement}event.
+ */
+ @SuppressWarnings("unchecked")
+ private List namespaceStack = new ArrayList();
+
+ /**
+ * Constructs a default instance with a default event factory. You must set the
+ * {@link XMLEventConsumer}via the {@link #setEventConsumer(XMLEventConsumer)}method.
+ */
+ public StAXEventContentHandler() {
+
+ this.eventFactory = XMLEventFactory.newInstance();
+
+ }
+
+ /**
+ * Constructs an instance that writes events to the provided XMLEventConsumer. Events will be
+ * constructed from a default XMLEventFactory instance.
+ *
+ * @param consumer The {@link XMLEventConsumer}to which events will be written.
+ */
+ public StAXEventContentHandler(XMLEventConsumer consumer) {
+
+ this.consumer = consumer;
+ this.eventFactory = XMLEventFactory.newInstance();
+
+ }
+
+ /**
+ * Constructs an instance that writes events constructed with the provided XMLEventFactory to
+ * the provided XMLEventConsumer
+ *
+ * @param consumer The {@link XMLEventConsumer} to which events will be written.
+ * @param factory The {@link XMLEventFactory} used to construct events. If <code>null</code>,
+ * a default instance will be constructed.
+ */
+ public StAXEventContentHandler(XMLEventConsumer consumer, XMLEventFactory factory) {
+ this.consumer = consumer;
+ if (factory != null) {
+ this.eventFactory = factory;
+ } else {
+ this.eventFactory = XMLEventFactory.newInstance();
+ }
+ }
+
+ /**
+ * Returns a reference to the {@link XMLEventConsumer} to which events will be written.
+ *
+ * @return The {@link XMLEventConsumer} to which events will be written.
+ */
+ public XMLEventConsumer getEventConsumer() {
+ return this.consumer;
+ }
+
+ /**
+ * Sets the {@link XMLEventConsumer} to which events are written.
+ *
+ * @param consumer The {@link XMLEventConsumer} to which events will be written.
+ */
+ public void setEventConsumer(XMLEventConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ /**
+ * Returns a reference to the {@link XMLEventFactory} used to construct events.
+ *
+ * @return The {@link XMLEventFactory} used to construct events.
+ */
+ public XMLEventFactory getEventFactory() {
+ return this.eventFactory;
+ }
+
+ /**
+ * Sets the {@link XMLEventFactory} used to create events.
+ *
+ * @param factory The {@link XMLEventFactory} used to create events.
+ */
+ public void setEventFactory(XMLEventFactory factory) {
+ this.eventFactory = factory;
+ }
+
+ @Override
+ public void startDocument() throws SAXException {
+ this.namespaces = new SimpleNamespaceContext();
+
+ // clear the namespaces in case we ended in error before.
+ this.namespaceStack.clear();
+
+ this.eventFactory.setLocation(this.getCurrentLocation());
+ try {
+ this.consumer.add(this.eventFactory.createStartDocument());
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ @Override
+ public void endDocument() throws SAXException {
+ this.eventFactory.setLocation(this.getCurrentLocation());
+
+ try {
+ this.consumer.add(this.eventFactory.createEndDocument());
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+
+ this.namespaces = null;
+
+ // clear the namespaces
+ this.namespaceStack.clear();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ this.namespaces = null;
+ // set document location
+ this.eventFactory.setLocation(this.getCurrentLocation());
+
+ // create attribute and namespace events
+ Collection[] events = { null, null };
+ this.createStartEvents(attributes, events);
+
+ // save a reference to the namespace collection so we can use them
+ // again
+ // in the end element
+ this.namespaceStack.add(events[0]);
+
+ try {
+ String[] qname = { null, null };
+ this.parseQName(qName, qname);
+
+ this.consumer.add(this.eventFactory.createStartElement(qname[0], uri, qname[1], events[1].iterator(),
+ events[0].iterator()));
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ } finally {
+ super.startElement(uri, localName, qName, attributes);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ this.namespaces = null;
+ super.endElement(uri, localName, qName);
+
+ this.eventFactory.setLocation(this.getCurrentLocation());
+
+ // parse name
+ String[] qname = { null, null };
+ this.parseQName(qName, qname);
+
+ // get namespaces
+ Collection nsList = (Collection) this.namespaceStack.remove(this.namespaceStack.size() - 1);
+ Iterator nsIter = nsList.iterator();
+
+ try {
+ this.consumer.add(this.eventFactory.createEndElement(qname[0], uri, qname[1], nsIter));
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ @Override
+ public void comment(char[] ch, int start, int length) throws SAXException {
+ this.eventFactory.setLocation(this.getCurrentLocation());
+
+ try {
+ this.consumer.add(this.eventFactory.createComment(new String(ch, start, length)));
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ super.characters(ch, start, length);
+
+ if (this.isCDATA) {
+ this.CDATABuffer.append(ch, start, length);
+ }
+
+ try {
+ if (!this.isCDATA) {
+ this.eventFactory.setLocation(this.getCurrentLocation());
+ this.consumer.add(this.eventFactory.createCharacters(new String(ch, start, length)));
+ }
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ @Override
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+ super.ignorableWhitespace(ch, start, length);
+ this.characters(ch, start, length);
+ }
+
+ @Override
+ public void processingInstruction(String target, String data) throws SAXException {
+ super.processingInstruction(target, data);
+ try {
+ this.consumer.add(this.eventFactory.createProcessingInstruction(target, data));
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ @Override
+ public void endCDATA() throws SAXException {
+ this.eventFactory.setLocation(this.getCurrentLocation());
+ try {
+ this.consumer.add(this.eventFactory.createCData(this.CDATABuffer.toString()));
+ } catch (XMLStreamException e) {
+ throw new SAXException(e);
+ }
+
+ this.isCDATA = false;
+ this.CDATABuffer.setLength(0);
+ }
+
+ /**
+ * Creates the {@link Namespace}and {@link Attribute}events associated with a
+ * {@link StartElement}.
+ *
+ * @param attributes The SAX attributes object.
+ * @param events An array used to return the two collections of {@link Namespace}and
+ * {@link Attribute}events. The namespaces will be placed at <code>events[0]</code>
+ * and the attributes as <code>events[1]</code>.
+ */
+ @SuppressWarnings("unchecked")
+ protected void createStartEvents(Attributes attributes, Collection[] events) {
+ Map nsMap = null;
+ List attrs = null;
+
+ // create namespaces
+ if (this.namespaces != null) {
+ Iterator prefixes = this.namespaces.getDeclaredPrefixes();
+ while (prefixes.hasNext()) {
+ String prefix = (String) prefixes.next();
+ String uri = this.namespaces.getNamespaceURI(prefix);
+
+ Namespace ns = this.createNamespace(prefix, uri);
+ if (nsMap == null) {
+ nsMap = new HashMap();
+ }
+ nsMap.put(prefix, ns);
+ }
+ }
+
+ // create attributes
+ String[] qname = { null, null };
+ for (int i = 0, s = attributes.getLength(); i < s; i++) {
+
+ this.parseQName(attributes.getQName(i), qname);
+
+ String attrPrefix = qname[0];
+ String attrLocal = qname[1];
+
+ String attrQName = attributes.getQName(i);
+ String attrValue = attributes.getValue(i);
+ String attrURI = attributes.getURI(i);
+
+ if ("xmlns".equals(attrQName) || "xmlns".equals(attrPrefix)) {
+
+ // namespace declaration disguised as an attribute. If the
+ // namespace has already been declared, skip it, otherwise
+ // write it as an namespace
+
+ if (!nsMap.containsKey(attrPrefix)) {
+ Namespace ns = this.createNamespace(attrPrefix, attrValue);
+ if (nsMap == null) {
+ nsMap = new HashMap();
+ }
+ nsMap.put(attrPrefix, ns);
+ }
+
+ } else {
+ Attribute attribute;
+ if (attrPrefix.length() > 0) {
+ attribute = this.eventFactory.createAttribute(attrPrefix, attrURI, attrLocal, attrValue);
+ } else {
+ attribute = this.eventFactory.createAttribute(attrLocal, attrValue);
+ }
+
+ if (attrs == null) {
+ attrs = new ArrayList();
+ }
+ attrs.add(attribute);
+ }
+ }
+
+ events[0] = nsMap == null ? Collections.EMPTY_LIST : nsMap.values();
+ events[1] = attrs == null ? Collections.EMPTY_LIST : attrs;
+ }
+
+ protected Namespace createNamespace(String prefix, String uri) {
+ if (prefix == null || prefix.length() == 0) {
+ return this.eventFactory.createNamespace(uri);
+ } else {
+ return this.eventFactory.createNamespace(prefix, uri);
+ }
+ }
+
+ /**
+ * Sets the {@link XMLReporter}to which warning and error messages will be sent.
+ *
+ * @param reporter The {@link XMLReporter}to notify of errors.
+ */
+ public void setXMLReporter(XMLReporter reporter) {
+ this.reporter = reporter;
+ }
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ this.docLocator = locator;
+ }
+
+ /**
+ * Calculates the STAX {@link Location}from the SAX {@link Locator} registered with this
+ * handler. If no {@link Locator}was provided, then this method will return <code>null</code>.
+ */
+ public Location getCurrentLocation() {
+ if (this.docLocator != null) {
+ return new SAXLocation(this.docLocator);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void error(SAXParseException e) throws SAXException {
+ this.reportException("ERROR", e);
+ }
+
+ @Override
+ public void fatalError(SAXParseException e) throws SAXException {
+ this.reportException("FATAL", e);
+ }
+
+ @Override
+ public void warning(SAXParseException e) throws SAXException {
+ this.reportException("WARNING", e);
+ }
+
+ @Override
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ if (prefix == null) {
+ prefix = "";
+ } else if (prefix.equals("xml")) {
+ return;
+ }
+
+ if (this.namespaces == null) {
+ this.namespaces = new SimpleNamespaceContext();
+ }
+ this.namespaces.setPrefix(prefix, uri);
+ }
+
+ @Override
+ public void endPrefixMapping(String prefix) throws SAXException {
+ }
+
+ @Override
+ public void startCDATA() throws SAXException {
+ this.isCDATA = true;
+ if (this.CDATABuffer == null) {
+ this.CDATABuffer = new StringBuffer();
+ } else {
+ this.CDATABuffer.setLength(0);
+ }
+ }
+
+ @Override
+ public void endDTD() throws SAXException {
+ }
+
+ @Override
+ public void endEntity(String name) throws SAXException {
+ }
+
+ @Override
+ public void startDTD(String name, String publicId, String systemId) throws SAXException {
+ }
+
+ @Override
+ public void startEntity(String name) throws SAXException {
+ }
+
+ /**
+ * Used to report a {@link SAXException}to the {@link XMLReporter} registered with this
+ * handler.
+ */
+ protected void reportException(String type, SAXException e) throws SAXException {
+ if (this.reporter != null) {
+ try {
+ this.reporter.report(e.getMessage(), type, e, this.getCurrentLocation());
+ } catch (XMLStreamException e1) {
+ throw new SAXException(e1);
+ }
+ }
+ }
+
+ /**
+ * Parses an XML qualified name, and places the resulting prefix and local name in the provided
+ * String array.
+ *
+ * @param qName The qualified name to parse.
+ * @param results An array where parse results will be placed. The prefix will be placed at
+ * <code>results[0]</code>, and the local part at <code>results[1]</code>
+ */
+ private void parseQName(String qName, String[] results) {
+ String prefix, local;
+ int idx = qName.indexOf(':');
+ if (idx >= 0) {
+ prefix = qName.substring(0, idx);
+ local = qName.substring(idx + 1);
+ } else {
+ prefix = "";
+ local = qName;
+ }
+
+ results[0] = prefix;
+ results[1] = local;
+ }
+
+ /**
+ * {@Link Location}implementation used to expose details from a SAX {@link Locator}.
+ *
+ * @author christian
+ * @version $Revision: 1.3 $
+ */
+ private class SAXLocation implements Location {
+
+ private int lineNumber;
+ private int columnNumber;
+ private String publicId;
+ private String systemId;
+
+ private SAXLocation(Locator locator) {
+ this.lineNumber = locator.getLineNumber();
+ this.columnNumber = locator.getColumnNumber();
+ this.publicId = locator.getPublicId();
+ this.systemId = locator.getSystemId();
+ }
+
+ public int getLineNumber() {
+ return this.lineNumber;
+ }
+
+ public int getColumnNumber() {
+ return this.columnNumber;
+ }
+
+ public int getCharacterOffset() {
+ return -1;
+ }
+
+ public String getPublicId() {
+ return this.publicId;
+ }
+
+ public String getSystemId() {
+ return this.systemId;
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StAXEventContentHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java?rev=740557&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java Wed Feb 4 01:13:31 2009
@@ -0,0 +1,45 @@
+/* Copyright (c) 2004, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.stax.converter.util;
+
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * Marker interface used to denote {@link NamespaceContext} implementations whose state is not
+ * transient or dependent on external objects/events and will remain stable unless explicitly
+ * updated.
+ *
+ * @author Christian Niles
+ * @version $Revision: 1.1 $
+ */
+public interface StaticNamespaceContext extends NamespaceContext {
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/main/java/org/apache/cocoon/stax/converter/util/StaticNamespaceContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain