org.apache.xmlbeans.XmlCursor Java Examples

The following examples show how to use org.apache.xmlbeans.XmlCursor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlPath.java    From mdw with Apache License 2.0 7 votes vote down vote up
private boolean verify_condition(XmlCursor cursor, Condition condition) {
    boolean more, found=false;
    XmlBookmark bookmark = new XmlBookmark(){};
    cursor.setBookmark(bookmark);
    if (condition.isAttribute) {
        for (more=cursor.toFirstAttribute(); more&&!found; more=cursor.toNextAttribute()) {
            if (cursor.getName().getLocalPart().equals(condition.name)) {
                found = cursor.getTextValue().trim().equals(condition.value);
            }
        }
    } else {
        for (more=cursor.toFirstChild(); more&&!found; more=cursor.toNextSibling()) {
            if (cursor.getName().getLocalPart().equals(condition.name)) {
                found = cursor.getTextValue().trim().equals(condition.value);
            }
        }
    }
    cursor.toBookmark(bookmark);
    return found;
}
 
Example #2
Source File: DhlXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
public void markDocumentsReceived(Collection<String> receivedDocumentIds) {
    String queryMethod = getDatabase() + "." + MARK_DOCUMENTS_RECEIVED + "." + MARK_DOCUMENTS_RECEIVED_VERSION;
    MarkDocumentsReceivedRequestType request = MarkDocumentsReceivedRequestType.Factory.newInstance();
    byte[] attachmentBody = createMarkDocumentsReceivedAttachmentBody(receivedDocumentIds);
    request.setDokumendid(null);
    String cid = AttachmentUtil.getUniqueCid();
    XmlCursor cursor = request.newCursor();
    cursor.toNextToken();
    Element node = (Element) cursor.getDomNode();
    node.setAttribute("href", "cid:" + cid);
    cursor.dispose();

    XRoadAttachment attachment = new XRoadAttachment(cid, "{http://www.w3.org/2001/XMLSchema}base64Binary", attachmentBody);
    log.debug("executing " + queryMethod);
    try {
        XRoadMessage<MarkDocumentsReceivedResponseType> response //
        = send(new XmlBeansXRoadMessage<MarkDocumentsReceivedRequestType>(request, Arrays.asList(attachment)), MARK_DOCUMENTS_RECEIVED,
                MARK_DOCUMENTS_RECEIVED_VERSION);
        if (!response.getContent().getStringValue().equalsIgnoreCase("OK")) {
            throw new RuntimeException("Service didn't respond with 'OK': " + response.getContent().getStringValue());
        }
    } catch (XRoadServiceConsumptionException e) {
        throw new WrappedXRoadServiceConsumptionException(e);
    }
}
 
Example #3
Source File: XML.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
static XML createFromXmlObject(XMLLibImpl lib, XmlObject xo)
{
    XScriptAnnotation anno;
    XmlCursor curs = xo.newCursor();
    if (curs.currentTokenType().isStartdoc())
    {
        curs.toFirstContentToken();
    }
    try {
        anno = new XScriptAnnotation(curs);
        curs.setBookmark(anno);
    } finally {
        curs.dispose();
    }
    return new XML(lib, anno);
}
 
Example #4
Source File: XML.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 */
void remove ()
{
    XmlCursor childCurs = newCursor();

    if (childCurs.currentTokenType().isStartdoc())
    {
        // Remove on the document removes all children.
        TokenType tt = childCurs.toFirstContentToken();
        while (!tt.isEnd() && !tt.isEnddoc())
        {
            removeToken(childCurs);
            tt = childCurs.currentTokenType();      // Now see where we're pointing after the delete -- next token.
        }
    }
    else
    {
            removeToken(childCurs);
    }

    childCurs.dispose();
}
 
