/** * Create a comment type BXML. * * @param content Text content * @return BXML Text type BXML */ public static BXML<?> createXMLText(String content) { // Remove carriage return on windows environments to eliminate additional 
 being added content = content.replace("\r\n", "\n"); OMText omText = OM_FACTORY.createOMText(content); return new BXMLItem(omText); }
/** * Create a processing instruction type BXML. * * @param tartget PI target * @param data PI data * @return BXML Processing instruction type BXML */ public static BXML<?> createXMLProcessingInstruction(String tartget, String data) { OMProcessingInstruction omText = OM_FACTORY.createOMProcessingInstruction(OM_FACTORY.createOMDocument(), tartget, data); return new BXMLItem(omText); }
/** * Create a comment type BXML. * * @param content Comment content * @return BXML Comment type BXML */ public static BXML<?> createXMLComment(String content) { OMComment omComment = OM_FACTORY.createOMComment(OM_FACTORY.createOMDocument(), content); return new BXMLItem(omComment); }
/** * Recursively traverse and add the descendant with the given name to the descendants list. * * @param descendants List to add descendants * @param currentElement Current node * @param qname Qualified name of the descendants to search */ protected void addDescendants(List<BXML<?>> descendants, OMElement currentElement, String qname) { Iterator<OMNode> childrenItr = currentElement.getChildren(); while (childrenItr.hasNext()) { OMNode child = childrenItr.next(); if (child.getType() != OMNode.ELEMENT_NODE) { continue; } if (qname.equals(((OMElement) child).getQName().toString())) { descendants.add(new BXMLItem(child)); continue; } addDescendants(descendants, (OMElement) child, qname); } }
/** * Converts a {@link BTable} to {@link BXML}. * * @param table {@link BTable} to convert * @return converted {@link BXML} */ @SuppressWarnings("rawtypes") public static BXML tableToXML(BTable table) { OMSourcedElementImpl omSourcedElement = new OMSourcedElementImpl(); omSourcedElement.init(new TableOMDataSource(table, null, null)); return new BXMLItem(omSourcedElement); }
/** * {@inheritDoc} */ @Override public BXML<?> children() { BValueArray elementsSeq = new BValueArray(); switch (nodeType) { case ELEMENT: Iterator<OMNode> childrenItr = ((OMElement) omNode).getChildren(); int i = 0; while (childrenItr.hasNext()) { elementsSeq.add(i++, new BXMLItem(childrenItr.next())); } break; default: break; } return new BXMLSequence(elementsSeq); }
/** * Create a XML sequence from string reader. * * @param reader XML reader * @return XML Sequence */ @SuppressWarnings("unchecked") public static BXML<?> parse(Reader reader) { BValueArray elementsSeq = new BValueArray(); OMDocument doc; try { doc = OMXMLBuilderFactory.createOMBuilder(STAX_PARSER_CONFIGURATION, reader).getDocument(); Iterator<OMNode> docChildItr = doc.getChildren(); int i = 0; while (docChildItr.hasNext()) { elementsSeq.add(i++, new BXMLItem(docChildItr.next())); } } catch (DeferredParsingException e) { throw new BallerinaException(e.getCause().getMessage()); } catch (Throwable e) { throw new BallerinaException("failed to create xml: " + e.getMessage()); } return new BXMLSequence(elementsSeq); }
/** * Create a XML sequence from string inputstream. * * @param xmlStream XML input stream * @return XML Sequence */ @SuppressWarnings("unchecked") public static BXML<?> parse(InputStream xmlStream) { BValueArray elementsSeq = new BValueArray(); OMDocument doc; try { doc = OMXMLBuilderFactory.createOMBuilder(STAX_PARSER_CONFIGURATION, xmlStream).getDocument(); Iterator<OMNode> docChildItr = doc.getChildren(); int i = 0; while (docChildItr.hasNext()) { elementsSeq.add(i++, new BXMLItem(docChildItr.next())); } } catch (DeferredParsingException e) { throw new BallerinaException(e.getCause().getMessage()); } catch (Throwable e) { throw new BallerinaException("failed to create xml: " + e.getMessage()); } return new BXMLSequence(elementsSeq); }
/** * {@inheritDoc} */ @Override public BXML<?> children(String qname) { BValueArray elementsSeq = new BValueArray(); switch (nodeType) { case ELEMENT: /* * Here we are not using "((OMElement) omNode).getChildrenWithName(qname))" method, since as per the * documentation of AxiomContainer.getChildrenWithName, if the namespace part of the qname is empty, it * will look for the elements which matches only the local part and returns. i.e: It will not match the * namespace. This is not the behavior we want. Hence we are explicitly creating an iterator which * will return elements that will match both namespace and the localName, regardless whether they are * empty or not. */ Iterator<OMNode> childrenItr = new OMChildrenQNameIterator(((OMElement) omNode).getFirstOMChild(), getQname(qname)); int i = 0; while (childrenItr.hasNext()) { OMNode node = childrenItr.next(); elementsSeq.add(i++, new BXMLItem(node)); } break; default: break; } return new BXMLSequence(elementsSeq); }
/** * Create a XML sequence from string inputstream with a given charset. * * @param xmlStream XML imput stream * @param charset Charset to be used for parsing * @return XML Sequence */ @SuppressWarnings("unchecked") public static BXML<?> parse(InputStream xmlStream, String charset) { BValueArray elementsSeq = new BValueArray(); OMDocument doc; try { doc = OMXMLBuilderFactory.createOMBuilder(STAX_PARSER_CONFIGURATION, xmlStream, charset).getDocument(); Iterator<OMNode> docChildItr = doc.getChildren(); int index = 0; while (docChildItr.hasNext()) { elementsSeq.add(index++, new BXMLItem(docChildItr.next())); } } catch (DeferredParsingException e) { throw new BallerinaException(e.getCause().getMessage()); } catch (Throwable e) { throw new BallerinaException("failed to create xml: " + e.getMessage()); } return new BXMLSequence(elementsSeq); }
case TypeTags.XML_TAG: String xmlValue = rs.getString(index); value = new BXMLItem(xmlValue); break; case TypeTags.ARRAY_TAG:
/** * {@inheritDoc} */ @Override public BXML<?> children() { BValueArray elementsSeq = new BValueArray(BTypes.typeXML); int index = 0; for (int i = 0; i < sequence.size(); i++) { BXMLItem element = (BXMLItem) sequence.getRefValue(i); if (element.getNodeType() != XMLNodeType.ELEMENT) { continue; } Iterator<OMNode> childrenItr = ((OMElement) element.value()).getChildren(); while (childrenItr.hasNext()) { elementsSeq.add(index++, new BXMLItem(childrenItr.next())); } } return new BXMLSequence(elementsSeq); }
/** * {@inheritDoc} */ @Override public BXML<?> children(String qname) { BValueArray elementsSeq = new BValueArray(); QName name = getQname(qname); int index = 0; for (int i = 0; i < sequence.size(); i++) { BXMLItem element = (BXMLItem) sequence.getRefValue(i); if (element.getNodeType() != XMLNodeType.ELEMENT) { continue; } Iterator<OMNode> childrenItr = ((OMElement) element.value()).getChildrenWithName(name); while (childrenItr.hasNext()) { OMNode child = childrenItr.next(); elementsSeq.add(index++, new BXMLItem(child)); } } return new BXMLSequence(elementsSeq); }
return new BXMLItem(omElement);
omElementArrayList, attributePrefix, arrayEntryTag); if (nodeName == null) { // Outermost object omElementArrayList.add(new BXMLItem(currentRoot)); currentRoot = null; omElementArrayList, attributePrefix, arrayEntryTag); if (nodeName == null) { // Outermost array omElementArrayList.add(new BXMLItem(currentRoot)); currentRoot = null;
return new BXMLItem(clonedNode);