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;
}
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;
}
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);
}
}
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);
}
}
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;
}
}
Aggregations