Example #5
Source File: Iso19139GmdEncoder.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
private void encodeGmdQuantitativeResult(DQResultPropertyType xbResult,
        GmdQuantitativeResult gmdQuantitativeResult) {
    DQQuantitativeResultType dqQuantitativeResultType = (DQQuantitativeResultType) xbResult
            .addNewAbstractDQResult().substitute(QN_GMD_QUANTITATIVE_RESULT, DQQuantitativeResultType.type);
    GmlBaseUnit unit = gmdQuantitativeResult.getUnit();
    UnitOfMeasurePropertyType valueUnit = dqQuantitativeResultType.addNewValueUnit();
    BaseUnitType xbBaseUnit =
            (BaseUnitType) valueUnit.addNewUnitDefinition().substitute(QN_GML_BASE_UNIT, BaseUnitType.type);
    CodeType xbCatalogSymbol = xbBaseUnit.addNewCatalogSymbol();
    xbCatalogSymbol.setCodeSpace(unit.getCatalogSymbol().getCodeSpace().toString());
    xbCatalogSymbol.setStringValue(unit.getCatalogSymbol().getValue());
    xbBaseUnit.setId(unit.getId());
    xbBaseUnit.addNewUnitsSystem().setHref(unit.getUnitSystem());
    xbBaseUnit.addNewIdentifier().setCodeSpace(unit.getIdentifier());
    if (gmdQuantitativeResult.isSetValueNilReason()) {
        dqQuantitativeResultType.addNewValue().setNilReason(gmdQuantitativeResult.getValueNilReason().name());
    } else {
        XmlCursor cursor = dqQuantitativeResultType.addNewValue().addNewRecord().newCursor();
        cursor.toNextToken();
        cursor.insertChars(gmdQuantitativeResult.getValue());
        cursor.dispose();
    }
}
 
Example #6
Source File: ViisaregisterXTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
public TaotluseAndmedVastus taotluseAndmedNrLiikParing(String taotluseLiik, String taotluseNr) throws XRoadServiceConsumptionException {
	TaotluseAndmedNrLiikSisend paring = TaotluseAndmedNrLiikSisend.Factory.newInstance();
	paring.setTaotluseLiik(com.nortal.jroad.client.viisaregister.types.ee.riik.xtee.viisaregister.producers.producer.viisaregister.TaotluseLiik.Enum.forString(taotluseLiik));
	paring.setTaotluseNr(taotluseNr);

	//Kuna viisaregister tahab kindlasti oma xsi:type atribuute näha, siis paneme need käsitsi külge
	XmlCursor cursor = paring.newCursor();
	while (!cursor.isEnddoc()) {
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("taotluseLiik")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "ns5:taotluseLiik");
		}
		if (cursor.isStart() && cursor.getName().getLocalPart().equals("taotluseNr")) {
			cursor.toNextToken();
			cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"), "xsd:string");
		}
		cursor.toNextToken();
	}

	return viisaregisterXRoadDatabase.taotlAndmedNrLiikParingV1(paring);
}
 
Example #7
Source File: XML.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @return
 */
boolean hasSimpleContent()
{
    boolean simpleContent = false;

    XmlCursor curs = newCursor();

    if (curs.isAttr() || curs.isText()) {
        return true;
    }

    if (curs.isStartdoc())
    {
        curs.toFirstContentToken();
    }

    simpleContent = !(curs.toFirstChild());

    curs.dispose();

    return simpleContent;
}
 
Example #8
Source File: LogicalEquality.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @param xmlOne
 * @param xmlTwo
 * @return
 */
private static boolean attributesEqual(XmlCursor xmlOne, XmlCursor xmlTwo)
{
    boolean result = false;

    if (xmlOne.isAttr() && xmlTwo.isAttr())
    {
        if (qnamesEqual(xmlOne.getName(), xmlTwo.getName()))
        {
            if (xmlOne.getTextValue().equals(xmlTwo.getTextValue()))
            {
                result = true;
            }
        }
    }

    return result;
}
 
Example #9
Source File: LogicalEquality.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * filter out empty textNodes here
 *
 * @param xml
 */
private static void nextToken(XmlCursor xml)
{
    do
    {
        xml.toNextToken();

        if (!xml.isText())
        {
            // Not a text node
            break;
        }
        else if (xml.getChars().trim().length() > 0)
        {
            // Text node is not empty
            break;
        }
    }
    while (true);
}
 
