try(Metadatametadata=newMetadata(Constants.InputDocx)){// Fetch all metadata properties from the fileIReadOnlyList<MetadataProperty>properties=metadata.findProperties(newAnySpecification());for(MetadataPropertyproperty:properties){// Process String and DateTime properties onlyif(property.getValue().getType()==MetadataPropertyType.String){System.out.println(property.getValue().toClass(String.class));}elseif(property.getValue().getType()==MetadataPropertyType.DateTime){System.out.println(property.getValue().toClass(Date.class));}}}
But if it’s necessary to process all supported types of values you may find the alternative way more convenient.
publicclassExtractUsingAcceptor{publicstaticvoidrun(){try(Metadatametadata=newMetadata(Constants.InputDocx)){// Fetch all metadata propertiesIReadOnlyList<MetadataProperty>properties=metadata.findProperties(newAnySpecification());ValueAcceptorvalueAcceptor=newExtractUsingAcceptor().newCustomValueAcceptor();for(MetadataPropertyproperty:properties){// Extract the property value using a custom acceptorproperty.getValue().acceptValue(valueAcceptor);}}}privateclassCustomValueAcceptorextendsValueAcceptor{protectedvoidacceptNull(){System.out.println("Null value extracted");}protectedvoidaccept(Stringvalue){System.out.println(String.format("String value extracted: %s",value));}protectedvoidaccept(booleanvalue){System.out.println(String.format("Boolean value extracted: %s",value));}protectedvoidaccept(Datevalue){System.out.println(String.format("DateTime value extracted: %s",value));}protectedvoidaccept(intvalue){System.out.println(String.format("Integer value extracted: %s",value));}protectedvoidaccept(longvalue){System.out.println(String.format("Long value extracted: %s",value));}protectedvoidaccept(doublevalue){System.out.println(String.format("Double value extracted: %s",value));}protectedvoidaccept(String[]value){System.out.println(String.format("String array extracted: %s",(Object)value));}protectedvoidaccept(byte[]value){System.out.println(String.format("Byte array extracted: %s",value));}protectedvoidaccept(double[]value){System.out.println(String.format("Double array extracted: %s",value));}protectedvoidaccept(int[]value){System.out.println(String.format("Integer array extracted: %s",value));}protectedvoidaccept(long[]value){System.out.println(String.format("Long array extracted: %s",value));}protectedvoidaccept(MetadataPackagevalue){System.out.println(String.format("Metadata package value extracted: %s",value));}protectedvoidaccept(MetadataPackage[]value){System.out.println(String.format("Metadata package array extracted: %s",(Object)value));}protectedvoidaccept(UUIDvalue){System.out.println(String.format("Guid value extracted: %s",value));}protectedvoidaccept(PropertyValue[]value){System.out.println(String.format("Property value array extracted: %s",(Object)value));}}}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: