Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

In this page you can find the example usage for org.dom4j QName QName.

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java

License:Apache License

/**
 * Add revision property if needed./*ww w.j  ava2 s  .  c  o m*/
 */
private void addRevision() {
    if (!propsPart.getRevisionProperty().hasValue())
        return;

    Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_REVISION, namespaceCoreProperties));
    if (elem == null) {
        // missing, we add it
        elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_REVISION, namespaceCoreProperties));
    } else {
        elem.clearContent();// clear the old value
    }
    elem.addText(propsPart.getRevisionProperty().getValue());
}

From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java

License:Apache License

/**
 * Add subject property if needed./*from  www  .  j av a 2 s . co m*/
 */
private void addSubject() {
    if (!propsPart.getSubjectProperty().hasValue())
        return;

    Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_SUBJECT, namespaceDC));
    if (elem == null) {
        // missing, we add it
        elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_SUBJECT, namespaceDC));
    } else {
        elem.clearContent();// clear the old value
    }
    elem.addText(propsPart.getSubjectProperty().getValue());
}

From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java

License:Apache License

/**
 * Add title property if needed./* www.j a  va 2s.  com*/
 */
private void addTitle() {
    if (!propsPart.getTitleProperty().hasValue())
        return;

    Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_TITLE, namespaceDC));
    if (elem == null) {
        // missing, we add it
        elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_TITLE, namespaceDC));
    } else {
        elem.clearContent();// clear the old value
    }
    elem.addText(propsPart.getTitleProperty().getValue());
}

From source file:org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.java

License:Apache License

private void addVersion() {
    if (!propsPart.getVersionProperty().hasValue())
        return;/*from w ww  . j a  va 2  s. c  o m*/

    Element elem = xmlDoc.getRootElement().element(new QName(KEYWORD_VERSION, namespaceCoreProperties));
    if (elem == null) {
        // missing, we add it
        elem = xmlDoc.getRootElement().addElement(new QName(KEYWORD_VERSION, namespaceCoreProperties));
    } else {
        elem.clearContent();// clear the old value
    }
    elem.addText(propsPart.getVersionProperty().getValue());
}

From source file:org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller.java

License:Apache License

/**
 * Save relationships into the part./*w w w.j  av  a2  s.c o  m*/
 *
 * @param rels
 *            The relationships collection to marshall.
 * @param relPartName
 *            Part name of the relationship part to marshall.
 * @param zos
 *            Zip output stream in which to save the XML content of the
 *            relationships serialization.
 */
public static boolean marshallRelationshipPart(PackageRelationshipCollection rels, PackagePartName relPartName,
        ZipOutputStream zos) {
    // Building xml
    Document xmlOutDoc = DocumentHelper.createDocument();
    // make something like <Relationships
    // xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS);
    Element root = xmlOutDoc.addElement(new QName(PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs));

    // <Relationship
    // TargetMode="External"
    // Id="rIdx"
    // Target="http://www.custom.com/images/pic1.jpg"
    // Type="http://www.custom.com/external-resource"/>

    URI sourcePartURI = PackagingURIHelper.getSourcePartUriFromRelationshipPartUri(relPartName.getURI());

    for (PackageRelationship rel : rels) {
        // the relationship element
        Element relElem = root.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME);

        // the relationship ID
        relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.getId());

        // the relationship Type
        relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel.getRelationshipType());

        // the relationship Target
        String targetValue;
        URI uri = rel.getTargetURI();
        if (rel.getTargetMode() == TargetMode.EXTERNAL) {
            // Save the target as-is - we don't need to validate it,
            //  alter it etc
            targetValue = uri.toString();

            // add TargetMode attribute (as it is external link external)
            relElem.addAttribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME, "External");
        } else {
            URI targetURI = rel.getTargetURI();
            targetValue = PackagingURIHelper.relativizeURI(sourcePartURI, targetURI, true).toString();
        }
        relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME, targetValue);
    }

    xmlOutDoc.normalize();

    // String schemaFilename = Configuration.getPathForXmlSchema()+
    // File.separator + "opc-relationships.xsd";

    // Save part in zip
    ZipEntry ctEntry = new ZipEntry(
            ZipHelper.getZipURIFromOPCName(relPartName.getURI().toASCIIString()).getPath());
    try {
        zos.putNextEntry(ctEntry);
        if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) {
            return false;
        }
        zos.closeEntry();
    } catch (IOException e) {
        logger.log(POILogger.ERROR, "Cannot create zip entry " + relPartName, e);
        return false;
    }
    return true; // success
}

From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

private String loadCategory(Document xmlDoc) {
    Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_CATEGORY, namespaceCP));
    if (el == null) {
        return null;
    }//from  w w  w.  j  ava 2s . co  m
    return el.getStringValue();
}

From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

private String loadContentStatus(Document xmlDoc) {
    Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_CONTENT_STATUS, namespaceCP));
    if (el == null) {
        return null;
    }/*w w  w. j av  a 2s .  co  m*/
    return el.getStringValue();
}

From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

private String loadContentType(Document xmlDoc) {
    Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_CONTENT_TYPE, namespaceCP));
    if (el == null) {
        return null;
    }//from  ww w  .  jav  a  2s.com
    return el.getStringValue();
}

From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

private String loadCreated(Document xmlDoc) {
    Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_CREATED, namespaceDcTerms));
    if (el == null) {
        return null;
    }/*  w  w  w  .j a va  2  s .  c  o m*/
    return el.getStringValue();
}

From source file:org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.java

License:Apache License

private String loadCreator(Document xmlDoc) {
    Element el = xmlDoc.getRootElement().element(new QName(KEYWORD_CREATOR, namespaceDC));
    if (el == null) {
        return null;
    }/*from www .ja  v a2  s  .  c  o m*/
    return el.getStringValue();
}