Example #10
Source File: DefaultEbicsRootElement.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Inserts a schema location to the current ebics root element.
 *
 * @param namespaceURI the name space URI
 * @param localPart the local part
 * @param prefix the prefix
 * @param value the value
 */
public void insertSchemaLocation(
    String namespaceURI, String localPart, String prefix, String value) {
  XmlCursor cursor;

  cursor = document.newCursor();
  while (cursor.hasNextToken()) {
    if (cursor.isStart()) {
      cursor.toNextToken();
      cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value);
      break;
    } else {
      cursor.toNextToken();
    }
  }
}
 
Example #11
Source File: XmlHelper.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to append the contents of the child docment to the end of
 * the parent XmlObject. This is useful when dealing with elements without
 * generated methods (like elements with xs:any)
 *
 * @param parent
 *            Parent to append contents to
 * @param childDoc
 *            Xml document containing contents to be appended
 */
public static void append(final XmlObject parent, final XmlObject childDoc) {
    final XmlCursor parentCursor = parent.newCursor();
    parentCursor.toEndToken();

    final XmlCursor childCursor = childDoc.newCursor();
    childCursor.toFirstChild();

    childCursor.moveXml(parentCursor);
    parentCursor.dispose();
    childCursor.dispose();
}
 
Example #12
Source File: XML.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @return
 */
Object copy()
{
    XmlCursor srcCurs = newCursor();

    if (srcCurs.isStartdoc())
    {
        srcCurs.toFirstContentToken();
    }

    XML xml = createEmptyXML(lib);

    XmlCursor destCurs = xml.newCursor();
    destCurs.toFirstContentToken();

    srcCurs.copyXml(destCurs);

    destCurs.dispose();
    srcCurs.dispose();

    return xml;
}
 
Example #13
Source File: XmlHelper.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
public static void fixNamespaceForXsiType(final XmlObject object, final QName value) {
    final XmlCursor cursor = object.newCursor();
    while (cursor.hasNextToken()) {
        if (cursor.toNextToken().isStart()) {
            final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE);
            if (xsiType != null) {

                final String[] toks = xsiType.split(":");
                String localName;
                if (toks.length > 1) {
                    localName = toks[1];
                } else {
                    localName = toks[0];
                }
                if (localName.equals(value.getLocalPart())) {
                    cursor.setAttributeText(W3CConstants.QN_XSI_TYPE,
                            Joiner.on(":").join(XmlHelper.getPrefixForNamespace(object, value.getNamespaceURI()),
                                    value.getLocalPart()));
                }
            }
        }
    }
    cursor.dispose();
}
 
Example #14
Source File: XmlHelper.java    From arctic-sea with Apache License 2.0 6 votes vote down vote up
public static void fixNamespaceForXsiType(XmlObject content, Map<?, ?> namespaces) {
    final XmlCursor cursor = content.newCursor();
    while (cursor.hasNextToken()) {
        if (cursor.toNextToken().isStart()) {
            final String xsiType = cursor.getAttributeText(W3CConstants.QN_XSI_TYPE);
            if (xsiType != null) {
                final String[] toks = xsiType.split(":");
                if (toks.length > 1) {
                    String prefix = toks[0];
                    String localName = toks[1];
                    if (namespaces.containsKey(prefix)) {
                        cursor.setAttributeText(
                                W3CConstants.QN_XSI_TYPE,
                                Joiner.on(":").join(
                                        XmlHelper.getPrefixForNamespace(content, (String) namespaces.get(prefix)),
                                        localName));
                    }
                }

            }
        }
    }
    cursor.dispose();

}
 
Example #15
Source File: RawCopier.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get Xml With Ouput relation Id.
 * 
 * @param inputRelationIdToOutputMap
 *            the relation ID mapping
 * @param inputPartURIToOutputPartURI
 *            the mapping form input part {@link PackagePartName} to output par {@link PackagePartName}
 * @param outputBody
 *            the input {@link IBody}
 * @param inputBody
 *            the ouput {@link IBody}
 * @param xmlObject
 *            the {@link XmlObject} to walk
 * @throws XmlException
 *             XmlException
 * @throws InvalidFormatException
 *             if image copy fails
 * @throws IOException
 *             if a {@link PackagePart} can't be read
 * @throws NoSuchAlgorithmException
 *             if MD5 can't be read
 */
