Search in sources :

Example 1 with CTProperty

use of org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty in project poi by apache.

the class POIXMLPropertiesTextExtractor method getCustomPropertiesText.

/**
    * Returns the custom document properties, if there are any
    * 
    * @return the custom document properties
    */
@SuppressWarnings({ "resource" })
public String getCustomPropertiesText() {
    POIXMLDocument document = getDocument();
    if (document == null) {
        // event based extractor does not have a document
        return "";
    }
    StringBuilder text = new StringBuilder();
    org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties props = document.getProperties().getCustomProperties().getUnderlyingProperties();
    for (CTProperty property : props.getPropertyArray()) {
        String val = "(not implemented!)";
        if (property.isSetLpwstr()) {
            val = property.getLpwstr();
        } else if (property.isSetLpstr()) {
            val = property.getLpstr();
        } else if (property.isSetDate()) {
            val = property.getDate().toString();
        } else if (property.isSetFiletime()) {
            val = property.getFiletime().toString();
        } else if (property.isSetBool()) {
            val = Boolean.toString(property.getBool());
        } else // Integers
        if (property.isSetI1()) {
            val = Integer.toString(property.getI1());
        } else if (property.isSetI2()) {
            val = Integer.toString(property.getI2());
        } else if (property.isSetI4()) {
            val = Integer.toString(property.getI4());
        } else if (property.isSetI8()) {
            val = Long.toString(property.getI8());
        } else if (property.isSetInt()) {
            val = Integer.toString(property.getInt());
        } else // Unsigned Integers
        if (property.isSetUi1()) {
            val = Integer.toString(property.getUi1());
        } else if (property.isSetUi2()) {
            val = Integer.toString(property.getUi2());
        } else if (property.isSetUi4()) {
            val = Long.toString(property.getUi4());
        } else if (property.isSetUi8()) {
            val = property.getUi8().toString();
        } else if (property.isSetUint()) {
            val = Long.toString(property.getUint());
        } else // Reals
        if (property.isSetR4()) {
            val = Float.toString(property.getR4());
        } else if (property.isSetR8()) {
            val = Double.toString(property.getR8());
        } else if (property.isSetDecimal()) {
            BigDecimal d = property.getDecimal();
            if (d == null) {
                val = null;
            } else {
                val = d.toPlainString();
            }
        }
        /*else if (property.isSetArray()) {
            // TODO Fetch the array values and output 
         }
         else if (property.isSetVector()) {
            // TODO Fetch the vector values and output
         }

         else if (property.isSetBlob() || property.isSetOblob()) {
            // TODO Decode, if possible
         }
         else if (property.isSetStream() || property.isSetOstream() ||
                  property.isSetVstream()) {
            // TODO Decode, if possible
         }
         else if (property.isSetStorage() || property.isSetOstorage()) {
            // TODO Decode, if possible
         }*/
        text.append(property.getName()).append(" = ").append(val).append("\n");
    }
    return text.toString();
}
Also used : CTProperty(org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty) BigDecimal(java.math.BigDecimal)

Example 2 with CTProperty

use of org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty in project tika by apache.

the class MetadataExtractor method extractMetadata.

private void extractMetadata(CustomProperties properties, Metadata metadata) {
    org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties props = properties.getUnderlyingProperties();
    for (int i = 0; i < props.sizeOfPropertyArray(); i++) {
        CTProperty property = props.getPropertyArray(i);
        String val = null;
        Date date = null;
        if (property.isSetLpwstr()) {
            val = property.getLpwstr();
        } else if (property.isSetLpstr()) {
            val = property.getLpstr();
        } else if (property.isSetDate()) {
            date = property.getDate().getTime();
        } else if (property.isSetFiletime()) {
            date = property.getFiletime().getTime();
        } else if (property.isSetBool()) {
            val = Boolean.toString(property.getBool());
        } else // Integers
        if (property.isSetI1()) {
            val = Integer.toString(property.getI1());
        } else if (property.isSetI2()) {
            val = Integer.toString(property.getI2());
        } else if (property.isSetI4()) {
            val = Integer.toString(property.getI4());
        } else if (property.isSetI8()) {
            val = Long.toString(property.getI8());
        } else if (property.isSetInt()) {
            val = Integer.toString(property.getInt());
        } else // Unsigned Integers
        if (property.isSetUi1()) {
            val = Integer.toString(property.getUi1());
        } else if (property.isSetUi2()) {
            val = Integer.toString(property.getUi2());
        } else if (property.isSetUi4()) {
            val = Long.toString(property.getUi4());
        } else if (property.isSetUi8()) {
            val = property.getUi8().toString();
        } else if (property.isSetUint()) {
            val = Long.toString(property.getUint());
        } else // Reals
        if (property.isSetR4()) {
            val = Float.toString(property.getR4());
        } else if (property.isSetR8()) {
            val = Double.toString(property.getR8());
        } else if (property.isSetDecimal()) {
            BigDecimal d = property.getDecimal();
            if (d == null) {
                val = null;
            } else {
                val = d.toPlainString();
            }
        } else if (property.isSetArray()) {
        // TODO Fetch the array values and output
        } else if (property.isSetVector()) {
        // TODO Fetch the vector values and output
        } else if (property.isSetBlob() || property.isSetOblob()) {
        // TODO Decode, if possible
        } else if (property.isSetStream() || property.isSetOstream() || property.isSetVstream()) {
        // TODO Decode, if possible
        } else if (property.isSetStorage() || property.isSetOstorage()) {
        // TODO Decode, if possible
        } else {
        // This type isn't currently supported yet, skip the property
        }
        String propName = "custom:" + property.getName();
        if (date != null) {
            Property tikaProp = Property.externalDate(propName);
            metadata.set(tikaProp, date);
        } else if (val != null) {
            metadata.set(propName, val);
        }
    }
}
Also used : CTProperty(org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty) CTProperty(org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty) Property(org.apache.tika.metadata.Property) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 3 with CTProperty

use of org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty in project poi by apache.

the class TestPackageCoreProperties method testListOfCustomProperties.

@Test
public void testListOfCustomProperties() throws Exception {
    File inp = POIDataSamples.getSpreadSheetInstance().getFile("ExcelWithAttachments.xlsm");
    OPCPackage pkg = OPCPackage.open(inp, PackageAccess.READ);
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
    assertNotNull(wb.getProperties());
    assertNotNull(wb.getProperties().getCustomProperties());
    for (CTProperty prop : wb.getProperties().getCustomProperties().getUnderlyingProperties().getPropertyList()) {
        assertNotNull(prop);
    }
    wb.close();
    pkg.close();
}
Also used : CTProperty(org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) File(java.io.File) Test(org.junit.Test)

Aggregations

CTProperty (org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty)3 BigDecimal (java.math.BigDecimal)2 File (java.io.File)1 Date (java.util.Date)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 Property (org.apache.tika.metadata.Property)1 Test (org.junit.Test)1