You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/02/03 21:09:37 UTC

svn commit: r1728361 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/ implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/

Author: veithen
Date: Wed Feb  3 20:09:36 2016
New Revision: 1728361

URL: http://svn.apache.org/viewvc?rev=1728361&view=rev
Log:
Deny FOMBuilder direct access to the StAX parser to achieve complete encapsulation in StAXOMBuilder.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMContent.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMText.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java?rev=1728361&r1=1728360&r2=1728361&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java Wed Feb  3 20:09:36 2016
@@ -93,7 +93,7 @@ public class StAXOMBuilder implements Bu
     private static final Log log = LogFactory.getLog(StAXOMBuilder.class);
     
     /** Field parser */
-    protected XMLStreamReader parser;
+    private XMLStreamReader parser;
 
     /** Field omfactory */
     private OMFactoryEx omfactory;
@@ -796,7 +796,6 @@ public class StAXOMBuilder implements Bu
         AxiomElement node = omfactory.createAxiomElement(
                 determineElementType(target, elementLevel, parser.getNamespaceURI(), parser.getLocalName()),
                 parser.getLocalName(), target, this);
-        postProcessElement(node);
         populateOMElement(node);
         return node;
     }
@@ -816,9 +815,6 @@ public class StAXOMBuilder implements Bu
         return AxiomElement.class;
     }
     