private void updateRelationIds(Map<String, String> inputRelationIdToOutputMap,
        Map<URI, URI> inputPartURIToOutputPartURI, IBody inputBody, IBody outputBody, XmlObject xmlObject)
        throws XmlException, InvalidFormatException, NoSuchAlgorithmException, IOException {
    final XmlObject idAttr = xmlObject.selectAttribute(RELATIONSHIPS_URI, "id");
    if (idAttr != null) {
        updateRelationAttribute(inputRelationIdToOutputMap, inputPartURIToOutputPartURI, inputBody, outputBody,
                idAttr);
    } else {
        final XmlObject embedAttr = xmlObject.selectAttribute(RELATIONSHIPS_URI, "embed");
        if (embedAttr != null) {
            updateRelationAttribute(inputRelationIdToOutputMap, inputPartURIToOutputPartURI, inputBody, outputBody,
                    embedAttr);
        }
    }
    final XmlCursor cursor = xmlObject.newCursor();
    if (cursor.toFirstChild()) {
        updateRelationIds(inputRelationIdToOutputMap, inputPartURIToOutputPartURI, inputBody, outputBody,
                cursor.getObject());
        while (cursor.toNextSibling()) {
            updateRelationIds(inputRelationIdToOutputMap, inputPartURIToOutputPartURI, inputBody, outputBody,
                    cursor.getObject());
        }
    }
    cursor.dispose();
}
 
Example #16
Source File: DefaultEbicsRootElement.java    From ebics-java-client with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
  * Inserts a schema location to the current ebics root element.
  * @param namespaceURI the name space URI
  * @param localPart the local part
  * @param prefix the prefix
  * @param value the value
  */
 public void insertSchemaLocation(String namespaceURI,
                                  String localPart,
                                  String prefix,
                                  String value)
 {
   XmlCursor 			cursor;

   cursor = document.newCursor();
   while (cursor.hasNextToken()) {
     if (cursor.isStart()) {
cursor.toNextToken();
cursor.insertAttributeWithValue(new QName(namespaceURI, localPart, prefix), value);
break;
     } else {
cursor.toNextToken();
     }
   }
 }
 
Example #17
Source File: XML.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 * @param ns
 */
void setNamespace(Namespace ns)
{
    XmlCursor cursor = newCursor();

    try
    {
        if(cursor.isStartdoc())
            cursor.toFirstContentToken();

        if(cursor.isText() ||
           cursor.isComment() ||
           cursor.isProcinst()) return;

        String prefix = ns.prefix();
        if (prefix == null) {
            prefix = "";
        }
        cursor.setName(new javax.xml.namespace.QName(
            ns.uri(), localName(), prefix));
    }
    finally
    {
        cursor.dispose();
    }
}
 
Example #18
Source File: CellBodyContainer.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
@Override
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
    XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor();
    XWPFTable table = insertNewTbl(cursor);

    // hack for cursor.removeXmlContents(); in XWPFTableCell
    List<XWPFTableRow> rows = table.getRows();
    for (int i = 0; i < rows.size(); i++) {
        table.removeRow(i);
    }
    for (int i = 0; i < row; i++) {
        XWPFTableRow tabRow = (table.getRow(i) == null) ? table.createRow() : table.getRow(i);
        for (int k = 0; k < col; k++) {
            if (tabRow.getCell(k) == null) {
                tabRow.createCell();
            }
        }
    }
    return table;
}
 
Example #19
Source File: HeaderFooterBodyContainer.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
@Override
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
    XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor();
    XWPFTable table = insertNewTbl(cursor);
    // hack for cursor.removeXmlContents(); in XWPFHeaderFooter
    List<XWPFTableRow> rows = table.getRows();
    for (int i = 0; i < rows.size(); i++) {
        table.removeRow(i);
    }
    for (int i = 0; i < row; i++) {
        XWPFTableRow tabRow = (table.getRow(i) == null) ? table.createRow() : table.getRow(i);
        for (int k = 0; k < col; k++) {
            if (tabRow.getCell(k) == null) {
                tabRow.createCell();
            }
        }
    }
    return table;
}
 
