Java Examples for org.docx4j.docProps.custom.Properties.Property

The following java examples will help you to understand the usage of org.docx4j.docProps.custom.Properties.Property. These source code samples are taken from different open source projects.

Example 1
Project: docx4j-master  File: AbstractFormattingSwitchTest.java View source code
public void generateSampleDocx(String filename) throws Docx4JException {
    // Also create mailmerge data source
    StringBuilder fieldname = new StringBuilder();
    StringBuilder row1 = new StringBuilder();
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    org.docx4j.openpackaging.parts.DocPropsCustomPart docPropsCustomPart = new DocPropsCustomPart();
    wordMLPackage.addTargetPart(docPropsCustomPart);
    org.docx4j.docProps.custom.ObjectFactory cpfactory = new org.docx4j.docProps.custom.ObjectFactory();
    org.docx4j.docProps.custom.Properties customProps = cpfactory.createProperties();
    docPropsCustomPart.setJaxbElement(customProps);
    org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
    int i = 1;
    for (SwitchTestQuad tt : quads) {
        //org.docx4j.wml.P  p = factory.createP();
        org.docx4j.wml.P p = mdp.addParagraphOfText(tt.val + " " + tt.format + " --> ");
        p.getContent().add(createSimpleField(tt, "myvar" + i, true));
        // Ok, let's add a custom property.
        org.docx4j.docProps.custom.Properties.Property newProp = cpfactory.createPropertiesProperty();
        newProp.setName("myvar" + i);
        // Magic string
        newProp.setFmtid(docPropsCustomPart.fmtidValLpwstr);
        newProp.setPid(customProps.getNextId());
        newProp.setLpwstr(tt.val);
        // .. add it
        customProps.getProperty().add(newProp);
        // For mailmerge
        fieldname.append("\"myvar" + i + "\",");
        row1.append("\"" + tt.val + "\",");
        i++;
    }
    // Pretty print the main document part
    //		System.out.println(
    //				XmlUtils.marshaltoString(mdp.getJaxbElement(), true, true) );
    // Optionally save it
    String path = System.getProperty("user.dir") + "/" + filename;
    wordMLPackage.save(new java.io.File(path));
    System.out.println("Saved " + path);
    System.out.println(fieldname.toString());
    System.out.println(row1.toString());
}
Example 2
Project: docx4all-master  File: DocUtil.java View source code
public static final String getChunkingStrategy(WordMLDocument doc) {
    String theStrategy = null;
    DocumentElement elem = (DocumentElement) doc.getDefaultRootElement();
    DocumentML docML = (DocumentML) elem.getElementML();
    WordprocessingMLPackage wmlPackage = docML.getWordprocessingMLPackage();
    if (wmlPackage != null) {
        org.docx4j.docProps.custom.Properties.Property chunkingStrategy = XmlUtil.getCustomProperty(wmlPackage, Constants.PLUTEXT_GROUPING_PROPERTY_NAME);
        if (chunkingStrategy != null) {
            theStrategy = chunkingStrategy.getLpwstr();
        }
    }
    return theStrategy;
}
Example 3
Project: Aspose_Words_Java-master  File: Docx4jWorkingWithDocProps.java View source code
public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(Docx4jWorkingWithDocProps.class);
    inputfilepath = dataDir + "document.docx";
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
    // Let's look at the core properties
    org.docx4j.openpackaging.parts.DocPropsCorePart docPropsCorePart = wordMLPackage.getDocPropsCorePart();
    org.docx4j.docProps.core.CoreProperties coreProps = (org.docx4j.docProps.core.CoreProperties) docPropsCorePart.getJaxbElement();
    // Title of the document
    // Note: Word for Mac 2010 doesn't set title
    String title = "Missing";
    List<String> list = coreProps.getTitle().getValue().getContent();
    if (list.size() > 0) {
        title = list.get(0);
    }
    System.out.println("'dc:title' is " + title);
    // Extended properties
    org.docx4j.openpackaging.parts.DocPropsExtendedPart docPropsExtendedPart = wordMLPackage.getDocPropsExtendedPart();
    org.docx4j.docProps.extended.Properties extendedProps = (org.docx4j.docProps.extended.Properties) docPropsExtendedPart.getJaxbElement();
    // Document creator Application
    System.out.println("'Application' is " + extendedProps.getApplication() + " v." + extendedProps.getAppVersion());
    // Custom properties
    org.docx4j.openpackaging.parts.DocPropsCustomPart docPropsCustomPart = wordMLPackage.getDocPropsCustomPart();
    if (docPropsCustomPart == null) {
        System.out.println("No Document Custom Properties.");
    } else {
        org.docx4j.docProps.custom.Properties customProps = (org.docx4j.docProps.custom.Properties) docPropsCustomPart.getJaxbElement();
        for (org.docx4j.docProps.custom.Properties.Property prop : customProps.getProperty()) {
            // Could create a generic Object getValue() method.
            if (prop.getLpwstr() != null) {
                System.out.println(prop.getName() + " = " + prop.getLpwstr());
            } else {
                System.out.println(prop.getName() + ": \n " + XmlUtils.marshaltoString(prop, true, Context.jcDocPropsCustom));
            }
        }
    }
    System.out.println("Done.");
}
Example 4
Project: Aspose_Java_for_Docx4j-master  File: Docx4jWorkingWithDocProps.java View source code
public static void main(String[] args) throws Exception {
    String dataPath = "src/featurescomparison/workingwithdocuments/accessdocproperties/data/";
    inputfilepath = dataPath + "document.docx";
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
    // Let's look at the core properties
    org.docx4j.openpackaging.parts.DocPropsCorePart docPropsCorePart = wordMLPackage.getDocPropsCorePart();
    org.docx4j.docProps.core.CoreProperties coreProps = (org.docx4j.docProps.core.CoreProperties) docPropsCorePart.getJaxbElement();
    // Title of the document
    // Note: Word for Mac 2010 doesn't set title
    String title = "Missing";
    List<String> list = coreProps.getTitle().getValue().getContent();
    if (list.size() > 0) {
        title = list.get(0);
    }
    System.out.println("'dc:title' is " + title);
    // Extended properties
    org.docx4j.openpackaging.parts.DocPropsExtendedPart docPropsExtendedPart = wordMLPackage.getDocPropsExtendedPart();
    org.docx4j.docProps.extended.Properties extendedProps = (org.docx4j.docProps.extended.Properties) docPropsExtendedPart.getJaxbElement();
    // Document creator Application
    System.out.println("'Application' is " + extendedProps.getApplication() + " v." + extendedProps.getAppVersion());
    // Custom properties
    org.docx4j.openpackaging.parts.DocPropsCustomPart docPropsCustomPart = wordMLPackage.getDocPropsCustomPart();
    if (docPropsCustomPart == null) {
        System.out.println("No Document Custom Properties.");
    } else {
        org.docx4j.docProps.custom.Properties customProps = (org.docx4j.docProps.custom.Properties) docPropsCustomPart.getJaxbElement();
        for (org.docx4j.docProps.custom.Properties.Property prop : customProps.getProperty()) {
            // Could create a generic Object getValue() method.
            if (prop.getLpwstr() != null) {
                System.out.println(prop.getName() + " = " + prop.getLpwstr());
            } else {
                System.out.println(prop.getName() + ": \n " + XmlUtils.marshaltoString(prop, true, Context.jcDocPropsCustom));
            }
        }
    }
    System.out.println("Done.");
}