| Constructor: |
public OMTextImpl(String s,
OMFactory factory) {
this(s, TEXT_NODE, factory);
}
|
public OMTextImpl(Object dataHandler,
OMFactory factory) {
this(dataHandler, true, factory);
}
Parameters:
dataHandler - To send binary optimised content Created programatically.
|
public OMTextImpl(String s,
int nodeType,
OMFactory factory) {
this(null, s, nodeType, factory);
}
Parameters:
s -
nodeType - - OMText can handle CHARACTERS, SPACES, CDATA and ENTITY REFERENCES.
Constants for this can be found in OMNode.
|
public OMTextImpl(OMContainer parent,
String text,
OMFactory factory) {
this(parent, text, TEXT_NODE, factory);
}
Parameters:
parent -
text -
|
public OMTextImpl(OMContainer parent,
OMTextImpl source,
OMFactory factory) {
super(parent, factory, true);
// Copy the value of the text
this.value = source.value;
this.nodeType = source.nodeType;
// Clone the charArray (if it exists)
if (source.charArray != null) {
this.charArray = new char[source.charArray.length];
System.arraycopy(source.charArray, 0, this.charArray, 0, source.charArray.length);
}
// Turn off calcNS...the namespace will need to be recalculated
// in the new tree's context.
this.calcNS = false;
this.textNS = null;
// Copy the optimized related settings.
this.optimize = source.optimize;
this.mimeType = source.mimeType;
this.isBinary = source.isBinary;
// TODO
// Do we need a deep copy of the data-handler
this.contentID = source.contentID;
this.dataHandlerObject = source.dataHandlerObject;
this.localName = source.localName;
if (source.attribute != null) {
this.attribute = factory.createOMAttribute(source.attribute.getLocalName(),
source.attribute.getNamespace(),
source.attribute.getAttributeValue());
}
}
Construct OMTextImpl that is a copy of the source OMTextImpl Parameters:
parent -
source - OMTextImpl
factory -
|
public OMTextImpl(OMContainer parent,
QName text,
OMFactory factory) {
this(parent, text, TEXT_NODE, factory);
}
|
public OMTextImpl(Object dataHandler,
boolean optimize,
OMFactory factory) {
super(factory);
this.dataHandlerObject = dataHandler;
this.isBinary = true;
this.optimize = optimize;
done = true;
this.nodeType = TEXT_NODE;
}
Parameters:
dataHandler -
optimize - To send binary content. Created progrmatically.
|
public OMTextImpl(OMContainer parent,
String text,
int nodeType,
OMFactory factory) {
super(parent, factory, true);
this.value = text == null ? EMTPY_STRING : text;
this.nodeType = nodeType;
}
|
public OMTextImpl(OMContainer parent,
char[] charArray,
int nodeType,
OMFactory factory) {
super(parent, factory, true);
this.charArray = charArray;
this.nodeType = nodeType;
}
|
public OMTextImpl(OMContainer parent,
QName text,
int nodeType,
OMFactory factory) {
super(parent, factory, true);
if (text == null) throw new IllegalArgumentException("QName text arg cannot be null!");
this.calcNS = true;
this.textNS =
((OMElementImpl) parent).handleNamespace(text.getNamespaceURI(), text.getPrefix());
this.value = textNS.getPrefix() + ":" + text.getLocalPart();
this.nodeType = nodeType;
}
|
public OMTextImpl(String s,
String mimeType,
boolean optimize,
OMFactory factory) {
this(null, s, mimeType, optimize, factory);
}
Parameters:
s - - base64 encoded String representation of Binary
mimeType - of the Binary
|
public OMTextImpl(String contentID,
OMContainer parent,
OMXMLParserWrapper builder,
OMFactory factory) {
super(parent, factory, false);
this.contentID = contentID;
this.optimize = true;
this.isBinary = true;
this.builder = builder;
this.nodeType = TEXT_NODE;
}
Parameters:
contentID -
parent -
builder - Used when the builder is encountered with a XOP:Include tag Stores a
reference to the builder and the content-id. Supports deferred parsing of
MIME messages.
|
public OMTextImpl(OMContainer parent,
String s,
String mimeType,
boolean optimize,
OMFactory factory) {
this(parent, s, factory);
this.mimeType = mimeType;
this.optimize = optimize;
this.isBinary = true;
done = true;
this.nodeType = TEXT_NODE;
}
Parameters:
parent -
s - - base64 encoded String representation of Binary
mimeType - of the Binary
|
| Method from org.apache.axiom.om.impl.llom.OMTextImpl Detail: |
public void buildWithAttachments() {
if (!this.done) {
this.build();
}
if (isOptimized()) {
this.getDataHandler();
}
}
|
public void discard() throws OMException {
if (done) {
this.detach();
}
}
A slightly different implementation of the discard method. |
public String getContentID() {
if (contentID == null) {
contentID = UUIDGenerator.getUUID()
+ "@apache.org";
}
return this.contentID;
}
|
public Object getDataHandler() {
if ((value != null || charArray != null) && isBinary) {
String text = getTextFromProperPlace();
return org.apache.axiom.attachments.utils.DataHandlerUtils
.getDataHandlerFromText(text, mimeType);
} else {
if (dataHandlerObject == null) {
if (contentID == null) {
throw new RuntimeException("ContentID is null");
}
dataHandlerObject = ((XOPBuilder) builder)
.getDataHandler(contentID);
}
return dataHandlerObject;
}
}
|
public InputStream getInputStream() throws OMException {
if (isBinary) {
if (dataHandlerObject == null) {
getDataHandler();
}
InputStream inStream;
javax.activation.DataHandler dataHandler =
(javax.activation.DataHandler) dataHandlerObject;
try {
inStream = dataHandler.getDataSource().getInputStream();
} catch (IOException e) {
throw new OMException(
"Cannot get InputStream from DataHandler." + e);
}
return inStream;
} else {
throw new OMException("Unsupported Operation");
}
}
|
public String getLocalName() {
return localName;
}
|
public OMNamespace getNamespace() {
// If the namespace has already been determined, return it
// Otherwise calculate the namespace if the text contains a colon and is not detached.
if (calcNS) {
return textNS;
} else {
calcNS = true;
if (getParent() != null) {
String text = getTextFromProperPlace();
if (text != null) {
int colon = text.indexOf(':");
if (colon > 0) {
textNS = ((OMElementImpl) getParent()).
findNamespaceURI(text.substring(0, colon));
if (textNS != null) {
charArray = null;
value = text.substring(colon + 1);
}
}
}
}
}
return textNS;
}
|
public String getText() throws OMException {
if (charArray != null || this.value != null) {
return getTextFromProperPlace();
} else {
try {
return TextHelper.toString(getInputStream());
} catch (Exception e) {
throw new OMException(e);
}
}
}
|
public QName getTextAsQName() throws OMException {
return ((OMElement)parent).resolveQName(getTextFromProperPlace());
}
|
public char[] getTextCharacters() {
return charArray != null ? charArray : value.toCharArray();
}
|
public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
internalSerializeLocal(writer);
}
|
public void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException {
internalSerializeLocal(writer);
}
|
public boolean isBinary() {
return isBinary;
}
|
public boolean isCharacters() {
return charArray != null;
}
|
public boolean isOptimized() {
return optimize;
}
|
static void serializeAttribute(OMAttribute attr,
XMLStreamWriter writer) throws XMLStreamException {
// first check whether the attribute is associated with a namespace
OMNamespace ns = attr.getNamespace();
String prefix;
String namespaceName;
if (ns != null) {
// add the prefix if it's availble
prefix = ns.getPrefix();
namespaceName = ns.getNamespaceURI();
if (prefix != null) {
writer.writeAttribute(prefix, namespaceName, attr
.getLocalName(), attr.getAttributeValue());
} else {
writer.writeAttribute(namespaceName, attr.getLocalName(), attr
.getAttributeValue());
}
} else {
writer.writeAttribute(attr.getLocalName(), attr.getAttributeValue());
}
}
Method serializeAttribute. |
static void serializeNamespace(OMNamespace namespace,
XMLStreamWriter writer) throws XMLStreamException {
if (namespace != null) {
String uri = namespace.getNamespaceURI();
String ns_prefix = namespace.getPrefix();
writer.writeNamespace(ns_prefix, namespace.getNamespaceURI());
writer.setPrefix(ns_prefix, uri);
}
}
Method serializeNamespace. |
public void setBinary(boolean value) {
isBinary = value;
}
Receiving binary can happen as either MTOM attachments or as Base64 Text In the case of
Base64 user has to explicitly specify that the content is binary, before calling
getDataHandler(), getInputStream().... |
public void setContentID(String cid) {
this.contentID = cid;
}
|
public void setOptimize(boolean value) {
this.optimize = value;
if (value) {
isBinary = true;
}
}
|