Author: ruchithf
Date: Wed Sep 13 01:53:11 2006
New Revision: 442903
URL: http://svn.apache.org/viewvc?view=rev&rev=442903
Log:
Adding QName and char[] support in DOOM OMText Impl
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java?view=diff&rev=442903&r1=442902&r2=442903
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
Wed Sep 13 01:53:11 2006
@@ -41,6 +41,10 @@
private boolean isBinary;
private String contentID = null;
+
+ protected OMNamespace textNS = null;
+
+ protected char[] charArray;
/**
* Field dataHandler contains the DataHandler. Declaring as Object to
remove
@@ -148,6 +152,14 @@
this.ns = XOP_NS;
}
+
+ public TextImpl(DocumentImpl ownerNode, char[] value, OMFactory factory) {
+ super(ownerNode, factory);
+ this.charArray = value;
+ this.done = true;
+ this.ns = XOP_NS;
+ }
+
/**
* @param ownerNode
* @param value
@@ -161,6 +173,22 @@
done = true;
}
+ public TextImpl(OMContainer parent, QName text,OMFactory factory) {
+ this(parent, text, OMNode.TEXT_NODE, factory);
+
+ }
+
+ public TextImpl(OMContainer parent, QName text, int nodeType,
+ OMFactory factory) {
+ this(((ElementImpl)parent).ownerNode, factory);
+ if(text != null) {
+ this.textNS = ((ElementImpl)
parent).findNamespace(text.getNamespaceURI(), text.getPrefix());
+ } else {
+
+ }
+ this.textValue = new StringBuffer((text == null) ? "" :
text.getLocalPart());
+ this.done = true;
+ }
/**
* Breaks this node into two nodes at the specified offset, keeping both in
* the tree as siblings. After being split, this node will contain all the
@@ -278,8 +306,10 @@
}
public String getText() {
- if (this.textValue != null) {
- return this.textValue.toString();
+ if (this.textNS != null) {
+ return getTextString();
+ } else if (this.charArray != null || this.textValue != null) {
+ return getTextFromProperPlace();
} else {
try {
InputStream inStream;
@@ -305,15 +335,64 @@
}
public char[] getTextCharacters() {
- return textValue.toString().toCharArray();
+ return charArray != null ? charArray : this.textValue.toString()
+ .toCharArray();
}
public boolean isCharacters() {
- return false; //To change body of implemented methods use File |
Settings | File Templates.
+ return charArray != null;
+ }
+
+ private String getTextFromProperPlace() {
+ return charArray != null ? new String(charArray) :
textValue.toString();
+ }
+
+ private String getTextString() {
+ if (textNS != null) {
+ String prefix = textNS.getPrefix();
+ if (prefix == null || "".equals(prefix)) {
+ return getTextFromProperPlace();
+ } else {
+ return prefix + ":" + getTextFromProperPlace();
+ }
+ }
+
+ return null;
}
public QName getTextAsQName() {
- throw new UnsupportedOperationException();
+ if (textNS != null) {
+ String prefix = textNS.getPrefix();
+ String name = textNS.getNamespaceURI();
+ if (prefix == null || "".equals(prefix)) {
+ return new QName(name, getTextFromProperPlace());
+ } else {
+ return new QName(textNS.getNamespaceURI(),
getTextFromProperPlace(), prefix);
+ }
+ } else if (this.textValue != null || charArray != null) {
+ return new QName(getTextFromProperPlace());
+ } else {
+ try {
+ InputStream inStream;
+ inStream = this.getInputStream();
+ byte[] data;
+ StringBuffer text = new StringBuffer();
+ do {
+ data = new byte[1024];
+ int len;
+ while ((len = inStream.read(data)) > 0) {
+ byte[] temp = new byte[len];
+ System.arraycopy(data, 0, temp, 0, len);
+ text.append(Base64.encode(temp));
+ }
+
+ } while (inStream.available() > 0);
+
+ return new QName(text.toString());
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
}
public String getNodeValue() throws DOMException {
@@ -332,9 +411,10 @@
* this should return a DataHandler containing the binary data
* reperesented by the Base64 strings stored in OMText
*/
- if (textValue != null & isBinary) {
+ if ((textValue != null|| charArray != null || textNS != null) &
isBinary) {
+ String text = textNS == null ? getTextFromProperPlace() :
getTextString();
return DataHandlerUtils
- .getDataHandlerFromText(textValue.toString(), mimeType);
+ .getDataHandlerFromText(text, mimeType);
} else {
if (dataHandlerObject == null) {
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?view=diff&rev=442903&r1=442902&r2=442903
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
Wed Sep 13 01:53:11 2006
@@ -182,9 +182,13 @@
}
public OMText createOMText(OMContainer parent, QName text) {
- throw new UnsupportedOperationException();
+ return new TextImpl(parent, text, this);
}
-
+
+ public OMText createOMText(OMContainer parent, QName text, int type) {
+ return new TextImpl(parent, text, type, this);
+ }
+
public OMText createOMText(OMContainer parent, String text, int type) {
OMText textNode = createOMText(parent, text);
((OMNodeEx) textNode).setType(type);
@@ -192,13 +196,11 @@
}
public OMText createOMText(OMContainer parent, char[] charArary, int type)
{
- // TODO : Fix me
- throw new UnsupportedOperationException();
- }
-
- public OMText createOMText(OMContainer parent, QName text, int type) {
- // TODO : Fix me
- throw new UnsupportedOperationException();
+ ElementImpl parentElem = (ElementImpl) parent;
+ TextImpl txt = new TextImpl((DocumentImpl) parentElem
+ .getOwnerDocument(), charArary, this);
+ parentElem.addChild(txt);
+ return txt;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]