use of org.apache.xmpbox.type.BooleanType 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;
}
}
use of org.apache.xmpbox.type.BooleanType in project pdfbox by apache.
the class AbstractXMPSchemaTest method testGetSetBooleanProperty.
protected void testGetSetBooleanProperty() throws Exception {
String setName = setMethod(property);
String getName = getMethod(property);
BooleanType bt = new BooleanType(metadata, null, schema.getPrefix(), property, value);
Method setMethod = schemaClass.getMethod(setName, BooleanType.class);
Method getMethod = schemaClass.getMethod(getName);
setMethod.invoke(schema, bt);
Boolean found = ((BooleanType) getMethod.invoke(schema)).getValue();
Assert.assertEquals(value, found);
}
use of org.apache.xmpbox.type.BooleanType 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;
}
use of org.apache.xmpbox.type.BooleanType in project pdfbox by apache.
the class XMPSchemaTest method testListAndContainerAccessor.
@Test
public void testListAndContainerAccessor() throws Exception {
String boolname = "bool";
boolean boolVal = true;
BooleanType bool = parent.getTypeMapping().createBoolean(null, schem.getPrefix(), boolname, boolVal);
Attribute att = new Attribute(XmpConstants.RDF_NAMESPACE, "test", "vgh");
schem.setAttribute(att);
schem.setBooleanProperty(bool);
Assert.assertEquals(schem.getAllProperties(), schem.getAllProperties());
Assert.assertTrue(schem.getAllProperties().contains(bool));
Assert.assertTrue(schem.getAllAttributes().contains(att));
Assert.assertEquals(bool, schem.getProperty(boolname));
}
use of org.apache.xmpbox.type.BooleanType in project pdfbox by apache.
the class XMPSchemaTest method testSeqManagement.
/**
* Check if Seq (Ordered Array) management is ok
*
* @throws IllegalArgumentException
* @throws java.io.IOException
*/
@Test
public void testSeqManagement() throws Exception {
Calendar date = Calendar.getInstance();
BooleanType bool = parent.getTypeMapping().createBoolean(null, "rdf", "li", true);
String textVal = "seqValue";
String seqName = "SEQNAME";
schem.addUnqualifiedSequenceDateValue(seqName, date);
schem.addUnqualifiedSequenceValue(seqName, bool);
schem.addUnqualifiedSequenceValue(seqName, textVal);
List<Calendar> dates = schem.getUnqualifiedSequenceDateValueList(seqName);
Assert.assertEquals(1, dates.size());
Assert.assertEquals(date, dates.get(0));
List<String> values = schem.getUnqualifiedSequenceValueList(seqName);
Assert.assertEquals(3, values.size());
Assert.assertEquals(DateConverter.toISO8601(date), values.get(0));
Assert.assertEquals(bool.getStringValue(), values.get(1));
Assert.assertEquals(textVal, values.get(2));
schem.removeUnqualifiedSequenceDateValue(seqName, date);
Assert.assertEquals(0, schem.getUnqualifiedSequenceDateValueList(seqName).size());
schem.removeUnqualifiedSequenceValue(seqName, bool);
schem.removeUnqualifiedSequenceValue(seqName, textVal);
Assert.assertEquals(0, schem.getUnqualifiedSequenceValueList(seqName).size());
}
Aggregations