Search in sources :

Example 6 with Property

use of org.apache.tika.metadata.Property in project tika by apache.

the class GribParser method parse.

public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
    //Set MIME type as grib2
    metadata.set(Metadata.CONTENT_TYPE, GRIB_MIME_TYPE);
    TikaInputStream tis = TikaInputStream.get(stream, new TemporaryResources());
    File gribFile = tis.getFile();
    try {
        NetcdfFile ncFile = NetcdfDataset.openFile(gribFile.getAbsolutePath(), null);
        // first parse out the set of global attributes
        for (Attribute attr : ncFile.getGlobalAttributes()) {
            Property property = resolveMetadataKey(attr.getFullName());
            if (attr.getDataType().isString()) {
                metadata.add(property, attr.getStringValue());
            } else if (attr.getDataType().isNumeric()) {
                int value = attr.getNumericValue().intValue();
                metadata.add(property, String.valueOf(value));
            }
        }
        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();
        xhtml.newline();
        xhtml.startElement("ul");
        xhtml.characters("dimensions:");
        xhtml.newline();
        for (Dimension dim : ncFile.getDimensions()) {
            xhtml.element("li", dim.getFullName() + "=" + String.valueOf(dim.getLength()) + ";");
            xhtml.newline();
        }
        xhtml.startElement("ul");
        xhtml.characters("variables:");
        xhtml.newline();
        for (Variable var : ncFile.getVariables()) {
            xhtml.element("p", String.valueOf(var.getDataType()) + var.getNameAndDimensions() + ";");
            for (Attribute element : var.getAttributes()) {
                xhtml.element("li", " :" + element + ";");
                xhtml.newline();
            }
        }
        xhtml.endElement("ul");
        xhtml.endElement("ul");
        xhtml.endDocument();
    } catch (IOException e) {
        throw new TikaException("NetCDF parse error", e);
    }
}
Also used : NetcdfFile(ucar.nc2.NetcdfFile) Variable(ucar.nc2.Variable) TikaException(org.apache.tika.exception.TikaException) Attribute(ucar.nc2.Attribute) TemporaryResources(org.apache.tika.io.TemporaryResources) TikaInputStream(org.apache.tika.io.TikaInputStream) Dimension(ucar.nc2.Dimension) IOException(java.io.IOException) XHTMLContentHandler(org.apache.tika.sax.XHTMLContentHandler) File(java.io.File) NetcdfFile(ucar.nc2.NetcdfFile) Property(org.apache.tika.metadata.Property)

Example 7 with Property

use of org.apache.tika.metadata.Property in project tika by apache.

the class CorePropertiesHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    Property prop = getProperty(uri, localName);
    if (prop != null) {
        if (prop.isMultiValuePermitted()) {
            metadata.add(prop, buffer.toString());
        } else {
            metadata.set(prop, buffer.toString());
        }
    }
    buffer.setLength(0);
}
Also used : Property(org.apache.tika.metadata.Property)

Example 8 with Property

use of org.apache.tika.metadata.Property in project tika by apache.

the class XMPMetadata method setAll.

/**
     * It will set all simple and array properties that have QName keys in registered namespaces.
     *
     * @see org.apache.tika.metadata.Metadata#setAll(java.util.Properties)
     */
@Override
public void setAll(Properties properties) {
    @SuppressWarnings("unchecked") Enumeration<String> names = (Enumeration<String>) properties.propertyNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        Property property = Property.get(name);
        if (property == null) {
            throw new PropertyTypeException("Unknown property: " + name);
        }
        String value = properties.getProperty(name);
        if (property.isMultiValuePermitted()) {
            this.set(property, new String[] { value });
        } else {
            this.set(property, value);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) PropertyTypeException(org.apache.tika.metadata.PropertyTypeException) XMPProperty(com.adobe.xmp.properties.XMPProperty) Property(org.apache.tika.metadata.Property)

Aggregations

Property (org.apache.tika.metadata.Property)8 IOException (java.io.IOException)2 Date (java.util.Date)2 TikaException (org.apache.tika.exception.TikaException)2 TemporaryResources (org.apache.tika.io.TemporaryResources)2 TikaInputStream (org.apache.tika.io.TikaInputStream)2 XHTMLContentHandler (org.apache.tika.sax.XHTMLContentHandler)2 Attribute (ucar.nc2.Attribute)2 Dimension (ucar.nc2.Dimension)2 NetcdfFile (ucar.nc2.NetcdfFile)2 Variable (ucar.nc2.Variable)2 XMPProperty (com.adobe.xmp.properties.XMPProperty)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 PropertyTypeException (org.apache.tika.metadata.PropertyTypeException)1 CTProperty (org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty)1