use of org.apache.poi.hpsf.CustomProperty in project poi by apache.
the class TestReadAllFiles method readCustomPropertiesFromFiles.
/**
* <p>Tests the simplified custom properties by reading them from the
* available test files.</p>
*
* @throws Throwable if anything goes wrong.
*/
@Test
public void readCustomPropertiesFromFiles() throws Exception {
/* Read a test document <em>doc</em> into a POI filesystem. */
NPOIFSFileSystem poifs = new NPOIFSFileSystem(file);
try {
/*
* If there is a document summry information stream, read it from
* the POI filesystem, else create a new one.
*/
DocumentSummaryInformation dsi = TestWriteWellKnown.getDocumentSummaryInformation(poifs);
if (dsi == null) {
dsi = PropertySetFactory.newDocumentSummaryInformation();
}
final CustomProperties cps = dsi.getCustomProperties();
if (cps == null) {
/* The document does not have custom properties. */
return;
}
for (CustomProperty cp : cps.properties()) {
assertNotNull(cp.getName());
assertNotNull(cp.getValue());
}
} finally {
poifs.close();
}
}
use of org.apache.poi.hpsf.CustomProperty in project poi by apache.
the class TestWriteWellKnown method testCustomerProperties.
/**
* Tests basic custom property features.
*/
@Test
public void testCustomerProperties() {
final String KEY = "Schlüssel ä";
final String VALUE_1 = "Wert 1";
final String VALUE_2 = "Wert 2";
CustomProperty cp;
CustomProperties cps = new CustomProperties();
assertEquals(0, cps.size());
/* After adding a custom property the size must be 1 and it must be
* possible to extract the custom property from the map. */
cps.put(KEY, VALUE_1);
assertEquals(1, cps.size());
Object v1 = cps.get(KEY);
assertEquals(VALUE_1, v1);
/* After adding a custom property with the same name the size must still
* be one. */
cps.put(KEY, VALUE_2);
assertEquals(1, cps.size());
Object v2 = cps.get(KEY);
assertEquals(VALUE_2, v2);
/* Removing the custom property must return the remove property and
* reduce the size to 0. */
cp = (CustomProperty) cps.remove(KEY);
assertEquals(KEY, cp.getName());
assertEquals(VALUE_2, cp.getValue());
assertEquals(0, cps.size());
}
Aggregations