当前位置: 首页>>代码示例>>Java>>正文


Java XmlUtils.unwrap方法代码示例

本文整理汇总了Java中org.docx4j.XmlUtils.unwrap方法的典型用法代码示例。如果您正苦于以下问题:Java XmlUtils.unwrap方法的具体用法?Java XmlUtils.unwrap怎么用?Java XmlUtils.unwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.docx4j.XmlUtils的用法示例。


在下文中一共展示了XmlUtils.unwrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChildrenElements

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public static <T> List<T> getChildrenElements(Object source, Class<T> targetClass) {  
    List<T> result = new ArrayList<T>();  
    //获取真实的对象
	Object target = XmlUtils.unwrap(source);
	//if (target.getClass().equals(targetClass)) {
    if (targetClass.isAssignableFrom(target.getClass())) { 
        result.add((T)target);
    } else if (target instanceof ContentAccessor) {  
        List<?> children = ((ContentAccessor) target).getContent();  
        //if (children.getClass().equals(targetClass)) {
        if (targetClass.isAssignableFrom(children.getClass())) { 
            result.add((T)children);
        }
    }
    return result;  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:17,代码来源:WMLPackageUtils.java

示例2: getTargetElements

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
/**
 * 这样会返回一个表示完整的空白(在此时)文档Java对象。现在我们可以使用Docx4J API添加、删除以及更新这个word文档的内容,Docx4J有一些你可以用于遍历该文档的工具类。
 * 我自己写了几个助手方法使查找指定占位符并用真实内容进行替换的操作变地很简单。让我们来看一下其中的一个,这个计算是几个JAXB计算的包装器,
 * 允许你针对一个特定的类来搜索指定元素以及它所有的孩子,例如,你可以用它获取文档中所有的表格、表格中所有的行以及其它类似的操作。 
 */
public static <T> List<T> getTargetElements(Object source, Class<T> targetClass) {  
       List<T> result = new ArrayList<T>();  
       //获取真实的对象
   	Object target = XmlUtils.unwrap(source);
       //if (target.getClass().equals(targetClass)) {
   	if (targetClass.isAssignableFrom(target.getClass())) { 
           result.add((T) target);  
       } else if (target instanceof ContentAccessor) {  
           List<?> children = ((ContentAccessor) target).getContent();  
           for (Object child : children) {  
               result.addAll(getTargetElements(child, targetClass));  
           }
       }
       return result;  
   }
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:21,代码来源:WMLPackageUtils.java

示例3: removeTableByIndex

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
/**
 * @Description:删除指定位置的表格,删除后表格数量减一
 */
public boolean removeTableByIndex(WordprocessingMLPackage wordMLPackage,
        int index) throws Exception {
    boolean flag = false;
    if (index < 0) {
        return flag;
    }
    List<Object> objList = wordMLPackage.getMainDocumentPart().getContent();
    if (objList == null) {
        return flag;
    }
    int k = -1;
    for (int i = 0, len = objList.size(); i < len; i++) {
        Object obj = XmlUtils.unwrap(objList.get(i));
        if (obj instanceof Tbl) {
            k++;
            if (k == index) {
                wordMLPackage.getMainDocumentPart().getContent().remove(i);
                flag = true;
                break;
            }
        }
    }
    return flag;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:28,代码来源:Docx4j_工具类_S3_Test.java

示例4: removeTrByIndex

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
/**
 * @Description: 删除指定行 删除后行数减一
 */
public boolean removeTrByIndex(Tbl tbl, int index) {
    boolean flag = false;
    if (index < 0) {
        return flag;
    }
    List<Object> objList = tbl.getContent();
    if (objList == null) {
        return flag;
    }
    int k = -1;
    for (int i = 0, len = objList.size(); i < len; i++) {
        Object obj = XmlUtils.unwrap(objList.get(i));
        if (obj instanceof Tr) {
            k++;
            if (k == index) {
                tbl.getContent().remove(i);
                flag = true;
                break;
            }
        }
    }
    return flag;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:27,代码来源:Docx4j_工具类_S3_Test.java

示例5: walkJAXBElements

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public void walkJAXBElements(Object parent) {  
    List children = getChildren(parent);  
    if (children != null) {  
        for (Object o : children) {  
            if (o instanceof javax.xml.bind.JAXBElement  
                    && (((JAXBElement) o).getName().getLocalPart()  
                            .equals("sdt"))) {  
                ((Child) ((JAXBElement) o).getValue()).setParent(XmlUtils  
                        .unwrap(parent));  
            } else {  
                o = XmlUtils.unwrap(o);  
                if (o instanceof Child) {  
                    ((Child) o).setParent(XmlUtils.unwrap(parent));  
                }  
            }  
            this.apply(o);  
            if (this.shouldTraverse(o)) {  
                walkJAXBElements(o);  
            }  
        }  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:23,代码来源:Docx4j_读取内容控件_S4_Test.java

示例6: findContentControls

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
/**
 * Sucht alle content controls die nicht in einer reapeating section
 * enthalten sind
 * 
 * @throws JAXBException
 * @throws XPathBinderAssociationIsPartialException
 */
static List<SdtElement> findContentControls(ContentAccessor container)
		throws Docx4JException, JAXBException {
	List<SdtElement> sdtElements = new LinkedList<SdtElement>();
	for (Object o : container.getContent()) {
		Object unwrapped = XmlUtils.unwrap(o);
		if (unwrapped instanceof SdtElement) {
			sdtElements.add((SdtElement) unwrapped);
		}
		if (unwrapped instanceof ContentAccessor) {
			List<SdtElement> list = findContentControls((ContentAccessor) unwrapped);
			sdtElements.addAll(list);
		}
	}
	return sdtElements;
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:23,代码来源:Docx4JWordTemplate.java

示例7: walkContent

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
private void walkContent(List<Object> contentElements) {
    int elementIndex = 0;
    for (Object contentElement : contentElements) {
        Object unwrappedObject = XmlUtils.unwrap(contentElement);
        if (unwrappedObject instanceof P) {
            P p = (P) unwrappedObject;
            ParagraphCoordinates coordinates = new ParagraphCoordinates(p, elementIndex);
            walkParagraph(coordinates);
        } else if (unwrappedObject instanceof Tbl) {
            Tbl table = (Tbl) unwrappedObject;
            TableCoordinates tableCoordinates = new TableCoordinates(table, elementIndex);
            walkTable(tableCoordinates);
        }
        elementIndex++;
    }
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:17,代码来源:CoordinatesWalker.java

示例8: walkParagraph

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
private void walkParagraph(ParagraphCoordinates paragraphCoordinates){
	int rowIndex = 0;
	List<CommentWrapper> commentsToDelete = new ArrayList<>();
	for (Object contentElement : paragraphCoordinates.getParagraph().getContent()){
		 if (XmlUtils.unwrap(contentElement) instanceof R) {
			 R run = (R) contentElement;
			 RunCoordinates runCooridnates = new RunCoordinates(run, rowIndex);
			 CommentWrapper commentToDelete = onRun(runCooridnates, paragraphCoordinates);
			 if (commentToDelete != null)
				 commentsToDelete.add(commentToDelete);
		 }
	}
	for (CommentWrapper cw : commentsToDelete)
		CommentUtil.deleteComment(cw);
	// we run the paragraph afterwards so that the comments inside work before the whole paragraph comments
	onParagraph(paragraphCoordinates);

}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:19,代码来源:CoordinatesWalker.java

示例9: walkTableCell

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
private void walkTableCell(TableCellCoordinates cellCoordinates) {
    onTableCell(cellCoordinates);
    int elementIndex = 0;
    for (Object cellContentElement : cellCoordinates.getCell().getContent()) {
        if (XmlUtils.unwrap(cellContentElement) instanceof P) {
            P p = (P) cellContentElement;
            ParagraphCoordinates paragraphCoordinates = new ParagraphCoordinates(p, elementIndex, cellCoordinates);
            onParagraph(paragraphCoordinates);
        } else if (XmlUtils.unwrap(cellContentElement) instanceof Tbl) {
            Tbl nestedTable = (Tbl) ((JAXBElement) cellContentElement).getValue();
            TableCoordinates innerTableCoordinates = new TableCoordinates(nestedTable, elementIndex, cellCoordinates);
            walkTable(innerTableCoordinates);
        }
        elementIndex++;
    }
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:17,代码来源:CoordinatesWalker.java

示例10: walk

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public void walk() {
    for (Object contentElement : contentAccessor.getContent()) {
        Object unwrappedObject = XmlUtils.unwrap(contentElement);
        if (unwrappedObject instanceof P) {
            P p = (P) unwrappedObject;
            walkParagraph(p);
        } else if (unwrappedObject instanceof Tbl) {
            Tbl table = (Tbl) unwrappedObject;
            walkTable(table);
        } else if (unwrappedObject instanceof Tr) {
            Tr row = (Tr) unwrappedObject;
            walkTableRow(row);
        } else if (unwrappedObject instanceof Tc) {
            Tc cell = (Tc) unwrappedObject;
            walkTableCell(cell);
        }
    }
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:19,代码来源:DocumentWalker.java

示例11: deleteCommentReference

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
private static void deleteCommentReference(ContentAccessor parent,
		BigInteger commentId) {
	int index = 0;
	Integer indexToDelete = null;
	for (Object contentObject : parent.getContent()) {
		if (contentObject instanceof R) {
			for (Object runContentObject : ((R) contentObject).getContent()) {
				Object unwrapped = XmlUtils.unwrap(runContentObject);
				if (unwrapped instanceof R.CommentReference) {
					BigInteger foundCommentId = ((R.CommentReference) unwrapped)
							.getId();
					if (foundCommentId.equals(commentId)) {
						indexToDelete = index;
						break;
					}
				}
			}
		}
		index++;
	}
	if (indexToDelete != null) {
		parent.getContent().remove(indexToDelete.intValue());
	}
}
 
开发者ID:thombergs,项目名称:docx-stamper,代码行数:25,代码来源:CommentUtil.java

示例12: createComment

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public static CTComments createComment(String cell) throws JAXBException { 
    String openXML = "<comments xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
            + "<authors>"
                + "<author>Author</author>"
            +"</authors>"
            + "<commentList>"
                + "<comment authorId=\"0\" ref=\"" + cell + "\">"
                    + "<text>"
                        + "<r>"
                            + "<rPr>"
                                + "<b/>"
                                + "<sz val=\"9\"/>"
                                + "<color indexed=\"81\"/>"
                                + "<rFont val=\"Tahoma\"/>"
                                + "<charset val=\"1\"/>"
                            +"</rPr>"
                            + "<t>Thomas: hello world!</t>"
                        +"</r>"
                    +"</text>"
                +"</comment>"
            +"</commentList>"
        +"</comments>";
    CTComments comments = (CTComments)XmlUtils.unwrap(
		XmlUtils.unmarshalString(openXML, Context.jcSML));
    return comments;
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Java_for_Docx4j,代码行数:27,代码来源:AddCommentsXlsx4j.java

示例13: mergeMatchedTexts

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public Set<Text> mergeMatchedTexts() {
    for (Object paragraphContentObject : paragraph.getContent()) {
        if (paragraphContentObject instanceof R) {
            R currentRun = (R) paragraphContentObject;
            for (Object runContentObject : currentRun.getContent()) {
                Object unwrappedRunContentObject = XmlUtils.unwrap(runContentObject);
                if (unwrappedRunContentObject instanceof Text) {
                    handleText((Text) unwrappedRunContentObject);
                }
            }
        }
    }

    removeUnnecessaryTexts();

    return resultingTexts;
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:18,代码来源:TextMerger.java

示例14: walkJAXBElements

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public void walkJAXBElements(Object parent) {
    List children = getChildren(parent);
    if (children != null) {

        for (Object object : children) {
            object = XmlUtils.unwrap(object);

            if (object instanceof Child) {
                ((Child) object).setParent(parent);
            }

            this.apply(object);

            if (this.shouldTraverse(object)) {
                walkJAXBElements(object);
            }
        }
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:20,代码来源:AliasVisitor.java

示例15: walkJAXBElements

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public void walkJAXBElements(Object parent) {  
    List children = getChildren(parent);  
    if (children != null) {  
        for (Object o : children) {  
            if (o instanceof javax.xml.bind.JAXBElement  
                    && (((JAXBElement) o).getName().getLocalPart()  
                            .equals("commentReference")  
                            || ((JAXBElement) o).getName()  
                                    .getLocalPart()  
                                    .equals("commentRangeStart") || ((JAXBElement) o)  
                            .getName().getLocalPart()  
                            .equals("commentRangeEnd"))) {  
                ((Child) ((JAXBElement) o).getValue())  
                        .setParent(XmlUtils.unwrap(parent));  
            } else {  
                o = XmlUtils.unwrap(o);  
                if (o instanceof Child) {  
                    ((Child) o).setParent(XmlUtils.unwrap(parent));  
                }  
            }  
            this.apply(o);  
            if (this.shouldTraverse(o)) {  
                walkJAXBElements(o);  
            }  
        }  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:28,代码来源:Docx4j_删除所有批注_S3_Test.java


注:本文中的org.docx4j.XmlUtils.unwrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。