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


Java XmlUtils.marshaltoString方法代码示例

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


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

示例1: writeToStream

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public static void writeToStream(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException {
	Assert.notNull(wmlPackage, " wmlPackage is not specified!");
	Assert.notNull(output, " output is not specified!");
	InputStream input = null;
	try {
		//Document对象
		MainDocumentPart document = wmlPackage.getMainDocumentPart();	
		//Document XML
		String documentXML = XmlUtils.marshaltoString(wmlPackage);
		//转成字节输入流
		input = IOUtils.toBufferedInputStream(new ByteArrayInputStream(documentXML.getBytes()));
		//输出模板
		IOUtils.copy(input, output);
	} finally {
		IOUtils.closeQuietly(input);
	}
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:18,代码来源:WordprocessingMLTemplateWriter.java

示例2: writeToWriter

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public void writeToWriter(WordprocessingMLPackage wmlPackage,Writer output) throws IOException, Docx4JException {
	Assert.notNull(wmlPackage, " wmlPackage is not specified!");
	Assert.notNull(output, " output is not specified!");
	InputStream input = null;
	try {
		//Document对象
		MainDocumentPart document = wmlPackage.getMainDocumentPart();	
		//Document XML
		String documentXML = XmlUtils.marshaltoString(wmlPackage.getPackage());
		//转成字节输入流
		input = IOUtils.toBufferedInputStream(new ByteArrayInputStream(documentXML.getBytes()));
		//获取模板输出编码格式
		String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_WMLTEMPLATE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME );
		//输出模板
		IOUtils.copy(input, output, Charset.forName(charsetName));
	} finally {
		IOUtils.closeQuietly(input);
	}
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:20,代码来源:WordprocessingMLTemplateWriter.java

示例3: testFormatTextOfBlock

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void testFormatTextOfBlock() throws Exception {
	SdtElement contentControl = createPlainTextContentControl(SdtBlock.class);
	RPr rPr = createRunProperties("<w:b/>");
	contentControl.getSdtPr().getRPrOrAliasOrLock().add(rPr);
	PlainTextContent plainTextContent = new PlainTextContent(contentControl);
	plainTextContent.setContent("content");

	String xmlString = XmlUtils.marshaltoString(
			plainTextContent.getXmlElement(), true);
	String content = getSdtContent(xmlString);
	String expectedContent = "<w:p>"//
			+ "<w:r>" //
			+ "<w:rPr><w:b/></w:rPr>" // formatierung
			+ "<w:t>content</w:t>" // text
			+ "</w:r>"//
			+ "</w:p>";
	assertEquals(expectedContent, content);

}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:21,代码来源:PlainTextContentTest.java

示例4: testFormatTextOfRun

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void testFormatTextOfRun() throws Exception {
	SdtElement contentControl = createPlainTextContentControl(SdtRun.class);
	RPr rPr = createRunProperties("<w:b/>");
	contentControl.getSdtPr().getRPrOrAliasOrLock().add(rPr);
	PlainTextContent plainTextContent = new PlainTextContent(contentControl);
	plainTextContent.setContent("content");
	String xmlString = XmlUtils.marshaltoString(
			plainTextContent.getXmlElement(), true);
	String content = getSdtContent(xmlString);
	String expectedContent = "<w:r>"//
			+ "<w:rPr><w:b/></w:rPr>" // formatierung
			+ "<w:t>content</w:t>" // text
			+ "</w:r>";
	assertEquals(expectedContent, content);
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:17,代码来源:PlainTextContentTest.java

示例5: testSetPlaceHolderText

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void testSetPlaceHolderText() throws Exception {
	SdtElement element = createPlainTextContentControl(SdtBlock.class);
	PlainTextContent plainTextContent = new PlainTextContent(element);
	plainTextContent.setPlaceHolderContent("placeHolderText");
	String xmlString = XmlUtils.marshaltoString(
			plainTextContent.getXmlElement(), true);
	int startContent = xmlString.indexOf("<w:sdtContent>")
			+ "<w:sdtContent>".length();
	int endContent = xmlString.lastIndexOf("</w:sdtContent>");
	String content = xmlString.substring(startContent, endContent);
	String expectedContent = "<w:p>"//
			+ "<w:r>"//
			+ "<w:rPr><w:rStyle w:val=\"PlaceholderText\"/></w:rPr>"//
			+ "<w:t>placeHolderText</w:t>"//
			+ "</w:r>"//
			+ "</w:p>";
	assertEquals(expectedContent, content);
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:20,代码来源:PlainTextContentTest.java

示例6: toDocumentTest

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void toDocumentTest() throws IOException, Docx4JException {
	WordTemplate<String> wordTemplate = createWordTemplate("org/wte4j/impl/simpleTemplate.docx");
	when(templateContext.resolveValue("value")).thenReturn("test123");
	File generatedDocument = File.createTempFile("generated", "docx");
	try (OutputStream out = new FileOutputStream(generatedDocument)) {
		wordTemplate.toDocument("gugus", out);
		WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
				.load(generatedDocument);
		String content = XmlUtils.marshaltoString(wordMLPackage
				.getMainDocumentPart().getContents(), true);
		assertTrue(content.contains("test123"));
	} finally {
		generatedDocument.deleteOnExit();
	}
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:17,代码来源:WordTemplateTest.java

示例7: toTestDocument

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void toTestDocument() throws IOException, Docx4JException {
	when(templateContext.resolveValue("value")).thenReturn(TestDataModel.STRING_TEXT);
	WordTemplate<String> wordTemplate = createWordTemplate("org/wte4j/impl/simpleTemplate.docx");
	File generatedDocument = File.createTempFile("generated", "docx");
	try (OutputStream out = new FileOutputStream(generatedDocument)) {
		wordTemplate.toTestDocument(out);
		WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
				.load(generatedDocument);
		String content = XmlUtils.marshaltoString(wordMLPackage
				.getMainDocumentPart().getContents(), true);
		assertTrue(content.contains(TestDataModel.STRING_TEXT));
	} finally {
		generatedDocument.delete();
	}
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:17,代码来源:WordTemplateTest.java

示例8: getRawXML

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
/**
 * @return raw XML of the docx file as string
 */
public String getRawXML() {
    if (wordMLPackage == null) {
        throw new NullPointerException();
    }
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    return XmlUtils.marshaltoString(documentPart.getJaxbElement(), true, true);
}
 
开发者ID:tokgozmusa,项目名称:docx4j-word-data-extractor,代码行数:11,代码来源:DocxExtractor.java

示例9: getTcMarshalStr

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
/** 
 * 获取单元格字符串 
 */  
private String[] getTcMarshalStr(Tr tr) {  
    List<Object> tcObjList = tr.getContent();  
    String[] marshaArr = new String[7];  
    // 跳过层次  
    for (int i = 1, len = tcObjList.size(); i < len; i++) {  
        marshaArr[i - 1] = XmlUtils.marshaltoString(tcObjList.get(i), true, false);  
    }  
    return marshaArr;  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:Docx4j_替换模板.java

示例10: convertToWmlObject

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
private static List<Object> convertToWmlObject(
		WordprocessingMLPackage wordMLPackage, String content)
		throws Docx4JException, JAXBException {
	MainDocumentPart document = wordMLPackage.getMainDocumentPart();
	//获取Jsoup参数
	String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_WMLTEMPLATE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME );
	
	List<Object> wmlObjList = null;
	String templateString = XmlUtils.marshaltoString(document.getContents().getBody());
	System.out.println(templateString);
	Body templateBody = document.getContents().getBody();
	try {
		document.getContents().setBody(XmlUtils.deepCopy(templateBody));
		document.getContent().clear();
		Document doc = Jsoup.parse(content);
		doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);
		//XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
		
		AlternativeFormatInputPart  part = document.addAltChunk(AltChunkType.Xhtml,doc.html().getBytes(Charset.forName(charsetName)));
		
		WordprocessingMLPackage tempPackage = document.convertAltChunks();
		File file = new File("d://temp.docx");
		tempPackage.save(file);
		wmlObjList = document.getContent();
		//part.getOwningRelationshipPart().getSourceP().get
		//wmlObjList = xhtmlImporter.convert(doc.html(), doc.baseUri());
	} finally {
		document.getContents().setBody(templateBody);
	}
	return wmlObjList;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:HtmlToDOCDemo.java

示例11: testCreateSdtBlockElement

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void testCreateSdtBlockElement() {
	SdtElement element = PlainTextContent.createSdtBlockElement();
	String text = XmlUtils.marshaltoString(element, true);
	String expectedContent = "<w:sdtPr>" //
			+ "<w:tag/>"//
			+ "<w:text/>"//
			+ "<w:showingPlcHdr/>"//
			+ "<w15:appearance w15:val=\"tags\"/>"//
			+ "</w:sdtPr>"//
			+ "<w:sdtContent/>";
	assertTrue(text.contains(expectedContent));
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:14,代码来源:PlainTextContentTest.java

示例12: testSetExpression

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void testSetExpression() throws Exception {
	SdtElement element = createPlainTextContentControl(SdtBlock.class);
	PlainTextContent plainTextContent = new PlainTextContent(element);
	plainTextContent.setExpression("expression");
	String xmlString = XmlUtils.marshaltoString(
			plainTextContent.getXmlElement(), true);
	assertTrue(xmlString.contains("<w:tag w:val=\"expression\"/>"));
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:10,代码来源:PlainTextContentTest.java

示例13: testSetTitle

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
@Test
public void testSetTitle() throws Exception {
	SdtElement element = createPlainTextContentControl(SdtBlock.class);
	PlainTextContent plainTextContent = new PlainTextContent(element);
	plainTextContent.setTitle("testLabel");
	String xmlString = XmlUtils.marshaltoString(
			plainTextContent.getXmlElement(), true);
	assertTrue(xmlString + " has no alias set",
			xmlString.contains("<w:alias w:val=\"testLabel\"/>"));
}
 
开发者ID:wte4j,项目名称:wte4j,代码行数:11,代码来源:PlainTextContentTest.java

示例14: writeToString

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public String writeToString(WordprocessingMLPackage wmlPackage) throws IOException, Docx4JException {
	MainDocumentPart document = wmlPackage.getMainDocumentPart();		
	return XmlUtils.marshaltoString(wmlPackage);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:5,代码来源:WordprocessingMLTemplateWriter.java

示例15: printSdtPrContent

import org.docx4j.XmlUtils; //导入方法依赖的package包/类
public void printSdtPrContent(SdtPr sdtPr) {  
    StringBuffer sb = new StringBuffer();  
    List<Object> rprList = sdtPr.getRPrOrAliasOrLock();  
    boolean flag=false;  
    for (Object obj : rprList) {  
        if (obj instanceof JAXBElement) {  
            String eName = ((JAXBElement) obj).getName().getLocalPart();  
            // System.out.println("---------=" + eName);  
            // 布尔类型特殊处理  
            if ("temporary".equals(eName)) {  
                sb.append(" 替换后是否删除内容控件:").append("是");  
            } else if ("text".equals(eName)) {  
                // 纯文本是否允许回车特殊处理  
                // CTSdtText判断是否回车代码不准确  
                // if (this.multiLine == null) {  
                // return true;  
                // }  
                flag=true;  
                String textXml = XmlUtils.marshaltoString(obj, true, true);  
                if (textXml.indexOf("w:multiLine") != -1) {  
                    sb.append(" 是否允许回车:").append("是");  
                }  
            }  
            obj = XmlUtils.unwrap(obj);  
            if (obj instanceof Alias) {  
                Alias alias = (Alias) obj;  
                if (alias != null) {  
                    sb.append(" 标题:").append(alias.getVal());  
                }  
            } else if (obj instanceof CTLock) {  
                CTLock lock = (CTLock) obj;  
                if (lock != null) {  
                    if (lock.getVal().value().toUpperCase().equals("CONTENTLOCKED")) {  
                        sb.append(" 锁定方式:").append("无法编辑内容");  
                    } else if (lock.getVal().value().toUpperCase().equals("SDTLOCKED")) {  
                        sb.append(" 锁定方式:").append("无法删除内容控件");  
                    }else if (lock.getVal().value().toUpperCase().equals("SDTCONTENTLOCKED")) {  
                        sb.append(" 锁定方式:").append("无法删除内容控件,无法编辑内容");  
                    } else {  
                        sb.append(" 锁定方式:").append(lock.getVal());  
                    }  
                }  
            }else if(obj instanceof RPr){  
                RPr rpr = (RPr) obj;  
                if(rpr!=null){  
                    RStyle rprStyle = rpr.getRStyle();  
                    if(rprStyle!=null){  
                        sb.append(" 样式名称:").append(rprStyle.getVal());  
                    }  
                }  
            }  
        } else if (obj instanceof Tag) {  
            Tag tag = (Tag) obj;  
            if (tag != null) {  
                sb.append(" tag标记:").append(tag.getVal());  
            }  
        } else if (obj instanceof Id) {  
            Id id = (Id) obj;  
            if (id != null) {  
                sb.append(" id:").append(id.getVal());  
            }  
        }  
    }  
    if(flag){  
        sb.append(" 内容控件类型:").append("纯文本");  
    }else{  
        sb.append(" 内容控件类型:").append("格式文本");  
    }  
    System.out.println(sb.toString());  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:71,代码来源:Docx4j_读取内容控件_S4_Test.java


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