Author: nscavell
Date: 2011-07-29 14:36:01 -0400 (Fri, 29 Jul 2011)
New Revision: 6954
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/Exceptions.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/StaxNavUtils.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilder.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilderImpl.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriter.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterImpl.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterUtils.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueType.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueTypes.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilder.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilderImpl.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilder.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilderImpl.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/NoOpFormatter.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/SimpleFormatter.java
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/XmlStreamingFormatter.java
portal/branches/gatein-management/component/common/src/test/java/org/gatein/
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/AbstractStaxWriterTest.java
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/LocalStaxWriterTest.java
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/QualifiedStaxWriterTest.java
Modified:
portal/branches/gatein-management/component/common/pom.xml
portal/branches/gatein-management/component/portal/pom.xml
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/DelimitedValueType.java
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/NavigationMarshaller.java
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshaller.java
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java
portal/branches/gatein-management/packaging/jboss-as5/pkg/pom.xml
portal/branches/gatein-management/packaging/jboss-as6/pkg/pom.xml
portal/branches/gatein-management/packaging/jetty/pkg/pom.xml
portal/branches/gatein-management/packaging/tomcat/pkg/pom.xml
portal/branches/gatein-management/pom.xml
Log:
Move stax writer into gatein, update staxnav version.
Modified: portal/branches/gatein-management/component/common/pom.xml
===================================================================
--- portal/branches/gatein-management/component/common/pom.xml 2011-07-29 17:42:53 UTC
(rev 6953)
+++ portal/branches/gatein-management/component/common/pom.xml 2011-07-29 18:36:01 UTC
(rev 6954)
@@ -67,6 +67,11 @@
<groupId>org.chromattic</groupId>
<artifactId>chromattic.spi</artifactId>
</dependency>
+ <!-- Staxnav -->
+ <dependency>
+ <groupId>org.staxnav</groupId>
+ <artifactId>staxnav.core</artifactId>
+ </dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
@@ -86,6 +91,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.chromattic</groupId>
<artifactId>chromattic.core</artifactId>
<scope>test</scope>
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/Exceptions.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/Exceptions.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/Exceptions.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.navigator;
+
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class Exceptions
+{
+ public static <N> StaxNavException expectedElement(StaxNavigator<N>
navigator, N expected)
+ {
+ return expectedElement(navigator, navigator.getNaming().getLocalPart(expected));
+ }
+
+ public static StaxNavException expectedElement(StaxNavigator navigator, String
expected)
+ {
+ StringBuilder message = new StringBuilder().append("Expected
'").append(expected)
+ .append("' but found
'").append(navigator.getLocalName()).append("' instead.");
+
+ return new StaxNavException(navigator.getLocation(), message.toString());
+ }
+
+ public static StaxNavException unexpectedElement(StaxNavigator navigator)
+ {
+ return new StaxNavException(navigator.getLocation(), "Unexpected element
'" + navigator.getLocalName() + "'");
+ }
+
+ public static StaxNavException unknownElement(StaxNavigator navigator)
+ {
+ return new StaxNavException(navigator.getLocation(), "Unknown element
'" + navigator.getLocalName() + "'");
+ }
+
+ public static StaxNavException invalidSequence(StaxNavigator navigator)
+ {
+ return new StaxNavException(navigator.getLocation(), "Element '" +
navigator.getLocalName() + "' is out of sequence.");
+ }
+
+ public static StaxNavException contentRequired(StaxNavigator navigator)
+ {
+ return new StaxNavException(navigator.getLocation(), "Content for element
'" + navigator.getLocalName() + "' is required.");
+ }
+
+ public static StaxNavException invalidParent(StaxNavigator navigator)
+ {
+ return new StaxNavException(navigator.getLocation(), "Invalid parent for
element '" + navigator.getLocalName() + "'");
+ }
+
+ public static StaxNavException unexpectedEndOfFile(StaxNavigator navigator)
+ {
+ return new StaxNavException(navigator.getLocation(), "Unexpected end of
file.");
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/StaxNavUtils.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/StaxNavUtils.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/StaxNavUtils.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.navigator;
+
+import org.gatein.common.xml.stax.navigator.builder.StaxNavBuilder;
+import org.gatein.common.xml.stax.navigator.builder.StaxNavBuilderImpl;
+import org.staxnav.EnumElement;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+import org.staxnav.ValueType;
+
+import javax.xml.namespace.QName;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.gatein.common.xml.stax.navigator.Exceptions.*;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class StaxNavUtils
+{
+ public static <N> StaxNavigator<N> createNavigator(Naming<N> naming,
InputStream in) throws StaxNavException
+ {
+ return buildDefaultNavigator().withInputStream(in).build(naming);
+ }
+
+ public static StaxNavigator<String> createNavigator(InputStream in) throws
StaxNavException
+ {
+ return createNavigator(new Naming.Local(), in);
+ }
+
+ public static StaxNavigator<QName> createQualifiedNavigator(InputStream in)
throws StaxNavException
+ {
+ return createNavigator(new Naming.Qualified(), in);
+ }
+
+ public static <E extends Enum<E> & EnumElement<E>>
StaxNavigator<E> createNavigator(Class<E> enumeratedClass,
+ E
noSuchElement, InputStream in) throws StaxNavException
+ {
+ Naming<E> naming;
+ if (EnumElement.class.isAssignableFrom(enumeratedClass))
+ {
+ naming = new Naming.Enumerated.Mapped<E>(enumeratedClass, noSuchElement);
+ }
+ else
+ {
+ naming = new Naming.Enumerated.Simple<E>(enumeratedClass, noSuchElement);
+ }
+
+ return createNavigator(naming, in);
+ }
+
+ public static <N> StaxNavigator<N> createNavigator(Naming<N> naming,
Reader reader) throws StaxNavException
+ {
+ return buildDefaultNavigator().withReader(reader).build(naming);
+ }
+
+ public static StaxNavigator<String> createNavigator(Reader reader) throws
StaxNavException
+ {
+ return createNavigator(new Naming.Local(), reader);
+ }
+
+ public static StaxNavigator<QName> createQualifiedNavigator(Reader reader)
throws StaxNavException
+ {
+ return createNavigator(new Naming.Qualified(), reader);
+ }
+
+ public static <E extends Enum<E> & EnumElement<E>>
StaxNavigator<E> createNavigator(Class<E> enumeratedClass,
+ E
noSuchElement, Reader reader) throws StaxNavException
+ {
+ Naming<E> naming;
+ if (EnumElement.class.isAssignableFrom(enumeratedClass))
+ {
+ naming = new Naming.Enumerated.Mapped<E>(enumeratedClass, noSuchElement);
+ }
+ else
+ {
+ naming = new Naming.Enumerated.Simple<E>(enumeratedClass, noSuchElement);
+ }
+
+ return createNavigator(naming, reader);
+ }
+
+ public static <N> void requiresChild(StaxNavigator<N> navigator, N
element)
+ {
+ if (navigator.child() != element)
+ {
+ throw expectedElement(navigator, element);
+ }
+ }
+
+ public static <N> void requiresSibling(StaxNavigator<N> navigator, N
element)
+ {
+ if (!navigator.sibling(element))
+ {
+ throw expectedElement(navigator, element);
+ }
+ }
+
+ public static String getRequiredAttribute(StaxNavigator navigator, String
attributeName) throws StaxNavException
+ {
+ String value = navigator.getAttribute(attributeName);
+ if (value == null)
+ {
+ throw new StaxNavException(navigator.getLocation(), "Attribute '"
+ attributeName + "' is required for element '" +
navigator.getLocalName() + "'");
+ }
+
+ return value;
+ }
+
+ public static <N> String getContent(StaxNavigator<N> navigator, boolean
trim)
+ {
+ boolean before = navigator.getTrimContent();
+ try
+ {
+ navigator.setTrimContent(trim);
+ return navigator.getContent();
+ }
+ finally
+ {
+ navigator.setTrimContent(before);
+ }
+ }
+
+ public static <N> String getRequiredContent(StaxNavigator<N> navigator,
boolean trim)
+ {
+ String content = getContent(navigator, trim);
+ if (content == null || content.length() == 0)
+ {
+ throw contentRequired(navigator);
+ }
+
+ return content;
+ }
+
+ public static <N, V> V parseContent(StaxNavigator<N> navigator,
ValueType<V> valueType, V defaultValue)
+ {
+ String content = getContent(navigator, true);
+ if (content != null && content.length() != 0)
+ {
+ return navigator.parseContent(valueType);
+ }
+ else
+ {
+ return defaultValue;
+ }
+ }
+
+ public static <N, V> V parseRequiredContent(StaxNavigator<N> navigator,
ValueType<V> valueType)
+ {
+ V value = parseContent(navigator, valueType, null);
+ if (value == null)
+ {
+ throw contentRequired(navigator);
+ }
+
+ return value;
+ }
+
+ public static <N> Set<N> forNames(N...names)
+ {
+ return new HashSet<N>(Arrays.asList(names));
+ }
+
+ private static StaxNavBuilder buildDefaultNavigator()
+ {
+ return new StaxNavBuilderImpl();
+ }
+
+ private StaxNavUtils() {}
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilder.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilder.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilder.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.navigator.builder;
+
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import java.io.InputStream;
+import java.io.Reader;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public interface StaxNavBuilder
+{
+ StaxNavBuilder withProperty(String name, Object value);
+
+ StaxNavBuilder withPropertyIfSupported(String name, Object value);
+
+ StaxNavBuilder withInputStream(InputStream inputStream);
+
+ StaxNavBuilder withInputStream(InputStream inputStream, String encoding);
+
+ StaxNavBuilder withReader(Reader reader);
+
+ StaxNavBuilder withSource(Source source);
+
+ StaxNavBuilder withXmlStreamReader(XMLStreamReader reader);
+
+ <N> StaxNavigator<N> build(Naming<N> naming) throws
StaxNavException, IllegalStateException;
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilderImpl.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilderImpl.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/navigator/builder/StaxNavBuilderImpl.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.navigator.builder;
+
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+import org.staxnav.StaxNavigatorFactory;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class StaxNavBuilderImpl implements StaxNavBuilder
+{
+ private Object input;
+ private String inputEncoding;
+ private XMLStreamReader reader;
+
+ private Map<String, Object> properties = new HashMap<String, Object>();
+ private Map<String, Object> supportedProperties = new HashMap<String,
Object>();
+
+ @Override
+ public StaxNavBuilder withProperty(String name, Object value)
+ {
+ if (name == null) throw new IllegalArgumentException("name is null");
+ if (value == null) throw new IllegalArgumentException("value is null");
+
+ properties.put(name, value);
+ return this;
+ }
+
+ @Override
+ public StaxNavBuilder withPropertyIfSupported(String name, Object value)
+ {
+ if (name == null) throw new IllegalArgumentException("name is null");
+ if (value == null) throw new IllegalArgumentException("value is null");
+
+ supportedProperties.put(name, value);
+ return this;
+ }
+
+ @Override
+ public StaxNavBuilder withInputStream(InputStream inputStream)
+ {
+ if (inputStream == null) throw new IllegalArgumentException("inputStream is
null");
+
+ input = inputStream;
+ return this;
+ }
+
+ @Override
+ public StaxNavBuilder withInputStream(InputStream inputStream, String encoding)
+ {
+ if (inputStream == null) throw new IllegalArgumentException("inputStream is
null");
+ if (encoding == null) throw new IllegalArgumentException("encoding is
null");
+
+ input = inputStream;
+ inputEncoding = encoding;
+ return this;
+ }
+
+ @Override
+ public StaxNavBuilder withReader(Reader reader)
+ {
+ if (reader == null) throw new IllegalArgumentException("reader is
null");
+
+ this.input = reader;
+ return this;
+ }
+
+ @Override
+ public StaxNavBuilder withSource(Source source)
+ {
+ if (source == null) throw new IllegalArgumentException("source is
null");
+
+ input = source;
+ return this;
+ }
+
+ @Override
+ public StaxNavBuilder withXmlStreamReader(XMLStreamReader reader)
+ {
+ if (reader == null) throw new IllegalArgumentException("reader is
null");
+
+ this.reader = reader;
+ return this;
+ }
+
+ @Override
+ public <N> StaxNavigator<N> build(Naming<N> naming) throws
StaxNavException, IllegalStateException
+ {
+ if (naming == null) throw new IllegalArgumentException("naming is
null");
+
+ if (reader == null && input == null)
+ throw new IllegalStateException("Cannot build stax reader. Try calling
withInputStream/withReader or pass in own XMLStreamReader.");
+
+ if (reader == null)
+ {
+ //TODO: Create solution to properly cache XMLInputFactory
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+
+ // Set properties
+ for (Map.Entry<String, Object> entry : properties.entrySet())
+ {
+ factory.setProperty(entry.getKey(), entry.getValue());
+ }
+
+ // Set properties if supported
+ for (Map.Entry<String, Object> entry : supportedProperties.entrySet())
+ {
+ String name = entry.getKey();
+ if (factory.isPropertySupported(name))
+ {
+ factory.setProperty(name, entry.getValue());
+ }
+ }
+
+ if (input instanceof InputStream)
+ {
+ if (inputEncoding == null)
+ {
+ try
+ {
+ reader = factory.createXMLStreamReader((InputStream) input,
inputEncoding);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(e);
+ }
+ }
+ else
+ {
+ try
+ {
+ reader = factory.createXMLStreamReader((InputStream) input);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(null, "Exception creating
XMLStreamReader with inputStream: " + input, e);
+ }
+ }
+ }
+ else if (input instanceof Reader)
+ {
+ try
+ {
+ reader = factory.createXMLStreamReader((Reader) input);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(null, "Exception creating XMLStreamReader
with reader: " + input, e);
+ }
+ }
+ else if (input instanceof Source)
+ {
+ try
+ {
+ reader = factory.createXMLStreamReader((Source) input);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(null, "Exception creating XMLStreamReader
with Source: " + input, e);
+ }
+ }
+ else
+ {
+ throw new IllegalStateException("Unknown input: " + input); //
should never happen...
+ }
+ }
+
+ return StaxNavigatorFactory.create(naming, reader);
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriter.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriter.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriter.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer;
+
+import org.staxnav.StaxNavException;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public interface StaxWriter<N>
+{
+ /**
+ * Writes the start tag of an xml element. Requires that an element has been started
first.
+ *
+ * @param element element to start
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeStartElement(N element) throws StaxNavException;
+
+ /**
+ * Writes an attribute for an xml element. Requires that an element has been started
first.
+ *
+ * @param name the name of the attribute
+ * @param value the value of the attribute
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeAttribute(String name, String value) throws
StaxNavException;
+
+ /**
+ * Writes an attribute for an xml element. Requires that an element has been started
first.
+ *
+ * @param name QName object representing the name of the attribute
+ * @param value the value of the attribute
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeAttribute(QName name, String value) throws StaxNavException;
+
+ /**
+ * Writes xml content. Requires an xml element has been started first.
+ *
+ * @param content content to be written
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeContent(String content) throws StaxNavException;
+
+ /**
+ * Writes xml content based on the ValueType responsible for converting the content to
string. Requires an xml element has been started first.
+ *
+ * @param valueType object responsible for writing content to string
+ * @param content content to be written
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ <V> StaxWriter<N> writeContent(WritableValueType<V> valueType, V
content) throws StaxNavException;
+
+ /**
+ * Writes an end tag for the previously started element. Requires that an element has
been started first.
+ *
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeEndElement() throws StaxNavException;
+
+ /**
+ * Convenience method for calling <code>writeStartElement</code>,
<code>writeContent</code>, <code>writeEndElement</code>
+ *
+ * @param element element to write
+ * @param content content to be written
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ <V> StaxWriter<N> writeElement(N element, String content) throws
StaxNavException;
+
+ /**
+ * Convenience method for calling <code>writeStartElement</code>,
<code>writeContent</code>, <code>writeEndElement</code>
+ *
+ * @param element element to write
+ * @param valueType object responsible for writing content to string
+ * @param content content to be written
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ <V> StaxWriter<N> writeElement(N element, WritableValueType<V>
valueType, V content) throws StaxNavException;
+
+ /**
+ * Writes the namespace. If prefix is an empty string, "xmlns", or null this
will delegate to writeDefaultNamespace
+ * @param prefix the prefix to bind the namespace to
+ * @param uri the uri to bind the prefix to
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeNamespace(String prefix, String uri) throws
StaxNavException;
+
+ /**
+ * Writes the default namespace
+ * @param uri the uri to bind the default namespace to
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeDefaultNamespace(String uri) throws StaxNavException;
+
+ /**
+ * Writes an xml comment
+ * @param comment the comment to write
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeComment(String comment) throws StaxNavException;
+
+ /**
+ * Writes a cdata section
+ * @param cdata content of the cdata
+ * @return StaxWriter
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ StaxWriter<N> writeCData(String cdata) throws StaxNavException;
+
+ /**
+ * Calling finish will flush and close the underlying stream. It will also call any
endElements for you
+ * if they were never explicitly called.
+ *
+ * @throws org.staxnav.StaxNavException if an exception occurs
+ */
+ void finish() throws StaxNavException;
+}
\ No newline at end of file
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterImpl.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterImpl.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterImpl.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,503 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer;
+
+
+import org.gatein.common.xml.stax.writer.formatting.NoOpFormatter;
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class StaxWriterImpl<N> implements StaxWriter<N>, XMLStreamConstants
+{
+ private Naming<N> naming;
+ private XMLStreamWriter writer;
+ private XmlStreamingFormatter formatter;
+
+ private Deque<Element> elementStack = new ArrayDeque<Element>();
+
+ public StaxWriterImpl(Naming<N> naming, XMLStreamWriter writer)
+ {
+ this(naming, writer, null);
+ }
+
+ public StaxWriterImpl(Naming<N> naming, XMLStreamWriter writer,
XmlStreamingFormatter formatter)
+ {
+ this(naming, writer, formatter, null, null);
+ }
+
+ public StaxWriterImpl(Naming<N> naming, XMLStreamWriter writer,
XmlStreamingFormatter formatter, String encoding, String version)
+ {
+ this.naming = naming;
+ this.writer = writer;
+ if (formatter == null) formatter = new NoOpFormatter();
+
+ this.formatter = formatter;
+ elementStack.push(new RootElement(writer, formatter, encoding, version));
+ }
+
+ public StaxWriter<N> writeAttribute(String name, String value)
+ {
+ if (name == null) throw new IllegalArgumentException("name cannot be
null");
+ if (value == null) throw new IllegalArgumentException("value cannot be
null");
+
+ Element current = elementStack.peek();
+ current.writeAttribute(name, value);
+ return this;
+ }
+
+ public StaxWriter<N> writeAttribute(QName name, String value)
+ {
+ if (name == null) throw new IllegalArgumentException("name cannot be
null");
+
+ Element current = elementStack.peek();
+ current.writeAttribute(name, value);
+ return this;
+ }
+
+ public StaxWriter<N> writeStartElement(N element) throws StaxNavException
+ {
+ Element current = elementStack.peek();
+ if (current instanceof RootElement)
+ {
+ if (((RootElement) current).started)
+ {
+ current = new StreamElement(writer, formatter);
+ elementStack.push(current);
+ }
+ }
+ else
+ {
+ current = new StreamElement(writer, formatter);
+ elementStack.push(current);
+ }
+
+ current.writeStartElement(naming, element);
+ return this;
+ }
+
+ public StaxWriter<N> writeEndElement() throws StaxNavException
+ {
+ if (elementStack.isEmpty()) throw new StaxNavException(null, "No matching
startElement was found for this endElement");
+
+ elementStack.pop().end();
+
+ return this;
+ }
+
+ public StaxWriter<N> writeContent(String content) throws StaxNavException
+ {
+ return writeContent(WritableValueTypes.STRING, content);
+ }
+
+ public <V> StaxWriter<N> writeContent(WritableValueType<V>
valueType, V content) throws StaxNavException
+ {
+ if (valueType == null) throw new IllegalArgumentException("valueType cannot be
null.");
+ if (content == null) throw new IllegalArgumentException("content cannot be
null.");
+
+ Element current = elementStack.peek();
+ current.writeContent(valueType.format(content));
+
+ return this;
+ }
+
+ public <V> StaxWriter<N> writeElement(N element, String content) throws
StaxNavException
+ {
+ return writeElement(element, WritableValueTypes.STRING, content);
+ }
+
+ public <V> StaxWriter<N> writeElement(N element,
WritableValueType<V> valueType, V content) throws StaxNavException
+ {
+ writeStartElement(element).writeContent(valueType, content).writeEndElement();
+ return this;
+ }
+
+ public StaxWriter<N> writeNamespace(String prefix, String uri) throws
StaxNavException
+ {
+ Element current = elementStack.peek();
+ current.writeNamespace(prefix, uri);
+ return this;
+ }
+
+ public StaxWriter<N> writeDefaultNamespace(String uri) throws StaxNavException
+ {
+ Element current = elementStack.peek();
+ current.writeDefaultNamespace(uri);
+ return this;
+ }
+
+ public StaxWriter<N> writeComment(final String comment) throws StaxNavException
+ {
+ Element current = elementStack.peek();
+ current.writeComment(comment);
+ return this;
+ }
+
+ public StaxWriter<N> writeCData(String cdata) throws StaxNavException
+ {
+ Element current = elementStack.peek();
+ current.writeCData(cdata);
+ return this;
+ }
+
+ public void finish() throws StaxNavException
+ {
+ while (!elementStack.isEmpty())
+ {
+ elementStack.pop().end();
+ }
+ }
+
+ private static abstract class Element
+ {
+ abstract void writeAttribute(String name, String value) throws StaxNavException;
+
+ abstract <N> void writeAttribute(QName name, String value) throws
StaxNavException;
+
+ abstract <N> void writeStartElement(Naming<N> naming, N name) throws
StaxNavException;
+
+ abstract void writeContent(String content) throws StaxNavException;
+
+ abstract void writeNamespace(String prefix, String uri) throws StaxNavException;
+
+ abstract void writeDefaultNamespace(String uri) throws StaxNavException;
+
+ abstract void writeComment(String comment) throws StaxNavException;
+
+ abstract void writeCData(String cdata) throws StaxNavException;
+
+ abstract void end();
+
+ XMLStreamWriter writer;
+ XmlStreamingFormatter formatter;
+ private List<StreamClosure> closures;
+
+ Element(XMLStreamWriter writer, XmlStreamingFormatter formatter)
+ {
+ this(writer, formatter, null);
+ }
+
+ Element(XMLStreamWriter writer, XmlStreamingFormatter formatter,
List<StreamClosure> closures)
+ {
+ this.writer = writer;
+ this.formatter = formatter;
+ this.closures = closures;
+ }
+
+ void apply(int event, StreamClosure closure) throws StaxNavException
+ {
+ try
+ {
+ formatter.before(writer, event);
+ closure.execute(writer);
+ formatter.after(writer, event);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(e);
+ }
+ }
+ }
+
+ private static class RootElement extends Element
+ {
+ private String encoding;
+ private String version;
+ private Element element;
+ private boolean started;
+
+ RootElement(XMLStreamWriter writer, XmlStreamingFormatter formatter, String
encoding, String version)
+ {
+ super(writer, formatter);
+ this.encoding = encoding;
+ this.version = version;
+ }
+
+ public void writeAttribute(String name, String value) throws StaxNavException
+ {
+ get().writeAttribute(name, value);
+ }
+
+ public <N> void writeAttribute(QName name, String value) throws
StaxNavException
+ {
+ get().writeAttribute(name, value);
+ }
+
+ public <N> void writeStartElement(Naming<N> naming, N name) throws
StaxNavException
+ {
+ get().writeStartElement(naming, name);
+ started = true;
+ }
+
+ public void writeContent(String content) throws StaxNavException
+ {
+ get().writeContent(content);
+ }
+
+ public void writeNamespace(String prefix, String uri) throws StaxNavException
+ {
+ get().writeNamespace(prefix, uri);
+ }
+
+ public void writeDefaultNamespace(String uri) throws StaxNavException
+ {
+ get().writeDefaultNamespace(uri);
+ }
+
+ public void writeComment(String comment) throws StaxNavException
+ {
+ get().writeComment(comment);
+ }
+
+ public void writeCData(String cdata) throws StaxNavException
+ {
+ get().writeCData(cdata);
+ }
+
+ public void end()
+ {
+ if (started)
+ {
+ get().end();
+ }
+ endDocument();
+ }
+
+ private Element get()
+ {
+ if (element == null)
+ {
+ startDocument();
+ element = new StreamElement(writer, formatter);
+ }
+ return element;
+ }
+
+ private void startDocument() throws StaxNavException
+ {
+ apply(START_DOCUMENT, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ if (encoding == null && version == null)
+ {
+ writer.writeStartDocument();
+ }
+ else if (encoding == null)
+ {
+ writer.writeStartDocument(version);
+ }
+ else
+ {
+ writer.writeStartDocument(encoding, version);
+ }
+ }
+ });
+ }
+
+ private void endDocument() throws StaxNavException
+ {
+ try
+ {
+ apply(END_DOCUMENT, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeEndDocument();
+ }
+ });
+
+ writer.flush();
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(e);
+ }
+ finally
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (XMLStreamException e)
+ {
+ }
+ }
+ }
+ }
+
+ private static class StreamElement extends Element
+ {
+ StreamElement(XMLStreamWriter writer, XmlStreamingFormatter formatter)
+ {
+ super(writer, formatter);
+ }
+
+ public void writeAttribute(final String name, final String value) throws
StaxNavException
+ {
+ apply(ATTRIBUTE, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeAttribute(name, value);
+ }
+ });
+ }
+
+ public <N> void writeAttribute(QName name, final String value) throws
StaxNavException
+ {
+ final String prefix = name.getPrefix();
+ final String uri = name.getNamespaceURI();
+ final String localPart = name.getLocalPart();
+
+ apply(ATTRIBUTE, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ if (uri == null || XMLConstants.NULL_NS_URI.equals(uri))
+ {
+ writer.writeAttribute(localPart, value);
+ }
+ else if (prefix == null || XMLConstants.DEFAULT_NS_PREFIX.equals(prefix))
+ {
+ writer.writeAttribute(uri, localPart, value);
+ }
+ else
+ {
+ writer.writeAttribute(prefix, uri, localPart, value);
+ }
+ }
+ });
+ }
+
+ public <N> void writeStartElement(Naming<N> naming, N name) throws
StaxNavException
+ {
+ final String prefix = naming.getPrefix(name);
+ final String uri = naming.getURI(name);
+ final String localPart = naming.getLocalPart(name);
+
+ apply(START_ELEMENT, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ if (uri == null || XMLConstants.NULL_NS_URI.equals(uri))
+ {
+ writer.writeStartElement(localPart);
+ }
+ else if (prefix == null || XMLConstants.DEFAULT_NS_PREFIX.equals(prefix))
+ {
+ writer.writeStartElement(uri, localPart);
+ }
+ else
+ {
+ writer.writeStartElement(prefix, localPart, uri);
+ }
+ }
+ });
+ }
+
+ public void writeContent(final String content) throws StaxNavException
+ {
+ apply(CHARACTERS, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeCharacters(content);
+ }
+ });
+ }
+
+ public void writeNamespace(final String prefix, final String uri) throws
StaxNavException
+ {
+ apply(NAMESPACE, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeNamespace(prefix, uri);
+ }
+ });
+ }
+
+ public void writeDefaultNamespace(final String uri) throws StaxNavException
+ {
+ apply(NAMESPACE, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeDefaultNamespace(uri);
+ }
+ });
+ }
+
+ public void writeComment(final String comment) throws StaxNavException
+ {
+ apply(COMMENT, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeComment(comment);
+ }
+ });
+ }
+
+ public void writeCData(final String cdata) throws StaxNavException
+ {
+ apply(CDATA, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeCData(cdata);
+ }
+ });
+ }
+
+ public void end()
+ {
+ apply(END_ELEMENT, new StreamClosure()
+ {
+ public void execute(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeEndElement();
+ }
+ });
+ }
+ }
+
+ private static interface StreamClosure
+ {
+ void execute(XMLStreamWriter writer) throws XMLStreamException;
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterUtils.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterUtils.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/StaxWriterUtils.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer;
+
+import org.gatein.common.xml.stax.writer.builder.StaxFormatterBuilder;
+import org.gatein.common.xml.stax.writer.builder.StaxFormatterBuilderImpl;
+import org.gatein.common.xml.stax.writer.builder.StaxWriterBuilder;
+import org.gatein.common.xml.stax.writer.builder.StaxWriterBuilderImpl;
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+import org.staxnav.EnumElement;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+
+import javax.xml.namespace.QName;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class StaxWriterUtils
+{
+ public static <N> StaxWriter<N> createWriter(Naming<N> naming,
OutputStream outputStream) throws StaxNavException
+ {
+ return buildDefaultWriter().withOutputStream(outputStream).build(naming);
+ }
+
+ public static StaxWriter<String> createWriter(OutputStream outputStream) throws
StaxNavException
+ {
+ return createWriter(new Naming.Local(), outputStream);
+ }
+
+ public static StaxWriter<QName> createQualifiedWriter(OutputStream outputStream)
throws StaxNavException
+ {
+ return createWriter(new Naming.Qualified(), outputStream);
+ }
+
+ public static <E extends Enum<E> & EnumElement<E>>
StaxWriter<E> createWriter(Class<E> enumeratedClass,
+
OutputStream outputStream) throws StaxNavException
+ {
+ Naming<E> naming;
+ if (EnumElement.class.isAssignableFrom(enumeratedClass))
+ {
+ naming = new Naming.Enumerated.Mapped<E>(enumeratedClass, null);
+ }
+ else
+ {
+ naming = new Naming.Enumerated.Simple<E>(enumeratedClass, null);
+ }
+
+ return createWriter(naming, outputStream);
+ }
+
+ public static <N> StaxWriter<N> createWriter(Naming<N> naming,
Writer writer) throws StaxNavException
+ {
+ return buildDefaultWriter().withWriter(writer).build(naming);
+ }
+
+ public static StaxWriter<String> createWriter(Writer writer) throws
StaxNavException
+ {
+ return createWriter(new Naming.Local(), writer);
+ }
+
+ public static StaxWriter<QName> createQualifiedWriter(Writer writer) throws
StaxNavException
+ {
+ return createWriter(new Naming.Qualified(), writer);
+ }
+
+ public static <E extends Enum<E> & EnumElement<E>>
StaxWriter<E> createWriter(Class<E> enumeratedClass,
+ Writer
writer) throws StaxNavException
+ {
+ Naming<E> naming;
+ if (EnumElement.class.isAssignableFrom(enumeratedClass))
+ {
+ naming = new Naming.Enumerated.Mapped<E>(enumeratedClass, null);
+ }
+ else
+ {
+ naming = new Naming.Enumerated.Simple<E>(enumeratedClass, null);
+ }
+
+ return createWriter(naming, writer);
+ }
+
+ public static StaxWriterBuilder buildWriter()
+ {
+ return new StaxWriterBuilderImpl();
+ }
+
+ public static XmlStreamingFormatter createFormatter()
+ {
+ return buildFormatter().withNewline(DEFAULT_NEWLINE)
+ .ofIndentSize(DEFAULT_INDENT_SIZE).withIndentCharacter(DEFAULT_INDENT_CHAR)
+ .build();
+ }
+
+ public static XmlStreamingFormatter createFormatter(int indentSize)
+ {
+ return buildFormatter().withNewline(DEFAULT_NEWLINE)
+ .ofIndentSize(indentSize).withIndentCharacter(DEFAULT_INDENT_CHAR)
+ .build();
+ }
+
+ public static StaxFormatterBuilder buildFormatter()
+ {
+ return new StaxFormatterBuilderImpl();
+ }
+
+ public static <N> void writeOptionalElement(StaxWriter<N> writer, N
element, String content)
+ {
+ if (content == null) return;
+
+ writer.writeElement(element, content);
+ }
+
+ public static <N, V> void writeOptionalElement(StaxWriter<N> writer, N
element, WritableValueType<V> valueType, V value)
+ {
+ if (value == null) return;
+
+ writer.writeElement(element, valueType, value);
+ }
+
+ public static <N> void writeOptionalContent(StaxWriter<N> writer, N
element, String content)
+ {
+ writer.writeStartElement(element);
+ if (content != null)
+ {
+ writer.writeContent(content);
+ }
+ writer.writeEndElement();
+ }
+
+ public static <N, V> void writeOptionalContent(StaxWriter<N> writer, N
element, WritableValueType<V> valueType, V value)
+ {
+ writer.writeStartElement(element);
+ if (value != null)
+ {
+ writer.writeContent(valueType, value);
+ }
+ writer.writeEndElement();
+ }
+
+ private static StaxWriterBuilder buildDefaultWriter()
+ {
+ return buildWriter().withEncoding("UTF-8").withVersion("1.0")
+ .withPropertyIfSupported("com.ctc.wstx.outputEscapeCr",
Boolean.FALSE)
+ .withFormatting(createFormatter());
+ }
+
+
+
+ private static final int DEFAULT_INDENT_SIZE = 3;
+ private static final char DEFAULT_INDENT_CHAR = ' ';
+ private static final String DEFAULT_NEWLINE;
+
+ static
+ {
+ String newline = null;
+ try
+ {
+ newline = System.getProperty("line.separator");
+ }
+ catch (Throwable ignored)
+ {
+ }
+ if (newline == null) newline = "\n";
+
+ DEFAULT_NEWLINE = newline;
+ }
+
+ private StaxWriterUtils(){}
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueType.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueType.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueType.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer;
+
+import org.staxnav.StaxNavException;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public interface WritableValueType<V>
+{
+ String format(V value) throws StaxNavException;
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueTypes.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueTypes.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/WritableValueTypes.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer;
+
+import org.staxnav.StaxNavException;
+
+import javax.xml.bind.DatatypeConverter;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public abstract class WritableValueTypes
+{
+ /**
+ * Returns a value type for an enum class.
+ *
+ * @param <E> the enum parameter type
+ * @return the corresponding value type
+ */
+ public static <E extends Enum<E>> WritableValueType<E>
getEnumType()
+ {
+ return new EnumType<E>();
+ }
+
+ public static final WritableValueType<String> STRING = new
WritableValueType<String>()
+ {
+ @Override
+ public String format(String value) throws StaxNavException
+ {
+ return value;
+ }
+ };
+
+ public static final WritableValueType<String> TRIMMED_STRING = new
WritableValueType<String>()
+ {
+ @Override
+ public String format(String value) throws StaxNavException
+ {
+ return value.trim();
+ }
+ };
+
+ public static final WritableValueType<Boolean> BOOLEAN = new
WritableValueType<Boolean>()
+ {
+ @Override
+ public String format(Boolean value) throws StaxNavException
+ {
+ return value.toString();
+ }
+ };
+
+ public static final WritableValueType<Integer> INTEGER = new
WritableValueType<Integer>()
+ {
+ @Override
+ public String format(Integer value) throws StaxNavException
+ {
+ return value.toString();
+ }
+ };
+
+ public static final WritableValueType<Date> DATE = new
WritableValueType<Date>()
+ {
+ @Override
+ public String format(Date value) throws StaxNavException
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(value);
+ return DatatypeConverter.printDate(cal);
+ }
+ };
+
+ public static final WritableValueType<Date> DATE_TIME = new
WritableValueType<Date>()
+ {
+
+ @Override
+ public String format(Date value) throws StaxNavException
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(value);
+ return DatatypeConverter.printDateTime(cal);
+ }
+ };
+
+ protected static class EnumType<E extends Enum<E>> implements
WritableValueType<E>
+ {
+ @Override
+ public String format(E value) throws StaxNavException
+ {
+ return value.name();
+ }
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilder.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilder.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilder.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.builder;
+
+
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public interface StaxFormatterBuilder
+{
+ StaxFormatterBuilder withIndentCharacter(char indentCharacter);
+
+ StaxFormatterBuilder ofIndentSize(int indentSize);
+
+ StaxFormatterBuilder withNewline(String newline);
+
+ XmlStreamingFormatter build() throws IllegalStateException;
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilderImpl.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilderImpl.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxFormatterBuilderImpl.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.builder;
+
+
+import org.gatein.common.xml.stax.writer.formatting.SimpleFormatter;
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class StaxFormatterBuilderImpl implements StaxFormatterBuilder
+{
+ private Character indentCharacter;
+ private Integer indentSize;
+ private String newline;
+
+ public StaxFormatterBuilder withIndentCharacter(char indentCharacter)
+ {
+ this.indentCharacter = indentCharacter;
+ return this;
+ }
+
+ public StaxFormatterBuilder ofIndentSize(int indentSize)
+ {
+ this.indentSize = indentSize;
+ return this;
+ }
+
+ public StaxFormatterBuilder withNewline(String newline)
+ {
+ this.newline = newline;
+ return this;
+ }
+
+ public XmlStreamingFormatter build()
+ {
+ if (indentCharacter == null) throw new IllegalStateException("indent character
is required value for this builder.");
+ if (indentSize == null) throw new IllegalArgumentException("indent size is a
required value for this builder.");
+ if (newline == null) throw new IllegalArgumentException("newline is a required
value for this builder.");
+
+ return new SimpleFormatter(indentCharacter, indentSize, newline);
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilder.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilder.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilder.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.builder;
+
+
+import org.gatein.common.xml.stax.writer.StaxWriter;
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public interface StaxWriterBuilder
+{
+ StaxWriterBuilder withProperty(String name, Object value);
+
+ StaxWriterBuilder withPropertyIfSupported(String name, Object value);
+
+ StaxWriterBuilder withEncoding(String encoding);
+
+ StaxWriterBuilder withVersion(String version);
+
+ StaxWriterBuilder withFormatting(XmlStreamingFormatter formatter);
+
+ StaxWriterBuilder withOutputStream(OutputStream outputStream);
+
+ StaxWriterBuilder withOutputStream(OutputStream outputStream, String encoding);
+
+ StaxWriterBuilder withWriter(Writer writer);
+
+ StaxWriterBuilder withResult(Result result);
+
+ StaxWriterBuilder withXmlStreamWriter(XMLStreamWriter writer);
+
+ <N> StaxWriter<N> build(Naming<N> naming) throws StaxNavException,
IllegalStateException;
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilderImpl.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilderImpl.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/builder/StaxWriterBuilderImpl.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,224 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.builder;
+
+import org.gatein.common.xml.stax.writer.StaxWriter;
+import org.gatein.common.xml.stax.writer.StaxWriterImpl;
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavException;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class StaxWriterBuilderImpl implements StaxWriterBuilder
+{
+ private XMLStreamWriter writer;
+ private Object output;
+ private String outputEncoding;
+ private String version;
+ private String encoding;
+
+ private XmlStreamingFormatter formatter;
+
+ private Map<String, Object> properties = new HashMap<String, Object>();
+ private Map<String, Object> supportedProperties = new HashMap<String,
Object>();
+
+ public StaxWriterBuilder withProperty(String name, Object value)
+ {
+ if (name == null) throw new IllegalArgumentException("name is null");
+ if (value == null) throw new IllegalArgumentException("value is null");
+
+ properties.put(name, value);
+ return this;
+ }
+
+ public StaxWriterBuilder withPropertyIfSupported(String name, Object value)
+ {
+ if (name == null) throw new IllegalArgumentException("name is null");
+ if (value == null) throw new IllegalArgumentException("value is null");
+
+ supportedProperties.put(name, value);
+ return this;
+ }
+
+ public StaxWriterBuilder withOutputStream(OutputStream outputStream)
+ {
+ if (outputStream == null) throw new IllegalArgumentException("outputStream is
null");
+
+ output = outputStream;
+ return this;
+ }
+
+ public StaxWriterBuilder withOutputStream(OutputStream outputStream, String encoding)
+ {
+ if (outputStream == null) throw new IllegalArgumentException("outputStream is
null");
+ if (encoding == null) throw new IllegalArgumentException("encoding is
null");
+
+ output = outputStream;
+ outputEncoding = encoding;
+ return this;
+ }
+
+ public StaxWriterBuilder withWriter(Writer writer)
+ {
+ if (writer == null) throw new IllegalArgumentException("writer is
null");
+
+ this.output = writer;
+ return this;
+ }
+
+ public StaxWriterBuilder withResult(Result result)
+ {
+ if (result == null) throw new IllegalArgumentException("result is
null");
+
+ output = result;
+ return this;
+ }
+
+ public StaxWriterBuilder withXmlStreamWriter(XMLStreamWriter writer)
+ {
+ if (writer == null) throw new IllegalArgumentException("writer is
null");
+
+ this.writer = writer;
+ return this;
+ }
+
+ public StaxWriterBuilder withEncoding(String encoding)
+ {
+ if (encoding == null) throw new IllegalArgumentException("encoding is
null");
+
+ this.encoding = encoding;
+ return this;
+ }
+
+ public StaxWriterBuilder withVersion(String version)
+ {
+ if (version == null) throw new IllegalArgumentException("version is
null");
+
+ this.version = version;
+ return this;
+ }
+
+ public StaxWriterBuilder withFormatting(XmlStreamingFormatter formatter)
+ {
+ if (formatter == null) throw new IllegalArgumentException("formatter is
null");
+
+ this.formatter = formatter;
+ return this;
+ }
+
+ public <N> StaxWriter<N> build(Naming<N> naming) throws
StaxNavException, IllegalStateException
+ {
+ if (naming == null) throw new IllegalArgumentException("naming is
null");
+
+ if (writer == null && output == null)
+ throw new IllegalStateException("Cannot build stax writer. Try calling
withOutputStream/withWriter or pass in own XMLStreamWriter.");
+
+ if (writer == null)
+ {
+ //TODO: Create solution to properly cache XMLOutputFactory
+ XMLOutputFactory factory = XMLOutputFactory.newInstance();
+
+ // Set properties
+ for (Map.Entry<String, Object> entry : properties.entrySet())
+ {
+ factory.setProperty(entry.getKey(), entry.getValue());
+ }
+
+ // Set properties if supported
+ for (Map.Entry<String, Object> entry : supportedProperties.entrySet())
+ {
+ String name = entry.getKey();
+ if (factory.isPropertySupported(name))
+ {
+ factory.setProperty(name, entry.getValue());
+ }
+ }
+
+ if (output instanceof OutputStream)
+ {
+ if (outputEncoding == null)
+ {
+ try
+ {
+ writer = factory.createXMLStreamWriter((OutputStream) output,
outputEncoding);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(e);
+ }
+ }
+ else
+ {
+ try
+ {
+ writer = factory.createXMLStreamWriter((OutputStream) output);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(null, "Exception creating
XMLStreamWriter with OutputStream: " + output, e);
+ }
+ }
+ }
+ else if (output instanceof Writer)
+ {
+ try
+ {
+ writer = factory.createXMLStreamWriter((Writer) output);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(null, "Exception creating XMLStreamWriter
with Writer: " + output, e);
+ }
+ }
+ else if (output instanceof Result)
+ {
+ try
+ {
+ writer = factory.createXMLStreamWriter((Result) output);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new StaxNavException(null, "Exception creating XMLStreamWriter
with Result: " + output, e);
+ }
+ }
+ else
+ {
+ throw new IllegalStateException("Unknown output: " + output); //
should never happen...
+ }
+ }
+
+ return new StaxWriterImpl<N>(naming, writer, formatter, encoding, version);
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/NoOpFormatter.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/NoOpFormatter.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/NoOpFormatter.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.formatting;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class NoOpFormatter implements XmlStreamingFormatter
+{
+ @Override
+ public void before(XMLStreamWriter writer, int event) throws XMLStreamException
+ {
+ // No-op
+ }
+
+ @Override
+ public void after(XMLStreamWriter writer, int event) throws XMLStreamException
+ {
+ // No-op
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/SimpleFormatter.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/SimpleFormatter.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/SimpleFormatter.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.formatting;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public class SimpleFormatter implements XmlStreamingFormatter
+{
+
+ public static final int DEFAULT_INDENT_SIZE = 3;
+ public static final char DEFAULT_INDENT_CHAR = ' ';
+ public static final String DEFAULT_NEWLINE;
+
+ static
+ {
+ String newline = null;
+ try
+ {
+ newline = System.getProperty("line.separator");
+ }
+ catch (Throwable ignored)
+ {
+ }
+ if (newline == null) newline = "\n";
+
+ DEFAULT_NEWLINE = newline;
+ }
+
+ private String indentSequence;
+ private String newline;
+ private int depth = 0;
+
+ private int previousEvent;
+
+ public SimpleFormatter()
+ {
+ this(DEFAULT_INDENT_CHAR, DEFAULT_INDENT_SIZE, DEFAULT_NEWLINE);
+ }
+
+ public SimpleFormatter(char indentCharacter, int indentSize, String newline)
+ {
+ if (newline == null) throw new IllegalArgumentException("newline cannot be
null");
+ this.newline = newline;
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < indentSize; i++)
+ {
+ sb.append(indentCharacter);
+ }
+ indentSequence = sb.toString();
+ }
+
+ public void before(XMLStreamWriter writer, int event) throws XMLStreamException
+ {
+ switch (event)
+ {
+ case START_ELEMENT:
+ depth++;
+ nl(writer);
+ indent(writer);
+ break;
+ case END_ELEMENT:
+ if (previousEvent == END_ELEMENT)
+ {
+ nl(writer);
+ indent(writer);
+ }
+ depth--;
+ }
+ }
+
+ public void after(XMLStreamWriter writer, int event) throws XMLStreamException
+ {
+ previousEvent = event;
+ }
+
+ private void nl(XMLStreamWriter writer) throws XMLStreamException
+ {
+ writer.writeCharacters(newline);
+ }
+
+ private void indent(XMLStreamWriter writer) throws XMLStreamException
+ {
+ for (int i = 0; i < depth - 1; i++)
+ {
+ writer.writeCharacters(indentSequence);
+ }
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/XmlStreamingFormatter.java
===================================================================
---
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/XmlStreamingFormatter.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/main/java/org/gatein/common/xml/stax/writer/formatting/XmlStreamingFormatter.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax.writer.formatting;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public interface XmlStreamingFormatter extends XMLStreamConstants
+{
+ void before(XMLStreamWriter writer, int event) throws XMLStreamException;
+
+ void after(XMLStreamWriter writer, int event) throws XMLStreamException;
+}
Added:
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/AbstractStaxWriterTest.java
===================================================================
---
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/AbstractStaxWriterTest.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/AbstractStaxWriterTest.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,357 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax;
+
+import junit.framework.TestCase;
+import org.gatein.common.xml.stax.writer.StaxWriter;
+import org.gatein.common.xml.stax.writer.StaxWriterImpl;
+import org.gatein.common.xml.stax.writer.WritableValueType;
+import org.gatein.common.xml.stax.writer.formatting.XmlStreamingFormatter;
+import org.mockito.InOrder;
+import org.staxnav.Naming;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamWriter;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
+ * @version $Revision$
+ */
+public abstract class AbstractStaxWriterTest<N> extends TestCase
+{
+ static final String ENCODING = "UTF-8";
+ static final String VERSION = "1.0";
+
+ private Naming<N> naming;
+ protected XMLStreamWriter stream;
+ protected XmlStreamingFormatter formatter;
+ protected StaxWriter<N> writer;
+
+ public abstract Naming<N> getNaming();
+
+ @Override
+ public void setUp() throws Exception
+ {
+ naming = getNaming();
+ formatter = mock(XmlStreamingFormatter.class);
+ stream = mock(XMLStreamWriter.class);
+ writer = new StaxWriterImpl<N>(naming, stream, formatter, ENCODING,
VERSION);
+ }
+
+ protected N createName(String localPart)
+ {
+ return naming.getName(null, null, localPart);
+ }
+
+ public void testEncodingAndVersion() throws Exception
+ {
+ String encoding = "UTF-8";
+ String version = "1.0";
+ StaxWriter<N> writer = new StaxWriterImpl<N>(naming, stream, formatter,
encoding, version);
+ writer.writeElement(createName("foo"), "blah");
+
+ verify(stream).writeStartDocument(encoding, version);
+
+ reset(stream);
+ encoding = "encoding";
+ version = "version";
+ writer = new StaxWriterImpl<N>(naming, stream, formatter, encoding,
version);
+ writer.writeElement(createName("foo"), "blah");
+
+ verify(stream).writeStartDocument(encoding, version);
+ }
+
+ public void testEncoding() throws Exception
+ {
+ String encoding = "ISO-8859-1";
+ StaxWriter<N> writer = new StaxWriterImpl<N>(naming, stream, formatter,
encoding, null);
+ writer.writeElement(createName("foo"), "blah");
+
+ verify(stream).writeStartDocument(encoding, null);
+ }
+
+ public void testNoEncoding() throws Exception
+ {
+ StaxWriter<N> writer = new StaxWriterImpl<N>(naming, stream,
formatter);
+ writer.writeElement(createName("foo"), "blah");
+
+ verify(stream).writeStartDocument();
+ }
+
+ public void testStartDocument() throws Exception
+ {
+ writer.writeStartElement(createName("foo"));
+ writer.writeComment("some comment");
+ writer.writeCData("some cdata < & ...");
+
+ verify(stream, times(1)).writeStartDocument(ENCODING, VERSION);
+
+ }
+
+ public void testWriteStartElement() throws Exception
+ {
+ writer.writeStartElement(createName("foo"));
+ verify(stream).writeStartElement("foo");
+ }
+
+ public void testWriteAttribute() throws Exception
+ {
+
writer.writeStartElement(createName("foo")).writeAttribute("name",
"value");
+
+ verify(stream).writeAttribute("name", "value");
+ }
+
+ public void testWriteQNameAttribute() throws Exception
+ {
+ writer.writeStartElement(createName("foo"))
+ .writeAttribute(new QName("uri", "local", "pre"),
"value")
+ .writeAttribute(new QName("uri", "local"),
"value");
+
+ verify(stream).writeAttribute("pre", "uri", "local",
"value");
+ verify(stream).writeAttribute("uri", "local",
"value");
+ }
+
+ public void testWriteElement() throws Exception
+ {
+ writer.writeElement(createName("foo"), "content");
+
+ verify(stream).writeStartElement("foo");
+ verify(stream).writeCharacters("content");
+ verify(stream).writeEndElement();
+ }
+
+ public void testWriteContent() throws Exception
+ {
+
+
writer.writeStartElement(createName("foo")).writeContent("blah");
+ verify(stream).writeCharacters("blah");
+
+ WritableValueType<String> vt = new WritableValueType<String>()
+ {
+ @Override
+ public String format(String value)
+ {
+ return "some value";
+ }
+ };
+
+ writer.writeStartElement(createName("bar")).writeContent(vt,
"content");
+ verify(stream).writeCharacters("some value");
+ }
+
+ public void testWriteNullContent() throws Exception
+ {
+ try
+ {
+ writer.writeContent(null);
+ fail("IllegalArgumentException expected to be thrown");
+ }
+ catch (IllegalArgumentException e){}
+ }
+
+ public void testNamespace() throws Exception
+ {
+
writer.writeStartElement(createName("foo")).writeNamespace("xsi",
XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
+
+ verify(stream).writeNamespace("xsi",
XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
+ }
+
+ public void testDefaultNamespace() throws Exception
+ {
+ String namespace = "http://www.example.com/ns/mynamespace";
+
+
writer.writeStartElement(createName("foo")).writeDefaultNamespace(namespace);
+
+ verify(stream).writeDefaultNamespace(namespace);
+ }
+
+ public void testComment() throws Exception
+ {
+ writer.writeComment("Some comment");
+ writer.writeStartElement(createName("foo"));
+
+ verify(stream, times(1)).writeStartDocument(ENCODING, VERSION);
+ verify(stream).writeComment("Some comment");
+ }
+
+ public void testCData() throws Exception
+ {
+ String cdata = "Some cdata stuff here < & \" ";
+ writer.writeCData(cdata);
+ writer.writeStartElement(createName("foo"));
+
+ verify(stream).writeStartDocument(ENCODING, VERSION);
+ verify(stream).writeCData(cdata);
+ }
+
+ public void testFinish() throws Exception
+ {
+ writer.writeStartElement(createName("foo")).finish();
+
+ verify(stream).flush();
+ verify(stream).close();
+ }
+
+ public void testFinishNoElements() throws Exception
+ {
+ writer.writeComment("comment");
+ writer.finish();
+ verify(stream).flush();
+ verify(stream).close();
+ }
+
+ public void testEndElementOnFinish() throws Exception
+ {
+ writer.writeStartElement(createName("foo")).
+ writeStartElement(createName("bar")).
+ writeElement(createName("foobar"), "stuff");
+
+ // Even though we never explicitly call endElement for the first two start
elements, finish will do that for us.
+ writer.finish();
+
+ verify(stream).writeStartElement("foo");
+ verify(stream).writeStartElement("bar");
+ verify(stream).writeStartElement("foobar");
+ verify(stream).writeCharacters("stuff");
+ verify(stream, times(3)).writeEndElement();
+ }
+
+ public void testFormatter() throws Exception
+ {
+ InOrder order = inOrder(formatter, stream);
+
+ // Start element
+ writer.writeStartElement(createName("foo"));
+ verifyFormatter(order, XMLStreamConstants.START_DOCUMENT, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ // first start element also writes the document
+ order.verify(stream).writeStartDocument(ENCODING, VERSION);
+ }
+ });
+ verifyFormatter(order, XMLStreamConstants.START_ELEMENT, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeStartElement("foo");
+ }
+ });
+
+ // Namespace
+ writer.writeNamespace("prefix", "uri");
+ verifyFormatter(order, XMLStreamConstants.NAMESPACE, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeNamespace("prefix", "uri");
+ }
+ });
+
+ // Default namespace
+ writer.writeDefaultNamespace("uri");
+ verifyFormatter(order, XMLStreamConstants.NAMESPACE, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeDefaultNamespace("uri");
+ }
+ });
+
+ // Attribute
+ writer.writeAttribute("name", "value");
+ verifyFormatter(order, XMLStreamConstants.ATTRIBUTE, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeAttribute("name", "value");
+ }
+ });
+
+ // Comment
+ writer.writeComment("comment");
+ verifyFormatter(order, XMLStreamConstants.COMMENT, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeComment("comment");
+ }
+ });
+
+ // CData
+ writer.writeCData("cdata");
+ verifyFormatter(order, XMLStreamConstants.CDATA, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeCData("cdata");
+ }
+ });
+
+ // Content
+ writer.writeContent("content");
+ verifyFormatter(order, XMLStreamConstants.CHARACTERS, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeCharacters("content");
+ }
+ });
+
+ // End element
+ writer.writeEndElement();
+ verifyFormatter(order, XMLStreamConstants.END_ELEMENT, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeEndElement();
+ }
+ });
+
+ // End document
+ writer.finish();
+ verifyFormatter(order, XMLStreamConstants.END_DOCUMENT, new VerifyClosure()
+ {
+ public void verify(InOrder order) throws Exception
+ {
+ order.verify(stream).writeEndDocument();
+ }
+ });
+ }
+
+ protected void verifyFormatter(InOrder order, int event, VerifyClosure closure) throws
Exception
+ {
+ order.verify(formatter).before(stream, event);
+ closure.verify(order);
+ order.verify(formatter).after(stream, event);
+ }
+
+ private static interface VerifyClosure
+ {
+ void verify(InOrder order) throws Exception;
+ }
+}
Added:
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/LocalStaxWriterTest.java
===================================================================
---
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/LocalStaxWriterTest.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/LocalStaxWriterTest.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax;
+
+import org.staxnav.Naming;
+
+public class LocalStaxWriterTest extends AbstractStaxWriterTest<String>
+{
+ @Override
+ public Naming<String> getNaming()
+ {
+ return new Naming.Local();
+ }
+}
\ No newline at end of file
Added:
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/QualifiedStaxWriterTest.java
===================================================================
---
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/QualifiedStaxWriterTest.java
(rev 0)
+++
portal/branches/gatein-management/component/common/src/test/java/org/gatein/common/xml/stax/QualifiedStaxWriterTest.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.common.xml.stax;
+
+import org.mockito.Mockito;
+import org.staxnav.Naming;
+
+import javax.xml.namespace.QName;
+
+public class QualifiedStaxWriterTest extends AbstractStaxWriterTest<QName>
+{
+ @Override
+ public Naming<QName> getNaming()
+ {
+ return new Naming.Qualified();
+ }
+
+ public void testWriteQualifiedStartElement() throws Exception
+ {
+ QName bar = new QName("uri", "pre", "bar");
+
+ writer.writeStartElement(bar);
+ Mockito.verify(stream).writeStartElement(bar.getPrefix(), bar.getLocalPart(),
bar.getNamespaceURI());
+
+ QName foobar = new
QName("http://www.gatein.org/xml/ns/gatein_objects_1_0", "foobar");
+ writer.writeStartElement(foobar);
+ Mockito.verify(stream).writeStartElement(foobar.getNamespaceURI(),
foobar.getLocalPart());
+ }
+}
\ No newline at end of file
Modified: portal/branches/gatein-management/component/portal/pom.xml
===================================================================
--- portal/branches/gatein-management/component/portal/pom.xml 2011-07-29 17:42:53 UTC
(rev 6953)
+++ portal/branches/gatein-management/component/portal/pom.xml 2011-07-29 18:36:01 UTC
(rev 6954)
@@ -79,11 +79,6 @@
</dependency>
<dependency>
- <groupId>org.gatein.management</groupId>
- <artifactId>gatein-management-common</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.picketlink.idm</groupId>
<artifactId>picketlink-idm-core</artifactId>
</dependency>
Modified:
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java
===================================================================
---
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java 2011-07-29
17:42:53 UTC (rev 6953)
+++
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -34,15 +34,13 @@
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PageBody;
import org.exoplatform.portal.config.model.TransientApplicationState;
-import org.exoplatform.portal.pom.data.ComponentData;
-import org.exoplatform.portal.pom.data.ContainerData;
+import org.gatein.common.xml.stax.writer.StaxWriter;
+import org.gatein.common.xml.stax.writer.WritableValueTypes;
import org.exoplatform.portal.pom.data.ModelDataStorage;
import org.exoplatform.portal.pom.spi.gadget.Gadget;
import org.exoplatform.portal.pom.spi.portlet.Portlet;
import org.exoplatform.portal.pom.spi.portlet.PortletBuilder;
import org.exoplatform.portal.pom.spi.portlet.Preference;
-import org.gatein.common.xml.stax.writer.StaxWriter;
-import org.gatein.common.xml.stax.writer.WritableValueTypes;
import org.gatein.management.api.binding.Marshaller;
import org.staxnav.StaxNavigator;
import org.staxnav.ValueType;
@@ -170,7 +168,7 @@
container.setChildren(new ArrayList<ModelObject>());
}
container.getChildren().add(unmarshalContainer(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case PORTLET_APPLICATION:
if (container.getChildren() == null)
@@ -178,7 +176,7 @@
container.setChildren(new ArrayList<ModelObject>());
}
container.getChildren().add(unmarshalPortletApplication(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case GADGET_APPLICATION:
if (container.getChildren() == null)
@@ -186,7 +184,7 @@
container.setChildren(new ArrayList<ModelObject>());
}
container.getChildren().add(unmarshalGadgetApplication(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case UNKNOWN:
throw unknownElement(navigator);
@@ -294,7 +292,7 @@
boolean showInfoBarParsed = false;
- Element current = navigator.getName();
+ Element current = navigator.sibling();
while (current != null)
{
switch (current)
@@ -497,7 +495,7 @@
boolean showInfoBarParsed = false;
- Element current = navigator.getName();
+ Element current = navigator.sibling();
while (current != null)
{
switch (current)
Modified:
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/DelimitedValueType.java
===================================================================
---
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/DelimitedValueType.java 2011-07-29
17:42:53 UTC (rev 6953)
+++
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/DelimitedValueType.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -22,14 +22,11 @@
package org.exoplatform.portal.mop.management.binding.xml;
-import org.exoplatform.portal.pom.config.Utils;
import org.gatein.common.xml.stax.writer.WritableValueType;
+import org.exoplatform.portal.pom.config.Utils;
import org.staxnav.StaxNavException;
import org.staxnav.ValueType;
-import java.util.Arrays;
-import java.util.List;
-
/**
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
* @version $Revision$
Modified:
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/NavigationMarshaller.java
===================================================================
---
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/NavigationMarshaller.java 2011-07-29
17:42:53 UTC (rev 6953)
+++
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/NavigationMarshaller.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -285,7 +285,7 @@
case NODE:
PageNode child = unmarshalNode(navigator.fork());
children.add(child);
- current = navigator.getName();
+ current = navigator.sibling();
break;
case UNKNOWN:
throw unknownElement(navigator);
Modified:
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshaller.java
===================================================================
---
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshaller.java 2011-07-29
17:42:53 UTC (rev 6953)
+++
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshaller.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -188,7 +188,7 @@
page.setChildren(new ArrayList<ModelObject>());
}
page.getChildren().add(unmarshalContainer(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case PORTLET_APPLICATION:
if (page.getChildren() == null)
@@ -196,7 +196,7 @@
page.setChildren(new ArrayList<ModelObject>());
}
page.getChildren().add(unmarshalPortletApplication(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case GADGET_APPLICATION:
if (page.getChildren() == null)
@@ -204,7 +204,7 @@
page.setChildren(new ArrayList<ModelObject>());
}
page.getChildren().add(unmarshalGadgetApplication(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case UNKNOWN:
throw unknownElement(navigator);
Modified:
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java
===================================================================
---
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java 2011-07-29
17:42:53 UTC (rev 6953)
+++
portal/branches/gatein-management/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/SiteLayoutMarshaller.java 2011-07-29
18:36:01 UTC (rev 6954)
@@ -231,7 +231,7 @@
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(unmarshalPortletApplication(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case GADGET_APPLICATION:
if (portalLayout == null)
@@ -239,7 +239,7 @@
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(unmarshalGadgetApplication(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case CONTAINER:
if (portalLayout == null)
@@ -247,7 +247,7 @@
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(unmarshalContainer(navigator.fork()));
- current = navigator.getName();
+ current = navigator.sibling();
break;
case UNKNOWN:
throw unknownElement(navigator);
Modified: portal/branches/gatein-management/packaging/jboss-as5/pkg/pom.xml
===================================================================
--- portal/branches/gatein-management/packaging/jboss-as5/pkg/pom.xml 2011-07-29 17:42:53
UTC (rev 6953)
+++ portal/branches/gatein-management/packaging/jboss-as5/pkg/pom.xml 2011-07-29 18:36:01
UTC (rev 6954)
@@ -369,10 +369,6 @@
</dependency>
<dependency>
<groupId>org.gatein.management</groupId>
- <artifactId>gatein-management-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.management</groupId>
<artifactId>gatein-management-core</artifactId>
</dependency>
<dependency>
Modified: portal/branches/gatein-management/packaging/jboss-as6/pkg/pom.xml
===================================================================
--- portal/branches/gatein-management/packaging/jboss-as6/pkg/pom.xml 2011-07-29 17:42:53
UTC (rev 6953)
+++ portal/branches/gatein-management/packaging/jboss-as6/pkg/pom.xml 2011-07-29 18:36:01
UTC (rev 6954)
@@ -367,10 +367,6 @@
</dependency>
<dependency>
<groupId>org.gatein.management</groupId>
- <artifactId>gatein-management-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.management</groupId>
<artifactId>gatein-management-core</artifactId>
</dependency>
<dependency>
Modified: portal/branches/gatein-management/packaging/jetty/pkg/pom.xml
===================================================================
--- portal/branches/gatein-management/packaging/jetty/pkg/pom.xml 2011-07-29 17:42:53 UTC
(rev 6953)
+++ portal/branches/gatein-management/packaging/jetty/pkg/pom.xml 2011-07-29 18:36:01 UTC
(rev 6954)
@@ -367,10 +367,6 @@
</dependency>
<dependency>
<groupId>org.gatein.management</groupId>
- <artifactId>gatein-management-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.management</groupId>
<artifactId>gatein-management-core</artifactId>
</dependency>
<dependency>
Modified: portal/branches/gatein-management/packaging/tomcat/pkg/pom.xml
===================================================================
--- portal/branches/gatein-management/packaging/tomcat/pkg/pom.xml 2011-07-29 17:42:53 UTC
(rev 6953)
+++ portal/branches/gatein-management/packaging/tomcat/pkg/pom.xml 2011-07-29 18:36:01 UTC
(rev 6954)
@@ -359,10 +359,6 @@
</dependency>
<dependency>
<groupId>org.gatein.management</groupId>
- <artifactId>gatein-management-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.management</groupId>
<artifactId>gatein-management-core</artifactId>
</dependency>
<dependency>
Modified: portal/branches/gatein-management/pom.xml
===================================================================
--- portal/branches/gatein-management/pom.xml 2011-07-29 17:42:53 UTC (rev 6953)
+++ portal/branches/gatein-management/pom.xml 2011-07-29 18:36:01 UTC (rev 6954)
@@ -57,7 +57,7 @@
<javax.servlet.version>2.5</javax.servlet.version>
<version.chromattic>1.1.0-beta6</version.chromattic>
<version.reflext>1.1.0-beta12</version.reflext>
- <org.staxnav.version>0.9.3</org.staxnav.version>
+ <org.staxnav.version>0.9.4</org.staxnav.version>
<jcip.version>1.0</jcip.version>
<!-- ************** -->
@@ -336,11 +336,6 @@
</dependency>
<dependency>
<groupId>org.gatein.management</groupId>
- <artifactId>gatein-management-common</artifactId>
- <version>${org.gatein.mgmt.version}</version>
- </dependency>
- <dependency>
- <groupId>org.gatein.management</groupId>
<artifactId>gatein-management-core</artifactId>
<version>${org.gatein.mgmt.version}</version>
</dependency>