01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /* $Id: ParseMetadata.java 426584 2006-07-28 16:01:47Z jeremias $ */
19:
20: package xmp;
21:
22: import java.net.URL;
23:
24: import javax.xml.transform.TransformerException;
25: import javax.xml.transform.stream.StreamResult;
26:
27: import org.apache.xmlgraphics.xmp.Metadata;
28: import org.apache.xmlgraphics.xmp.XMPArray;
29: import org.apache.xmlgraphics.xmp.XMPConstants;
30: import org.apache.xmlgraphics.xmp.XMPParser;
31: import org.apache.xmlgraphics.xmp.XMPProperty;
32: import org.apache.xmlgraphics.xmp.XMPSerializer;
33: import org.xml.sax.SAXException;
34:
35: /**
36: * This example shows how to parse an XMP metadata file.
37: */
38: public class ParseMetadata {
39:
40: private static void parseMetadata() throws TransformerException,
41: SAXException {
42: URL url = ParseMetadata.class.getResource("pdf-example.xmp");
43: Metadata meta = XMPParser.parseXMP(url);
44: XMPProperty prop;
45: prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE,
46: "creator");
47: XMPArray array;
48: array = prop.getArrayValue();
49: for (int i = 0, c = array.getSize(); i < c; i++) {
50: System.out.println("Creator: " + array.getValue(i));
51: }
52: prop = meta.getProperty(XMPConstants.DUBLIN_CORE_NAMESPACE,
53: "title");
54: System.out.println("Title: " + prop.getValue());
55: prop = meta.getProperty(XMPConstants.XMP_BASIC_NAMESPACE,
56: "CreateDate");
57: System.out.println("Creation Date: " + prop.getValue());
58: prop = meta.getProperty(XMPConstants.XMP_BASIC_NAMESPACE,
59: "CreatorTool");
60: System.out.println("Creator Tool: " + prop.getValue());
61: prop = meta.getProperty(XMPConstants.ADOBE_PDF_NAMESPACE,
62: "Producer");
63: System.out.println("Producer: " + prop.getValue());
64: prop = meta.getProperty(XMPConstants.ADOBE_PDF_NAMESPACE,
65: "PDFVersion");
66: System.out.println("PDF version: " + prop.getValue());
67:
68: StreamResult res = new StreamResult(System.out);
69: XMPSerializer.writeXML(meta, res);
70: }
71:
72: /**
73: * Command-line interface.
74: * @param args the command-line arguments
75: */
76: public static void main(String[] args) {
77: try {
78: parseMetadata();
79: } catch (Exception e) {
80: e.printStackTrace();
81: }
82: }
83:
84: }
|