org.apache.axiom.om.OMText类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.apache.axiom.om.OMText类的一些代码示例,展示了OMText类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OMText类的具体详情如下:
包路径:org.apache.axiom.om.OMText
类名称:OMText

OMText介绍

[英]Represents character data in an XML document. A node of this type is used to represent character data that may appear in element content as well as the prolog and epilog of a document. Note that this node type is used for normal character data, CDATA sections and ignorable whitespace. The OMNode#getType() method may be used to distinguish between these different types of character data.

By default, Axiom uses StAX parsers configured in coalescing mode. As a consequence, CDATA sections will not result in nodes of type OMNode#CDATA_SECTION_NODE nodes, but of type OMNode#TEXT_NODE(See the Javadoc of org.apache.axiom.om.util.StAXUtils for information about how to change this behavior). In addition, the object model instance will never contain two adjacent OMText siblings.

The same is not necessarily true for Axiom trees that have been built or updated programmatically or that contain nodes resulting from the expansion of an OMSourcedElement. Therefore, code that manipulates character data MUST NOT assume that text nodes are always coalesced. In particular, when extracting character data from an element, OMElement#getText()should be used instead of OMText#getText().

An OMText node stores the character data as String, char[] or a javax.activation.DataHandler. The latter is used for base64 encoded binary data.
[中]表示XML文档中的字符数据。这种类型的节点用于表示可能出现在元素内容以及文档的序言和尾声中的字符数据。请注意,此节点类型用于普通字符数据、CDATA节和可忽略的空白。OMNode#getType()方法可用于区分这些不同类型的字符数据。
默认情况下,Axiom使用以合并模式配置的StAX解析器。因此,CDATA节不会产生OMNode#CDATA#SECTION#NODE NODE类型的节点,而是OMNode#TEXT#NODE类型的节点(有关如何更改此行为的信息,请参阅org.apache.axiom.om.util.StAXUtils的Javadoc)。此外,对象模型实例永远不会包含两个相邻的OMText同级。
对于以编程方式构建或更新的Axiom树,或者包含OMSourceElement扩展产生的节点的Axiom树,情况不一定如此。因此,操纵字符数据的代码不能假定文本节点总是合并的。特别是,从元素中提取字符数据时,应该使用OmeElement#getText()而不是OMText#getText()。
OMText节点将字符数据存储为字符串、char[]或javax。激活。数据处理程序。后者用于base64编码的二进制数据。

代码示例

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * Retrieve the string-value of a text node. This must not be null and should not be the empty
 * string. The XPath data model does not allow empty text nodes.
 *
 * @param object the text node
 * @return Returns the string-value of the node.
 */
public String getTextStringValue(Object object) {
  return ((OMText) object).getText();
}

代码示例来源:origin: org.apache.axis2/axis2-adb

public static DataHandler getDataHandler(OMElement element) {
  OMNode node = element.getFirstOMChild();
  if (node instanceof OMText) {
    OMText txt = (OMText)node;
    if (txt.isOptimized()) {
      return (DataHandler)txt.getDataHandler();
    } else {
      return new DataHandler(new ByteArrayDataSource(Base64Utils.decode(txt.getText())));
    }
  }
  return null;
}

代码示例来源:origin: org.apache.rampart/rampart-core

/**
 * Mark the requied Base64 text values as optimized
 * @param env
 * @param optimizeParts This is a set of xPath expressions
 *  
 * @throws WSSecurityException
 */