Example #20
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Special constructor for making an attribute
 *
 */
private static XML createAttributeXML(XMLLibImpl lib, XmlCursor cursor)
{
    if (!cursor.isAttr())
        throw new IllegalArgumentException();

    XScriptAnnotation anno = new XScriptAnnotation(cursor);
    cursor.setBookmark(anno);

    return new XML(lib, anno);
}
 
Example #21
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param name
 */
void setName(QName qname)
{
    XmlCursor cursor = newCursor();

    try
    {
        if(cursor.isStartdoc())
            cursor.toFirstContentToken();

        if(cursor.isText() || cursor.isComment()) return;

        if(cursor.isProcinst())
        {
            String localName = qname.localName();
            cursor.setName(new javax.xml.namespace.QName(localName));
        }
        else
        {
            String prefix = qname.prefix();
            if (prefix == null) { prefix = ""; }
            cursor.setName(new javax.xml.namespace.QName(
                qname.uri(), qname.localName(), prefix));
        }
    }
    finally
    {
        cursor.dispose();
    }
}
 
Example #22
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @return
 */
Object nodeKind()
{
    String result;
    XmlCursor.TokenType tt = tokenType();

    if (tt == XmlCursor.TokenType.ATTR)
    {
        result = "attribute";
    }
    else if (tt == XmlCursor.TokenType.TEXT)
    {
        result = "text";
    }
    else if (tt == XmlCursor.TokenType.COMMENT)
    {
        result = "comment";
    }
    else if (tt == XmlCursor.TokenType.PROCINST)
    {
        result = "processing-instruction";
    }
    else if (tt == XmlCursor.TokenType.START)
    {
        result = "element";
    }
    else
    {
        // A non-existant node has the nodeKind() of text
        result = "text";
    }

    return result;
}
 
Example #23
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void changeNS (String oldURI, String newURI)
{
    XmlCursor curs = newCursor();
    while (curs.toParent()) {
      /* Goto the top of the document */
    }

    TokenType tt = curs.currentTokenType();
    if (tt.isStartdoc())
    {
        tt = curs.toFirstContentToken();
    }

    if (tt.isStart())
    {
        do
        {
            if (tt.isStart() || tt.isAttr() || tt.isNamespace())
            {
                javax.xml.namespace.QName currQName = curs.getName();
                if (oldURI.equals(currQName.getNamespaceURI()))
                {
                    curs.setName(new javax.xml.namespace.QName(newURI, currQName.getLocalPart()));
                }
            }

            tt = curs.toNextToken();
        } while (!tt.isEnddoc() && !tt.isNone());
    }

    curs.dispose();
}
 
Example #24
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param attrCurs
 * @return
 */
private XML createAttributeObject (XmlCursor attrCurs)
{
    XML result = null;

    if (attrCurs.currentTokenType().isAttr())
    {
        result = createAttributeXML(lib, attrCurs);
    }

    return result;
}
 
Example #25
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param destCurs
 * @param newValue
 */
private void replace(XmlCursor destCurs, XML newValue)
{
    if (destCurs.isStartdoc())
    {
        // Can't overwrite a whole document (user really wants to overwrite the contents of).
        destCurs.toFirstContentToken();
    }

    // Orphan the token -- don't delete it outright on the XmlCursor.
    removeToken(destCurs);

    XmlCursor srcCurs = newValue.newCursor();
    if (srcCurs.currentTokenType().isStartdoc())
    {
        // Cann't append a whole document (user really wants to append the contents of).
        srcCurs.toFirstContentToken();
    }

    moveSrcToDest(srcCurs, destCurs, false);

    // Re-link a new annotation to this cursor -- we just deleted the previous annotation on entrance to replace.
    if (!destCurs.toPrevSibling())
    {
        destCurs.toPrevToken();
    }
    destCurs.setBookmark(new XScriptAnnotation(destCurs));

    // todo would be nice if destCurs.toNextSibling went to where the next token if the cursor was pointing at the last token in the stream.
    destCurs.toEndToken();
    destCurs.toNextToken();

    srcCurs.dispose();
}
 
