abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r557747 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/model/ parser/src/main/java/org/apache/abdera/parser/stax/
Date Thu, 19 Jul 2007 19:19:10 GMT
Author: jmsnell
Date: Thu Jul 19 12:19:08 2007
New Revision: 557747

URL: http://svn.apache.org/viewvc?view=rev&rev=557747
Log:
One of the mildly annoying bits about the XPath implementation is that the selectSingleNode
selectNodes methods will return Axiom objects when an xpath uses the comment(), 
processing-instruction(), text(), and @attr queries.  While these are not likely to be used
extensively, this change hides the Axiom objects behind an Abdera facade.

e.g. 

instead of 

  OMText text = (OMText)xpath.selectSingleNode("//a:title/text()",entry);

we can do...

  TextValue tv = (TextValue)xpath.selectSingleNode("//a:title/text()",entry);
  

The one downside to this is that for it to work, Axiom requires us to change the value
of the default OMFactory implementation, which could be problematic when using Abdera with
other Axiom based software.  We want to play nice with other software packages, so we won't

register the default automatically.  Instead, call FOMFactory.registerAsDefault() if/when
you're sure you want to use the TextValue class.

Added:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Attribute.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Comment.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ProcessingInstruction.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/TextValue.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMAttribute.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMComment.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMProcessingInstruction.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMTextValue.java
Modified:
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Attribute.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Attribute.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Attribute.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Attribute.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,34 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.model;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.factory.Factory;
+
+public interface Attribute {
+
+  QName getQName();
+  
+  String getText();
+  
+  void setText(String text);
+  
+  Factory getFactory();
+  
+}

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Comment.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Comment.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Comment.java (added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Comment.java Thu
Jul 19 12:19:08 2007
@@ -0,0 +1,33 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.model;
+
+import org.apache.abdera.factory.Factory;
+
+public interface Comment {
+
+  void discard();
+  
+  String getText();
+  
+  void setText(String text);
+  
+  Factory getFactory();
+  
+  <T extends Base>T getParentElement();
+}

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ProcessingInstruction.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ProcessingInstruction.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ProcessingInstruction.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/ProcessingInstruction.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,38 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.model;
+
+import org.apache.abdera.factory.Factory;
+
+public interface ProcessingInstruction {
+
+  void discard();
+  
+  Factory getFactory();
+  
+  <T extends Base>T getParentElement();
+  
+  String getTarget();
+  
+  void setTarget(String target);
+  
+  String getText();
+  
+  void setText(String text);
+  
+}

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/TextValue.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/TextValue.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/TextValue.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/TextValue.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,36 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.model;
+
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+
+public interface TextValue {
+
+  DataHandler getDataHandler();
+  
+  InputStream getInputStream();
+  
+  String getText();
+  
+  <T extends Base>T getParentElement();
+  
+  void discard();
+  
+}

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMAttribute.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMAttribute.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMAttribute.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMAttribute.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,76 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.parser.stax;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Attribute;
+import org.apache.axiom.om.OMAttribute;
+
+public class FOMAttribute 
+  implements Attribute {
+
+  private final OMAttribute attr;
+  
+  protected FOMAttribute(OMAttribute attr) {
+    this.attr = attr;
+  }
+  
+  public QName getQName() {
+    return attr.getQName();
+  }
+  
+  public String getText() {
+    return attr.getAttributeValue();
+  }
+  
+  public void setText(String text) {
+    attr.setAttributeValue(text);
+  }
+  
+  public Factory getFactory() {
+    return (Factory) attr.getOMFactory();
+  }
+
+  @Override
+  public int hashCode() {
+    final int PRIME = 31;
+    int result = 1;
+    result = PRIME * result + ((attr == null) ? 0 : attr.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    final FOMAttribute other = (FOMAttribute) obj;
+    if (attr == null) {
+      if (other.attr != null)
+        return false;
+    } else if (!attr.equals(other.attr))
+      return false;
+    return true;
+  }
+  
+}

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMComment.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMComment.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMComment.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMComment.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,72 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.parser.stax;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Comment;
+import org.apache.abdera.model.Element;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.impl.llom.OMCommentImpl;
+
+public class FOMComment 
+  extends OMCommentImpl 
+  implements Comment {
+
+  public FOMComment(OMContainer arg0, OMFactory arg1) {
+    super(arg0, arg1);
+  }
+
+  public FOMComment(OMContainer arg0, String arg1, OMFactory arg2) {
+    super(arg0, arg1, arg2);
+  }
+  
+  public String getText() {
+    return super.getValue();
+  }
+  
+  public void setText(String text) {
+    super.setValue(text);
+  }
+  
+  @SuppressWarnings("unchecked")
+  public <T extends Base>T getParentElement() {
+    T parent = (T)super.getParent();
+    return (T) ((parent instanceof Element) ? 
+      getWrapped((Element)parent) : parent);
+  } 
+  
+  protected Element getWrapped(Element internal) {
+    if (internal == null) return null;
+    FOMFactory factory = (FOMFactory) getFactory();
+    return factory.getElementWrapper(internal);
+  }
+  
+  public Factory getFactory() {
+    return (Factory) this.factory;
+  }
+
+  public String toString() {
+    java.io.CharArrayWriter w = new java.io.CharArrayWriter();
+    try {
+      super.serialize(w);
+    } catch (Exception e) {}
+    return w.toString();
+  }
+}

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java?view=diff&rev=557747&r1=557746&r2=557747
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
Thu Jul 19 12:19:08 2007
@@ -55,10 +55,14 @@
 import org.apache.abdera.util.Constants;
 import org.apache.abdera.util.MimeTypeHelper;
 import org.apache.abdera.util.Version;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMProcessingInstruction;
+import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 
@@ -69,6 +73,12 @@
   private final ExtensionFactoryMap factoriesMap;
   private final Abdera abdera;
   
+  public static void registerAsDefault() {
+    System.setProperty(
+      OMAbstractFactory.OM_FACTORY_NAME_PROPERTY, 
+      FOMFactory.class.getName());
+  }
+  
   public FOMFactory() {
     this(new Abdera());
   }
@@ -831,4 +841,72 @@
   public String[] listExtensionFactories() {
     return factoriesMap.listExtensionFactories();
   }
+
+  
+  @Override
+  public OMText createOMText(Object arg0, boolean arg1) {
+    return new FOMTextValue(arg0,arg1,this);
+  }
+
+  @Override
+  public OMText createOMText(OMContainer arg0, char[] arg1, int arg2) {
+    return new FOMTextValue(arg0,arg1,arg2,this);
+  }
+
+  @Override
+  public OMText createOMText(OMContainer arg0, QName arg1, int arg2) {
+    return new FOMTextValue(arg0,arg1,arg2,this);
+  }
+
+  @Override
+  public OMText createOMText(OMContainer arg0, QName arg1) {
+    return new FOMTextValue(arg0,arg1,this);
+  }
+
+  @Override
+  public OMText createOMText(OMContainer arg0, String arg1, int arg2) {
+    return new FOMTextValue(arg0,arg1,arg2,this);
+  }
+
+  @Override
+  public OMText createOMText(OMContainer arg0, String arg1, String arg2, boolean arg3) {
+    return new FOMTextValue(arg0,arg1,arg2,arg3,this);
+  }
+
+  @Override
+  public OMText createOMText(OMContainer arg0, String arg1) {
+    return new FOMTextValue(arg0,arg1,this);
+  }
+
+  @Override
+  public OMText createOMText(String arg0, int arg1) {
+    return new FOMTextValue(arg0,arg1,this);
+  }
+
+  @Override
+  public OMText createOMText(String arg0, OMContainer arg1, OMXMLParserWrapper arg2) {
+    return new FOMTextValue(arg0,arg1,arg2,this);
+  }
+
+  @Override
+  public OMText createOMText(String arg0, String arg1, boolean arg2) {
+    return new FOMTextValue(arg0,arg1,arg2,this);
+  }
+
+  @Override
+  public OMText createOMText(String arg0) {
+    return new FOMTextValue(arg0,this);
+  }
+
+  @Override
+  public OMComment createOMComment(OMContainer arg0, String arg1) {
+    return new FOMComment(arg0,arg1,this);
+  }
+
+  @Override
+  public OMProcessingInstruction createOMProcessingInstruction(OMContainer arg0, String arg1,
String arg2) {
+    return new FOMProcessingInstruction(arg0,arg1,arg2,this);
+  }
+  
+  
 }

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMProcessingInstruction.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMProcessingInstruction.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMProcessingInstruction.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMProcessingInstruction.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,72 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.parser.stax;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ProcessingInstruction;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.impl.llom.OMProcessingInstructionImpl;
+
+public class FOMProcessingInstruction 
+  extends OMProcessingInstructionImpl
+  implements ProcessingInstruction {
+
+  public FOMProcessingInstruction(OMContainer arg0, OMFactory arg1) {
+    super(arg0, arg1);
+  }
+
+  public FOMProcessingInstruction(OMContainer arg0, String arg1, String arg2, OMFactory arg3)
{
+    super(arg0, arg1, arg2, arg3);
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T extends Base>T getParentElement() {
+    T parent = (T)super.getParent();
+    return (T) ((parent instanceof Element) ? 
+      getWrapped((Element)parent) : parent);
+  } 
+  
+  protected Element getWrapped(Element internal) {
+    if (internal == null) return null;
+    FOMFactory factory = (FOMFactory) getFactory();
+    return factory.getElementWrapper(internal);
+  }
+  
+  public Factory getFactory() {
+    return (Factory) this.factory;
+  }
+
+  public String getText() {
+    return getValue();
+  }
+
+  public void setText(String text) {
+    setValue(text);
+  }
+
+  public String toString() {
+    java.io.CharArrayWriter w = new java.io.CharArrayWriter();
+    try {
+      super.serialize(w);
+    } catch (Exception e) {}
+    return w.toString();
+  }
+}

Added: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMTextValue.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMTextValue.java?view=auto&rev=557747
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMTextValue.java
(added)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMTextValue.java
Thu Jul 19 12:19:08 2007
@@ -0,0 +1,110 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.parser.stax;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.TextValue;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+
+public class FOMTextValue 
+  extends OMTextImpl
+  implements TextValue {
+
+  public FOMTextValue(Object arg0, boolean arg1, OMFactory arg2) {
+    super(arg0, arg1, arg2);
+  }
+
+  public FOMTextValue(Object arg0, OMFactory arg1) {
+    super(arg0, arg1);
+  }
+
+  public FOMTextValue(OMContainer arg0, char[] arg1, int arg2, OMFactory arg3) {
+    super(arg0, arg1, arg2, arg3);
+  }
+
+  public FOMTextValue(OMContainer arg0, QName arg1, int arg2, OMFactory arg3) {
+    super(arg0, arg1, arg2, arg3);
+  }
+
+  public FOMTextValue(OMContainer arg0, QName arg1, OMFactory arg2) {
+    super(arg0, arg1, arg2);
+  }
+
+  public FOMTextValue(OMContainer arg0, String arg1, int arg2, OMFactory arg3) {
+    super(arg0, arg1, arg2, arg3);
+  }
+
+  public FOMTextValue(OMContainer arg0, String arg1, OMFactory arg2) {
+    super(arg0, arg1, arg2);
+  }
+
+  public FOMTextValue(OMContainer arg0, String arg1, String arg2, boolean arg3, OMFactory
arg4) {
+    super(arg0, arg1, arg2, arg3, arg4);
+  }
+
+  public FOMTextValue(String arg0, int arg1, OMFactory arg2) {
+    super(arg0, arg1, arg2);
+  }
+
+  public FOMTextValue(String arg0, OMContainer arg1, OMXMLParserWrapper arg2, OMFactory arg3)
{
+    super(arg0, arg1, arg2, arg3);
+  }
+
+  public FOMTextValue(String arg0, OMFactory arg1) {
+    super(arg0, arg1);
+  }
+
+  public FOMTextValue(String arg0, String arg1, boolean arg2, OMFactory arg3) {
+    super(arg0, arg1, arg2, arg3);
+  }
+
+  public DataHandler getDataHandler() {
+    return (DataHandler) super.getDataHandler();
+  }
+  
+  @SuppressWarnings("unchecked")
+  public <T extends Base>T getParentElement() {
+    T parent = (T)super.getParent();
+    return (T) ((parent instanceof Element) ? 
+      getWrapped((Element)parent) : parent);
+  } 
+  
+  protected Element getWrapped(Element internal) {
+    if (internal == null) return null;
+    FOMFactory factory = (FOMFactory) getFactory();
+    return factory.getElementWrapper(internal);
+  }
+  
+  public Factory getFactory() {
+    return (Factory) this.factory;
+  }
+
+  @Override
+  public String toString() {
+    return getText();
+  }
+
+}

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java?view=diff&rev=557747&r1=557746&r2=557747
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
Thu Jul 19 12:19:08 2007
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.parser.stax;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -27,6 +28,7 @@
 import org.apache.abdera.parser.stax.util.ResolveFunction;
 import org.apache.abdera.util.AbstractXPath;
 import org.apache.abdera.xpath.XPathException;
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.xpath.DocumentNavigator;
 import org.jaxen.BaseXPath;
 import org.jaxen.Function;
@@ -146,6 +148,7 @@
     return getXPath(path, namespaces, null, null);
   }
 
+  @SuppressWarnings("unchecked")
   public List selectNodes(
     String path, 
     Base base, 
@@ -154,8 +157,17 @@
     Map<QName,Object> variables) 
       throws XPathException {
     try {
+      List nodes = new ArrayList();
       XPath xpath = getXPath(path, namespaces, functions, variables);
-      return xpath.selectNodes(base);
+      List results = xpath.selectNodes(base);
+      for (Object obj : results) {
+        if (obj instanceof OMAttribute) {
+          nodes.add(new FOMAttribute((OMAttribute) obj));
+        } else {
+          nodes.add(obj);
+        }
+      }
+      return nodes;
     } catch (JaxenException e) {
       throw new XPathException(e);
     }
@@ -176,7 +188,9 @@
     Map<QName,Object> variables) throws XPathException {
     try {
       XPath xpath = getXPath(path, namespaces, functions, variables);
-      return xpath.selectSingleNode(base);
+      Object obj = xpath.selectSingleNode(base);
+      if (obj instanceof OMAttribute) obj = new FOMAttribute((OMAttribute) obj);
+      return obj;
     } catch (JaxenException e) {
       throw new XPathException(e);
     }



Mime
View raw message