public static void optimize(SOAPEnvelope env, String optimizeParts) throws WSSecurityException {
  String separater = "<>";
  StringTokenizer tokenizer = new StringTokenizer(optimizeParts, separater);
  while(tokenizer.hasMoreTokens()) {
    String xpathExpr = tokenizer.nextToken(); 
    //Find binary content
    List list = findElements(env,xpathExpr);
    Iterator cipherValueElements = list.iterator();
    while (cipherValueElements.hasNext()) {
      OMElement element = (OMElement) cipherValueElements.next();
      OMText text = (OMText)element.getFirstOMChild();
      text.setOptimize(true);
    }
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * @deprecated
 * Serialization code should use
 * {@link XMLStreamWriterUtils#writeDataHandler(XMLStreamWriter, DataHandler, String, boolean)}
 * or {@link XMLStreamWriterUtils#writeDataHandler(XMLStreamWriter, DataHandlerProvider, String, boolean)}
 * to submit any binary content and let this writer decide whether the content should be
 * written as base64 encoded character data or using <tt>xop:Include</tt>. If this is not
 * possible, then {@link #prepareDataHandler(DataHandler)} should be used.
 */
public void writeOptimized(OMText node) {
  log.debug("Start MTOMXMLStreamWriter.writeOptimized()");
  otherParts.add(new Part(node.getContentID(), (DataHandler)node.getDataHandler()));    
  log.debug("Exit MTOMXMLStreamWriter.writeOptimized()");
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public void writeTextTo(Writer writer) throws XMLStreamException, IOException {
  switch (currentEvent) {
    case CHARACTERS:
    case CDATA:
    case SPACE:
      OMText text = (OMText)node;
      if (text.isCharacters()) {
        writer.write(text.getTextCharacters());
      } else {
        // TODO: we should cover the binary case in an optimized way
        writer.write(text.getText());
      }
      break;
    case COMMENT:
      writer.write(((OMComment)node).getValue());
      break;
    default:
      throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

OMText importedText = (OMText) child;
OMText newText;
if (importedText.isBinary()) {
  boolean isOptimize = importedText.isOptimized();
  newText = createOMText(importedText
      .getDataHandler(), isOptimize);
} else if (importedText.isCharacters()) {
  newText = createOMText(null, importedText
      .getTextCharacters(), importedText.getType());
} else {
  newText = createOMText(null, importedText
      .getText()/*, importedText.getOMNodeType()*/);

代码示例来源:origin: org.apache.synapse/synapse-samples

public boolean mediate(MessageContext msgCtx) {
  try {
    log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length);
    SOAPBody soapBody = msgCtx.getEnvelope().getBody();
    OMElement firstElement = soapBody.getFirstElement();
    log.debug("First Element : "+firstElement.getLocalName());
    log.debug("First Element Text : "+firstElement.getText());
    OMText binaryNode =(OMText) firstElement.getFirstOMChild();
    log.debug("First Element Node Text : "+binaryNode.getText());
    DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler();
    InputStream inputStream = dataHandler.getInputStream();
    byte[] searchByte = new byte[length];
    inputStream.skip(offset - 1);
    int readBytes = inputStream.read(searchByte,0,length);
    String outString = new String(searchByte,binaryEncoding);
    msgCtx.setProperty(variableName,outString);
    log.debug("Set property to MsgCtx, "+variableName+" = "+outString);
    inputStream.close();
  } catch (IOException e) {
    log.error("Excepton on mediation : "+e.getMessage());
  }
  return true;
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public DataHandler getDataHandler() throws XMLStreamException {
  if (node instanceof OMText) {
    return (DataHandler)((OMText)node).getDataHandler();
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.sandesha2/sandesha2-samples

public void MTOMPing(OMElement in) throws Exception  {
    OMElement attachmentElem = in.getFirstChildWithName(new QName(applicationNamespaceName, Attachment));
    if (attachmentElem == null)
      throw new AxisFault("'Attachment' element is not present as a child of the 'Ping' element");

    OMText binaryElem = (OMText) attachmentElem.getFirstOMChild();

    binaryElem.setOptimize(true);
    DataHandler dataHandler = (DataHandler) binaryElem.getDataHandler();

    try {
      
      File destinationFile = new File(DESTINATION_IMAGE_FILE);
      if (destinationFile.exists())
        destinationFile.delete();

      FileOutputStream fileOutputStream = new FileOutputStream(DESTINATION_IMAGE_FILE);

      InputStream inputStream = dataHandler.getDataSource().getInputStream();
      byte[] bytes = new byte[5000];
      int length = inputStream.read(bytes);
      fileOutputStream.write(bytes, 0, length);
      fileOutputStream.close();

    } catch (Exception e) {
      throw AxisFault.makeFault(e);
    }
  }
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

if (lastNode instanceof OMText) {
  OMText text = (OMText) lastNode;
  return new Boolean(text.isBinary());
if (lastNode instanceof OMText) {
  OMText text = (OMText) lastNode;    
  if (text.isBinary())
    return text.getDataHandler();

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public boolean isOptimized() {
  if (node instanceof OMText) {
    return ((OMText)node).isOptimized();
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

public String getContentID() {
  if (node instanceof OMText) {
    return ((OMText)node).getContentID();
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

OMText importedText = (OMText) child;
OMText newText;
if (importedText.isBinary()) {
  boolean isOptimize = importedText.isOptimized();
  newText = createOMText(importedText
      .getDataHandler(), isOptimize);
} else if (importedText.isCharacters()) {
  newText = createOMText(null, importedText
      .getTextCharacters(), importedText.getType());
} else {
  newText = createOMText(null, importedText
      .getText()/*, importedText.getOMNodeType()*/);

代码示例来源:origin: org.wso2.ei/org.wso2.ei.samples

public boolean mediate(MessageContext msgCtx) {
  try {
    log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length);
    SOAPBody soapBody = msgCtx.getEnvelope().getBody();
    OMElement firstElement = soapBody.getFirstElement();
    log.debug("First Element : "+firstElement.getLocalName());
    log.debug("First Element Text : "+firstElement.getText());
    OMText binaryNode =(OMText) firstElement.getFirstOMChild();
    log.debug("First Element Node Text : "+binaryNode.getText());
    DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler();
    InputStream inputStream = dataHandler.getInputStream();
    byte[] searchByte = new byte[length];
    inputStream.skip(offset - 1);
    int readBytes = inputStream.read(searchByte,0,length);
    String outString = new String(searchByte,binaryEncoding);
    msgCtx.setProperty(variableName,outString);
    log.debug("Set property to MsgCtx, "+variableName+" = "+outString);
    inputStream.close();
  } catch (IOException e) {
    log.error("Excepton on mediation : "+e.getMessage());
  }
  return true;
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public DataHandler getDataHandler() throws XMLStreamException {
  if (node instanceof OMText) {
    return (DataHandler)((OMText)node).getDataHandler();
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public void writeTextTo(Writer writer) throws XMLStreamException, IOException {
  switch (currentEvent) {
    case CHARACTERS:
    case CDATA:
    case SPACE:
      OMText text = (OMText)node;
      if (text.isCharacters()) {
        writer.write(text.getTextCharacters());
      } else {
        // TODO: we should cover the binary case in an optimized way
        writer.write(text.getText());
      }
      break;
    case COMMENT:
      writer.write(((OMComment)node).getValue());
      break;
    default:
      throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public boolean isOptimized() {
  if (node instanceof OMText) {
    return ((OMText)node).isOptimized();
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

public String getContentID() {
  if (node instanceof OMText) {
    return ((OMText)node).getContentID();
  } else {
    throw new IllegalStateException();
  }
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-c14n

public String getNodeValue() {
  return txt.getText();
}

代码示例来源:origin: org.bluestemsoftware.open.eoa.ext/open-eoa-aspect-axiom

OMText importedText = (OMText) child;
OMText newText;
if (importedText.isBinary()) {
  boolean isOptimize = importedText.isOptimized();
  newText = this.factory.createOMText(importedText
      .getDataHandler(), isOptimize);
} else if (importedText.isCharacters()) {
  newText = new TextImpl((DocumentImpl) this.getOwnerDocument(),
              importedText.getTextCharacters(), this.factory);
} else {
  newText = new TextImpl((DocumentImpl) this.getOwnerDocument(),
              importedText.getText(), this.factory);

相关文章