Search in sources :

Example 11 with TextType

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

the class XMPSchema method getUnqualifiedLanguagePropertyValue.

/**
 * Get the value of a multi-lingual property.
 *
 * @param name
 *            The name of the property, without the namespace prefix.
 * @param expectedLanguage
 *            The language code of the value. If null then "x-default" is assumed.
 *
 * @return The value of the language property.
 */
public String getUnqualifiedLanguagePropertyValue(String name, String expectedLanguage) {
    String language = (expectedLanguage != null) ? expectedLanguage : XmpConstants.X_DEFAULT;
    AbstractField property = getAbstractProperty(name);
    if (property != null) {
        if (property instanceof ArrayProperty) {
            ArrayProperty arrayProp = (ArrayProperty) property;
            for (AbstractField child : arrayProp.getContainer().getAllProperties()) {
                Attribute text = child.getAttribute(XmpConstants.LANG_NAME);
                if (text != null && text.getValue().equals(language)) {
                    return ((TextType) child).getStringValue();
                }
            }
            return null;
        } else {
            throw new IllegalArgumentException("The property '" + name + "' is not of Lang Alt type");
        }
    }
    return null;
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) Attribute(org.apache.xmpbox.type.Attribute) TextType(org.apache.xmpbox.type.TextType)

Example 12 with TextType

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

the class XMPSchema method mergeComplexProperty.

private boolean mergeComplexProperty(Iterator<AbstractField> itNewValues, ArrayProperty arrayProperty) {
    while (itNewValues.hasNext()) {
        TextType tmpNewValue = (TextType) itNewValues.next();
        for (AbstractField abstractField : arrayProperty.getContainer().getAllProperties()) {
            TextType tmpOldValue = (TextType) abstractField;
            if (tmpOldValue.getStringValue().equals(tmpNewValue.getStringValue())) {
                return true;
            }
        }
        arrayProperty.getContainer().addProperty(tmpNewValue);
    }
    return false;
}
Also used : AbstractField(org.apache.xmpbox.type.AbstractField) TextType(org.apache.xmpbox.type.TextType)

Example 13 with TextType

use of org.apache.xmpbox.type.TextType 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 14 with TextType

use of org.apache.xmpbox.type.TextType 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 15 with TextType

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

the class XMPSchemaTest method testProperties.

/**
 * Test All common simple properties management in XMPSchema
 *
 * @throws IllegalArgumentException
 * @throws BadFieldValueException
 */
@Test
public void testProperties() throws Exception {
    Assert.assertEquals("nsURI", schem.getNamespace());
    // In real cases, rdf ns will be declared before !
    schem.addNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
    String aboutVal = "aboutTest";
    schem.setAboutAsSimple(aboutVal);
    Assert.assertEquals(aboutVal, schem.getAboutValue());
    Attribute about = new Attribute(XmpConstants.RDF_NAMESPACE, "about", "YEP");
    schem.setAbout(about);
    Assert.assertEquals(about, schem.getAboutAttribute());
    String textProp = "textProp";
    String textPropVal = "TextPropTest";
    schem.setTextPropertyValue(textProp, textPropVal);
    Assert.assertEquals(textPropVal, schem.getUnqualifiedTextPropertyValue(textProp));
    TextType text = parent.getTypeMapping().createText(null, "nsSchem", "textType", "GRINGO");
    schem.setTextProperty(text);
    Assert.assertEquals(text, schem.getUnqualifiedTextProperty("textType"));
    Calendar dateVal = Calendar.getInstance();
    String date = "nsSchem:dateProp";
    schem.setDatePropertyValue(date, dateVal);
    Assert.assertEquals(dateVal, schem.getDatePropertyValue(date));
    DateType dateType = parent.getTypeMapping().createDate(null, "nsSchem", "dateType", Calendar.getInstance());
    schem.setDateProperty(dateType);
    Assert.assertEquals(dateType, schem.getDateProperty("dateType"));
    String bool = "nsSchem:booleanTestProp";
    Boolean boolVal = false;
    schem.setBooleanPropertyValue(bool, boolVal);
    Assert.assertEquals(boolVal, schem.getBooleanPropertyValue(bool));
    BooleanType boolType = parent.getTypeMapping().createBoolean(null, "nsSchem", "boolType", false);
    schem.setBooleanProperty(boolType);
    Assert.assertEquals(boolType, schem.getBooleanProperty("boolType"));
    String intProp = "nsSchem:IntegerTestProp";
    Integer intPropVal = 5;
    schem.setIntegerPropertyValue(intProp, intPropVal);
    Assert.assertEquals(intPropVal, schem.getIntegerPropertyValue(intProp));
    IntegerType intType = parent.getTypeMapping().createInteger(null, "nsSchem", "intType", 5);
    schem.setIntegerProperty(intType);
    Assert.assertEquals(intType, schem.getIntegerProperty("intType"));
    // Check bad type verification
    boolean ok = false;
    try {
        schem.getIntegerProperty("boolType");
    } catch (IllegalArgumentException e) {
        ok = true;
    }
    Assert.assertTrue(ok);
    ok = false;
    try {
        schem.getUnqualifiedTextProperty("intType");
    } catch (IllegalArgumentException e) {
        ok = true;
    }
    Assert.assertTrue(ok);
    ok = false;
    try {
        schem.getDateProperty("textType");
    } catch (IllegalArgumentException e) {
        ok = true;
    }
    Assert.assertTrue(ok);
    ok = false;
    try {
        schem.getBooleanProperty("dateType");
    } catch (IllegalArgumentException e) {
        ok = true;
    }
}
Also used : IntegerType(org.apache.xmpbox.type.IntegerType) Attribute(org.apache.xmpbox.type.Attribute) Calendar(java.util.Calendar) BooleanType(org.apache.xmpbox.type.BooleanType) DateType(org.apache.xmpbox.type.DateType) TextType(org.apache.xmpbox.type.TextType) Test(org.junit.Test)

Aggregations

TextType (org.apache.xmpbox.type.TextType)37 AbstractField (org.apache.xmpbox.type.AbstractField)5 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)5 Test (org.junit.Test)4 Method (java.lang.reflect.Method)3 Attribute (org.apache.xmpbox.type.Attribute)3 XMPMetadata (org.apache.xmpbox.XMPMetadata)2 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)1 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)1 BooleanType (org.apache.xmpbox.type.BooleanType)1 DateType (org.apache.xmpbox.type.DateType)1 IntegerType (org.apache.xmpbox.type.IntegerType)1 TypeMapping (org.apache.xmpbox.type.TypeMapping)1 URIType (org.apache.xmpbox.type.URIType)1 URLType (org.apache.xmpbox.type.URLType)1 DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)1