Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategory.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategory.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategory.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategory.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,112 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Category;
+import org.apache.abdera2.model.Element;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+public class FOMCategory extends FOMExtensibleElement implements Category {
+
+ private static final long serialVersionUID = -4313042828936786803L;
+
+ public FOMCategory() {
+ super(Constants.CATEGORY);
+ }
+
+ public FOMCategory(String term) {
+ this();
+ setTerm(term);
+ }
+
+ public FOMCategory(String term, String scheme, String label) {
+ this();
+ setTerm(term);
+ setScheme(scheme);
+ setLabel(label);
+ }
+
+ public FOMCategory(String name, OMNamespace namespace, OMContainer parent,
OMFactory factory) throws OMException {
+ super(name, namespace, parent, factory);
+ }
+
+ public FOMCategory(QName qname, OMContainer parent, OMFactory factory) {
+ super(qname, parent, factory);
+ }
+
+ public FOMCategory(QName qname, OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) {
+ super(qname, parent, factory, builder);
+ }
+
+ public FOMCategory(OMContainer parent, OMFactory factory) {
+ super(CATEGORY, parent, factory);
+ }
+
+ public FOMCategory(OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) {
+ super(CATEGORY, parent, factory, builder);
+ }
+
+ public String getTerm() {
+ return getAttributeValue(TERM);
+ }
+
+ public Category setTerm(String term) {
+ complete();
+ return setAttributeValue(TERM,term);
+ }
+
+ public IRI getScheme() {
+ String value = getAttributeValue(SCHEME);
+ return (value != null) ? new IRI(value) : null;
+ }
+
+ public Category setScheme(String scheme) {
+ complete();
+ return setAttributeValue(SCHEME,scheme==null?null:new
IRI(scheme).toString());
+ }
+
+ public String getLabel() {
+ return getAttributeValue(LABEL);
+ }
+
+ public Category setLabel(String label) {
+ complete();
+ return setAttributeValue(LABEL, label);
+ }
+
+ public String getValue() {
+ return getText();
+ }
+
+ public void setValue(String value) {
+ complete();
+ if (value != null)
+ ((Element)this).setText(value);
+ else
+ _removeAllChildren();
+ }
+
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCategory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,280 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.activation.MimeType;
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+import org.apache.abdera2.common.selector.Selector;
+import org.apache.abdera2.model.Categories;
+import org.apache.abdera2.model.Category;
+import org.apache.abdera2.model.Collection;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Text;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+@SuppressWarnings("deprecation")
+public class FOMCollection extends FOMExtensibleElement implements Collection {
+
+ private static final String[] ENTRY =
{"application/atom+xml;type=\"entry\""};
+ private static final String[] EMPTY = new String[0];
+
+ private static final long serialVersionUID = -5291734055253987136L;
+
+ public FOMCollection() {
+ super(Constants.COLLECTION);
+ }
+
+ public FOMCollection(String title, String href, String[] accepts) {
+ this();
+ setTitle(title);
+ setHref(href);
+ setAccept(accepts);
+ }
+
+ public FOMCollection(String name, OMNamespace namespace, OMContainer
parent, OMFactory factory)
+ throws OMException {
+ super(name, namespace, parent, factory);
+ }
+
+ public FOMCollection(QName qname, OMContainer parent, OMFactory factory) {
+ super(qname, parent, factory);
+ }
+
+ public FOMCollection(QName qname, OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) {
+ super(qname, parent, factory, builder);
+ }
+
+ public FOMCollection(OMContainer parent, OMFactory factory) {
+ super(COLLECTION, parent, factory);
+ }
+
+ public FOMCollection(OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) {
+ super(COLLECTION, parent, factory, builder);
+ }
+
+ public String getTitle() {
+ Text title = this.getFirstChild(TITLE);
+ return (title != null) ? title.getValue() : null;
+ }
+
+ private Text setTitle(String title, Text.Type type) {
+ complete();
+ FOMFactory fomfactory = (FOMFactory)factory;
+ Text text = fomfactory.newText(PREFIXED_TITLE, type);
+ text.setValue(title);
+ this._setChild(PREFIXED_TITLE, (OMElement)text);
+ return text;
+ }
+
+ public Text setTitle(String title) {
+ return setTitle(title, Text.Type.TEXT);
+ }
+
+ public Text setTitleAsHtml(String title) {
+ return setTitle(title, Text.Type.HTML);
+ }
+
+ public Text setTitleAsXHtml(String title) {
+ return setTitle(title, Text.Type.XHTML);
+ }
+
+ public Text getTitleElement() {
+ return getFirstChild(TITLE);
+ }
+
+ public IRI getHref() {
+ return _getUriValue(getAttributeValue(HREF));
+ }
+
+ public IRI getResolvedHref() {
+ return _resolve(getResolvedBaseUri(), getHref());
+ }
+
+ public Collection setHref(String href) {
+ complete();
+ return setAttributeValue(HREF, href==null?null:(new
IRI(href).toString()));
+ }
+
+ public String[] getAccept() {
+ List<String> accept = new ArrayList<String>();
+ Iterator<?> i = getChildrenWithName(ACCEPT);
+ if (i == null || !i.hasNext())
+ i = getChildrenWithName(PRE_RFC_ACCEPT);
+ while (i.hasNext()) {
+ Element e = (Element)i.next();
+ String t = e.getText();
+ if (t != null) {
+ accept.add(t.trim());
+ }
+ }
+ if (accept.size() > 0) {
+ String[] list = accept.toArray(new String[accept.size()]);
+ return MimeTypeHelper.condense(list);
+ } else {
+ return EMPTY;
+ }
+ }
+
+ public Collection setAccept(String mediaRange) {
+ return setAccept(new String[] {mediaRange});
+ }
+
+ public Collection setAccept(String... mediaRanges) {
+ complete();
+ if (mediaRanges != null && mediaRanges.length > 0) {
+ _removeChildren(ACCEPT, true);
+ _removeChildren(PRE_RFC_ACCEPT, true);
+ if (mediaRanges.length == 1 && mediaRanges[0].equals("")) {
+ addExtension(ACCEPT);
+ } else {
+ mediaRanges = MimeTypeHelper.condense(mediaRanges);
+ for (String type : mediaRanges) {
+ if (type.equalsIgnoreCase("entry")) {
+ addSimpleExtension(ACCEPT,
"application/atom+xml;type=entry");
+ } else {
+ try {
+ addSimpleExtension(ACCEPT, new
MimeType(type).toString());
+ } catch (javax.activation.MimeTypeParseException e) {
+ throw new
org.apache.abdera2.common.mediatype.MimeTypeParseException(e);
+ }
+ }
+ }
+ }
+ } else {
+ _removeChildren(ACCEPT, true);
+ _removeChildren(PRE_RFC_ACCEPT, true);
+ }
+ return this;
+ }
+
+ public Collection addAccepts(String mediaRange) {
+ return addAccepts(new String[] {mediaRange});
+ }
+
+ public Collection addAccepts(String... mediaRanges) {
+ complete();
+ if (mediaRanges != null) {
+ for (String type : mediaRanges) {
+ if (!accepts(type)) {
+ try {
+ addSimpleExtension(ACCEPT, new
MimeType(type).toString());
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+ return this;
+ }
+
+ public Collection addAcceptsEntry() {
+ return addAccepts("application/atom+xml;type=entry");
+ }
+
+ public Collection setAcceptsEntry() {
+ return setAccept("application/atom+xml;type=entry");
+ }
+
+ public Collection setAcceptsNothing() {
+ return setAccept("");
+ }
+
+ public boolean acceptsEntry() {
+ return accepts("application/atom+xml;type=entry");
+ }
+
+ public boolean acceptsNothing() {
+ return accepts("");
+ }
+
+ public boolean accepts(String mediaType) {
+ String[] accept = getAccept();
+ if (accept.length == 0)
+ accept = ENTRY;
+ for (String a : accept) {
+ if (MimeTypeHelper.isMatch(a, mediaType))
+ return true;
+ }
+ return false;
+ }
+
+ public boolean accepts(MimeType mediaType) {
+ return accepts(mediaType.toString());
+ }
+
+ public Categories addCategories() {
+ complete();
+ return ((FOMFactory)factory).newCategories(this);
+ }
+
+ public Collection addCategories(Categories categories) {
+ complete();
+ addChild((OMElement)categories);
+ return this;
+ }
+
+ public Categories addCategories(String href) {
+ complete();
+ Categories cats = ((FOMFactory)factory).newCategories();
+ cats.setHref(href);
+ addCategories(cats);
+ return cats;
+ }
+
+ public Categories addCategories(List<Category> categories, boolean fixed,
String scheme) {
+ complete();
+ Categories cats = ((FOMFactory)factory).newCategories();
+ cats.setFixed(fixed);
+ if (scheme != null)
+ cats.setScheme(scheme);
+ if (categories != null) {
+ for (Category category : categories) {
+ cats.addCategory(category);
+ }
+ }
+ addCategories(cats);
+ return cats;
+ }
+
+ public List<Categories> getCategories() {
+ List<Categories> list = _getChildrenAsSet(CATEGORIES);
+ if (list == null || list.size() == 0)
+ list = _getChildrenAsSet(PRE_RFC_CATEGORIES);
+ return list;
+ }
+
+ public List<Categories> getCategories(Selector selector) {
+ List<Categories> list = _getChildrenAsSet(CATEGORIES,selector);
+ if (list == null || list.size() == 0)
+ list = _getChildrenAsSet(PRE_RFC_CATEGORIES,selector);
+ return list;
+ }
+
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMComment.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMComment.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMComment.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMComment.java
Tue Sep 20 15:56:46 2011
@@ -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.abdera2.parser.axiom;
+
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Comment;
+import org.apache.abdera2.model.Element;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.impl.llom.OMCommentImpl;
+
+@SuppressWarnings("unchecked")
+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 Comment setText(String text) {
+ super.setValue(text);
+ return this;
+ }
+
+ 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();
+ }
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMComment.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMContent.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMContent.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMContent.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMContent.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,370 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import javax.activation.DataHandler;
+import javax.activation.MimeType;
+import javax.activation.URLDataSource;
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.Localizer;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Div;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ElementWrapper;
+import org.apache.axiom.attachments.utils.DataHandlerUtils;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+@SuppressWarnings("unchecked")
+public class FOMContent extends FOMExtensibleElement implements Content {
+
+ private static final long serialVersionUID = -5499917654824498563L;
+ protected Type type = Type.TEXT;
+
+ public FOMContent(Content.Type type) {
+ super(Constants.CONTENT);
+ init(type);
+ }
+
+ public FOMContent(String name, OMNamespace namespace, Type type,
OMContainer parent, OMFactory factory)
+ throws OMException {
+ super(name, namespace, parent, factory);
+ init(type);
+ }
+
+ public FOMContent(QName qname, Type type, OMContainer parent, OMFactory
factory) {
+ super(qname, parent, factory);
+ init(type);
+ }
+
+ public FOMContent(QName qname, Type type, OMContainer parent, OMFactory
factory, OMXMLParserWrapper builder) {
+ super(qname, parent, factory, builder);
+ init(type);
+ }
+
+ public FOMContent(Type type, OMContainer parent, OMFactory factory) throws
OMException {
+ super(CONTENT, parent, factory);
+ init(type);
+ }
+
+ public FOMContent(Type type, OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) {
+ super(CONTENT, parent, factory, builder);
+ init(type);
+ }
+
+ private void init(Type type) {
+ this.type = type;
+ if (type == null || type == Type.MEDIA)
+ removeAttribute(TYPE);
+ else
+ setAttributeValue(TYPE,type.label());
+ }
+
+ public final Type getContentType() {
+ return type;
+ }
+
+ public Content setContentType(Type type) {
+ complete();
+ init(type);
+ return this;
+ }
+
+ public <T extends Element> T getValueElement() {
+ FOMFactory factory = (FOMFactory)getFactory();
+ return (T)factory.getElementWrapper((Element)this.getFirstElement());
+ }
+
+ public <T extends Element> Content setValueElement(T value) {
+ complete();
+ if (value != null) {
+ if (this.getFirstElement() != null)
+ this.getFirstElement().discard();
+
+ MimeType mtype = this.getMimeType();
+ if (mtype == null) {
+ String mt = getFactory().getMimeType(value);
+ if (mt != null) {
+ setMimeType(mt);
+ mtype = getMimeType();
+ }
+ }
+
+ if (value instanceof Div && type != Content.Type.XML)
+ init(Content.Type.XHTML);
+ else {
+ if (mtype == null) {
+ init(Content.Type.XML);
+ }
+ }
+ OMElement el = (OMElement)(value instanceof ElementWrapper ?
((ElementWrapper)value).getInternal() : value);
+ this.setFirstChild(el);
+ } else {
+ _removeAllChildren();
+ }
+ return this;
+ }
+
+ public MimeType getMimeType() {
+ MimeType type = null;
+ String mimeType = getAttributeValue(TYPE);
+ if (mimeType != null) {
+ try {
+ type = new MimeType(mimeType);
+ } catch (Exception e) {
+ }
+ }
+ return type;
+ }
+
+ public Content setMimeType(String type) {
+ try {
+ complete();
+ return setAttributeValue(TYPE,type==null?null:(new
MimeType(type)).toString());
+ } catch (javax.activation.MimeTypeParseException e) {
+ throw new
org.apache.abdera2.common.mediatype.MimeTypeParseException(e);
+ }
+ }
+
+ public IRI getSrc() {
+ return _getUriValue(getAttributeValue(SRC));
+ }
+
+ public IRI getResolvedSrc() {
+ return _resolve(getResolvedBaseUri(), getSrc());
+ }
+
+ public Content setSrc(String src) {
+ complete();
+ return setAttributeValue(SRC, src==null?null:(new IRI(src)).toString());
+ }
+
+ public DataHandler getDataHandler() {
+ if (!Type.MEDIA.equals(type))
+ throw new
UnsupportedOperationException(Localizer.get("DATA.HANDLER.NOT.SUPPORTED"));
+ MimeType type = getMimeType();
+ java.net.URL src = null;
+ try {
+ src = getSrc().toURL();
+ } catch (Exception e) {
+ }
+ DataHandler dh = null;
+ if (src == null) {
+ dh =
+ (DataHandler)DataHandlerUtils
+ .getDataHandlerFromText(getText(), (type != null) ?
type.toString() : null);
+ } else {
+ dh = new DataHandler(new URLDataSource(src));
+ }
+ return dh;
+ }
+
+ public Content setDataHandler(DataHandler dataHandler) {
+ complete();
+ if (Type.MEDIA != type)
+ throw new IllegalArgumentException();
+ if (dataHandler.getContentType() != null) {
+ try {
+ setMimeType(dataHandler.getContentType());
+ } catch (Exception e) {
+ }
+ }
+ _removeAllChildren();
+ addChild(factory.createOMText(dataHandler, true));
+ return this;
+ }
+
+ public String getValue() {
+ String val = null;
+ switch(type) {
+ case MEDIA:
+ case TEXT:
+ case HTML: val = getText(); break;
+ case XHTML:
+ FOMDiv div = (FOMDiv)this.getFirstChildWithName(Constants.DIV);
+ if (div != null)
+ val = div.getInternalValue();
+ break;
+ case XML:
+ OMElement el = this.getFirstElement();
+ if (el != null)
+ val = el.toString();
+ break;
+ }
+ return val;
+ }
+
+ public <T extends Element> T setText(Content.Type type, String value) {
+ complete();
+ init(type);
+ if (value != null) {
+ OMNode child = this.getFirstOMChild();
+ while (child != null) {
+ if (child.getType() == OMNode.TEXT_NODE) {
+ child.detach();
+ }
+ child = child.getNextOMSibling();
+ }
+ getOMFactory().createOMText(this, value);
+ } else
+ _removeAllChildren();
+ return (T)this;
+ }
+
+ public void setText(String value) {
+ setText(Content.Type.TEXT, value);
+ }
+
+ public Content setValue(String value) {
+ complete();
+ if (value != null)
+ removeAttribute(SRC);
+ if (value != null) {
+ switch(type) {
+ case TEXT:
+ case HTML:
+ _removeAllChildren();
+ setText(type, value);
+ break;
+ case XHTML: {
+ IRI baseUri = null;
+ Element element = null;
+ value = String.format("<div xmlns=\"%s\">%s</div>",XHTML_NS,value);
+ try {
+ baseUri = getResolvedBaseUri();
+ element = _parse(value, baseUri);
+ } catch (Exception e) {
+ }
+ if (element != null && element instanceof Div)
+ setValueElement((Div)element);
+ break;
+ }
+ case XML: {
+ IRI baseUri = null;
+ Element element = null;
+ try {
+ baseUri = getResolvedBaseUri();
+ element = _parse(value, baseUri);
+ } catch (Exception e) {
+ }
+ if (element != null)
+ setValueElement(element);
+ try {
+ if (getMimeType() == null)
+ setMimeType("application/xml");
+ } catch (Exception e) {
+ }
+ break;
+ }
+ case MEDIA:
+ _removeAllChildren();
+ setText(type, value);
+ try {
+ if (getMimeType() == null)
+ setMimeType("text/plain");
+ } catch (Exception e) {
+ }
+ break;
+ }
+ } else {
+ _removeAllChildren();
+ }
+ return this;
+ }
+
+ public String getWrappedValue() {
+ if (Type.XHTML == type) {
+ return this.getFirstChildWithName(Constants.DIV).toString();
+ } else {
+ return getText();
+ }
+ }
+
+ public Content setWrappedValue(String wrappedValue) {
+ complete();
+ if (Type.XHTML == type) {
+ IRI baseUri = null;
+ Element element = null;
+ try {
+ baseUri = getResolvedBaseUri();
+ element = _parse(wrappedValue, baseUri);
+ } catch (Exception e) {
+ }
+ if (element != null && element instanceof Div)
+ setValueElement((Div)element);
+ } else {
+ ((Element)this).setText(wrappedValue);
+ }
+ return this;
+ }
+
+ @Override
+ public IRI getBaseUri() {
+ if (Type.XHTML == type) {
+ Element el = getValueElement();
+ if (el != null) {
+ if (el.getAttributeValue(BASE) != null) {
+ if (getAttributeValue(BASE) != null)
+ return
super.getBaseUri().resolve(el.getAttributeValue(BASE));
+ else
+ return _getUriValue(el.getAttributeValue(BASE));
+ }
+ }
+ }
+ return super.getBaseUri();
+ }
+
+ @Override
+ public IRI getResolvedBaseUri() {
+ if (Type.XHTML == type) {
+ Element el = getValueElement();
+ if (el != null) {
+ if (el.getAttributeValue(BASE) != null) {
+ return
super.getResolvedBaseUri().resolve(el.getAttributeValue(BASE));
+ }
+ }
+ }
+ return super.getResolvedBaseUri();
+ }
+
+ @Override
+ public String getLanguage() {
+ String lang = null;
+ if (Type.XHTML == type) {
+ Element el = getValueElement();
+ lang = el.getAttributeValue(LANG);
+ }
+ return lang != null ? lang : super.getLanguage();
+ }
+
+ @Override
+ public Object clone() {
+ FOMContent content = (FOMContent)super.clone();
+ content.type = this.type;
+ return content;
+ }
+
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMContent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMControl.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMControl.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMControl.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMControl.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.model.Control;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+@SuppressWarnings("deprecation")
+public class FOMControl extends FOMExtensibleElement implements Control {
+
+ private static final long serialVersionUID = -3816493378953555206L;
+
+ public FOMControl() {
+ super(Constants.CONTROL);
+ }
+
+ public FOMControl(String name, OMNamespace namespace, OMContainer parent,
OMFactory factory) throws OMException {
+ super(name, namespace, parent, factory);
+ }
+
+ public FOMControl(QName qname, OMContainer parent, OMFactory factory) {
+ super(qname, parent, factory);
+ }
+
+ public FOMControl(QName qname, OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) {
+ super(qname, parent, factory, builder);
+ }
+
+ public FOMControl(OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) throws OMException {
+ super(CONTROL, parent, factory, builder);
+ }
+
+ public FOMControl(OMContainer parent, OMFactory factory) throws
OMException {
+ super(CONTROL, parent, factory);
+ }
+
+ public boolean isDraft() {
+ String value = _getElementValue(DRAFT);
+ if (value == null)
+ value = _getElementValue(PRE_RFC_DRAFT);
+ return (value != null && YES.equalsIgnoreCase(value));
+ }
+
+ public Control setDraft(boolean draft) {
+ complete();
+ _removeChildren(PRE_RFC_DRAFT, true);
+ _setElementValue(DRAFT, (draft) ? YES : NO);
+ return this;
+ }
+
+ public Control unsetDraft() {
+ complete();
+ _removeChildren(PRE_RFC_DRAFT, true);
+ _removeChildren(DRAFT, true);
+ return this;
+ }
+
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMControl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDateTime.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDateTime.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDateTime.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDateTime.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,157 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.model.DateTime;
+import org.apache.abdera2.model.Element;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+public class FOMDateTime extends FOMElement implements DateTime {
+
+ private static final long serialVersionUID = -6611503566172011733L;
+ private org.apache.abdera2.common.date.DateTime value;
+
+ public FOMDateTime(QName qname) {
+ super(qname);
+ }
+
+ public FOMDateTime(QName qname, Date date) {
+ this(qname);
+ setDate(date);
+ }
+
+ public FOMDateTime(QName qname, Calendar calendar) {
+ this(qname);
+ setCalendar(calendar);
+ }
+
+ public FOMDateTime(QName qname, String value) {
+ this(qname);
+ setString(value);
+ }
+
+ public FOMDateTime(QName qname, long time) {
+ this(qname);
+ setTime(time);
+ }
+
+ public FOMDateTime(QName qname, org.apache.abdera2.common.date.DateTime
dateTime) {
+ this(qname);
+ setValue(dateTime);
+ }
+
+ public FOMDateTime(String name, OMNamespace namespace, OMContainer parent,
OMFactory factory) throws OMException {
+ super(name, namespace, parent, factory);
+ }
+
+ public FOMDateTime(QName qname, OMContainer parent, OMFactory factory)
throws OMException {
+ super(qname, parent, factory);
+ }
+
+ public FOMDateTime(QName qname, OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder)
+ throws OMException {
+ super(qname, parent, factory, builder);
+ }
+
+ public org.apache.abdera2.common.date.DateTime getValue() {
+ if (value == null) {
+ String v = getText();
+ if (v != null) {
+ value = org.apache.abdera2.common.date.DateTime.valueOf(v);
+ }
+ }
+ return value;
+ }
+
+ public DateTime setValue(org.apache.abdera2.common.date.DateTime dateTime)
{
+ complete();
+ value = null;
+ if (dateTime != null)
+ ((Element)this).setText(dateTime.getValue());
+ else
+ _removeAllChildren();
+ return this;
+ }
+
+ public DateTime setDate(Date date) {
+ complete();
+ value = null;
+ if (date != null)
+
((Element)this).setText(org.apache.abdera2.common.date.DateTime.valueOf(date).getValue());
+ else
+ _removeAllChildren();
+ return this;
+ }
+
+ public DateTime setCalendar(Calendar date) {
+ complete();
+ value = null;
+ if (date != null)
+
((Element)this).setText(org.apache.abdera2.common.date.DateTime.valueOf(date).getValue());
+ else
+ _removeAllChildren();
+ return this;
+ }
+
+ public DateTime setTime(long date) {
+ complete();
+ value = null;
+
((Element)this).setText(org.apache.abdera2.common.date.DateTime.valueOf(date).getValue());
+ return this;
+ }
+
+ public DateTime setString(String date) {
+ complete();
+ value = null;
+ if (date != null)
+
((Element)this).setText(org.apache.abdera2.common.date.DateTime.valueOf(date).getValue());
+ else
+ _removeAllChildren();
+ return this;
+ }
+
+ public Date getDate() {
+ org.apache.abdera2.common.date.DateTime ad = getValue();
+ return (ad != null) ? ad.getDate() : null;
+ }
+
+ public Calendar getCalendar() {
+ org.apache.abdera2.common.date.DateTime ad = getValue();
+ return (ad != null) ? ad.getCalendar() : null;
+ }
+
+ public long getTime() {
+ org.apache.abdera2.common.date.DateTime ad = getValue();
+ return (ad != null) ? ad.getTime() : null;
+ }
+
+ public String getString() {
+ org.apache.abdera2.common.date.DateTime ad = getValue();
+ return (ad != null) ? ad.getValue() : null;
+ }
+
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDateTime.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDiv.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDiv.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDiv.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDiv.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,145 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Div;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMXMLParserWrapper;
+
+public class FOMDiv extends FOMExtensibleElement implements Div {
+
+ private static final long serialVersionUID = -2319449893405850433L;
+
+ public FOMDiv() {
+ super(Constants.DIV);
+ }
+
+ public FOMDiv(String name, OMNamespace namespace, OMContainer parent,
OMFactory factory) throws OMException {
+ super(name, namespace, parent, factory);
+ }
+
+ public FOMDiv(QName qname, OMContainer parent, OMFactory factory) throws
OMException {
+ super(qname, parent, factory);
+ }
+
+ public FOMDiv(QName qname, OMContainer parent, OMFactory factory,
OMXMLParserWrapper builder) throws OMException {
+ super(qname, parent, factory, builder);
+ }
+
+ public String[] getXhtmlClass() {
+ String _class = getAttributeValue(CLASS);
+ String[] classes = null;
+ if (_class != null) {
+ classes = _class.split(" ");
+ }
+ return classes;
+ }
+
+ public String getId() {
+ return getAttributeValue(AID);
+ }
+
+ public String getTitle() {
+ return getAttributeValue(ATITLE);
+ }
+
+ public Div setId(String id) {
+ complete();
+ return setAttributeValue(AID,id);
+ }
+
+ public Div setTitle(String title) {
+ complete();
+ return setAttributeValue(ATITLE,title);
+ }
+
+ public Div setXhtmlClass(String[] classes) {
+ complete();
+ if (classes != null) {
+ StringBuilder val = new StringBuilder();
+ for (String s : classes) {
+ if (s.length() > 0)
+ val.append(" ");
+ val.append(s);
+ }
+ setAttributeValue(CLASS, val.toString());
+ } else
+ removeAttribute(CLASS);
+ return this;
+ }
+
+ public String getValue() {
+ return getInternalValue();
+ }
+
+ public void setValue(String value) {
+ complete();
+ _removeAllChildren();
+ if (value != null) {
+ IRI baseUri = null;
+ value = String.format("<div xmlns=\"%s\">%s</div>",XHTML_NS,value);
+ OMElement element = null;
+ try {
+ baseUri = getResolvedBaseUri();
+ element = (OMElement)_parse(value, baseUri);
+ } catch (Exception e) {
+ }
+ List<Object> list = new ArrayList<Object>();
+ for (Iterator<?> i = element.getChildren(); i.hasNext();)
+ list.add(i.next());
+ for (Object o : list) {
+ OMNode node = (OMNode)o;
+ node.detach();
+ this.addChild(node);
+ }
+ }
+ }
+
+ protected String getInternalValue() {
+ try {
+ StringWriter out = new StringWriter();
+ XMLStreamWriter writer =
XMLOutputFactory.newInstance().createXMLStreamWriter(out);
+ writer.writeStartElement("");
+ for (Iterator<?> nodes = this.getChildren(); nodes.hasNext();) {
+ OMNode node = (OMNode)nodes.next();
+ node.serialize(writer);
+ }
+ writer.writeEndElement();
+ return out.getBuffer().toString().substring(2);
+ } catch (Exception e) {
+ }
+ return "";
+ }
+
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDiv.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDocument.java
URL:
http://svn.apache.org/viewvc/abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDocument.java?rev=1173209&view=auto
==============================================================================
---
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDocument.java
(added)
+++
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDocument.java
Tue Sep 20 15:56:46 2011
@@ -0,0 +1,364 @@
+/*
+ * 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.abdera2.parser.axiom;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.activation.MimeType;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.common.xml.XMLVersion;
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ElementWrapper;
+import org.apache.abdera2.writer.Writer;
+import org.apache.abdera2.writer.WriterOptions;
+import org.apache.axiom.om.OMComment;
+import org.apache.axiom.om.OMDocType;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMProcessingInstruction;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.llom.OMDocumentImpl;
+import org.apache.axiom.om.util.StAXUtils;
+
+@SuppressWarnings("unchecked")
+public class FOMDocument<T extends Element> extends OMDocumentImpl implements
Document<T> {
+
+ private static final long serialVersionUID = -3255339511063344662L;
+ protected IRI base = null;
+ protected MimeType contentType = null;
+ protected Date lastModified = null;
+ protected EntityTag etag = null;
+ protected String language = null;
+ protected String slug = null;
+ protected boolean preserve = true;
+
+ public FOMDocument() {
+ super(new FOMFactory());
+ }
+
+ protected FOMDocument(OMElement documentElement, OMXMLParserWrapper
parserWrapper, OMFactory factory) {
+ super(documentElement, parserWrapper, factory);
+ }
+
+ protected FOMDocument(OMElement documentElement, OMXMLParserWrapper
parserWrapper) {
+ super(documentElement, parserWrapper, new FOMFactory());
+ }
+
+ protected FOMDocument(OMFactory factory) {
+ super(factory);
+ }
+
+ protected FOMDocument(OMXMLParserWrapper parserWrapper, OMFactory factory)
{
+ super(parserWrapper, factory);
+ }
+
+ protected FOMDocument(OMXMLParserWrapper parserWrapper) {
+ super(parserWrapper, new FOMFactory());
+ }
+
+ public T getRoot() {
+ FOMFactory factory = (FOMFactory)getFactory();
+ return (T)factory.getElementWrapper((T)this.getOMDocumentElement());
+ }
+
+ public Document<T> setRoot(T root) {
+ if (root instanceof OMElement) {
+ this.setOMDocumentElement((OMElement)root);
+ } else if (root instanceof ElementWrapper) {
+
this.setOMDocumentElement((OMElement)((ElementWrapper)root).getInternal());
+ }
+ return this;
+ }
+
+ public IRI getBaseUri() {
+ return base;
+ }
+
+ public Document<T> setBaseUri(String base) {
+ this.base = new IRI(base);
+ return this;
+ }
+
+ public void writeTo(OutputStream out, WriterOptions options) throws
IOException {
+ Writer writer = this.getFactory().getAbdera().getWriter();
+ writer.writeTo(this, out, options);
+ }
+
+ public void writeTo(java.io.Writer out, WriterOptions options) throws
IOException {
+ Writer writer = this.getFactory().getAbdera().getWriter();
+ writer.writeTo(this, out, options);
+ }
+
+ public void writeTo(Writer writer, OutputStream out) throws IOException {
+ writer.writeTo(this, out);
+ }
+
+ public void writeTo(Writer writer, java.io.Writer out) throws IOException {
+ writer.writeTo(this, out);
+ }
+
+ public void writeTo(Writer writer, OutputStream out, WriterOptions
options) throws IOException {
+ writer.writeTo(this, out, options);
+ }
+
+ public void writeTo(Writer writer, java.io.Writer out, WriterOptions
options) throws IOException {
+ writer.writeTo(this, out, options);
+ }
+
+ public void writeTo(OutputStream out) throws IOException {
+ String charset = getCharset();
+ if (charset == null)
+ charset = "UTF-8";
+ Writer writer = getFactory().getAbdera().getWriter();
+ writeTo(writer, new OutputStreamWriter(out, charset));
+ }
+
+ public void writeTo(java.io.Writer writer) throws IOException {
+ Writer out = getFactory().getAbdera().getWriter();
+ if (!(out instanceof FOMWriter)) {
+ out.writeTo(this, writer);
+ } else {
+ try {
+ OMOutputFormat outputFormat = new OMOutputFormat();
+ if (this.getCharsetEncoding() != null)
+ outputFormat.setCharSetEncoding(this.getCharsetEncoding());
+ MTOMXMLStreamWriter omwriter = new
MTOMXMLStreamWriter(StAXUtils.createXMLStreamWriter(writer));
+ omwriter.setOutputFormat(outputFormat);
+ this.internalSerialize(omwriter);
+ omwriter.flush();
+ } catch (XMLStreamException e) {
+ throw new FOMException(e);
+ }
+ }
+ }
+
+ public MimeType getContentType() {
+ return contentType;
+ }
+
+ public Document<T> setContentType(String contentType) {
+ try {
+ this.contentType = new MimeType(contentType);
+ if (this.contentType.getParameter("charset") != null)
+ setCharset(this.contentType.getParameter("charset"));
+ } catch (javax.activation.MimeTypeParseException e) {
+ throw new
org.apache.abdera2.common.mediatype.MimeTypeParseException(e);
+ }
+ return this;
+ }
+
+ public Date getLastModified() {
+ return this.lastModified;
+ }
+
+ public Document<T> setLastModified(Date lastModified) {
+ this.lastModified = lastModified;
+ return this;
+ }
+
+ public Object clone() {
+ Document<T> doc = ((FOMFactory)factory).newDocument();
+ OMDocument omdoc = (OMDocument)doc;
+ for (Iterator<OMNode> i = getChildren(); i.hasNext();) {
+ OMNode node = i.next();
+ switch (node.getType()) {
+ case OMNode.COMMENT_NODE:
+ OMComment comment = (OMComment)node;
+ factory.createOMComment(omdoc, comment.getValue());
+ break;
+ case OMNode.DTD_NODE:
+ OMDocType doctype = (OMDocType)node;
+ factory.createOMDocType(omdoc, doctype.getValue());
+ break;
+ case OMNode.ELEMENT_NODE:
+ Element el = (Element)node;
+ omdoc.addChild((OMNode)el.clone());
+ break;
+ case OMNode.PI_NODE:
+ OMProcessingInstruction pi = (OMProcessingInstruction)node;
+ factory.createOMProcessingInstruction(omdoc,
pi.getTarget(), pi.getValue());
+ break;
+ }
+ }
+ return doc;
+ }
+
+ public String getCharset() {
+ return this.getCharsetEncoding();
+ }
+
+ public Document<T> setCharset(String charset) {
+ this.setCharsetEncoding(charset);
+ return this;
+ }
+
+ public Factory getFactory() {
+ return (Factory)this.factory;
+ }
+
+ public String[] getProcessingInstruction(String target) {
+ List<String> values = new ArrayList<String>();
+ for (Iterator<OMNode> i = getChildren(); i.hasNext();) {
+ OMNode node = i.next();
+ if (node.getType() == OMNode.PI_NODE) {
+ OMProcessingInstruction pi = (OMProcessingInstruction)node;
+ if (pi.getTarget().equalsIgnoreCase(target))
+ values.add(pi.getValue());
+ }
+ }
+ return values.toArray(new String[values.size()]);
+ }
+
+ public Document<T> addProcessingInstruction(String target, String value) {
+ OMProcessingInstruction pi =
this.factory.createOMProcessingInstruction(null, target, value);
+ if (this.getOMDocumentElement() != null) {
+ this.getOMDocumentElement().insertSiblingBefore(pi);
+ } else {
+ this.addChild(pi);
+ }
+ return this;
+ }
+
+ public Document<T> addStylesheet(String href, String media) {
+ if (media == null) {
+ addProcessingInstruction("xml-stylesheet", "href=\"" + href +
"\"");
+ } else {
+ addProcessingInstruction("xml-stylesheet", "href=\"" + href + "\"
media=\"" + media + "\"");
+ }
+ return this;
+ }
+
+ public <X extends Base> X addComment(String value) {
+ OMComment comment = this.factory.createOMComment(null, value);
+ if (this.getOMDocumentElement() != null) {
+ this.getOMDocumentElement().insertSiblingBefore(comment);
+ } else {
+ this.addChild(comment);
+ }
+ return (X)this;
+ }
+
+ public EntityTag getEntityTag() {
+ return etag;
+ }
+
+ public Document<T> setEntityTag(EntityTag tag) {
+ this.etag = tag;
+ return this;
+ }
+
+ public Document<T> setEntityTag(String tag) {
+ this.etag = new EntityTag(tag);
+ return this;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public Lang getLanguageTag() {
+ String lang = getLanguage();
+ return (lang != null) ? new Lang(lang) : null;
+ }
+
+ public Document<T> setLanguage(String lang) {
+ this.language = lang;
+ return this;
+ }
+
+ public String getSlug() {
+ return slug;
+ }
+
+ public Document<T> setSlug(String slug) {
+ this.slug = slug;
+ return this;
+ }
+
+ public boolean getMustPreserveWhitespace() {
+ return preserve;
+ }
+
+ public Document<T> setMustPreserveWhitespace(boolean preserve) {
+ this.preserve = preserve;
+ return this;
+ }
+
+ public XMLVersion getXmlVersion() {
+ return XMLVersion.get(super.getXMLVersion());
+ }
+
+ public WriterOptions getDefaultWriterOptions() {
+ return new FOMWriter().getDefaultWriterOptions();
+ }
+
+ /**
+ * Ensure that the underlying streams are fully parsed. We might
eventually need to find a more efficient way of
+ * doing this, but for now, calling toString() will ensure that this
particular object is fully parsed and ready to
+ * be modified.
+ */
+ public <X extends Base> X complete() {
+ if (!isComplete() && getRoot() != null)
+ getRoot().complete();
+ return (X)this;
+ }
+
+ public void writeTo(String writer, OutputStream out) throws IOException {
+ writeTo(getFactory().getAbdera().getWriterFactory().getWriter(writer),
out);
+ }
+
+ public void writeTo(String writer, java.io.Writer out) throws IOException {
+ writeTo(getFactory().getAbdera().getWriterFactory().getWriter(writer),
out);
+ }
+
+ public void writeTo(String writer, OutputStream out, WriterOptions
options) throws IOException {
+ writeTo(getFactory().getAbdera().getWriterFactory().getWriter(writer),
out, options);
+ }
+
+ public void writeTo(String writer, java.io.Writer out, WriterOptions
options) throws IOException {
+ writeTo(getFactory().getAbdera().getWriterFactory().getWriter(writer),
out, options);
+ }
+
+ public String toFormattedString() {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ writeTo("prettyxml", out);
+ return new String(out.toByteArray(), "UTF-8");
+ } catch (Exception e) {
+ return toString();
+ }
+ }
+}
Propchange:
abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMDocument.java
------------------------------------------------------------------------------
svn:mime-type = text/plain