-    protected void postProcessElement(OMElement element) {
-    }
-    
     /**
      * Method createOMText.
      *

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java?rev=1728361&r1=1728360&r2=1728361&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java Wed Feb  3 20:09:36 2016
@@ -21,15 +21,12 @@ import java.io.Closeable;
 
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.abdera.model.Content;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
-import org.apache.abdera.model.Text;
 import org.apache.abdera.parser.ParseException;
 import org.apache.abdera.parser.ParserOptions;
 import org.apache.abdera.util.Constants;
 import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.common.builder.StAXOMBuilder;
@@ -51,31 +48,6 @@ public class FOMBuilder extends StAXOMBu
         return parserOptions;
     }
 
-    protected Text.Type getTextType() {
-        Text.Type ttype = Text.Type.TEXT;
-        String type = parser.getAttributeValue(null, LN_TYPE);
-        if (type != null) {
-            ttype = Text.Type.typeFromString(type);
-            if (ttype == null)
-                throw new FOMUnsupportedTextTypeException(type);
-        }
-        return ttype;
-    }
-
-    protected Content.Type getContentType() {
-        Content.Type ctype = Content.Type.TEXT;
-        String type = parser.getAttributeValue(null, LN_TYPE);
-        String src = parser.getAttributeValue(null, LN_SRC);
-        if (type != null) {
-            ctype = Content.Type.typeFromString(type);
-            if (ctype == null)
-                throw new FOMUnsupportedContentTypeException(type);
-        } else if (type == null && src != null) {
-            ctype = Content.Type.MEDIA;
-        }
-        return ctype;
-    }
-
     /**
      * Method next.
      * 
@@ -97,17 +69,6 @@ public class FOMBuilder extends StAXOMBu
         return fomfactory.determineElementType(parent, namespaceURI, localName);
     }
 
-    @Override
-    protected void postProcessElement(OMElement element) {
-        if (element instanceof FOMContent) {
-            Content.Type type = getContentType();
-            ((FOMContent)element).setContentType(type == null ? Content.Type.TEXT : type);
-        } else if (element instanceof FOMText) {
-            Text.Type type = getTextType();
-            ((FOMText)element).setTextType(type == null ? Text.Type.TEXT : type);
-        }
-    }
-
     public <T extends Element> Document<T> getFomDocument() {
         // For compatibility with earlier Abdera versions, force creation of the document element.
         // Note that the only known case where this has a visible effect is when the document is

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMContent.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMContent.java?rev=1728361&r1=1728360&r2=1728361&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMContent.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMContent.java Wed Feb  3 20:09:36 2016
@@ -44,14 +44,26 @@ import org.apache.axiom.util.base64.Base
 
 @SuppressWarnings("unchecked")
 public class FOMContent extends FOMExtensibleElement implements AbderaContent {
-    protected Type type = Type.TEXT;
+    private Type cachedType;
 
     public final Type getContentType() {
-        return type;
+        if (cachedType == null) {
+            cachedType = Content.Type.TEXT;
+            String type = getAttributeValue(TYPE);
+            String src = getAttributeValue(SRC);
+            if (type != null) {
+                cachedType = Content.Type.typeFromString(type);
+                if (cachedType == null)
+                    throw new FOMUnsupportedContentTypeException(type);
+            } else if (type == null && src != null) {
+                cachedType = Content.Type.MEDIA;
+            }
+        }
+        return cachedType;
     }
 
     public Content setContentType(Type type) {
-        this.type = type;
+        this.cachedType = type;
         if (Type.TEXT.equals(type))
             setAttributeValue(TYPE, "text");
         else if (Type.HTML.equals(type))
@@ -85,7 +97,7 @@ public class FOMContent extends FOMExten
                 }
             }
 
-            if (value instanceof Div && !type.equals(Content.Type.XML))
+            if (value instanceof Div && !getContentType().equals(Content.Type.XML))
                 setContentType(Content.Type.XHTML);
             else {
                 if (mtype == null) {
@@ -136,7 +148,7 @@ public class FOMContent extends FOMExten
     }
 
     public DataHandler getDataHandler() {
-        if (!Type.MEDIA.equals(type))
+        if (!Type.MEDIA.equals(getContentType()))
             throw new UnsupportedOperationException(Localizer.get("DATA.HANDLER.NOT.SUPPORTED"));
         MimeType type = getMimeType();
         java.net.URL src = null;
@@ -156,7 +168,7 @@ public class FOMContent extends FOMExten
     }
 
     public Content setDataHandler(DataHandler dataHandler) {
-        if (!Type.MEDIA.equals(type))
+        if (!Type.MEDIA.equals(getContentType()))
             throw new IllegalArgumentException();
         if (dataHandler.getContentType() != null) {
             try {
@@ -171,6 +183,7 @@ public class FOMContent extends FOMExten
 
     public String getValue() {
         String val = null;
+        Type type = getContentType();
         if (Type.TEXT.equals(type)) {
             val = getText();
         } else if (Type.HTML.equals(type)) {
@@ -214,6 +227,7 @@ public class FOMContent extends FOMExten
         if (value != null)
             removeAttribute(SRC);
         if (value != null) {
+            Type type = getContentType();
             if (Type.TEXT.equals(type)) {
                 _removeAllChildren();
                 setText(type, value);
@@ -262,7 +276,7 @@ public class FOMContent extends FOMExten
     }
 
     public String getWrappedValue() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getContentType())) {
             return _getFirstChildWithName(Constants.DIV).toString();
         } else {
             return getText();
@@ -270,7 +284,7 @@ public class FOMContent extends FOMExten
     }
 
     public Content setWrappedValue(String wrappedValue) {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getContentType())) {
             IRI baseUri = null;
             Element element = null;
             try {
@@ -288,7 +302,7 @@ public class FOMContent extends FOMExten
 
     @Override
     public IRI getBaseUri() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getContentType())) {
             Element el = getValueElement();
             if (el != null) {
                 if (el.getAttributeValue(BASE) != null) {
@@ -304,7 +318,7 @@ public class FOMContent extends FOMExten
 
     @Override
     public IRI getResolvedBaseUri() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getContentType())) {
             Element el = getValueElement();
             if (el != null) {
                 if (el.getAttributeValue(BASE) != null) {
@@ -317,7 +331,7 @@ public class FOMContent extends FOMExten
 
     @Override
     public String getLanguage() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getContentType())) {
             Element el = getValueElement();
             if (el.getAttributeValue(LANG) != null)
                 return el.getAttributeValue(LANG);
@@ -328,7 +342,7 @@ public class FOMContent extends FOMExten
     @Override
     public Object clone() {
         FOMContent content = (FOMContent)super.clone();
-        content.type = this.type;
+        content.cachedType = this.cachedType;
         return content;
     }
 

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMText.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMText.java?rev=1728361&r1=1728360&r2=1728361&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMText.java (original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMText.java Wed Feb  3 20:09:36 2016
@@ -34,14 +34,23 @@ import org.apache.axiom.om.OMNode;
 
 @SuppressWarnings("unchecked")
 public class FOMText extends FOMElement implements AbderaText {
-    protected Type type = Type.TEXT;
+    private Type cachedType;
 
     public final Type getTextType() {
-        return type;
+        if (cachedType == null) {
+            cachedType = Text.Type.TEXT;
+            String type = getAttributeValue(TYPE);
+            if (type != null) {
+                cachedType = Text.Type.typeFromString(type);
+                if (cachedType == null)
+                    throw new FOMUnsupportedTextTypeException(type);
+            }
+        }
+        return cachedType;
     }
 
     public Text setTextType(Type type) {
-        this.type = type;
+        this.cachedType = type;
         if (Type.TEXT.equals(type))
             setAttributeValue(TYPE, "text");
         else if (Type.HTML.equals(type))
@@ -71,6 +80,7 @@ public class FOMText extends FOMElement
 
     public String getValue() {
         String val = null;
+        Type type = getTextType();
         if (Type.TEXT.equals(type)) {
             val = getText();
         } else if (Type.HTML.equals(type)) {
@@ -105,6 +115,7 @@ public class FOMText extends FOMElement
 
     public Text setValue(String value) {
         if (value != null) {
+            Type type = getTextType();
             if (Type.TEXT.equals(type)) {
                 setText(type, value);
             } else if (Type.HTML.equals(type)) {
@@ -127,7 +138,7 @@ public class FOMText extends FOMElement
     }
 
     public String getWrappedValue() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getTextType())) {
             return _getFirstChildWithName(Constants.DIV).toString();
         } else {
             return getValue();
@@ -135,7 +146,7 @@ public class FOMText extends FOMElement
     }
 
     public Text setWrappedValue(String wrappedValue) {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getTextType())) {
             IRI baseUri = null;
             Element element = null;
             try {
@@ -154,7 +165,7 @@ public class FOMText extends FOMElement
 
     @Override
     public IRI getBaseUri() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getTextType())) {
             Element el = getValueElement();
             if (el != null) {
                 if (el.getAttributeValue(BASE) != null) {
@@ -170,7 +181,7 @@ public class FOMText extends FOMElement
 
     @Override
     public IRI getResolvedBaseUri() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getTextType())) {
             Element el = getValueElement();
             if (el != null) {
                 if (el.getAttributeValue(BASE) != null) {
@@ -183,7 +194,7 @@ public class FOMText extends FOMElement
 
     @Override
     public String getLanguage() {
-        if (Type.XHTML.equals(type)) {
+        if (Type.XHTML.equals(getTextType())) {
             Element el = getValueElement();
             if (el != null && el.getAttributeValue(LANG) != null)
                 return el.getAttributeValue(LANG);
@@ -194,7 +205,7 @@ public class FOMText extends FOMElement
     @Override
     public Object clone() {
         FOMText text = (FOMText)super.clone();
-        text.type = type;
+        text.cachedType = cachedType;
         return text;
     }