Search in sources :

Example 6 with ArrayProperty

use of org.apache.xmpbox.type.ArrayProperty in project pdfbox by apache.

the class XMPSchema method internalAddBagValue.

private void internalAddBagValue(String qualifiedBagName, String bagValue) {
    ArrayProperty bag = (ArrayProperty) getAbstractProperty(qualifiedBagName);
    TextType li = createTextType(XmpConstants.LIST_NAME, bagValue);
    if (bag != null) {
        bag.getContainer().addProperty(li);
    } else {
        ArrayProperty newBag = createArrayProperty(qualifiedBagName, Cardinality.Bag);
        newBag.getContainer().addProperty(li);
        addProperty(newBag);
    }
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) TextType(org.apache.xmpbox.type.TextType)

Example 7 with ArrayProperty

use of org.apache.xmpbox.type.ArrayProperty in project pdfbox by apache.

the class XMPSchema method addUnqualifiedSequenceValue.

/**
 * Add a new value to a sequence property.
 *
 * @param simpleSeqName
 *            The name of the sequence property without the namespace prefix
 * @param seqValue
 *            The value to add to the sequence.
 */
public void addUnqualifiedSequenceValue(String simpleSeqName, String seqValue) {
    ArrayProperty seq = (ArrayProperty) getAbstractProperty(simpleSeqName);
    TextType li = createTextType(XmpConstants.LIST_NAME, seqValue);
    if (seq != null) {
        seq.getContainer().addProperty(li);
    } else {
        ArrayProperty newSeq = createArrayProperty(simpleSeqName, Cardinality.Seq);
        newSeq.getContainer().addProperty(li);
        addProperty(newSeq);
    }
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) TextType(org.apache.xmpbox.type.TextType)

Example 8 with ArrayProperty

use of org.apache.xmpbox.type.ArrayProperty in project pdfbox by apache.

the class XMPSchemaTest method testArrayList.

@Test
public void testArrayList() throws Exception {
    XMPMetadata meta = XMPMetadata.createXMPMetadata();
    ArrayProperty newSeq = meta.getTypeMapping().createArrayProperty(null, "nsSchem", "seqType", Cardinality.Seq);
    TypeMapping tm = meta.getTypeMapping();
    TextType li1 = tm.createText(null, "rdf", "li", "valeur1");
    TextType li2 = tm.createText(null, "rdf", "li", "valeur2");
    newSeq.getContainer().addProperty(li1);
    newSeq.getContainer().addProperty(li2);
    schem.addProperty(newSeq);
    List<AbstractField> list = schem.getUnqualifiedArrayList("seqType");
    Assert.assertTrue(list.contains(li1));
    Assert.assertTrue(list.contains(li2));
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) XMPMetadata(org.apache.xmpbox.XMPMetadata) TypeMapping(org.apache.xmpbox.type.TypeMapping) TextType(org.apache.xmpbox.type.TextType) Test(org.junit.Test)

Example 9 with ArrayProperty

use of org.apache.xmpbox.type.ArrayProperty in project pdfbox by apache.

the class FontMetaDataValidation method analyseRights.

/**
 * If XMP MetaData are present, they must have followings information :
 * <UL>
 * <li>dc:rights
 * <li>Marked (with the value true)
 * <li>Owner
 * <li>UsageTerms
 * </UL>
 *
 * @param metadata
 *            XMPMetaData of the Font File Stream
 * @param fontDesc
 *            The FontDescriptor dictionary
 * @param ve
 *            the list of validation error to update if the validation fails
 * @return true if the analysis found no problems, false if it did.
 */
public boolean analyseRights(XMPMetadata metadata, PDFontDescriptor fontDesc, List<ValidationError> ve) {
    DublinCoreSchema dc = metadata.getDublinCoreSchema();
    if (dc != null) {
        ArrayProperty copyrights = dc.getRightsProperty();
        if (copyrights == null || copyrights.getContainer() == null || copyrights.getContainer().getAllProperties().isEmpty()) {
            ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, "CopyRights is missing from the XMP information (dc:rights) of the Font File Stream."));
            return false;
        }
    }
    XMPRightsManagementSchema rights = metadata.getXMPRightsManagementSchema();
    if (rights != null) {
        BooleanType marked = rights.getMarkedProperty();
        if (marked != null && !marked.getValue()) {
            ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, "the XMP information (xmpRights:Marked) is invalid for the Font File Stream."));
            return false;
        }
    /*
             * rights.getUsageTerms() & rights.getOwnerValue() should be present but it is only a recommendation : may
             * be it should be useful to append a Warning if these entries are missing.
             */
    }
    return true;
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) BooleanType(org.apache.xmpbox.type.BooleanType) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) XMPRightsManagementSchema(org.apache.xmpbox.schema.XMPRightsManagementSchema)

Example 10 with ArrayProperty

use of org.apache.xmpbox.type.ArrayProperty in project pdfbox by apache.

the class DomXmpParser method manageArray.

private void manageArray(XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer container) throws XmpParsingException {
    TypeMapping tm = xmp.getTypeMapping();
    String prefix = property.getPrefix();
    String name = property.getLocalName();
    String namespace = property.getNamespaceURI();
    Element bagOrSeq = DomHelper.getUniqueElementChild(property);
    // ensure this is the good type of array
    if (bagOrSeq == null) {
        // not an array
        String whatFound = "nothing";
        if (property.getFirstChild() != null) {
            whatFound = property.getFirstChild().getClass().getName();
        }
        throw new XmpParsingException(ErrorType.Format, "Invalid array definition, expecting " + type.card() + " and found " + whatFound + " [prefix=" + prefix + "; name=" + name + "]");
    }
    if (!bagOrSeq.getLocalName().equals(type.card().name())) {
        // not the good array type
        throw new XmpParsingException(ErrorType.Format, "Invalid array type, expecting " + type.card() + " and found " + bagOrSeq.getLocalName() + " [prefix=" + prefix + "; name=" + name + "]");
    }
    ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
    container.addProperty(array);
    List<Element> lis = DomHelper.getElementChildren(bagOrSeq);
    for (Element element : lis) {
        QName propertyQName = new QName(element.getLocalName());
        AbstractField ast = parseLiElement(xmp, propertyQName, element, type.type());
        if (ast != null) {
            array.addProperty(ast);
        }
    }
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) TypeMapping(org.apache.xmpbox.type.TypeMapping)

Aggregations

ArrayProperty (org.apache.xmpbox.type.ArrayProperty)17 AbstractField (org.apache.xmpbox.type.AbstractField)11 TextType (org.apache.xmpbox.type.TextType)5 Attribute (org.apache.xmpbox.type.Attribute)4 TypeMapping (org.apache.xmpbox.type.TypeMapping)4 ArrayList (java.util.ArrayList)3 AbstractStructuredType (org.apache.xmpbox.type.AbstractStructuredType)3 Element (org.w3c.dom.Element)3 List (java.util.List)2 AbstractSimpleProperty (org.apache.xmpbox.type.AbstractSimpleProperty)2 DefinedStructuredType (org.apache.xmpbox.type.DefinedStructuredType)2 PDFAPropertyType (org.apache.xmpbox.type.PDFAPropertyType)2 PropertiesDescription (org.apache.xmpbox.type.PropertiesDescription)2 PropertyType (org.apache.xmpbox.type.PropertyType)2 Method (java.lang.reflect.Method)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 XMPMetadata (org.apache.xmpbox.XMPMetadata)1