/** Unmarshal a String as an object in the package org.docx4j.jaxb.document. * Note: you should ensure you include a namespace declaration for w: and * any other namespace in the xml string. * Also, the object you are attempting to unmarshall to might need to * have an @XmlRootElement annotation for things to work. */ public static Object unmarshalString(String str) throws JAXBException { return unmarshalString(str, Context.jc); }
public static Notes createNotes() throws JAXBException { return (Notes)XmlUtils.unmarshalString(COMMON_SLIDE_NOTES, Context.jcPML, Notes.class); }
/** * Create a Hyperlink object, which is suitable for adding to a w:p * @param bookmarkName * @param linkText * @return */ public static Hyperlink hyperlinkToBookmark(String bookmarkName, String linkText) { try { String hpl = "<w:hyperlink w:anchor=\"" + bookmarkName + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " + "w:history=\"1\" >" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"Hyperlink\" />" + // TODO: enable this style in the document! "</w:rPr>" + "<w:t>" + linkText + "</w:t>" + "</w:r>" + "</w:hyperlink>"; return (Hyperlink)XmlUtils.unmarshalString(hpl); } catch (Exception e) { // Shouldn't happen e.printStackTrace(); return null; } }
public static Object unmarshallFromTemplate(String wmlTemplateString, java.util.Map<String, ?> mappings, JAXBContext jc, Class<?> declaredType) throws JAXBException { String wmlString = replace(wmlTemplateString, new StringBuilder(), mappings).toString(); return unmarshalString(wmlString, jc, declaredType); }
public static Object unmarshallFromTemplate(String wmlTemplateString, java.util.Map<String, ?> mappings, JAXBContext jc) throws JAXBException { String wmlString = replace(wmlTemplateString, new StringBuilder(), mappings).toString(); log.debug("Results of substitution: " + wmlString); return unmarshalString(wmlString, jc); }
/** * Create a paragraph from the xml string <w:p>...</w:p> , * and add it to the document. You'll need to ensure the * string contains namespace declarations (including for w:) * * @param simpleText * @return */ public org.docx4j.wml.P addParagraph(String pXml) throws JAXBException { org.docx4j.wml.P para = (org.docx4j.wml.P)org.docx4j.XmlUtils.unmarshalString(pXml); this.getContent().add( para ); return para; }
protected static CTEncryption parseDescriptor(String descriptor) { // try { // return EncryptionDocument.Factory.parse(descriptor); // } catch (XmlException e) { // throw new EncryptedDocumentException("Unable to parse encryption descriptor", e); // } log.error(descriptor); CTEncryption encryption = null; try { encryption = (CTEncryption)XmlUtils.unmarshalString(descriptor, Context.jcEncryption, CTEncryption.class); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } return encryption; }
/** * @param relId * @param url * @return * @throws JAXBException */ public Hyperlink generateHyperlink(String relId, String url) throws JAXBException { String hpl = "<w:hyperlink r:id=\"" + relId + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" " + "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" >" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"" + getHyperlinkStyleId() + "\" />" + "</w:rPr>" + "<w:t>" + url + "</w:t>" + "</w:r>" + "</w:hyperlink>"; return (Hyperlink)XmlUtils.unmarshalString(hpl); }
return (CTTextParagraphProperties)XmlUtils.unmarshalString(str, Context.jcPML, CTTextParagraphProperties.class);
/** * @param bookmarkName * @param url * @return * @throws JAXBException */ public Hyperlink generateHyperlink(String bookmarkName, String url) throws JAXBException { if (url.startsWith(COMPONENT_REF)) { String hpl = "<w:hyperlink w:anchor=\"" + bookmarkName + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" >" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"" + getHyperlinkStyleId() + "\" />" + "</w:rPr>" + "<w:t>" + url + "</w:t>" + "</w:r>" + "</w:hyperlink>"; return (Hyperlink)XmlUtils.unmarshalString(hpl); } else { return super.generateHyperlink(bookmarkName /* actually, relId here */, url); } }
public static Notes createNotesMinimal() throws JAXBException { ObjectFactory factory = Context.getpmlObjectFactory(); Notes notes = factory.createNotes(); notes.setCSld( (CommonSlideData)XmlUtils.unmarshalString(COMMON_SLIDE_DATA, Context.jcPML, CommonSlideData.class) ); // sld.setClrMapOvr(value) return notes; }
public static Sld createSld() throws JAXBException { ObjectFactory factory = Context.getpmlObjectFactory(); Sld sld = factory.createSld(); sld.setCSld( (CommonSlideData)XmlUtils.unmarshalString(COMMON_SLIDE_DATA, Context.jcPML, CommonSlideData.class) ); // sld.setClrMapOvr(value) return sld; }
public static SldMaster createSldMaster() throws JAXBException { ObjectFactory factory = Context.getpmlObjectFactory(); SldMaster sldMaster = factory.createSldMaster(); sldMaster.setCSld( (CommonSlideData)XmlUtils.unmarshalString(COMMON_SLIDE_DATA, Context.jcPML, CommonSlideData.class) ); sldMaster.setClrMap( (CTColorMapping)XmlUtils.unmarshalString(COLOR_MAPPING, Context.jcPML, CTColorMapping.class ) ); SlideLayoutIdList slideLayoutIdList = factory.createSlideLayoutIdList(); sldMaster.setSldLayoutIdLst(slideLayoutIdList); return sldMaster; }
public Style getDefaultCharacterStyle() { if (defaultCharacterStyle==null) { defaultCharacterStyle = getDefaultStyle("character"); } // OpenOffice conversion to docx // doesn't necessarily contain a default character style // so manufacture one if (defaultCharacterStyle==null) { try { defaultCharacterStyle = (Style)XmlUtils.unmarshalString(DEFAULT_CHARACTER_STYLE_DEFAULT); this.getJaxbElement().getStyle().add(defaultCharacterStyle); } catch (JAXBException e) { e.printStackTrace(); } } return defaultCharacterStyle; }
public static SldLayout createSldLayout() throws JAXBException { ObjectFactory factory = Context.getpmlObjectFactory(); SldLayout sldLayout = factory.createSldLayout(); CommonSlideData cSld = (CommonSlideData)XmlUtils.unmarshalString(COMMON_SLIDE_DATA, Context.jcPML, CommonSlideData.class); cSld.setName("Title Slide"); sldLayout.setCSld( cSld ); return sldLayout; }
+"</w:p>"; P pIn = (P)XmlUtils.unmarshalString(pString);
/** * @since 2.7 */ public static Presentation createJaxbPresentationElement(SlideSizesWellKnown sz, boolean landscape) throws JAXBException { ObjectFactory factory = Context.getpmlObjectFactory(); Presentation presentation = factory.createPresentation(); // Create empty lists Presentation.SldMasterIdLst masterIds = factory.createPresentationSldMasterIdLst(); Presentation.SldIdLst slideIds = factory.createPresentationSldIdLst(); presentation.setSldMasterIdLst(masterIds); presentation.setSldIdLst(slideIds); presentation.setNotesSz( (CTPositiveSize2D)XmlUtils.unmarshalString(DEFAULT_NOTES_SIZE, Context.jcPML, CTPositiveSize2D.class) ); if (sz==null) { presentation.setSldSz( (Presentation.SldSz)XmlUtils.unmarshalString(DEFAULT_SLIDE_SIZE, Context.jcPML, Presentation.SldSz.class)); } else { presentation.setSldSz( MainPresentationPart.createSlideSize(sz, landscape) ); } return presentation; }
"</w:hyperlink>"; contents.add((Hyperlink)XmlUtils.unmarshalString(hpl));
Style style = (Style)XmlUtils.unmarshalString(XML_TOCHeading_BasedOn_Nothing); style.getBasedOn().setVal(HEADING1_STYLE); documentPart.getStyleDefinitionsPart().getContents().getStyle().add(style); Style style = (Style)XmlUtils.unmarshalString(XML_TOCHeading_BasedOn_Heading1); style.getBasedOn().setVal(HEADING1_STYLE); documentPart.getStyleDefinitionsPart().getContents().getStyle().add(style);
TblPr tblPr = null; try { tblPr = (TblPr)XmlUtils.unmarshalString(strTblPr); } catch (JAXBException e) {