Example usage for com.itextpdf.text.xml.xmp XmpReader serializeDoc

List of usage examples for com.itextpdf.text.xml.xmp XmpReader serializeDoc

Introduction

In this page you can find the example usage for com.itextpdf.text.xml.xmp XmpReader serializeDoc.

Prototype

public byte[] serializeDoc() throws IOException 

Source Link

Document

Writes the document to a byte array.

Usage

From source file:org.crossref.pdfmark.XmpUtils.java

License:Open Source License

/**
 * Parse out all the XmpSchema from a blob of XMP data.
 *///from   w  ww.  j  av  a2  s  .  co  m
public static XmpSchema[] parseSchemata(byte[] xmpData) throws XmpException {
    Document doc = null;

    try {
        XmpReader reader = new XmpReader(xmpData);
        byte[] xmlData = reader.serializeDoc();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.parse(new ByteArrayInputStream(xmlData));
    } catch (IOException e) {
        throw new XmpException(e);
    } catch (SAXException e) {
        throw new XmpException(e);
    } catch (ParserConfigurationException e) {
        throw new XmpException(e);
    }

    NodeList descriptionNodes = doc.getElementsByTagName("rdf:Description");
    Map<String, XmpSchema> schemata = new HashMap<String, XmpSchema>();

    for (int i = 0; i < descriptionNodes.getLength(); i++) {
        Element description = (Element) descriptionNodes.item(i);
        NodeList children = description.getChildNodes();

        for (int j = 0; j < children.getLength(); j++) {
            Node n = children.item(j);
            if (n instanceof Element) {
                parseRdfElement(schemata, (Element) n);
            }
        }
    }

    return schemata.values().toArray(new XmpSchema[0]);
}