Example #26
Source File: NiceXWPFDocument.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
private boolean toStartCursor(XmlCursor newCursor) {
    do {
        if (newCursor.currentTokenType().isStart()) {
            return true;
        } else if (newCursor.hasNextToken()) { 
            newCursor.toNextToken();
        } else return false;
    } while (true);
}
 
Example #27
Source File: NiceXWPFDocument.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
private void mergeNamespaces(NiceXWPFDocument docMerge) {
    CTDocument1 document = this.getDocument();
    XmlCursor newCursor = document.newCursor();
    if (toStartCursor(newCursor)) {
        CTDocument1 documentMerge = docMerge.getDocument();
        XmlCursor mergeCursor = documentMerge.newCursor();
        if (toStartCursor(mergeCursor)) {
            Map<String, String> addToThis = new HashMap<>();
            mergeCursor.getAllNamespaces(addToThis);
            addToThis.forEach(newCursor::insertNamespace);
        }
        mergeCursor.dispose();
    }
    newCursor.dispose();
}
 
Example #28
Source File: InlineIterableProcessor.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
@Override
public void next(IterableTemplate iterable, ParentContext parentContext, IterableContext context, Object model) {
    ParagraphContext paragraphContext = (ParagraphContext) parentContext;
    RunTemplate end = iterable.getEndMark();
    CTR endCtr = end.getRun().getCTR();
    int startPos = context.getStart();
    int endPos = context.getEnd();

    // copy position cursor
    int insertPostionCursor = end.getRunPos();

    // copy content
    List<XWPFRun> runs = paragraphContext.getParagraph().getRuns();
    List<XWPFRun> copies = new ArrayList<XWPFRun>();
    for (int i = startPos + 1; i < endPos; i++) {
        insertPostionCursor = end.getRunPos();

        XWPFRun xwpfRun = runs.get(i);
        XWPFRun insertNewRun = paragraphContext.insertNewRun(xwpfRun, insertPostionCursor);
        XWPFRun replaceXwpfRun = paragraphContext.createRun(xwpfRun, (IRunBody) paragraphContext.getParagraph());
        paragraphContext.setAndUpdateRun(replaceXwpfRun, insertNewRun, insertPostionCursor);

        XmlCursor newCursor = endCtr.newCursor();
        newCursor.toPrevSibling();
        XmlObject object = newCursor.getObject();
        XWPFRun copy = paragraphContext.createRun(object, (IRunBody) paragraphContext.getParagraph());
        DocPrSupport.updateDocPrId(copy);
        copies.add(copy);
        paragraphContext.setAndUpdateRun(copy, replaceXwpfRun, insertPostionCursor);
    }

    // re-parse
    List<MetaTemplate> templates = this.resolver.resolveXWPFRuns(copies);

    // render
    process(templates, model);
}
 
Example #29
Source File: DocumentBodyContainer.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
@Override
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
    XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor();
    XWPFTable table = insertNewTbl(cursor);
    for (int i = 0; i < row; i++) {
        XWPFTableRow tabRow = (table.getRow(i) == null) ? table.createRow() : table.getRow(i);
        for (int k = 0; k < col; k++) {
            if (tabRow.getCell(k) == null) {
                tabRow.createCell();
            }
        }
    }
    return table;
}
 
Example #30
Source File: XML.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 * @param cursor
 * @param opts
 * @return
 */
private static String dumpNode(XmlCursor cursor, XmlOptions opts)
{
    if (cursor.isText())
        return cursor.getChars();

    if (cursor.isFinish())
        return "";

    cursor.push();
    boolean wanRawText = cursor.isStartdoc() && !cursor.toFirstChild();
    cursor.pop();

    return wanRawText ? cursor.getTextValue() : cursor.xmlText( opts );
}