pdfbox-1.8.11/ 0000755 0000000 0000000 00000000000 12645760246 011576 5 ustar root root pdfbox-1.8.11/LICENSE.txt 0000644 0000000 0000000 00000043260 12645757434 013433 0 ustar root root
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
EXTERNAL COMPONENTS
Apache PDFBox includes a number of components with separate copyright notices
and license terms. Your use of these components is subject to the terms and
conditions of the following licenses.
Contributions made to the original PDFBox, JempBox and FontBox projects:
Copyright (c) 2002-2007, www.pdfbox.org
Copyright (c) 2006-2007, www.jempbox.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of pdfbox; nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Adobe Font Metrics (AFM) for PDF Core 14 Fonts
This file and the 14 PostScript(R) AFM files it accompanies may be used,
copied, and distributed for any purpose and without charge, with or without
modification, provided that all copyright notices are retained; that the
AFM files are not distributed without this file; that all modifications
to this file or any of the AFM files are prominently noted in the modified
file(s); and that this paragraph is not modified. Adobe Systems has no
responsibility or obligation to support the use of the AFM files.
CMaps for PDF Fonts (http://opensource.adobe.com/wiki/display/cmap/Downloads)
Copyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Glyphlist (http://www.adobe.com/devnet/opentype/archives/glyph.html)
Copyright (c) 1997,1998,2002,2007 Adobe Systems Incorporated
Permission is hereby granted, free of charge, to any person obtaining a
copy of this documentation file to use, copy, publish, distribute,
sublicense, and/or sell copies of the documentation, and to permit
others to do the same, provided that:
- No modification, editing or other alteration of this document is
allowed; and
- The above copyright notice and this permission notice shall be
included in all copies of the documentation.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this documentation file, to create their own derivative works
from the content of this document to use, copy, publish, distribute,
sublicense, and/or sell the derivative works, and to permit others to do
the same, provided that the derived work is not represented as being a
copy or version of this document.
Adobe shall not be liable to any party for any loss of revenue or profit
or for indirect, incidental, special, consequential, or other similar
damages, whether based on tort (including without limitation negligence
or strict liability), contract or other legal or equitable grounds even
if Adobe has been advised or had reason to know of the possibility of
such damages. The Adobe materials are provided on an "AS IS" basis.
Adobe specifically disclaims all express, statutory, or implied
warranties relating to the Adobe materials, including but not limited to
those concerning merchantability or fitness for a particular purpose or
non-infringement of any third party rights regarding the Adobe
materials.
PaDaF PDF/A preflight (http://sourceforge.net/projects/padaf)
Copyright 2010 Atos Worldline SAS
Licensed by Atos Worldline SAS under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
Atos Worldline SAS licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
pdfbox-1.8.11/parent/ 0000755 0000000 0000000 00000000000 12645757436 013076 5 ustar root root pdfbox-1.8.11/parent/pom.xml 0000644 0000000 0000000 00000021641 12645757434 014415 0 ustar root root
4.0.0org.apacheapache10org.apache.pdfboxpdfbox-parent1.8.11pomPDFBox parent2002The Apache Software Foundationhttp://pdfbox.apache.orgjirahttps://issues.apache.org/jira/browse/PDFBOXISO-8859-13.0.0pedanticorg.apache.ratapache-rat-pluginverifycheckmaven-compiler-plugin1.51.5maven-javadoc-plugin1.5
http://download.oracle.com/javase/1.5.0/docs/api/
maven-release-pluginfalsedeploy-Papache-release,pedantictrueorg.apache.maven.pluginsmaven-jar-plugintruetrueorg.codehaus.mojoanimal-sniffer-maven-plugin1.13org.codehaus.mojo.signaturejava151.0check-java-compatibilitytestcheckorg.apache.ratapache-rat-plugin0.6release.propertiesorg.apache.felixmaven-bundle-plugin2.3.7org.eclipse.m2elifecycle-mapping1.0.0
org.apache.maven.plugins
maven-antrun-plugin
[1.6,)runlehmiAndreas LehmkühlerPMC ChairadamAdam NicholsPMC MemberblitchfieldBen LitchfieldPMC MembercarrierBrian CarrierPMC MemberdanielwilsonDaniel WilsonPMC MemberleleueriEric LeleuPMC Member (emeritus)gbailleulGuillaume BailleulPMC MemberjeremiasJeremias MaerkiPMC MemberkochJohannes KochPMC MemberjukkaJukka ZittingPMC Member (emeritus)kjacksonKevin JacksonPMC MembermsayhounMaruan SayhounPMC MemberpkochPhillipp KochPMC MembertchojeckiThomas ChojeckiPMC MembertboehmeTimo BoehmePMC MembervfedVillu RuusmannPMC Memberscm:svn:http://svn.apache.org/repos/asf/maven/pom/tags/1.8.11/pdfbox-parentscm:svn:https://svn.apache.org/repos/asf/maven/pom/tags/1.8.11/pdfbox-parenthttp://svn.apache.org/viewvc/maven/pom/tags/1.8.11/pdfbox-parent
pdfbox-1.8.11/pdfbox-checkstyle.xml 0000644 0000000 0000000 00000016421 12645757426 015750 0 ustar root root
pdfbox-1.8.11/war/ 0000755 0000000 0000000 00000000000 12645760124 012362 5 ustar root root pdfbox-1.8.11/war/src/ 0000755 0000000 0000000 00000000000 12645757434 013163 5 ustar root root pdfbox-1.8.11/war/src/main/ 0000755 0000000 0000000 00000000000 12645757434 014107 5 ustar root root pdfbox-1.8.11/war/src/main/webapp/ 0000755 0000000 0000000 00000000000 12645757434 015365 5 ustar root root pdfbox-1.8.11/war/src/main/webapp/WEB-INF/ 0000755 0000000 0000000 00000000000 12645757434 016414 5 ustar root root pdfbox-1.8.11/war/src/main/webapp/WEB-INF/web.xml 0000644 0000000 0000000 00000002003 12645757434 017706 0 ustar root root
Web application for PDFBox examples.
pdfbox-1.8.11/war/src/main/webapp/bookmarks.xml 0000644 0000000 0000000 00000002103 12645757434 020073 0 ustar root root
pdfbox-1.8.11/war/src/main/webapp/highlight.jsp 0000644 0000000 0000000 00000003330 12645757434 020051 0 ustar root root <%--
! Licensed to the Apache Software Foundation (ASF) under one or more
! contributor license agreements. See the NOTICE file distributed with
! this work for additional information regarding copyright ownership.
! The ASF licenses this file to You under the Apache License, Version 2.0
! (the "License"); you may not use this file except in compliance with
! the License. You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
--%>
<%@ page import="org.apache.pdfbox.pdmodel.PDDocument"%>
<%@ page import="org.apache.pdfbox.util.PDFHighlighter"%>
<%@ page import="java.net.URL"%>
<%
long start = System.currentTimeMillis();
response.setHeader("Cache-Control","no-cache") ;
response.setHeader("Pragma","no-cache") ;
response.setDateHeader("Expires",0);
String pdfURLString = request.getParameter( "pdf" );
String highlightWords = request.getParameter( "words" );
URL pdfURL = new URL( pdfURLString );
PDDocument doc = null;
try
{
doc = PDDocument.load( pdfURL.openStream() );
PDFHighlighter highlighter = new PDFHighlighter();
highlighter.generateXMLHighlight( doc, highlightWords.split( " " ), out );
}
finally
{
if( doc != null )
{
doc.close();
}
}
long stop = System.currentTimeMillis();
System.out.println( "Highlighter time:" +(stop-start) );
%>
pdfbox-1.8.11/war/src/main/webapp/index.html 0000644 0000000 0000000 00000004502 12645757434 017363 0 ustar root root
PDFBox Examples
PDFBox Highlighter example
This is a simple example to show off the PDFBox highlighting capabilities. Enter a URL PDF that you would like to view and
some words that you would like to search on.
See the PDF Highlighter spec for more detailed information.
pdfbox-1.8.11/war/pom.xml 0000644 0000000 0000000 00000003065 12645757434 013715 0 ustar root root
4.0.0org.apache.pdfboxpdfbox-parent1.8.11../parent/pom.xmlpdfbox-warwarApache PDFBox webapp${project.groupId}pdfbox${project.version}
pdfbox-1.8.11/xmpbox/ 0000755 0000000 0000000 00000000000 12645757534 013121 5 ustar root root pdfbox-1.8.11/xmpbox/src/ 0000755 0000000 0000000 00000000000 12645757426 013710 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/ 0000755 0000000 0000000 00000000000 12645757426 014634 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/ 0000755 0000000 0000000 00000000000 12645757426 015555 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/org/ 0000755 0000000 0000000 00000000000 12645757426 016344 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/org/apache/ 0000755 0000000 0000000 00000000000 12645757426 017565 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/ 0000755 0000000 0000000 00000000000 12645757426 021102 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/ 0000755 0000000 0000000 00000000000 12645757426 022342 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPRightsManagementSchema.java 0000644 0000000 0000000 00000022225 12645757426 030153 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.util.List;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.BooleanType;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.Types;
import org.apache.xmpbox.type.URLType;
/**
* Representation of XMP Rights Management Schema
*
* @author a183132
*
*/
@StructuredType(preferedPrefix = "xmpRights", namespace = "http://ns.adobe.com/xap/1.0/rights/")
public class XMPRightsManagementSchema extends XMPSchema
{
@PropertyType(type = Types.URL, card = Cardinality.Simple)
public static final String CERTIFICATE = "Certificate";
@PropertyType(type = Types.Boolean, card = Cardinality.Simple)
public static final String MARKED = "Marked";
@PropertyType(type = Types.ProperName, card = Cardinality.Bag)
public static final String OWNER = "Owner";
@PropertyType(type = Types.LangAlt, card = Cardinality.Simple)
public static final String USAGETERMS = "UsageTerms";
@PropertyType(type = Types.URL, card = Cardinality.Simple)
public static final String WEBSTATEMENT = "WebStatement";
/**
* Constructor of XMPRightsManagement Schema with preferred prefix
*
* @param metadata
* The metadata to attach this schema
*/
public XMPRightsManagementSchema(XMPMetadata metadata)
{
super(metadata);
}
/**
* Constructor of XMPRightsManagement schema with specified prefix
*
* @param metadata
* The metadata to attach this schema
* @param ownPrefix
* The prefix to assign
*/
public XMPRightsManagementSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
/**
* Add a legal owner for the described resource.
*
* @param value
* value to add
*/
public void addOwner(String value)
{
addQualifiedBagValue(OWNER, value);
}
public void removeOwner(String value)
{
removeUnqualifiedBagValue(OWNER, value);
}
/**
* Return the Bag of owner(s)
*
* @return owners property
*/
public ArrayProperty getOwnersProperty()
{
return (ArrayProperty) getProperty(OWNER);
}
/**
* Return a String list of owner(s)
*
* @return list of defined owners
*/
public List getOwners()
{
return getUnqualifiedBagValueList(OWNER);
}
/**
* Set Marked value
*
* @param marked
* value to add
*/
public void setMarked(Boolean marked)
{
BooleanType tt = (BooleanType) instanciateSimple(MARKED, marked ? BooleanType.TRUE : BooleanType.FALSE);
setMarkedProperty(tt);
}
/**
* Set Marked property
*
* @param marked
* Marked property to set
*/
public void setMarkedProperty(BooleanType marked)
{
addProperty(marked);
}
/**
* Get Marked property
*
* @return Marked property
*/
public BooleanType getMarkedProperty()
{
return (BooleanType) getProperty(MARKED);
}
/**
* Get Marked value
*
* @return marked value
*/
public Boolean getMarked()
{
BooleanType bt = ((BooleanType) getProperty(MARKED));
return bt == null ? null : bt.getValue();
}
/**
* Add an usageTerms value
*
* @param lang
* concerned language
* @param value
* value to set
*/
public void addUsageTerms(String lang, String value)
{
setUnqualifiedLanguagePropertyValue(USAGETERMS, lang, value);
}
/**
* Set the default usage terms for this resource.
*
* @param terms
* The resource usage terms.
*/
public void setUsageTerms(String terms)
{
addUsageTerms(null, terms);
}
/**
* Convenience method for jempbox signature compatibility
*
* @see XMPRightsManagementSchema#addUsageTerms(String, String)
*/
@Deprecated
public void setDescription(String language, String terms)
{
addUsageTerms(language, terms);
}
/**
* Return the Lang alt UsageTerms
*
* @return usageterms property
*/
public ArrayProperty getUsageTermsProperty()
{
return (ArrayProperty) getProperty(USAGETERMS);
}
/**
* Return a list of languages defined in description property
*
* @return list of languages defined for usageterms
*/
public List getUsageTermsLanguages()
{
return getUnqualifiedLanguagePropertyLanguagesValue(USAGETERMS);
}
/**
* Return a language value for description property
*
* @param lang
* concerned language
* @return value of specified language
*/
public String getUsageTerms(String lang)
{
return getUnqualifiedLanguagePropertyValue(USAGETERMS, lang);
}
/**
* Get the default usage terms for the document.
*
* @return The terms for this resource.
*/
public String getUsageTerms()
{
return getUsageTerms(null);
}
/**
* Return the WebStatement URL as TextType.
*
* @return Webstatement URL property
*/
public TextType getWebStatementProperty()
{
return ((TextType) getProperty(WEBSTATEMENT));
}
/**
* Return the WebStatement URL as String.
*
* @return webStatement URL value
*/
public String getWebStatement()
{
TextType tt = ((TextType) getProperty(WEBSTATEMENT));
return tt == null ? null : tt.getStringValue();
}
/**
* Set the WebStatement url
*
* @param url
* WebStatemen url value to set
*/
public void setWebStatement(String url)
{
URLType tt = (URLType) instanciateSimple(WEBSTATEMENT, url);
setWebStatementProperty(tt);
}
/**
* Set the WebStatement url
*
* @param url
* WebStatemen url property to set
*/
public void setWebStatementProperty(URLType url)
{
addProperty(url);
}
/**
* Return the Certificate URL as TextType.
*
* @return certificate url property
*/
public TextType getCertificateProperty()
{
return ((TextType) getProperty(CERTIFICATE));
}
/**
* Return the Certificate URL as String.
*
* @return certificate URL value
*/
public String getCertificate()
{
TextType tt = ((TextType) getProperty(CERTIFICATE));
return tt == null ? null : tt.getStringValue();
}
/**
* Convenience method for jempbox signature compatibility
*
* @see XMPRightsManagementSchema#getCertificate()
*/
@Deprecated
public String getCopyright()
{
return getCertificate();
}
/**
* Convenience method for jempbox signature compatibility
*
* @see XMPRightsManagementSchema#getCertificate()
*/
@Deprecated
public String getCertificateURL()
{
return getCertificate();
}
/**
* Set the Certificate URL.
*
* @param url
* certficate url value to set
*/
public void setCertificate(String url)
{
URLType tt = (URLType) instanciateSimple(CERTIFICATE, url);
setCertificateProperty(tt);
}
/**
* Convenience method for jempbox signature compatibility
*
* @see XMPRightsManagementSchema#setCertificate(String)
*/
@Deprecated
public void setCertificateURL(String certificate)
{
setCertificate(certificate);
}
/**
* Convenience method for jempbox signature compatibility
*
* @see XMPRightsManagementSchema#setCertificate(String)
*/
@Deprecated
public void setCopyright(String certificate)
{
setCertificate(certificate);
}
/**
* Set the Certificate URL.
*
* @param url
* certificate url property to set
*/
public void setCertificateProperty(URLType url)
{
addProperty(url);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java 0000644 0000000 0000000 00000127706 12645757426 025007 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import javax.xml.XMLConstants;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.XmpConstants;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.AbstractSimpleProperty;
import org.apache.xmpbox.type.AbstractStructuredType;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Attribute;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.type.BooleanType;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.ComplexPropertyContainer;
import org.apache.xmpbox.type.DateType;
import org.apache.xmpbox.type.IntegerType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.TypeMapping;
import org.apache.xmpbox.type.Types;
/**
* This class represents a metadata schema that can be stored in an XMP document. It handles all generic properties that
* are available. See subclasses for access to specific properties. MODIFIED TO INCLUDE OBJECT REPRESENTATION
*
*/
public class XMPSchema extends AbstractStructuredType
{
/**
* Create a new blank schema that can be populated.
*
* @param metadata
* The parent XMP metadata that this schema will be part of.
* @param namespaceURI
* The URI of the namespace, ie "http://ns.adobe.com/pdf/1.3/"
* @param prefix
* The prefix to be used
* @param name
* The name of the namespace, ie pdf,dc,...
*
*/
public XMPSchema(XMPMetadata metadata, String namespaceURI, String prefix, String name)
{
super(metadata, namespaceURI, prefix, name);
addNamespace(getNamespace(), getPrefix());
}
public XMPSchema(XMPMetadata metadata)
{
this(metadata, null, null, null);
}
public XMPSchema(XMPMetadata metadata, String prefix)
{
this(metadata, null, prefix, null);
}
public XMPSchema(XMPMetadata metadata, String namespaceURI, String prefix)
{
this(metadata, namespaceURI, prefix, null);
}
/**
* Retrieve a generic simple type property
*
* @param qualifiedName
* Full qualified name of proeprty wanted
* @return The generic simple type property according to its qualified Name
*/
public AbstractField getAbstractProperty(String qualifiedName)
{
Iterator it = getContainer().getAllProperties().iterator();
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
if (tmp.getPropertyName().equals(qualifiedName))
{
return tmp;
}
}
return null;
}
/**
* Get the RDF about attribute
*
* @return The RDF 'about' attribute.
*/
public Attribute getAboutAttribute()
{
return getAttribute(XmpConstants.ABOUT_NAME);
}
/**
* Get the RDF about value.
*
* @return The RDF 'about' value. If there are not rdf:about attribute, an empty string is returned.
*/
public String getAboutValue()
{
Attribute prop = getAttribute(XmpConstants.ABOUT_NAME);
if (prop != null)
{
return prop.getValue();
}
return ""; // PDFBOX-1685 : if missing rdf:about should be considered as empty string
}
/**
* Set the RDF 'about' attribute
*
* @param about
* the well-formed attribute
* @throws BadFieldValueException
* Bad Attribute name (not corresponding to about attribute)
*/
public void setAbout(Attribute about) throws BadFieldValueException
{
if (XmpConstants.RDF_NAMESPACE.equals(about.getNamespace()))
{
if (XmpConstants.ABOUT_NAME.equals(about.getName()))
{
setAttribute(about);
return;
}
}
// else
throw new BadFieldValueException("Attribute 'about' must be named 'rdf:about' or 'about'");
}
/**
* Set the RDF 'about' attribute. Passing in null will clear this attribute.
*
* @param about
* The new RFD about value.
*/
public void setAboutAsSimple(String about)
{
if (about == null)
{
removeAttribute(XmpConstants.ABOUT_NAME);
}
else
{
setAttribute(new Attribute(XmpConstants.RDF_NAMESPACE, XmpConstants.ABOUT_NAME, about));
}
}
private void setSpecifiedSimpleTypeProperty(Types type, String qualifiedName, Object propertyValue)
{
if (propertyValue == null)
{
// Search in properties to erase
Iterator it = getContainer().getAllProperties().iterator();
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
if (tmp.getPropertyName().equals(qualifiedName))
{
getContainer().removeProperty(tmp);
return;
}
}
}
else
{
AbstractSimpleProperty specifiedTypeProperty;
try
{
TypeMapping tm = getMetadata().getTypeMapping();
specifiedTypeProperty = tm.instanciateSimpleProperty(null, getPrefix(), qualifiedName, propertyValue,
type);
}
catch (Exception e)
{
throw new IllegalArgumentException(
"Failed to create property with the specified type given in parameters", e);
}
// attribute placement for simple property has been removed
// Search in properties to erase
Iterator it = getAllProperties().iterator();
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
if (tmp.getPropertyName().equals(qualifiedName))
{
removeProperty(tmp);
addProperty(specifiedTypeProperty);
return;
}
}
addProperty(specifiedTypeProperty);
}
}
/**
* Add a SimpleProperty to this schema
*
* @param prop
* The Property to add
*/
private void setSpecifiedSimpleTypeProperty(AbstractSimpleProperty prop)
{
// attribute placement for simple property has been removed
// Search in properties to erase
Iterator it = getAllProperties().iterator();
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
if (tmp.getPropertyName().equals(prop.getPropertyName()))
{
removeProperty(tmp);
addProperty(prop);
return;
}
}
addProperty(prop);
}
/**
* Set TextType property
*
* @param prop
* The text property to add
*/
public void setTextProperty(TextType prop)
{
setSpecifiedSimpleTypeProperty(prop);
}
/**
* Set a simple text property on the schema.
*
* @param qualifiedName
* The name of the property, it must contain the namespace prefix, ie "pdf:Keywords"
* @param propertyValue
* The value for the property, can be any string. Passing null will remove the property.
*/
public void setTextPropertyValue(String qualifiedName, String propertyValue)
{
setSpecifiedSimpleTypeProperty(Types.Text, qualifiedName, propertyValue);
}
/**
* Set a simple text property on the schema, using the current prefix.
*
* @param simpleName
* the name of the property without prefix
* @param propertyValue
* The value for the property, can be any string. Passing null will remove the property.
*/
public void setTextPropertyValueAsSimple(String simpleName, String propertyValue)
{
this.setTextPropertyValue(simpleName, propertyValue);
}
/**
* Get a TextProperty Type from its name
*
* @param name
* The full qualified name of the property wanted
* @return The Text Type property wanted
*/
public TextType getUnqualifiedTextProperty(String name)
{
String qualifiedName = name;
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof TextType)
{
return (TextType) prop;
}
else
{
throw new IllegalArgumentException("Property asked is not a Text Property");
}
}
return null;
}
/**
* Get the value of a simple text property.
*
* @param name
* The name of the property to get, it must include the namespace prefix. ie "pdf:Keywords".
*
* @return The value of the text property or the null if there is no value.
*
*/
public String getUnqualifiedTextPropertyValue(String name)
{
TextType tt = getUnqualifiedTextProperty(name);
return tt == null ? null : tt.getStringValue();
}
/**
* Get the Date property with its name
*
* @param qualifiedName
* The name of the property to get, it must include the namespace prefix. ie "pdf:Keywords".
* @return Date Type property
*
*/
public DateType getDateProperty(String qualifiedName)
{
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof DateType)
{
return (DateType) prop;
}
else
{
throw new IllegalArgumentException("Property asked is not a Date Property");
}
}
return null;
}
/**
* Get a simple date property value on the schema, using the current prefix.
*
* @param simpleName
* the local name of the property to get
* @return The value of the property as a calendar.
*
*/
public Calendar getDatePropertyValueAsSimple(String simpleName)
{
return this.getDatePropertyValue(simpleName);
}
/**
* Get the value of the property as a date.
*
* @param qualifiedName
* The fully qualified property name for the date.
*
* @return The value of the property as a date.
*
*/
public Calendar getDatePropertyValue(String qualifiedName)
{
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof DateType)
{
return ((DateType) prop).getValue();
}
else
{
throw new IllegalArgumentException("Property asked is not a Date Property");
}
}
return null;
}
/**
* Set a new DateProperty
*
* @param date
* The DateType Property
*/
public void setDateProperty(DateType date)
{
setSpecifiedSimpleTypeProperty(date);
}
/**
* Set a simple Date property on the schema, using the current prefix.
*
* @param simpleName
* the name of the property without prefix
* @param date
* The calendar value for the property, can be any string. Passing null will remove the property.
*/
public void setDatePropertyValueAsSimple(String simpleName, Calendar date)
{
this.setDatePropertyValue(simpleName, date);
}
/**
* Set the value of the property as a date.
*
* @param qualifiedName
* The fully qualified property name for the date.
* @param date
* The date to set, or null to clear.
*/
public void setDatePropertyValue(String qualifiedName, Calendar date)
{
setSpecifiedSimpleTypeProperty(Types.Date, qualifiedName, date);
}
/**
* Get a BooleanType property with its name
*
* @param qualifiedName
* the full qualified name of property wanted
* @return boolean Type property
*/
public BooleanType getBooleanProperty(String qualifiedName)
{
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof BooleanType)
{
return (BooleanType) prop;
}
else
{
throw new IllegalArgumentException("Property asked is not a Boolean Property");
}
}
return null;
}
/**
* Get a simple boolean property value on the schema, using the current prefix.
*
* @param simpleName
* the local name of property wanted
* @return The value of the property as a boolean.
*/
public Boolean getBooleanPropertyValueAsSimple(String simpleName)
{
return this.getBooleanPropertyValue(simpleName);
}
/**
* Get the value of the property as a boolean.
*
* @param qualifiedName
* The fully qualified property name for the boolean.
*
* @return The value of the property as a boolean. Return null if property not exist
*/
public Boolean getBooleanPropertyValue(String qualifiedName)
{
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof BooleanType)
{
return ((BooleanType) prop).getValue();
}
else
{
throw new IllegalArgumentException("Property asked is not a Boolean Property");
}
}
// Return null if property not exist. This method give the property
// value so treat this return in this way.
// If you want to use this value like a condition, you must check this
// return before
return null;
}
/**
* Set a BooleanType property
*
* @param bool
* the booleanType property
*/
public void setBooleanProperty(BooleanType bool)
{
setSpecifiedSimpleTypeProperty(bool);
}
/**
* Set a simple Boolean property on the schema, using the current prefix.
*
* @param simpleName
* the name of the property without prefix
* @param bool
* The value for the property, can be any string. Passing null will remove the property.
*/
public void setBooleanPropertyValueAsSimple(String simpleName, Boolean bool)
{
this.setBooleanPropertyValue(simpleName, bool);
}
/**
* Set the value of the property as a boolean.
*
* @param qualifiedName
* The fully qualified property name for the boolean.
* @param bool
* The boolean to set, or null to clear.
*/
public void setBooleanPropertyValue(String qualifiedName, Boolean bool)
{
setSpecifiedSimpleTypeProperty(Types.Boolean, qualifiedName, bool);
}
/**
* Get the Integer property with its name
*
* @param qualifiedName
* the full qualified name of property wanted
* @return Integer Type property
*/
public IntegerType getIntegerProperty(String qualifiedName)
{
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof IntegerType)
{
return ((IntegerType) prop);
}
else
{
throw new IllegalArgumentException("Property asked is not an Integer Property");
}
}
return null;
}
/**
* Get a simple integer property value on the schema, using the current prefix.
*
* @param simpleName
* the local name of property wanted
* @return The value of the property as an integer.
*/
public Integer getIntegerPropertyValueAsSimple(String simpleName)
{
return this.getIntegerPropertyValue(simpleName);
}
/**
* Get the value of the property as an integer.
*
* @param qualifiedName
* The fully qualified property name for the integer.
*
* @return The value of the property as an integer.
*/
public Integer getIntegerPropertyValue(String qualifiedName)
{
AbstractField prop = getAbstractProperty(qualifiedName);
if (prop != null)
{
if (prop instanceof IntegerType)
{
return ((IntegerType) prop).getValue();
}
else
{
throw new IllegalArgumentException("Property asked is not an Integer Property");
}
}
return null;
}
/**
* Add an integerProperty
*
* @param prop
* The Integer Type property
*/
public void setIntegerProperty(IntegerType prop)
{
setSpecifiedSimpleTypeProperty(prop);
}
/**
* Set a simple Integer property on the schema, using the current prefix.
*
* @param simpleName
* the name of the property without prefix
* @param intValue
* The value for the property, can be any string. Passing null will remove the property.
*/
public void setIntegerPropertyValueAsSimple(String simpleName, Integer intValue)
{
this.setIntegerPropertyValue(simpleName, intValue);
}
/**
* Set the value of the property as an integer.
*
* @param qualifiedName
* The fully qualified property name for the integer.
* @param intValue
* The int to set, or null to clear.
*/
public void setIntegerPropertyValue(String qualifiedName, Integer intValue)
{
setSpecifiedSimpleTypeProperty(Types.Integer, qualifiedName, intValue);
}
/**
* Generic array property removing
*
* @param qualifiedArrayName
* the full qualified name of property wanted
* @param fieldValue
* the field value
*/
private void removeUnqualifiedArrayValue(String arrayName, String fieldValue)
{
ArrayProperty array = (ArrayProperty) getAbstractProperty(arrayName);
if (array != null)
{
ArrayList toDelete = new ArrayList();
Iterator it = array.getContainer().getAllProperties().iterator();
AbstractSimpleProperty tmp;
while (it.hasNext())
{
tmp = (AbstractSimpleProperty) it.next();
if (tmp.getStringValue().equals(fieldValue))
{
toDelete.add(tmp);
}
}
Iterator eraseProperties = toDelete.iterator();
while (eraseProperties.hasNext())
{
array.getContainer().removeProperty(eraseProperties.next());
}
}
}
/**
* Remove all matching entries with the given value from the bag.
*
* @param bagName
* The name of the bag, it must include the namespace prefix. ie "pdf:Keywords".
* @param bagValue
* The value to remove from the bagList.
*/
public void removeUnqualifiedBagValue(String bagName, String bagValue)
{
removeUnqualifiedArrayValue(bagName, bagValue);
}
/**
* add a bag value property on the schema, using the current prefix.
*
* @param simpleName
* the local name of property
* @param bagValue
* the string value to add
*/
public void addBagValueAsSimple(String simpleName, String bagValue)
{
this.internalAddBagValue(simpleName, bagValue);
}
private void internalAddBagValue(String qualifiedBagName, String bagValue)
{
ArrayProperty bag = (ArrayProperty) getAbstractProperty(qualifiedBagName);
TextType li = createTextType(XmpConstants.LIST_NAME, bagValue);
if (bag != null)
{
bag.getContainer().addProperty(li);
}
else
{
ArrayProperty newBag = createArrayProperty(qualifiedBagName, Cardinality.Bag);
newBag.getContainer().addProperty(li);
addProperty(newBag);
}
}
/**
* Add an entry to a bag property.
*
* @param simpleName
* The name of the bag without the namespace prefix
* @param bagValue
* The value to add to the bagList.
*/
public void addQualifiedBagValue(String simpleName, String bagValue)
{
internalAddBagValue(simpleName, bagValue);
}
/**
* Get all the values of the bag property. This will return a list of java.lang.String objects, this is a read-only
* list.
*
* @param bagName
* The name of the bag property to get without namespace prefix.
*
* @return All values of the bag property in a list.
*/
public List getUnqualifiedBagValueList(String bagName)
{
ArrayProperty array = (ArrayProperty) getAbstractProperty(bagName);
if (array != null)
{
return array.getElementsAsString();
}
else
{
return null;
}
}
/**
* Remove all matching values from a sequence property.
*
* @param qualifiedSeqName
* The name of the sequence property. It must include the namespace prefix. ie "pdf:Keywords".
* @param seqValue
* The value to remove from the list.
*/
public void removeUnqualifiedSequenceValue(String qualifiedSeqName, String seqValue)
{
removeUnqualifiedArrayValue(qualifiedSeqName, seqValue);
}
/**
* Generic method to remove a field from an array with an Elementable Object
*
* @param arrayName
* the full qualified name of the property concerned
* @param fieldValue
* the elementable field value
*/
public void removeUnqualifiedArrayValue(String arrayName, AbstractField fieldValue)
{
String qualifiedArrayName = arrayName;
ArrayProperty array = (ArrayProperty) getAbstractProperty(qualifiedArrayName);
if (array != null)
{
ArrayList toDelete = new ArrayList();
Iterator it = array.getContainer().getAllProperties().iterator();
AbstractSimpleProperty tmp;
while (it.hasNext())
{
tmp = (AbstractSimpleProperty) it.next();
if (tmp.equals(fieldValue))
{
toDelete.add(tmp);
}
}
Iterator eraseProperties = toDelete.iterator();
while (eraseProperties.hasNext())
{
array.getContainer().removeProperty(eraseProperties.next());
}
}
}
/**
* Remove a value from a sequence property. This will remove all entries from the list.
*
* @param qualifiedSeqName
* The name of the sequence property. It must include the namespace prefix. ie "pdf:Keywords".
* @param seqValue
* The value to remove from the list.
*/
public void removeUnqualifiedSequenceValue(String qualifiedSeqName, AbstractField seqValue)
{
removeUnqualifiedArrayValue(qualifiedSeqName, seqValue);
}
/**
* Add a new value to a sequence property.
*
* @param simpleSeqName
* The name of the sequence property without the namespace prefix
* @param seqValue
* The value to add to the sequence.
*/
public void addUnqualifiedSequenceValue(String simpleSeqName, String seqValue)
{
String qualifiedSeqName = simpleSeqName;
ArrayProperty seq = (ArrayProperty) getAbstractProperty(qualifiedSeqName);
TextType li = createTextType(XmpConstants.LIST_NAME, seqValue);
if (seq != null)
{
seq.getContainer().addProperty(li);
}
else
{
ArrayProperty newSeq = createArrayProperty(simpleSeqName, Cardinality.Seq);
newSeq.getContainer().addProperty(li);
addProperty(newSeq);
}
}
/**
* Add a new value to a bag property.
*
* @param qualifiedSeqName
* The name of the sequence property, it must include the namespace prefix. ie "pdf:Keywords"
* @param seqValue
* The value to add to the bag.
*/
public void addBagValue(String qualifiedSeqName, AbstractField seqValue)
{
ArrayProperty bag = (ArrayProperty) getAbstractProperty(qualifiedSeqName);
if (bag != null)
{
bag.getContainer().addProperty(seqValue);
}
else
{
ArrayProperty newBag = createArrayProperty(qualifiedSeqName, Cardinality.Bag);
newBag.getContainer().addProperty(seqValue);
addProperty(newBag);
}
}
/**
* Add a new value to a sequence property.
*
* @param seqName
* The name of the sequence property, it must include the namespace prefix. ie "pdf:Keywords"
* @param seqValue
* The value to add to the sequence.
*/
public void addUnqualifiedSequenceValue(String seqName, AbstractField seqValue)
{
String qualifiedSeqName = seqName;
ArrayProperty seq = (ArrayProperty) getAbstractProperty(qualifiedSeqName);
if (seq != null)
{
seq.getContainer().addProperty(seqValue);
}
else
{
ArrayProperty newSeq = createArrayProperty(seqName, Cardinality.Seq);
newSeq.getContainer().addProperty(seqValue);
addProperty(newSeq);
}
}
/**
* Get all the values in a sequence property.
*
* @param seqName
* The name of the sequence property without namespace prefix.
*
* @return A read-only list of java.lang.String objects or null if the property does not exist.
*/
public List getUnqualifiedSequenceValueList(String seqName)
{
ArrayProperty array = (ArrayProperty) getAbstractProperty(seqName);
if (array != null)
{
return array.getElementsAsString();
}
else
{
return null;
}
}
/**
* Remove a date sequence value from the list.
*
* @param seqName
* The name of the sequence property, it must include the namespace prefix. ie "pdf:Keywords"
* @param date
* The date to remove from the sequence property.
*/
public void removeUnqualifiedSequenceDateValue(String seqName, Calendar date)
{
String qualifiedSeqName = seqName;
ArrayProperty seq = (ArrayProperty) getAbstractProperty(qualifiedSeqName);
if (seq != null)
{
ArrayList toDelete = new ArrayList();
Iterator it = seq.getContainer().getAllProperties().iterator();
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
if (tmp instanceof DateType)
{
if (((DateType) tmp).getValue().equals(date))
{
toDelete.add(tmp);
}
}
}
Iterator eraseProperties = toDelete.iterator();
while (eraseProperties.hasNext())
{
seq.getContainer().removeProperty(eraseProperties.next());
}
}
}
/**
* Add a date sequence value to the list using the current prefix
*
* @param simpleName
* the local name of the property
* @param date
* the value to add
*/
public void addSequenceDateValueAsSimple(String simpleName, Calendar date)
{
addUnqualifiedSequenceDateValue(simpleName, date);
}
/**
* Add a date sequence value to the list.
*
* @param seqName
* The name of the sequence property, it must include the namespace prefix. ie "pdf:Keywords"
* @param date
* The date to add to the sequence property.
*/
public void addUnqualifiedSequenceDateValue(String seqName, Calendar date)
{
addUnqualifiedSequenceValue(
seqName,
getMetadata().getTypeMapping().createDate(null, XmpConstants.DEFAULT_RDF_LOCAL_NAME,
XmpConstants.LIST_NAME, date));
}
/**
* Get all the date values in a sequence property.
*
* @param seqName
* The name of the sequence property, it must include the namespace prefix. ie "pdf:Keywords".
*
* @return A read-only list of java.util.Calendar objects or null if the property does not exist.
*
*/
public List getUnqualifiedSequenceDateValueList(String seqName)
{
String qualifiedSeqName = seqName;
List retval = null;
ArrayProperty seq = (ArrayProperty) getAbstractProperty(qualifiedSeqName);
if (seq != null)
{
retval = new ArrayList();
Iterator it = seq.getContainer().getAllProperties().iterator();
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
if (tmp instanceof DateType)
{
retval.add(((DateType) tmp).getValue());
}
}
}
return retval;
}
/**
* Method used to place the 'x-default' value in first in Language alternatives as said in xmp spec
*
* @param alt
* The property to reorganize
*/
public void reorganizeAltOrder(ComplexPropertyContainer alt)
{
Iterator it = alt.getAllProperties().iterator();
AbstractField xdefault = null;
boolean xdefaultFound = false;
// If alternatives contains x-default in first value
if (it.hasNext())
{
if (it.next().getAttribute(XmpConstants.LANG_NAME).getValue().equals(XmpConstants.X_DEFAULT))
{
return;
}
}
// Find the xdefault definition
while (it.hasNext() && !xdefaultFound)
{
xdefault = it.next();
if (xdefault.getAttribute(XmpConstants.LANG_NAME).getValue().equals(XmpConstants.X_DEFAULT))
{
alt.removeProperty(xdefault);
xdefaultFound = true;
}
}
if (xdefaultFound)
{
it = alt.getAllProperties().iterator();
ArrayList reordered = new ArrayList();
ArrayList toDelete = new ArrayList();
reordered.add(xdefault);
AbstractField tmp;
while (it.hasNext())
{
tmp = it.next();
reordered.add(tmp);
toDelete.add(tmp);
}
Iterator eraseProperties = toDelete.iterator();
while (eraseProperties.hasNext())
{
alt.removeProperty(eraseProperties.next());
}
it = reordered.iterator();
while (it.hasNext())
{
alt.addProperty(it.next());
}
}
}
/**
* Set the value of a multi-lingual property.
*
* @param name
* The name of the property, it must include the namespace prefix. ie "pdf:Keywords"
* @param language
* The language code of the value. If null then "x-default" is assumed.
* @param value
* The value of the property in the specified language.
*/
public void setUnqualifiedLanguagePropertyValue(String name, String language, String value)
{
String qualifiedName = name;
AbstractField property = getAbstractProperty(qualifiedName);
ArrayProperty prop;
if (property != null)
{
// Analyzing content of property
if (property instanceof ArrayProperty)
{
prop = (ArrayProperty) property;
Iterator itCplx = prop.getContainer().getAllProperties().iterator();
// try to find the same lang definition
AbstractField tmp;
// Try to find a definition
while (itCplx.hasNext())
{
tmp = itCplx.next();
// System.err.println(tmp.getAttribute("xml:lang").getStringValue());
if (tmp.getAttribute(XmpConstants.LANG_NAME).getValue().equals(language))
{
// the same language has been found
if (value == null)
{
// if value null, erase this definition
prop.getContainer().removeProperty(tmp);
}
else
{
prop.getContainer().removeProperty(tmp);
TextType langValue;
langValue = createTextType(XmpConstants.LIST_NAME, value);
langValue.setAttribute(new Attribute(XMLConstants.XML_NS_URI, XmpConstants.LANG_NAME,
language));
prop.getContainer().addProperty(langValue);
}
reorganizeAltOrder(prop.getContainer());
return;
}
}
// if no definition found, we add a new one
TextType langValue;
langValue = createTextType(XmpConstants.LIST_NAME, value);
langValue.setAttribute(new Attribute(XMLConstants.XML_NS_URI, XmpConstants.LANG_NAME, language));
prop.getContainer().addProperty(langValue);
reorganizeAltOrder(prop.getContainer());
}
}
else
{
prop = createArrayProperty(name, Cardinality.Alt);
TextType langValue;
langValue = createTextType(XmpConstants.LIST_NAME, value);
langValue.setAttribute(new Attribute(XMLConstants.XML_NS_URI, XmpConstants.LANG_NAME, language));
prop.getContainer().addProperty(langValue);
addProperty(prop);
}
}
/**
* Get the value of a multi-lingual property.
*
* @param name
* The name of the property, without the namespace prefix.
* @param expectedLanguage
* The language code of the value. If null then "x-default" is assumed.
*
* @return The value of the language property.
*/
public String getUnqualifiedLanguagePropertyValue(String name, String expectedLanguage)
{
String language = (expectedLanguage != null) ? expectedLanguage : XmpConstants.X_DEFAULT;
AbstractField property = getAbstractProperty(name);
if (property != null)
{
if (property instanceof ArrayProperty)
{
ArrayProperty prop = (ArrayProperty) property;
Iterator langsDef = prop.getContainer().getAllProperties().iterator();
AbstractField tmp;
Attribute text;
while (langsDef.hasNext())
{
tmp = langsDef.next();
text = tmp.getAttribute(XmpConstants.LANG_NAME);
if (text != null)
{
if (text.getValue().equals(language))
{
return ((TextType) tmp).getStringValue();
}
}
}
return null;
}
else
{
throw new IllegalArgumentException("The property '" + name + "' is not of Lang Alt type");
}
}
return null;
}
/**
* Get a list of all languages that are currently defined for a specific property.
*
* @param name
* The name of the property, it must include the namespace prefix. ie "pdf:Keywords"
*
* @return A list of all languages, this will return an non-null empty list if none have been defined.
*/
public List getUnqualifiedLanguagePropertyLanguagesValue(String name)
{
List retval = new ArrayList();
AbstractField property = getAbstractProperty(name);
if (property != null)
{
if (property instanceof ArrayProperty)
{
ArrayProperty prop = (ArrayProperty) property;
Iterator langsDef = prop.getContainer().getAllProperties().iterator();
AbstractField tmp;
Attribute text;
while (langsDef.hasNext())
{
tmp = langsDef.next();
text = tmp.getAttribute(XmpConstants.LANG_NAME);
if (text != null)
{
retval.add(text.getValue());
}
else
{
retval.add(XmpConstants.X_DEFAULT);
}
}
return retval;
}
else
{
throw new IllegalArgumentException("The property '" + name + "' is not of Lang Alt type");
}
}
// no property with that name
return null;
}
/**
* A basic schema merge, it merges bags and sequences and replace everything else.
*
* @param xmpSchema
* The schema to merge.
* @throws IOException
* If there is an error during the merge.
*/
public void merge(XMPSchema xmpSchema) throws IOException
{
if (!xmpSchema.getClass().equals(this.getClass()))
{
throw new IOException("Can only merge schemas of the same type.");
}
Iterator itAtt = xmpSchema.getAllAttributes().iterator();
Attribute att;
while (itAtt.hasNext())
{
att = itAtt.next();
if (att.getNamespace().equals(getNamespace()))
{
setAttribute(att);
}
}
String analyzedPropQualifiedName;
Iterator itProp = xmpSchema.getContainer().getAllProperties().iterator();
AbstractField prop;
while (itProp.hasNext())
{
prop = itProp.next();
if (prop.getPrefix().equals(getPrefix()))
{
if (prop instanceof ArrayProperty)
{
analyzedPropQualifiedName = prop.getPropertyName();
Iterator itActualEmbeddedProperties = getAllProperties().iterator();
AbstractField tmpEmbeddedProperty;
Iterator itNewValues;
TextType tmpNewValue;
Iterator itOldValues;
TextType tmpOldValue;
boolean alreadyPresent = false;
while (itActualEmbeddedProperties.hasNext())
{
tmpEmbeddedProperty = itActualEmbeddedProperties.next();
if (tmpEmbeddedProperty instanceof ArrayProperty)
{
if (tmpEmbeddedProperty.getPropertyName().equals(analyzedPropQualifiedName))
{
itNewValues = ((ArrayProperty) prop).getContainer().getAllProperties().iterator();
// Merge a complex property
while (itNewValues.hasNext())
{
tmpNewValue = (TextType) itNewValues.next();
itOldValues = ((ArrayProperty) tmpEmbeddedProperty).getContainer()
.getAllProperties().iterator();
while (itOldValues.hasNext() && !alreadyPresent)
{
tmpOldValue = (TextType) itOldValues.next();
if (tmpOldValue.getStringValue().equals(tmpNewValue.getStringValue()))
{
alreadyPresent = true;
}
}
if (!alreadyPresent)
{
((ArrayProperty) tmpEmbeddedProperty).getContainer().addProperty(tmpNewValue);
}
}
}
}
}
}
else
{
addProperty(prop);
}
}
}
}
/**
* Get an AbstractField list corresponding to the content of an array Return null if the property is unknown
*
* @param name
* the property name whitout namespace;
* @return List of property contained in the complex property
* @throws BadFieldValueException
* Property not contains property (not complex property)
*/
public List getUnqualifiedArrayList(String name) throws BadFieldValueException
{
ArrayProperty array = null;
Iterator itProp = getAllProperties().iterator();
AbstractField tmp;
while (itProp.hasNext())
{
tmp = itProp.next();
if (tmp.getPropertyName().equals(name))
{
if (tmp instanceof ArrayProperty)
{
array = (ArrayProperty) tmp;
break;
}
else
{
throw new BadFieldValueException("Property asked not seems to be an array");
}
}
}
if (array != null)
{
Iterator it = array.getContainer().getAllProperties().iterator();
List list = new ArrayList();
while (it.hasNext())
{
list.add(it.next());
}
return list;
}
return null;
}
protected AbstractSimpleProperty instanciateSimple(String param, Object value)
{
TypeMapping tm = getMetadata().getTypeMapping();
return tm.instanciateSimpleField(getClass(), null, getPrefix(), param, value);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/DublinCoreSchema.java 0000644 0000000 0000000 00000046576 12645757426 026376 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.util.Calendar;
import java.util.List;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.MIMEType;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.Types;
/**
* Representation of a DublinCore Schema
*
* @author a183132
*
*/
@StructuredType(preferedPrefix = "dc", namespace = "http://purl.org/dc/elements/1.1/")
public class DublinCoreSchema extends XMPSchema
{
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String CONTRIBUTOR = "contributor";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String COVERAGE = "coverage";
@PropertyType(type = Types.Text, card = Cardinality.Seq)
public static final String CREATOR = "creator";
@PropertyType(type = Types.Date, card = Cardinality.Seq)
public static final String DATE = "date";
@PropertyType(type = Types.LangAlt, card = Cardinality.Simple)
public static final String DESCRIPTION = "description";
@PropertyType(type = Types.MIMEType, card = Cardinality.Simple)
public static final String FORMAT = "format";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String IDENTIFIER = "identifier";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String LANGUAGE = "language";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String PUBLISHER = "publisher";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String RELATION = "relation";
@PropertyType(type = Types.LangAlt, card = Cardinality.Simple)
public static final String RIGHTS = "rights";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String SOURCE = "source";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String SUBJECT = "subject";
@PropertyType(type = Types.LangAlt, card = Cardinality.Simple)
public static final String TITLE = "title";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String TYPE = "type";
/**
* Constructor of a Dublin Core schema with preferred prefix
*
* @param metadata
* The metadata to attach this schema
*/
public DublinCoreSchema(XMPMetadata metadata)
{
super(metadata);
}
/**
* Constructor of a Dublin Core schema with specified prefix
*
* @param metadata
* The metadata to attach this schema
* @param ownPrefix
* The prefix to assign
*/
public DublinCoreSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
/**
* set contributor(s) to the resource (other than the authors)
*
* @param properName
* Value to set
*/
public void addContributor(String properName)
{
addQualifiedBagValue(CONTRIBUTOR, properName);
}
public void removeContributor(String properName)
{
removeUnqualifiedBagValue(CONTRIBUTOR, properName);
}
/**
* set the extent or scope of the resource
*
* @param text
* Value to set
*/
public void setCoverage(String text)
{
addProperty(createTextType(COVERAGE, text));
}
/**
* set the extent or scope of the resource
*
* @param text
* Property to set
*/
public void setCoverageProperty(TextType text)
{
addProperty(text);
}
/**
* set the autor(s) of the resource
*
* @param properName
* Value to add
* @throws InappropriateTypeException
*/
public void addCreator(String properName)
{
addUnqualifiedSequenceValue(CREATOR, properName);
}
public void removeCreator(String name)
{
removeUnqualifiedSequenceValue(CREATOR, name);
}
/**
* Set date(s) that something interesting happened to the resource
*
* @param date
* Value to add
*/
public void addDate(Calendar date)
{
addUnqualifiedSequenceDateValue(DATE, date);
}
public void removeDate(Calendar date)
{
removeUnqualifiedSequenceDateValue(DATE, date);
}
/**
* add a textual description of the content of the resource (multiple values may be present for different languages)
*
* @param lang
* language concerned
* @param value
* Value to add
*/
public void addDescription(String lang, String value)
{
setUnqualifiedLanguagePropertyValue(DESCRIPTION, lang, value);
}
/**
* Set the default value for the description.
*
* @param value
* The description of this resource.
*/
public void setDescription(String value)
{
addDescription(null, value);
}
/**
* Convenience method for signature compatibility with jempbox
*
* @see DublinCoreSchema#addDescription(String, String)
*/
@Deprecated
public void setDescription(String language, String description)
{
addDescription(language, description);
}
/**
* set the file format used when saving the resource.
*
* @param mimeType
* Value to set
*/
public void setFormat(String mimeType)
{
addProperty(createTextType(FORMAT, mimeType));
}
/**
* Set the unique identifier of the resource
*
* @param text
* Value to set
*/
public void setIdentifier(String text)
{
addProperty(createTextType(IDENTIFIER, text));
}
/**
* Set the unique identifier of the resource
*
* @param text
* Property to set
*/
public void setIdentifierProperty(TextType text)
{
addProperty(text);
}
/**
* Add language(s) used in this resource
*
* @param locale
* Value to set
*/
public void addLanguage(String locale)
{
addQualifiedBagValue(LANGUAGE, locale);
}
public void removeLanguage(String locale)
{
removeUnqualifiedBagValue(LANGUAGE, locale);
}
/**
* add publisher(s)
*
* @param properName
* Value to add
*/
public void addPublisher(String properName)
{
addQualifiedBagValue(PUBLISHER, properName);
}
public void removePublisher(String name)
{
removeUnqualifiedBagValue(PUBLISHER, name);
}
/**
* Add relationships to other documents
*
* @param text
* Value to set
*/
public void addRelation(String text)
{
addQualifiedBagValue(RELATION, text);
}
public void removeRelation(String text)
{
removeUnqualifiedBagValue(RELATION, text);
}
/**
* add informal rights statement, by language.
*
* @param lang
* Language concerned
* @param value
* Value to set
*/
public void addRights(String lang, String value)
{
setUnqualifiedLanguagePropertyValue(RIGHTS, lang, value);
}
/**
* Convenience method for signature compatibility with jempbox
*
* @see DublinCoreSchema#addRights(String, String)
*/
@Deprecated
public void setRights(String language, String rights)
{
addRights(language, rights);
}
/**
* Convenience method for signature compatibility with jempbox. Add default rights
*
* @see DublinCoreSchema#addRights(String, String)
*/
@Deprecated
public void setRights(String rights)
{
addRights(null, rights);
}
/**
* Set the unique identifer of the work from which this resource was derived
*
* @param text
* Value to set
*/
public void setSource(String text)
{
addProperty(createTextType(SOURCE, text));
}
/**
* Set the unique identifer of the work from which this resource was derived
*
* @param text
* Property to set
*/
public void setSourceProperty(TextType text)
{
addProperty(text);
}
/**
* Set the unique identifer of the work from which this resource was derived
*
* @param text
* Property to set
*/
public void setFormatProperty(MIMEType text)
{
addProperty(text);
}
/**
* add descriptive phrases or keywords that specify the topic of the content of the resource
*
* @param text
* Value to add
*/
public void addSubject(String text)
{
addQualifiedBagValue(SUBJECT, text);
}
public void removeSubject(String text)
{
removeUnqualifiedBagValue(SUBJECT, text);
}
/**
* set the title of the document, or the name given to the resource (by language)
*
* @param lang
* Language concerned
* @param value
* Value to set
*/
public void setTitle(String lang, String value)
{
setUnqualifiedLanguagePropertyValue(TITLE, lang, value);
}
/**
* set default title
*
* @param value
* Value to set
*/
public void setTitle(String value)
{
setTitle(null, value);
}
/**
* set the title of the document, or the name given to the resource (by language)
*
* @see DublinCoreSchema#setTitle(String)
*
*/
public void addTitle(String lang, String value)
{
setTitle(lang, value);
}
/**
* set the document type (novel, poem, ...)
*
* @param type
* Value to set
*/
public void addType(String type)
{
addQualifiedBagValue(TYPE, type);
}
/**
* Return the Bag of contributor(s)
*
* @return Contributor property
*/
public ArrayProperty getContributorsProperty()
{
return (ArrayProperty) getProperty(CONTRIBUTOR);
}
/**
* Return a String list of contributor(s)
*
* @return List of contributors values
*/
public List getContributors()
{
return getUnqualifiedBagValueList(CONTRIBUTOR);
}
/**
* Return the Coverage TextType Property
*
* @return Coverage property
*/
public TextType getCoverageProperty()
{
return (TextType) getProperty(COVERAGE);
}
/**
* Return the value of the coverage
*
* @return Coverage value
*/
public String getCoverage()
{
TextType tt = (TextType) getProperty(COVERAGE);
return tt == null ? null : tt.getStringValue();
}
/**
* Return the Sequence of contributor(s)
*
* @return Creator property
*/
public ArrayProperty getCreatorsProperty()
{
return (ArrayProperty) getProperty(CREATOR);
}
/**
* Return the creator(s) string value
*
* @return List of creators values
*/
public List getCreators()
{
return getUnqualifiedSequenceValueList(CREATOR);
}
/**
* Return the sequence of date(s)
*
* @return date property
*/
public ArrayProperty getDatesProperty()
{
return (ArrayProperty) getProperty(DATE);
}
/**
* Return a calendar list of date
*
* @return List of dates values
*/
public List getDates()
{
return getUnqualifiedSequenceDateValueList(DATE);
}
/**
* Return the Lang alt Description
*
* @return Description property
*/
public ArrayProperty getDescriptionProperty()
{
return (ArrayProperty) getProperty(DESCRIPTION);
}
/**
* Return a list of languages defined in description property
*
* @return get List of languages defined for description property
*/
public List getDescriptionLanguages()
{
return getUnqualifiedLanguagePropertyLanguagesValue(DESCRIPTION);
}
/**
* Return a language value for description property
*
* @param lang
* The language wanted
* @return Desription value for specified language
*/
public String getDescription(String lang)
{
return getUnqualifiedLanguagePropertyValue(DESCRIPTION, lang);
}
/**
* Get the default value for the description.
*
* @return The description of this resource.
*/
public String getDescription()
{
return getDescription(null);
}
/**
* Return the file format property
*
* @return the format property
*/
public TextType getFormatProperty()
{
return (TextType) getProperty(FORMAT);
}
/**
* return the file format value
*
* @return the format value
*/
public String getFormat()
{
TextType tt = (TextType) getProperty(FORMAT);
return tt == null ? null : tt.getStringValue();
}
/**
* Return the unique identifier property of this resource
*
* @return the identifier property
*/
public TextType getIdentifierProperty()
{
return (TextType) getProperty(IDENTIFIER);
}
/**
* return the unique identifier value of this resource
*
* @return the unique identifier value
*/
public String getIdentifier()
{
TextType tt = (TextType) getProperty(IDENTIFIER);
return tt == null ? null : tt.getStringValue();
}
/**
* Return the bag DC language
*
* @return language property
*/
public ArrayProperty getLanguagesProperty()
{
return (ArrayProperty) getProperty(LANGUAGE);
}
/**
* Return the list of values defined in the DC language
*
* @return list of languages defined for language property
*/
public List getLanguages()
{
return getUnqualifiedBagValueList(LANGUAGE);
}
/**
* Return the bag DC publisher
*
* @return publisher property
*/
public ArrayProperty getPublishersProperty()
{
return (ArrayProperty) getProperty(PUBLISHER);
}
/**
* Return the list of values defined in the DC publisher
*
* @return list of values for publisher property
*/
public List getPublishers()
{
return getUnqualifiedBagValueList(PUBLISHER);
}
/**
* Return the bag DC relation
*
* @return relation property
*/
public ArrayProperty getRelationsProperty()
{
return (ArrayProperty) getProperty(RELATION);
}
/**
* Return the list of values defined in the DC relation
*
* @return list of values for relation property
*/
public List getRelations()
{
return getUnqualifiedBagValueList(RELATION);
}
/**
* Convenience method for signature compatibility with jempbox
*
* @see DublinCoreSchema#getRelations()
*/
@Deprecated
public List getRelationships()
{
return getRelations();
}
/**
* Return the Lang alt Rights
*
* @return rights property
*/
public ArrayProperty getRightsProperty()
{
return (ArrayProperty) getProperty(RIGHTS);
}
/**
* Return a list of languages defined in Right property
*
* @return list of rights languages values defined
*/
public List getRightsLanguages()
{
return getUnqualifiedLanguagePropertyLanguagesValue(RIGHTS);
}
/**
* Return a language value for Right property
*
* @param lang
* language concerned
* @return the rights value for specified language
*/
public String getRights(String lang)
{
return getUnqualifiedLanguagePropertyValue(RIGHTS, lang);
}
/**
* Return the default value for Right property
*
* @see DublinCoreSchema#getRights(String)
*/
public String getRights()
{
return getRights(null);
}
/**
* Return the source property of this resource
*
* @return source property
*/
public TextType getSourceProperty()
{
return (TextType) getProperty(SOURCE);
}
/**
* return the source value of this resource
*
* @return value of source property
*/
public String getSource()
{
TextType tt = (TextType) getProperty(SOURCE);
return tt == null ? null : tt.getStringValue();
}
/**
* Return the bag DC Subject
*
* @return the subject property
*/
public ArrayProperty getSubjectsProperty()
{
return (ArrayProperty) getProperty(SUBJECT);
}
/**
* Return the list of values defined in the DC Subject
*
* @return the list of subject values
*/
public List getSubjects()
{
return getUnqualifiedBagValueList(SUBJECT);
}
/**
* Return the Lang alt Title
*
* @return the title property
*/
public ArrayProperty getTitleProperty()
{
return (ArrayProperty) getProperty(TITLE);
}
/**
* Return a list of languages defined in Title property
*
* @return list of languages defined for title property
*/
public List getTitleLanguages()
{
return getUnqualifiedLanguagePropertyLanguagesValue(TITLE);
}
/**
* Return a language value for Title property
*
* @param lang
* the language concerned
* @return the title value for specified language
*/
public String getTitle(String lang)
{
return getUnqualifiedLanguagePropertyValue(TITLE, lang);
}
/**
* Get the default value for the title.
*
* @return The default title of this resource.
*/
public String getTitle()
{
return getTitle(null);
}
/**
* Return the bag DC Type
*
* @return the type property
*/
public ArrayProperty getTypesProperty()
{
return (ArrayProperty) getProperty(TYPE);
}
/**
* Return the list of values defined in the DC Type
*
* @return the value of type property
*/
public List getTypes()
{
return getUnqualifiedBagValueList(TYPE);
}
public void removeType(String type)
{
removeUnqualifiedBagValue(TYPE, type);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/AdobePDFSchema.java 0000644 0000000 0000000 00000013326 12645757426 025677 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.Types;
/**
* Representation of Adobe PDF Schema
*
* @author a183132
*
*/
@StructuredType(preferedPrefix = "pdf", namespace = "http://ns.adobe.com/pdf/1.3/")
public class AdobePDFSchema extends XMPSchema
{
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String KEYWORDS = "Keywords";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String PDF_VERSION = "PDFVersion";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String PRODUCER = "Producer";
/**
* Constructor of an Adobe PDF schema with preferred prefix
*
* @param metadata
* The metadata to attach this schema
*/
public AdobePDFSchema(XMPMetadata metadata)
{
super(metadata);
}
/**
* Constructor of an Adobe PDF schema with specified prefix
*
* @param metadata
* The metadata to attach this schema
* @param ownPrefix
* The prefix to assign
*/
public AdobePDFSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
/**
* Set the PDF keywords
*
* @param value
* Value to set
*/
public void setKeywords(String value)
{
TextType keywords;
keywords = createTextType(KEYWORDS, value);
addProperty(keywords);
}
/**
* Set the PDF keywords
*
* @param keywords
* Property to set
*/
public void setKeywordsProperty(TextType keywords)
{
addProperty(keywords);
}
/**
* Set the PDFVersion
*
* @param value
* Value to set
*/
public void setPDFVersion(String value)
{
TextType version;
version = createTextType(PDF_VERSION, value);
addProperty(version);
}
/**
* Set the PDFVersion
*
* @param version
* Property to set
*/
public void setPDFVersionProperty(TextType version)
{
addProperty(version);
}
/**
* Set the PDFProducer
*
* @param value
* Value to set
*/
public void setProducer(String value)
{
TextType producer;
producer = createTextType(PRODUCER, value);
addProperty(producer);
}
/**
* Set the PDFProducer
*
* @param producer
* Property to set
*/
public void setProducerProperty(TextType producer)
{
addProperty(producer);
}
/**
* Give the PDF Keywords property
*
* @return The property object
*/
public TextType getKeywordsProperty()
{
AbstractField tmp = getProperty(KEYWORDS);
if (tmp instanceof TextType)
{
return (TextType) tmp;
}
return null;
}
/**
* Give the PDF Keywords property value (string)
*
* @return The property value
*/
public String getKeywords()
{
AbstractField tmp = getProperty(KEYWORDS);
if (tmp instanceof TextType)
{
return ((TextType) tmp).getStringValue();
}
return null;
}
/**
* Give the PDFVersion property
*
* @return The property object
*/
public TextType getPDFVersionProperty()
{
AbstractField tmp = getProperty(PDF_VERSION);
if (tmp instanceof TextType)
{
return (TextType) tmp;
}
return null;
}
/**
* Give the PDFVersion property value (string)
*
* @return The property value
*/
public String getPDFVersion()
{
AbstractField tmp = getProperty(PDF_VERSION);
if (tmp instanceof TextType)
{
return ((TextType) tmp).getStringValue();
}
return null;
}
/**
* Give the producer property
*
* @return The property object
*/
public TextType getProducerProperty()
{
AbstractField tmp = getProperty(PRODUCER);
if (tmp instanceof TextType)
{
return (TextType) tmp;
}
return null;
}
/**
* Give the producer property value (string)
*
* @return The property value
*/
public String getProducer()
{
AbstractField tmp = getProperty(PRODUCER);
if (tmp instanceof TextType)
{
return ((TextType) tmp).getStringValue();
}
return null;
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/PhotoshopSchema.java 0000644 0000000 0000000 00000037460 12645757426 026323 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.util.ArrayList;
import java.util.List;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.DateType;
import org.apache.xmpbox.type.IntegerType;
import org.apache.xmpbox.type.LayerType;
import org.apache.xmpbox.type.ProperNameType;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.Types;
import org.apache.xmpbox.type.URIType;
@StructuredType(preferedPrefix = "photoshop", namespace = "http://ns.adobe.com/photoshop/1.0/")
public class PhotoshopSchema extends XMPSchema
{
public PhotoshopSchema(XMPMetadata metadata)
{
super(metadata);
}
public PhotoshopSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
public static final String PREFERED_PREFIX = "photoshop";
public static final String PHOTOSHOPURI = "http://ns.adobe.com/photoshop/1.0/";
@PropertyType(type = Types.URI, card = Cardinality.Simple)
public static final String ANCESTORID = "AncestorID";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String AUTHORS_POSITION = "AuthorsPosition";
@PropertyType(type = Types.ProperName, card = Cardinality.Simple)
public static final String CAPTION_WRITER = "CaptionWriter";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String CATEGORY = "Category";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String CITY = "City";
@PropertyType(type = Types.Integer, card = Cardinality.Simple)
public static final String COLOR_MODE = "ColorMode";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String COUNTRY = "Country";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String CREDIT = "Credit";
@PropertyType(type = Types.Date, card = Cardinality.Simple)
public static final String DATE_CREATED = "DateCreated";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String DOCUMENT_ANCESTORS = "DocumentAncestors";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String HEADLINE = "Headline";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String HISTORY = "History";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String ICC_PROFILE = "ICCProfile";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String INSTRUCTIONS = "Instructions";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String SOURCE = "Source";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String STATE = "State";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String SUPPLEMENTAL_CATEGORIES = "SupplementalCategories";
@PropertyType(type = Types.Layer, card = Cardinality.Seq)
public static final String TEXT_LAYERS = "TextLayers";
private ArrayProperty seqLayer;
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String TRANSMISSION_REFERENCE = "TransmissionReference";
@PropertyType(type = Types.Integer, card = Cardinality.Simple)
public static final String URGENCY = "Urgency";
public URIType getAncestorIDProperty()
{
return (URIType) getProperty(ANCESTORID);
}
public String getAncestorID()
{
TextType tt = ((TextType) getProperty(ANCESTORID));
return tt == null ? null : tt.getStringValue();
}
public void setAncestorID(String text)
{
URIType tt = (URIType) instanciateSimple(ANCESTORID, text);
setAncestorIDProperty(tt);
}
public void setAncestorIDProperty(URIType text)
{
addProperty(text);
}
public TextType getAuthorsPositionProperty()
{
return (TextType) getProperty(AUTHORS_POSITION);
}
public String getAuthorsPosition()
{
TextType tt = ((TextType) getProperty(AUTHORS_POSITION));
return tt == null ? null : tt.getStringValue();
}
public void setAuthorsPosition(String text)
{
TextType tt = (TextType) instanciateSimple(AUTHORS_POSITION, text);
setAuthorsPositionProperty(tt);
}
public void setAuthorsPositionProperty(TextType text)
{
addProperty(text);
}
public TextType getCaptionWriterProperty()
{
return (TextType) getProperty(CAPTION_WRITER);
}
public String getCaptionWriter()
{
TextType tt = ((TextType) getProperty(CAPTION_WRITER));
return tt == null ? null : tt.getStringValue();
}
public void setCaptionWriter(String text)
{
ProperNameType tt = (ProperNameType) instanciateSimple(CAPTION_WRITER, text);
setCaptionWriterProperty(tt);
}
public void setCaptionWriterProperty(ProperNameType text)
{
addProperty(text);
}
public TextType getCategoryProperty()
{
return (TextType) getProperty(CATEGORY);
}
public String getCategory()
{
TextType tt = ((TextType) getProperty(CATEGORY));
return tt == null ? null : tt.getStringValue();
}
public void setCategory(String text)
{
TextType tt = (TextType) instanciateSimple(CATEGORY, text);
setCategoryProperty(tt);
}
public void setCategoryProperty(TextType text)
{
addProperty(text);
}
public TextType getCityProperty()
{
return (TextType) getProperty(CITY);
}
public String getCity()
{
TextType tt = ((TextType) getProperty(CITY));
return tt == null ? null : tt.getStringValue();
}
public void setCity(String text)
{
TextType tt = (TextType) instanciateSimple(CITY, text);
setCityProperty(tt);
}
public void setCityProperty(TextType text)
{
addProperty(text);
}
public IntegerType getColorModeProperty()
{
return (IntegerType) getProperty(COLOR_MODE);
}
public Integer getColorMode()
{
IntegerType tt = ((IntegerType) getProperty(COLOR_MODE));
return tt == null ? null : tt.getValue();
}
public void setColorMode(String text)
{
IntegerType tt = (IntegerType) instanciateSimple(COLOR_MODE, text);
setColorModeProperty(tt);
}
public void setColorModeProperty(IntegerType text)
{
addProperty(text);
}
public TextType getCountryProperty()
{
return (TextType) getProperty(COUNTRY);
}
public String getCountry()
{
TextType tt = ((TextType) getProperty(COUNTRY));
return tt == null ? null : tt.getStringValue();
}
public void setCountry(String text)
{
TextType tt = (TextType) instanciateSimple(COUNTRY, text);
setCountryProperty(tt);
}
public void setCountryProperty(TextType text)
{
addProperty(text);
}
public TextType getCreditProperty()
{
return (TextType) getProperty(CREDIT);
}
public String getCredit()
{
TextType tt = ((TextType) getProperty(CREDIT));
return tt == null ? null : tt.getStringValue();
}
public void setCredit(String text)
{
TextType tt = (TextType) instanciateSimple(CREDIT, text);
setCreditProperty(tt);
}
public void setCreditProperty(TextType text)
{
addProperty(text);
}
public DateType getDateCreatedProperty()
{
return (DateType) getProperty(DATE_CREATED);
}
public String getDateCreated()
{
TextType tt = ((TextType) getProperty(DATE_CREATED));
return tt == null ? null : tt.getStringValue();
}
public void setDateCreated(String text)
{
DateType tt = (DateType) instanciateSimple(DATE_CREATED, text);
setDateCreatedProperty(tt);
}
public void setDateCreatedProperty(DateType text)
{
addProperty(text);
}
public void addDocumentAncestors(String text)
{
addQualifiedBagValue(DOCUMENT_ANCESTORS, text);
}
public ArrayProperty getDocumentAncestorsProperty()
{
return (ArrayProperty) getProperty(DOCUMENT_ANCESTORS);
}
public List getDocumentAncestors()
{
return getUnqualifiedBagValueList(DOCUMENT_ANCESTORS);
}
public TextType getHeadlineProperty()
{
return (TextType) getProperty(HEADLINE);
}
public String getHeadline()
{
TextType tt = ((TextType) getProperty(HEADLINE));
return tt == null ? null : tt.getStringValue();
}
public void setHeadline(String text)
{
TextType tt = (TextType) instanciateSimple(HEADLINE, text);
setHeadlineProperty(tt);
}
public void setHeadlineProperty(TextType text)
{
addProperty(text);
}
public TextType getHistoryProperty()
{
return (TextType) getProperty(HISTORY);
}
public String getHistory()
{
TextType tt = ((TextType) getProperty(HISTORY));
return tt == null ? null : tt.getStringValue();
}
public void setHistory(String text)
{
TextType tt = (TextType) instanciateSimple(HISTORY, text);
setHistoryProperty(tt);
}
public void setHistoryProperty(TextType text)
{
addProperty(text);
}
public TextType getICCProfileProperty()
{
return (TextType) getProperty(ICC_PROFILE);
}
public String getICCProfile()
{
TextType tt = ((TextType) getProperty(ICC_PROFILE));
return tt == null ? null : tt.getStringValue();
}
public void setICCProfile(String text)
{
TextType tt = (TextType) instanciateSimple(ICC_PROFILE, text);
setICCProfileProperty(tt);
}
public void setICCProfileProperty(TextType text)
{
addProperty(text);
}
public TextType getInstructionsProperty()
{
return (TextType) getProperty(INSTRUCTIONS);
}
public String getInstructions()
{
TextType tt = ((TextType) getProperty(INSTRUCTIONS));
return tt == null ? null : tt.getStringValue();
}
public void setInstructions(String text)
{
TextType tt = (TextType) instanciateSimple(INSTRUCTIONS, text);
setInstructionsProperty(tt);
}
public void setInstructionsProperty(TextType text)
{
addProperty(text);
}
public TextType getSourceProperty()
{
return (TextType) getProperty(SOURCE);
}
public String getSource()
{
TextType tt = ((TextType) getProperty(SOURCE));
return tt == null ? null : tt.getStringValue();
}
public void setSource(String text)
{
TextType source = (TextType) instanciateSimple(SOURCE, text);
setSourceProperty(source);
}
public void setSourceProperty(TextType text)
{
addProperty(text);
}
public TextType getStateProperty()
{
return (TextType) getProperty(STATE);
}
public String getState()
{
TextType tt = ((TextType) getProperty(STATE));
return tt == null ? null : tt.getStringValue();
}
public void setState(String text)
{
TextType tt = (TextType) instanciateSimple(STATE, text);
setStateProperty(tt);
}
public void setStateProperty(TextType text)
{
addProperty(text);
}
public void addSupplementalCategories(String text)
{
addQualifiedBagValue(SUPPLEMENTAL_CATEGORIES, text);
}
public void removeSupplementalCategories(String text)
{
removeUnqualifiedBagValue(SUPPLEMENTAL_CATEGORIES, text);
}
/**
* Add a new supplemental category.
*
* @param s
* The supplemental category.
*/
public void addSupplementalCategory(String s)
{
addSupplementalCategories(s);
}
public void removeSupplementalCategory(String text)
{
removeSupplementalCategories(text);
}
public ArrayProperty getSupplementalCategoriesProperty()
{
return (ArrayProperty) getProperty(SUPPLEMENTAL_CATEGORIES);
}
public List getSupplementalCategories()
{
return getUnqualifiedBagValueList(SUPPLEMENTAL_CATEGORIES);
}
public void addTextLayers(String layerName, String layerText)
{
if (seqLayer == null)
{
seqLayer = createArrayProperty(TEXT_LAYERS, Cardinality.Seq);
addProperty(seqLayer);
}
LayerType layer = new LayerType(getMetadata());
layer.setLayerName(layerName);
layer.setLayerText(layerText);
seqLayer.getContainer().addProperty(layer);
}
public List getTextLayers() throws BadFieldValueException
{
List tmp = getUnqualifiedArrayList(TEXT_LAYERS);
if (tmp != null)
{
List layers = new ArrayList();
for (AbstractField abstractField : tmp)
{
if (abstractField instanceof LayerType)
{
layers.add((LayerType) abstractField);
}
else
{
throw new BadFieldValueException("Layer expected and " + abstractField.getClass().getName()
+ " found.");
}
}
return layers;
}
return null;
}
public TextType getTransmissionReferenceProperty()
{
return (TextType) getProperty(TRANSMISSION_REFERENCE);
}
public String getTransmissionReference()
{
TextType tt = ((TextType) getProperty(TRANSMISSION_REFERENCE));
return tt == null ? null : tt.getStringValue();
}
public void setTransmissionReference(String text)
{
TextType tt = (TextType) instanciateSimple(TRANSMISSION_REFERENCE, text);
setTransmissionReferenceProperty(tt);
}
public void setTransmissionReferenceProperty(TextType text)
{
addProperty(text);
}
public IntegerType getUrgencyProperty()
{
return (IntegerType) getProperty(URGENCY);
}
public Integer getUrgency()
{
IntegerType tt = ((IntegerType) getProperty(URGENCY));
return tt == null ? null : tt.getValue();
}
public void setUrgency(String s)
{
IntegerType tt = (IntegerType) instanciateSimple(URGENCY, s);
setUrgencyProperty(tt);
}
public void setUrgency(Integer s)
{
IntegerType tt = (IntegerType) instanciateSimple(URGENCY, s);
setUrgencyProperty(tt);
}
public void setUrgencyProperty(IntegerType text)
{
addProperty(text);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XmpSchemaException.java 0000644 0000000 0000000 00000003445 12645757426 026757 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
/**
* Exception thrown when problems occurs in Schema Treatment
*
* @author a183132
*
*/
public class XmpSchemaException extends Exception
{
/**
* serial version uid
*/
private static final long serialVersionUID = -980712488563404867L;
/**
* Create an instance of XmpSchemaException
*
* @param message
* a description of the encountered problem
*/
public XmpSchemaException(String message)
{
super(message);
}
/**
* Create an instance of XmpSchemaException
*
* @param message
* a description of the encountered problem
* @param cause
* the cause of the exception
*/
public XmpSchemaException(String message, Throwable cause)
{
super(message, cause);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPMediaManagementSchema.java 0000644 0000000 0000000 00000043406 12645757426 027736 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.util.List;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.AgentNameType;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.RenditionClassType;
import org.apache.xmpbox.type.ResourceRefType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.Types;
import org.apache.xmpbox.type.URIType;
/**
* Representation of XMPMediaManagement Schema
*
* @author gbailleul
*
*/
@StructuredType(preferedPrefix = "xmpMM", namespace = "http://ns.adobe.com/xap/1.0/mm/")
public class XMPMediaManagementSchema extends XMPSchema
{
/**
* Constructor of XMPMediaManagement Schema with preferred prefix
*
* @param metadata
* The metadata to attach this schema
*/
public XMPMediaManagementSchema(XMPMetadata metadata)
{
super(metadata);
}
/**
* Constructor of XMPMediaManagementSchema schema with specified prefix
*
* @param metadata
* The metadata to attach this schema
* @param ownPrefix
* The prefix to assign
*/
public XMPMediaManagementSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
// -------------------------------- ResourceRef --------------------
@PropertyType(type = Types.ResourceRef, card = Cardinality.Simple)
public static final String DERIVED_FROM = "DerivedFrom";
/**
* Set ResourceRef property
*
* @param tt
* ResourceRef property to set
*/
public void setDerivedFromProperty(ResourceRefType tt)
{
addProperty(tt);
}
/**
* Get ResourceRef property
*
* @return ResourceRef property
*/
public ResourceRefType getResourceRefProperty()
{
return (ResourceRefType) getProperty(DERIVED_FROM);
}
// --------------------------------------- DocumentID
// ----------------------------
@PropertyType(type = Types.URI, card = Cardinality.Simple)
public static final String DOCUMENTID = "DocumentID";
/**
* Set DocumentId value
*
* @param url
* DocumentId value to set
*/
public void setDocumentID(String url)
{
URIType tt = (URIType) instanciateSimple(DOCUMENTID, url);
setDocumentIDProperty(tt);
}
/**
* Set DocumentId Property
*
* @param tt
* DocumentId Property to set
*/
public void setDocumentIDProperty(URIType tt)
{
addProperty(tt);
}
/**
* Get DocumentId property
*
* @return DocumentId property
*/
public TextType getDocumentIDProperty()
{
return (TextType) getProperty(DOCUMENTID);
}
/**
* Get DocumentId value
*
* @return DocumentId value
*/
public String getDocumentID()
{
TextType tt = getDocumentIDProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- Manager
// ----------------------------
@PropertyType(type = Types.AgentName, card = Cardinality.Simple)
public static final String MANAGER = "Manager";
/**
* Set Manager value
*
* @param value
* Manager value to set
*/
public void setManager(String value)
{
AgentNameType tt = (AgentNameType) instanciateSimple(MANAGER, value);
setManagerProperty(tt);
}
/**
* Set Manager property
*
* @param tt
* Manager property to set
*/
public void setManagerProperty(AgentNameType tt)
{
addProperty(tt);
}
/**
* Get Manager property
*
* @return Manager property
*/
public TextType getManagerProperty()
{
return (TextType) getProperty(MANAGER);
}
/**
* Get Manager value
*
* @return Manager value
*/
public String getManager()
{
TextType tt = getManagerProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- ManageTo
// ----------------------------
@PropertyType(type = Types.URI, card = Cardinality.Simple)
public static final String MANAGETO = "ManageTo";
/**
* Set ManageTo Value
*
* @param value
* ManageTo Value to set
*/
public void setManageTo(String value)
{
URIType tt = (URIType) instanciateSimple(MANAGETO, value);
setManageToProperty(tt);
}
/**
* Set ManageTo property
*
* @param tt
* ManageTo property to set
*/
public void setManageToProperty(URIType tt)
{
addProperty(tt);
}
/**
* get ManageTo property
*
* @return ManageTo property
*/
public TextType getManageToProperty()
{
return (TextType) getProperty(MANAGETO);
}
/**
* get ManageTo value
*
* @return ManageTo value
*/
public String getManageTo()
{
TextType tt = getManageToProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- ManageUI
// ----------------------------
@PropertyType(type = Types.URI, card = Cardinality.Simple)
public static final String MANAGEUI = "ManageUI";
/**
* Set ManageUI value
*
* @param value
* ManageUI value to set
*/
public void setManageUI(String value)
{
URIType tt = (URIType) instanciateSimple(MANAGEUI, value);
setManageUIProperty(tt);
}
/**
* Set ManageUI property
*
* @param tt
* ManageUI property to set
*/
public void setManageUIProperty(URIType tt)
{
addProperty(tt);
}
/**
* Get ManageUI property
*
* @return ManageUI property
*/
public TextType getManageUIProperty()
{
return (TextType) getProperty(MANAGEUI);
}
/**
* Get ManageUI Value
*
* @return ManageUI Value
*/
public String getManageUI()
{
TextType tt = getManageUIProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- ManagerVariant
// ----------------------------
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String MANAGERVARIANT = "ManagerVariant";
/**
* Set ManagerVariant value
*
* @param value
* ManagerVariant value to set
*/
public void setManagerVariant(String value)
{
TextType tt = (TextType) instanciateSimple(MANAGERVARIANT, value);
setManagerVariantProperty(tt);
}
/**
* Set ManagerVariant Property
*
* @param tt
* ManagerVariant Property to set
*/
public void setManagerVariantProperty(TextType tt)
{
addProperty(tt);
}
/**
* Get ManagerVariant property
*
* @return ManagerVariant property
*/
public TextType getManagerVariantProperty()
{
return (TextType) getProperty(MANAGERVARIANT);
}
/**
* Get ManagerVariant value
*
* @return ManagerVariant value
*/
public String getManagerVariant()
{
TextType tt = getManagerVariantProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- InstanceID
// ----------------------------
@PropertyType(type = Types.URI, card = Cardinality.Simple)
public static final String INSTANCEID = "InstanceID";
/**
* Set InstanceId value
*
* @param value
* InstanceId value to set
*/
public void setInstanceID(String value)
{
URIType tt = (URIType) instanciateSimple(INSTANCEID, value);
setInstanceIDProperty(tt);
}
/**
* Set InstanceId property
*
* @param tt
* InstanceId property to set
*/
public void setInstanceIDProperty(URIType tt)
{
addProperty(tt);
}
/**
* Get InstanceId property
*
* @return InstanceId property
*/
public TextType getInstanceIDProperty()
{
return (TextType) getProperty(INSTANCEID);
}
/**
* Get InstanceId value
*
* @return InstanceId value
*/
public String getInstanceID()
{
TextType tt = getInstanceIDProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- ManageFrom
// ----------------------------
@PropertyType(type = Types.ResourceRef, card = Cardinality.Simple)
public static final String MANAGED_FROM = "ManagedFrom";
// /**
// * set ManageFrom Value
// *
// * @param url
// * ManageFrom Value to set
// */
// public void setManagedFrom(ResourceRefType resourceRef) {
//
// setManagedFromProperty(new TextType(metadata, localPrefix, MANAGED_FROM,
// url));
// }
/**
* set ManageFrom Property
*
* @param resourceRef
* ManageFrom Property to set
*/
public void setManagedFromProperty(ResourceRefType resourceRef)
{
addProperty(resourceRef);
}
/**
* get ManageFrom Property
*
* @return ManageFrom Property
*/
public ResourceRefType getManagedFromProperty()
{
return (ResourceRefType) getProperty(MANAGED_FROM);
}
// /**
// * Get ManageFrom value
// *
// * @return ManageFrom value
// */
// public String getManagedFrom() {
// TextType tt = getManagedFromProperty();
// return tt != null ? tt.getStringValue() : null;
// }
// --------------------------------------- OriginalDocumentID
// ----------------------------
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String ORIGINALDOCUMENTID = "OriginalDocumentID";
/**
* Set OriginalDocumentId value
*
* @param url
* OriginalDocumentId value to set
*/
public void setOriginalDocumentID(String url)
{
TextType tt = (TextType) instanciateSimple(ORIGINALDOCUMENTID, url);
setOriginalDocumentIDProperty(tt);
}
/**
* Set OriginalDocumentId property
*
* @param tt
* OriginalDocumentId property to set
*/
public void setOriginalDocumentIDProperty(TextType tt)
{
addProperty(tt);
}
/**
* Get OriginalDocumentId property
*
* @return OriginalDocumentId property
*/
public TextType getOriginalDocumentIDProperty()
{
return (TextType) getProperty(ORIGINALDOCUMENTID);
}
/**
* Get OriginalDocumentId value
*
* @return OriginalDocumentId value
*/
public String getOriginalDocumentID()
{
TextType tt = getOriginalDocumentIDProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- RenditionClass
// ----------------------------
@PropertyType(type = Types.RenditionClass, card = Cardinality.Simple)
public static final String RENDITIONCLASS = "RenditionClass";
/**
* Set renditionClass Value
*
* @param value
* renditionClass Value to set
*/
public void setRenditionClass(String value)
{
RenditionClassType tt = (RenditionClassType) instanciateSimple(RENDITIONCLASS, value);
setRenditionClassProperty(tt);
}
/**
* Set RenditionClass Property
*
* @param tt
* renditionClass Property to set
*/
public void setRenditionClassProperty(RenditionClassType tt)
{
addProperty(tt);
}
/**
* Get RenditionClass property
*
* @return RenditionClass property
*/
public TextType getRenditionClassProperty()
{
return (TextType) getProperty(RENDITIONCLASS);
}
/**
* Get RenditionClass value
*
* @return RenditionClass value
*/
public String getRenditionClass()
{
TextType tt = getRenditionClassProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- RenditionParams
// ----------------------------
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String RENDITIONPARAMS = "RenditionParams";
/**
* Set RenditionParams Value
*
* @param url
* RenditionParams Value to set
*/
public void setRenditionParams(String url)
{
TextType tt = (TextType) instanciateSimple(RENDITIONPARAMS, url);
setRenditionParamsProperty(tt);
}
/**
* Set RenditionParams property
*
* @param tt
* RenditionParams property to set
*/
public void setRenditionParamsProperty(TextType tt)
{
addProperty(tt);
}
/**
* Get RenditionParams property
*
* @return RenditionParams property
*/
public TextType getRenditionParamsProperty()
{
return (TextType) getProperty(RENDITIONPARAMS);
}
/**
* Get RenditionParams value
*
* @return RenditionParams value
*/
public String getRenditionParams()
{
TextType tt = getRenditionParamsProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- VersionID
// ----------------------------
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String VERSIONID = "VersionID";
/**
* Set VersionId value
*
* @param value
* VersionId value to set
*/
public void setVersionID(String value)
{
TextType tt = (TextType) instanciateSimple(VERSIONID, value);
setVersionIDProperty(tt);
}
/**
* Set VersionId property
*
* @param tt
* VersionId property to set
*/
public void setVersionIDProperty(TextType tt)
{
addProperty(tt);
}
/**
* Get VersionId property
*
* @return VersionId property
*/
public TextType getVersionIDProperty()
{
return (TextType) getProperty(VERSIONID);
}
/**
* Get VersionId value
*
* @return VersionId value
*/
public String getVersionID()
{
TextType tt = getVersionIDProperty();
return tt != null ? tt.getStringValue() : null;
}
// --------------------------------------- Versions
// ----------------------------
@PropertyType(type = Types.Version, card = Cardinality.Seq)
public static final String VERSIONS = "Versions";
public void addVersions(String value)
{
addQualifiedBagValue(VERSIONS, value);
}
/**
* Get Versions property
*
* @return version property to set
*/
public ArrayProperty getVersionsProperty()
{
return (ArrayProperty) getProperty(VERSIONS);
}
public List getVersions()
{
return getUnqualifiedBagValueList(VERSIONS);
}
// --------------------------------------- History
// ----------------------------
@PropertyType(type = Types.ResourceEvent, card = Cardinality.Seq)
public static final String HISTORY = "History";
/**
* Add a History Value
*
* @param history
* History Value to add
*/
public void addHistory(String history)
{
addUnqualifiedSequenceValue(HISTORY, history);
}
/**
* Get History Property
*
* @return History Property
*/
public ArrayProperty getHistoryProperty()
{
return (ArrayProperty) getProperty(HISTORY);
}
/**
* Get List of History values
*
* @return List of History values
*/
public List getHistory()
{
return getUnqualifiedSequenceValueList(HISTORY);
}
// --------------------------------------- Ingredients
// ----------------------------
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String INGREDIENTS = "Ingredients";
/**
* Add an Ingredients value
*
* @param ingredients
* Ingredients value to add
*/
public void addIngredients(String ingredients)
{
addQualifiedBagValue(INGREDIENTS, ingredients);
}
/**
* . Get Ingredients Property
*
* @return Ingredients property
*/
public ArrayProperty getIngredientsProperty()
{
return (ArrayProperty) getProperty(INGREDIENTS);
}
/**
* Get List of Ingredients values
*
* @return List of Ingredients values
*/
public List getIngredients()
{
return getUnqualifiedBagValueList(INGREDIENTS);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/PDFAIdentificationSchema.java 0000644 0000000 0000000 00000020561 12645757426 027716 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.Attribute;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.IntegerType;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.Types;
/**
* Representation of PDF/A Identification Schema
*
* @author a183132
*
*/
@StructuredType(preferedPrefix = "pdfaid", namespace = "http://www.aiim.org/pdfa/ns/id/")
public class PDFAIdentificationSchema extends XMPSchema
{
@PropertyType(type = Types.Integer, card = Cardinality.Simple)
public static final String PART = "part";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String AMD = "amd";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String CONFORMANCE = "conformance";
/*
*
* B1
*/
/**
* Constructor of a PDF/A Identification schema
*
* @param metadata
* The metadata to attach this schema
*/
public PDFAIdentificationSchema(XMPMetadata metadata)
{
super(metadata);
}
public PDFAIdentificationSchema(XMPMetadata metadata, String prefix)
{
super(metadata, prefix);
}
/**
* Set the PDFA Version identifier (with string)
*
* @param value
* The version Id value to set
*
*/
public void setPartValueWithString(String value)
{
IntegerType part = (IntegerType) instanciateSimple(PART, value);
addProperty(part);
}
/**
* Set the PDFA Version identifier (with an int)
*
* @param value
* The version Id value to set
*/
public void setPartValueWithInt(int value)
{
IntegerType part = (IntegerType) instanciateSimple(PART, value);
addProperty(part);
}
/**
* Set the PDF/A Version identifier (with an int)
*
* @param value
* The version Id property to set
*/
public void setPart(Integer value)
{
setPartValueWithInt(value.intValue());
}
/**
* Set the PDF/A Version identifier
*
* @param part
* set the PDF/A Version id property
*/
public void setPartProperty(IntegerType part)
{
addProperty(part);
}
/**
* Set the PDF/A amendment identifier
*
* @param value
* The amendment identifier value to set
*/
public void setAmd(String value)
{
TextType amd = createTextType(AMD, value);
addProperty(amd);
}
/**
* Set the PDF/A amendment identifier
*
* @param amd
* The amendment identifier property to set
*/
public void setAmdProperty(TextType amd)
{
addProperty(amd);
}
/**
* Set the PDF/A conformance level
*
* @param value
* The conformance level value to set
* @throws BadFieldValueException
* If Conformance Value not 'A' or 'B'
*/
public void setConformance(String value) throws BadFieldValueException
{
if (value.equals("A") || value.equals("B"))
{
TextType conf = createTextType(CONFORMANCE, value);
addProperty(conf);
}
else
{
throw new BadFieldValueException(
"The property given not seems to be a PDF/A conformance level (must be A or B)");
}
}
/**
* Set the PDF/A conformance level
*
* @param conf
* The conformance level property to set
* @throws BadFieldValueException
* If Conformance Value not 'A' or 'B'
*/
public void setConformanceProperty(TextType conf) throws BadFieldValueException
{
String value = conf.getStringValue();
if (value.equals("A") || value.equals("B"))
{
addProperty(conf);
}
else
{
throw new BadFieldValueException(
"The property given not seems to be a PDF/A conformance level (must be A or B)");
}
}
/**
* Give the PDFAVersionId (as an integer)
*
* @return Part value (Integer)
*/
public Integer getPart()
{
AbstractField tmp = getPartProperty();
if (tmp instanceof IntegerType)
{
return ((IntegerType) tmp).getValue();
}
else
{
for (Attribute attribute : getAllAttributes())
{
if (attribute.getName().equals(PART))
{
return Integer.valueOf(attribute.getValue());
}
}
return null;
}
}
/**
* Give the property corresponding to the PDFA Version id
*
* @return Part property
*/
public IntegerType getPartProperty()
{
AbstractField tmp = getProperty(PART);
if (tmp instanceof IntegerType)
{
return (IntegerType) tmp;
}
return null;
}
/**
* Give the PDFAAmendmentId (as an String)
*
* @return Amendment value
*/
public String getAmendment()
{
AbstractField tmp = getProperty(AMD);
if (tmp instanceof TextType)
{
return ((TextType) tmp).getStringValue();
}
return null;
}
/**
* Give the property corresponding to the PDFA Amendment id
*
* @return Amendment property
*/
public TextType getAmdProperty()
{
AbstractField tmp = getProperty(AMD);
if (tmp instanceof TextType)
{
return (TextType) tmp;
}
return null;
}
/**
* Give the PDFA Amendment Id (as an String)
*
* @return Amendment Value
*/
public String getAmd()
{
TextType tmp = getAmdProperty();
if (tmp == null)
{
for (Attribute attribute : getAllAttributes())
{
if (attribute.getName().equals(AMD))
{
return attribute.getValue();
}
}
return null;
}
else
{
return tmp.getStringValue();
}
}
/**
* Give the property corresponding to the PDFA Conformance id
*
* @return conformance property
*/
public TextType getConformanceProperty()
{
AbstractField tmp = getProperty(CONFORMANCE);
if (tmp instanceof TextType)
{
return (TextType) tmp;
}
return null;
}
/**
* Give the Conformance id
*
* @return conformance id value
*/
public String getConformance()
{
TextType tt = getConformanceProperty();
if (tt == null)
{
for (Attribute attribute : getAllAttributes())
{
if (attribute.getName().equals(CONFORMANCE))
{
return attribute.getValue();
}
}
return null;
}
else
{
return tt.getStringValue();
}
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPBasicSchema.java 0000644 0000000 0000000 00000036775 12645757426 025756 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.AgentNameType;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.DateType;
import org.apache.xmpbox.type.IntegerType;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TextType;
import org.apache.xmpbox.type.ThumbnailType;
import org.apache.xmpbox.type.Types;
import org.apache.xmpbox.type.URLType;
/**
* Representation of XMPBasic Schema
*
* @author a183132
*
*/
@StructuredType(preferedPrefix = "xmp", namespace = "http://ns.adobe.com/xap/1.0/")
public class XMPBasicSchema extends XMPSchema
{
@PropertyType(type = Types.XPath, card = Cardinality.Bag)
public static final String ADVISORY = "Advisory";
@PropertyType(type = Types.URL, card = Cardinality.Simple)
public static final String BASEURL = "BaseURL";
@PropertyType(type = Types.Date, card = Cardinality.Simple)
public static final String CREATEDATE = "CreateDate";
@PropertyType(type = Types.AgentName, card = Cardinality.Simple)
public static final String CREATORTOOL = "CreatorTool";
@PropertyType(type = Types.Text, card = Cardinality.Bag)
public static final String IDENTIFIER = "Identifier";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String LABEL = "Label";
@PropertyType(type = Types.Date, card = Cardinality.Simple)
public static final String METADATADATE = "MetadataDate";
@PropertyType(type = Types.Date, card = Cardinality.Simple)
public static final String MODIFYDATE = "ModifyDate";
@PropertyType(type = Types.Text, card = Cardinality.Simple)
public static final String NICKNAME = "Nickname";
@PropertyType(type = Types.Integer, card = Cardinality.Simple)
public static final String RATING = "Rating";
@PropertyType(type = Types.Thumbnail, card = Cardinality.Alt)
public static final String THUMBNAILS = "Thumbnails";
private ArrayProperty altThumbs;
/**
* Constructor of XMPBasic schema with preferred prefix
*
* @param metadata
* The metadata to attach this schema
*/
public XMPBasicSchema(XMPMetadata metadata)
{
super(metadata);
}
/**
* Constructor of XMPBasic schema with specified prefix
*
* @param metadata
* The metadata to attach this schema
* @param ownPrefix
* The prefix to assign
*/
public XMPBasicSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
/**
* Add thumbnail to thumbnails list
*
* @param height
* height format
* @param width
* width format
* @param format
* thumbnail format
* @param img
* Image data
*/
public void addThumbnails(Integer height, Integer width, String format, String img)
{
if (altThumbs == null)
{
altThumbs = createArrayProperty(THUMBNAILS, Cardinality.Alt);
addProperty(altThumbs);
}
ThumbnailType thumb = new ThumbnailType(getMetadata());
thumb.setHeight(height);
thumb.setWidth(width);
thumb.setFormat(format);
thumb.setImage(img);
altThumbs.getContainer().addProperty(thumb);
}
/**
* Add a property specification that were edited outside the authoring application
*
* @param xpath
* the value to add
*/
public void addAdvisory(String xpath)
{
addQualifiedBagValue(ADVISORY, xpath);
}
public void removeAdvisory(String xpath)
{
removeUnqualifiedBagValue(ADVISORY, xpath);
}
/**
* Set the base URL for relative URLs in the document content
*
* @param url
* the Base url value to set
*/
public void setBaseURL(String url)
{
URLType tt = (URLType) instanciateSimple(BASEURL, url);
setBaseURLProperty(tt);
}
/**
* Set the base URL property
*
* @param url
* the Base url property to set
*/
public void setBaseURLProperty(URLType url)
{
addProperty(url);
}
/**
* Set the date and time the resource was originally created
*
* @param date
* the value to set
*/
public void setCreateDate(Calendar date)
{
DateType tt = (DateType) instanciateSimple(CREATEDATE, date);
setCreateDateProperty(tt);
}
/**
* Set the create date property
*
* @param date
* the create date property to set
*/
public void setCreateDateProperty(DateType date)
{
addProperty(date);
}
/**
* set the name of the first known tool used to create this resource
*
* @param creatorTool
* the creator tool value to set
*/
public void setCreatorTool(String creatorTool)
{
AgentNameType tt = (AgentNameType) instanciateSimple(CREATORTOOL, creatorTool);
setCreatorToolProperty(tt);
}
/**
* set the creatorTool property
*
* @param creatorTool
* the creator tool property to set
*/
public void setCreatorToolProperty(AgentNameType creatorTool)
{
addProperty(creatorTool);
}
/**
* Add a text string which unambiguously identify the resource within a given context
*
* @param text
* the identifier value to add
*/
public void addIdentifier(String text)
{
addQualifiedBagValue(IDENTIFIER, text);
}
public void removeIdentifier(String text)
{
removeUnqualifiedBagValue(IDENTIFIER, text);
}
/**
* set a word or a short phrase which identifies a document as a member of a user-defined collection
*
* @param text
* the label value to set
*/
public void setLabel(String text)
{
TextType tt = (TextType) instanciateSimple(LABEL, text);
setLabelProperty(tt);
}
/**
* set the label property
*
* @param text
* the label property to set
*/
public void setLabelProperty(TextType text)
{
addProperty(text);
}
/**
* Set the date and time that any metadata for this resource was last changed. (should be equals or more recent than
* the createDate)
*
* @param date
* the Metadata Date value to set
*/
public void setMetadataDate(Calendar date)
{
DateType tt = (DateType) instanciateSimple(METADATADATE, date);
setMetadataDateProperty(tt);
}
/**
* Set the MetadataDate property
*
* @param date
* the Metadata Date property to set
*/
public void setMetadataDateProperty(DateType date)
{
addProperty(date);
}
/**
* Set the date and time the resource was last modified
*
* @param date
* the Modify Date value to set
*/
public void setModifyDate(Calendar date)
{
DateType tt = (DateType) instanciateSimple(MODIFYDATE, date);
setModifyDateProperty(tt);
}
/**
* Set the ModifyDate property
*
* @param date
* the Modify Date property to set
*/
public void setModifyDateProperty(DateType date)
{
addProperty(date);
}
/**
* Set a short informal name for the resource
*
* @param text
* the Nickname value to set
*/
public void setNickname(String text)
{
TextType tt = (TextType) instanciateSimple(NICKNAME, text);
setNicknameProperty(tt);
}
/**
* Set the NickName property
*
* @param text
* the Nickname property to set
*/
public void setNicknameProperty(TextType text)
{
addProperty(text);
}
/**
* Set a number that indicates a document's status relative to other documents, used to organize documents in a file
* browser (values are user-defined within an application-defined range)
*
* @param rate
* the rate value to set
*/
public void setRating(Integer rate)
{
// addProperty(new IntegerType(metadata, localPrefix, RATING, rate));
IntegerType tt = (IntegerType) instanciateSimple(RATING, rate);
setRatingProperty(tt);
}
/**
* Set Rating Property
*
* @param rate
* the rate property to set
*/
public void setRatingProperty(IntegerType rate)
{
addProperty(rate);
}
/**
* Get the Advisory property
*
* @return the advisory property
*/
public ArrayProperty getAdvisoryProperty()
{
return (ArrayProperty) getProperty(ADVISORY);
}
/**
* Get the Advisory property values
*
* @return list of adivory values
*/
public List getAdvisory()
{
return getUnqualifiedBagValueList(ADVISORY);
}
/**
* Convenience method for jempbox signature compatibility
*
* @see XMPBasicSchema#getAdvisory()
*/
@Deprecated
public List getAdvisories()
{
return getAdvisory();
}
/**
* Get the BaseURL property
*
* @return the base url property
*/
public TextType getBaseURLProperty()
{
return (TextType) getProperty(BASEURL);
}
/**
* Get the BaseURL property value
*
* @return the base url value
*/
public String getBaseURL()
{
TextType tt = ((TextType) getProperty(BASEURL));
return tt == null ? null : tt.getStringValue();
}
/**
* Get the CreateDate property
*
* @return the CreateDate property
*/
public DateType getCreateDateProperty()
{
return (DateType) getProperty(CREATEDATE);
}
/**
* Get the CreateDate property value
*
* @return the CreateDate value
*/
public Calendar getCreateDate()
{
DateType createDate = (DateType) getProperty(CREATEDATE);
if (createDate != null)
{
return createDate.getValue();
}
return null;
}
/**
* Get the CreationTool property
*
* @return the CreationTool property
*/
public TextType getCreatorToolProperty()
{
return (TextType) getProperty(CREATORTOOL);
}
/**
* Get the CreationTool property value
*
* @return the CreationTool value
*/
public String getCreatorTool()
{
TextType tt = ((TextType) getProperty(CREATORTOOL));
return tt == null ? null : tt.getStringValue();
}
/**
* Get the Identifier property
*
* @return the Identifier property
*/
public ArrayProperty getIdentifiersProperty()
{
return (ArrayProperty) getProperty(IDENTIFIER);
}
/**
* Get the Identifier property values
*
* @return list of all identifier values
*/
public List getIdentifiers()
{
return getUnqualifiedBagValueList(IDENTIFIER);
}
/**
* Get the label property
*
* @return the label property
*/
public TextType getLabelProperty()
{
return (TextType) getProperty(LABEL);
}
/**
* Get the label property value
*
* @return the label value
*/
public String getLabel()
{
TextType tt = ((TextType) getProperty(LABEL));
return tt == null ? null : tt.getStringValue();
}
/**
* Get the MetadataDate property
*
* @return the MetadataDate property
*/
public DateType getMetadataDateProperty()
{
return (DateType) getProperty(METADATADATE);
}
/**
* Get the MetadataDate property value
*
* @return the MetadataDate value
*/
public Calendar getMetadataDate()
{
DateType dt = ((DateType) getProperty(METADATADATE));
return dt == null ? null : dt.getValue();
}
/**
* Get the ModifyDate property
*
* @return the ModifyDate property
*/
public DateType getModifyDateProperty()
{
return (DateType) getProperty(MODIFYDATE);
}
/**
* Get the ModifyDate property value
*
* @return the ModifyDate value
*/
public Calendar getModifyDate()
{
DateType modifyDate = (DateType) getProperty(MODIFYDATE);
if (modifyDate != null)
{
return modifyDate.getValue();
}
return null;
}
/**
* Get the Nickname property
*
* @return the Nickname property
*/
public TextType getNicknameProperty()
{
return (TextType) getProperty(NICKNAME);
}
/**
* Get the Nickname property value
*
* @return the Nickname value
*/
public String getNickname()
{
TextType tt = ((TextType) getProperty(NICKNAME));
return tt == null ? null : tt.getStringValue();
}
/**
* Get the Rating property
*
* @return the Rating property
*/
public IntegerType getRatingProperty()
{
return ((IntegerType) getProperty(RATING));
}
/**
* Get the Rating property value
*
* @return the Rating value
*/
public Integer getRating()
{
IntegerType it = ((IntegerType) getProperty(RATING));
return it == null ? null : it.getValue();
}
/**
* Get list of Thumbnails
*
* @return List of all thumbnails properties defined
* @throws BadFieldValueException
* if one thumbnail is not thumbnail type
*/
public List getThumbnailsProperty() throws BadFieldValueException
{
List tmp = getUnqualifiedArrayList(THUMBNAILS);
if (tmp != null)
{
List thumbs = new ArrayList();
for (AbstractField abstractField : tmp)
{
if (abstractField instanceof ThumbnailType)
{
thumbs.add((ThumbnailType) abstractField);
}
else
{
throw new BadFieldValueException("Thumbnail expected and " + abstractField.getClass().getName()
+ " found.");
}
}
return thumbs;
}
return null;
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPBasicJobTicketSchema.java 0000644 0000000 0000000 00000007145 12645757426 027542 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.util.ArrayList;
import java.util.List;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.JobType;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.Types;
@StructuredType(preferedPrefix = "xmpBJ", namespace = "http://ns.adobe.com/xap/1.0/bj/")
public class XMPBasicJobTicketSchema extends XMPSchema
{
@PropertyType(type = Types.Job, card = Cardinality.Bag)
public static final String JOB_REF = "JobRef";
private ArrayProperty bagJobs;
public XMPBasicJobTicketSchema(XMPMetadata metadata)
{
this(metadata, null);
}
public XMPBasicJobTicketSchema(XMPMetadata metadata, String ownPrefix)
{
super(metadata, ownPrefix);
}
public void addJob(String id, String name, String url)
{
addJob(id, name, url, null);
}
public void addJob(String id, String name, String url, String fieldPrefix)
{
JobType job = new JobType(getMetadata(), fieldPrefix);
job.setId(id);
job.setName(name);
job.setUrl(url);
addJob(job);
}
public void addJob(JobType job)
{
String prefix = getNamespacePrefix(job.getNamespace());
if (prefix != null)
{
// use same prefix for all jobs
job.setPrefix(prefix);
}
else
{
// add prefix
addNamespace(job.getNamespace(), job.getPrefix());
}
// create bag if not existing
if (bagJobs == null)
{
bagJobs = createArrayProperty(JOB_REF, Cardinality.Bag);
addProperty(bagJobs);
}
// add job
bagJobs.getContainer().addProperty(job);
}
public List getJobs() throws BadFieldValueException
{
List tmp = getUnqualifiedArrayList(JOB_REF);
if (tmp != null)
{
List layers = new ArrayList();
for (AbstractField abstractField : tmp)
{
if (abstractField instanceof JobType)
{
layers.add((JobType) abstractField);
}
else
{
throw new BadFieldValueException("Job expected and " + abstractField.getClass().getName()
+ " found.");
}
}
return layers;
}
return null;
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/PDFAExtensionSchema.java 0000644 0000000 0000000 00000004173 12645757426 026742 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.Types;
/**
* Representation of a PDF/A Extension schema description schema
*
* @author a183132
*
*/
@StructuredType(preferedPrefix = "pdfaExtension", namespace = "http://www.aiim.org/pdfa/ns/extension/")
public class PDFAExtensionSchema extends XMPSchema
{
@PropertyType(type = Types.PDFASchema, card = Cardinality.Bag)
public static final String SCHEMAS = "schemas";
/**
* Build a new PDFExtension schema
*
* @param metadata
* The metadata to attach this schema XMPMetadata
*/
public PDFAExtensionSchema(XMPMetadata metadata)
{
super(metadata);
}
public PDFAExtensionSchema(XMPMetadata metadata, String prefix)
{
super(metadata, prefix);
}
/**
*
* @return the list of subject values
*/
public ArrayProperty getSchemasProperty()
{
return (ArrayProperty) getProperty(SCHEMAS);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchemaFactory.java 0000644 0000000 0000000 00000010216 12645757426 026322 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.schema;
import java.lang.reflect.Constructor;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.type.PropertiesDescription;
import org.apache.xmpbox.type.PropertyType;
/**
* A factory for each kind of schemas
*
* @author a183132
*
*/
public class XMPSchemaFactory
{
private String namespace;
private Class extends XMPSchema> schemaClass;
private PropertiesDescription propDef;
private String nsName;
/**
* Factory Constructor for basic known schemas
*
* @param namespace
* namespace URI to treat
* @param schemaClass
* Class representation associated to this URI
* @param propDef
* Properties Types list associated
*/
public XMPSchemaFactory(String namespace, Class extends XMPSchema> schemaClass, PropertiesDescription propDef)
{
this.namespace = namespace;
this.schemaClass = schemaClass;
this.propDef = propDef;
}
/**
* Get namespace URI treated by this factory
*
* @return The namespace URI
*/
public String getNamespace()
{
return namespace;
}
/**
* Get type declared for the name property given
*
* @param name
* The property name
* @return null if propery name is unknown
*/
public PropertyType getPropertyType(String name)
{
return propDef.getPropertyType(name);
}
/**
* Create a schema that corresponding to this factory and add it to metadata
*
* @param metadata
* Metadata to attach the Schema created
* @param prefix
* The namespace prefix (optional)
* @return the schema created and added to metadata
* @throws XmpSchemaException
* When Instancing specified Object Schema failed
*/
public XMPSchema createXMPSchema(XMPMetadata metadata, String prefix) throws XmpSchemaException
{
XMPSchema schema = null;
Class>[] argsClass;
Object[] schemaArgs;
if (schemaClass == XMPSchema.class)
{
argsClass = new Class[] { XMPMetadata.class, String.class, String.class };
schemaArgs = new Object[] { metadata, namespace, nsName };
}
else if (prefix != null && !"".equals(prefix))
{
argsClass = new Class[] { XMPMetadata.class, String.class };
schemaArgs = new Object[] { metadata, prefix };
}
else
{
argsClass = new Class[] { XMPMetadata.class };
schemaArgs = new Object[] { metadata };
}
Constructor extends XMPSchema> schemaConstructor;
try
{
schemaConstructor = schemaClass.getConstructor(argsClass);
schema = schemaConstructor.newInstance(schemaArgs);
if (schema != null)
{
metadata.addSchema(schema);
}
return schema;
}
catch (Exception e)
{
throw new XmpSchemaException("Cannot Instanciate specified Object Schema", e);
}
}
public PropertiesDescription getPropertyDefinition()
{
return this.propDef;
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/XmpConstants.java 0000644 0000000 0000000 00000004001 12645757426 024401 0 ustar root root /*****************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox;
public final class XmpConstants
{
public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
public static final String DEFAULT_XPACKET_BEGIN = "\uFEFF";
public static final String DEFAULT_XPACKET_ID = "W5M0MpCehiHzreSzNTczkc9d";
public static final String DEFAULT_XPACKET_ENCODING = "UTF-8";
public static final String DEFAULT_XPACKET_BYTES = null;
public static final String DEFAULT_XPACKET_END = "w";
public static final String DEFAULT_RDF_PREFIX = "rdf";
public static final String DEFAULT_RDF_LOCAL_NAME = "RDF";
public static final String LIST_NAME = "li";
public static final String LANG_NAME = "lang";
public static final String ABOUT_NAME = "about";
public static final String DESCRIPTION_NAME = "Description";
public static final String RESOURCE_NAME = "Resource";
public static final String PARSE_TYPE = "parseType";
public static final String X_DEFAULT = "x-default";
private XmpConstants()
{
// hide constructor
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java 0000644 0000000 0000000 00000024024 12645757426 024514 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.SimpleTimeZone;
/**
* This class is used to convert dates to strings and back using the PDF date standards. Date are described in
* PDFReference1.4 section 3.8.2
*
* @author Ben Litchfield
* @author Christopher Oezbek
*
* @version $Revision: 1.3 $
*/
public class DateConverter
{
// The Date format is supposed to be the PDF_DATE_FORMAT, but not all PDF
// documents
// will use that date, so I have added a couple other potential formats
// to try if the original one does not work.
private static final SimpleDateFormat[] POTENTIAL_FORMATS = new SimpleDateFormat[] {
new SimpleDateFormat("EEEE, dd MMM yyyy hh:mm:ss a"),
new SimpleDateFormat("EEEE, MMM dd, yyyy hh:mm:ss a"), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz") };
/**
* According to check-style, Utility classes should not have a public or default constructor.
*/
protected DateConverter()
{
};
/**
* This will convert a string to a calendar.
*
* @param date
* The string representation of the calendar.
*
* @return The calendar that this string represents.
*
* @throws IOException
* If the date string is not in the correct format.
*/
public static Calendar toCalendar(String date) throws IOException
{
Calendar retval = null;
if ((date != null) && (date.trim().length() > 0))
{
// these are the default values
int year = 0;
int month = 1;
int day = 1;
int hour = 0;
int minute = 0;
int second = 0;
// first string off the prefix if it exists
try
{
SimpleTimeZone zone = null;
if (date.startsWith("D:"))
{
date = date.substring(2, date.length());
}
date = date.replaceAll("[-:T]", "");
if (date.length() < 4)
{
throw new IOException("Error: Invalid date format '" + date + "'");
}
year = Integer.parseInt(date.substring(0, 4));
if (date.length() >= 6)
{
month = Integer.parseInt(date.substring(4, 6));
}
if (date.length() >= 8)
{
day = Integer.parseInt(date.substring(6, 8));
}
if (date.length() >= 10)
{
hour = Integer.parseInt(date.substring(8, 10));
}
if (date.length() >= 12)
{
minute = Integer.parseInt(date.substring(10, 12));
}
int timeZonePos = 12;
if (date.length() - 12 > 5 || (date.length() - 12 == 3 && date.endsWith("Z")))
{
if (date.length() >= 14)
{
second = Integer.parseInt(date.substring(12, 14));
}
timeZonePos = 14;
}
else
{
second = 0;
}
if (date.length() >= (timeZonePos + 1))
{
char sign = date.charAt(timeZonePos);
if (sign == 'Z')
{
zone = new SimpleTimeZone(0, "Unknown");
}
else
{
int hours = 0;
int minutes = 0;
if (date.length() >= (timeZonePos + 3))
{
if (sign == '+')
{
// parseInt cannot handle the + sign
hours = Integer.parseInt(date.substring((timeZonePos + 1), (timeZonePos + 3)));
}
else
{
hours = -Integer.parseInt(date.substring(timeZonePos, (timeZonePos + 2)));
}
}
if (sign == '+')
{
if (date.length() >= (timeZonePos + 5))
{
minutes = Integer.parseInt(date.substring((timeZonePos + 3), (timeZonePos + 5)));
}
}
else
{
if (date.length() >= (timeZonePos + 4))
{
minutes = Integer.parseInt(date.substring((timeZonePos + 2), (timeZonePos + 4)));
}
}
zone = new SimpleTimeZone(hours * 60 * 60 * 1000 + minutes * 60 * 1000, "Unknown");
}
}
if (zone == null)
{
retval = new GregorianCalendar();
}
else
{
retval = new GregorianCalendar(zone);
}
retval.clear();
retval.set(year, month - 1, day, hour, minute, second);
}
catch (NumberFormatException e)
{
// remove the arbitrary : in the timezone. SimpleDateFormat
// can't handle it
if (date.substring(date.length() - 3, date.length() - 2).equals(":")
&& (date.substring(date.length() - 6, date.length() - 5).equals("+") || date.substring(
date.length() - 6, date.length() - 5).equals("-")))
{
// thats a timezone string, remove the :
date = date.substring(0, date.length() - 3) + date.substring(date.length() - 2);
}
for (int i = 0; (retval == null) && (i < POTENTIAL_FORMATS.length); i++)
{
try
{
Date utilDate = POTENTIAL_FORMATS[i].parse(date);
retval = new GregorianCalendar();
retval.setTime(utilDate);
}
catch (ParseException pe)
{
// ignore and move to next potential format
}
}
if (retval == null)
{
// we didn't find a valid date format so throw an exception
IOException ioe = new IOException("Error converting date:" + date);
ioe.initCause(e);
throw ioe;
}
}
}
return retval;
}
/**
* Append Zero to String Buffer before number < 10 ('1' become '01')
*
* @param out
* The String buffer
* @param number
* The concerned number
*/
private static void zeroAppend(StringBuffer out, int number)
{
if (number < 10)
{
out.append("0");
}
out.append(number);
}
/**
* Convert the date to iso 8601 string format.
*
* @param cal
* The date to convert.
* @return The date represented as an ISO 8601 string.
*/
public static String toISO8601(Calendar cal)
{
StringBuffer retval = new StringBuffer();
retval.append(cal.get(Calendar.YEAR));
retval.append("-");
zeroAppend(retval, cal.get(Calendar.MONTH) + 1);
retval.append("-");
zeroAppend(retval, cal.get(Calendar.DAY_OF_MONTH));
retval.append("T");
zeroAppend(retval, cal.get(Calendar.HOUR_OF_DAY));
retval.append(":");
zeroAppend(retval, cal.get(Calendar.MINUTE));
retval.append(":");
zeroAppend(retval, cal.get(Calendar.SECOND));
int timeZone = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
if (timeZone < 0)
{
retval.append("-");
}
else
{
retval.append("+");
}
timeZone = Math.abs(timeZone);
// milliseconds/1000 = seconds = seconds / 60 = minutes = minutes/60 =
// hours
int hours = timeZone / 1000 / 60 / 60;
int minutes = (timeZone - (hours * 1000 * 60 * 60)) / 1000 / 1000;
if (hours < 10)
{
retval.append("0");
}
retval.append(Integer.toString(hours));
retval.append(":");
if (minutes < 10)
{
retval.append("0");
}
retval.append(Integer.toString(minutes));
return retval.toString();
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/ 0000755 0000000 0000000 00000000000 12645757426 021702 5 ustar root root pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializationException.java 0000644 0000000 0000000 00000003373 12645757426 027734 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.xml;
/**
* Exception when Parsing cannot be made
*
* @author a183132
*
*/
public class XmpSerializationException extends Exception
{
private static final long serialVersionUID = -3495894314480173555L;
/**
* Create an instance of TransformException
*
* @param message
* a description of the encountered problem
*/
public XmpSerializationException(String message)
{
super(message);
}
/**
* Create an instance of TransformException
*
* @param message
* a description of the encountered problem
* @param cause
* the cause of the exception
*/
public XmpSerializationException(String message, Throwable cause)
{
super(message, cause);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpParsingException.java 0000644 0000000 0000000 00000004742 12645757426 026523 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.xml;
/**
* Exception thrown when Parsing failed
*
* @author a183132
*
*/
public class XmpParsingException extends Exception
{
public enum ErrorType
{
Undefined, Configuration, XpacketBadStart, XpacketBadEnd, NoRootElement, NoSchema, // undefined
// schema
InvalidPdfaSchema, NoType, // undefined type
InvalidType, Format, // weird things in serialized document
NoValueType, RequiredProperty, InvalidPrefix, // unexpected namespace
// prefix used
}
private ErrorType errorType;
/**
* serial version uid
*/
private static final long serialVersionUID = -8843096358184702908L;
/**
* Create an instance of XmpParsingException
*
* @param message
* a description of the encountered problem
* @param cause
* the cause of the exception
*/
public XmpParsingException(ErrorType error, String message, Throwable cause)
{
super(message, cause);
this.errorType = error;
}
/**
* Create an instance of XmpParsingException
*
* @param message
* a description of the encountered problem
*/
public XmpParsingException(ErrorType error, String message)
{
super(message);
this.errorType = error;
}
public ErrorType getErrorType()
{
return errorType;
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/DomHelper.java 0000644 0000000 0000000 00000007434 12645757426 024434 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.xml;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.xmpbox.XmpConstants;
import org.apache.xmpbox.xml.XmpParsingException.ErrorType;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public final class DomHelper
{
private DomHelper()
{
}
public static Element getUniqueElementChild(Element description) throws XmpParsingException
{
NodeList nl = description.getChildNodes();
int pos = -1;
for (int i = 0; i < nl.getLength(); i++)
{
if (nl.item(i) instanceof Element)
{
if (pos >= 0)
{
// invalid : found two child elements
throw new XmpParsingException(ErrorType.Undefined, "Found two child elements in " + description);
}
else
{
pos = i;
}
}
}
return (Element) nl.item(pos);
}
/**
* Return the first child element of the element parameter. If there is no child, null is returned
*
* @param description
* @return the first child element. Might be null.
* @throws XmpParsingException
*/
public static Element getFirstChildElement(Element description) throws XmpParsingException
{
NodeList nl = description.getChildNodes();
for (int i = 0; i < nl.getLength(); i++)
{
if (nl.item(i) instanceof Element)
{
return (Element) nl.item(i);
}
}
return null;
}
public static List getElementChildren(Element description) throws XmpParsingException
{
NodeList nl = description.getChildNodes();
List ret = new ArrayList(nl.getLength());
for (int i = 0; i < nl.getLength(); i++)
{
if (nl.item(i) instanceof Element)
{
ret.add((Element) nl.item(i));
}
}
return ret;
}
public static QName getQName(Element element)
{
return new QName(element.getNamespaceURI(), element.getLocalName(), element.getPrefix());
}
public static boolean isRdfDescription(Element element)
{
return (XmpConstants.DEFAULT_RDF_PREFIX.equals(element.getPrefix()) && XmpConstants.DESCRIPTION_NAME
.equals(element.getLocalName()));
}
public static boolean isParseTypeResource(Element element)
{
Attr parseType = element.getAttributeNodeNS(XmpConstants.RDF_NAMESPACE, XmpConstants.PARSE_TYPE);
if (parseType != null && XmpConstants.RESOURCE_NAME.equals(parseType.getValue()))
{
// parseType resourc
return true;
}
// else
return false;
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/PdfaExtensionHelper.java 0000644 0000000 0000000 00000034345 12645757426 026465 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.xml;
import java.util.List;
import java.util.Map;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.schema.PDFAExtensionSchema;
import org.apache.xmpbox.schema.XMPSchema;
import org.apache.xmpbox.schema.XMPSchemaFactory;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.AbstractStructuredType;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.DefinedStructuredType;
import org.apache.xmpbox.type.PDFAFieldType;
import org.apache.xmpbox.type.PDFAPropertyType;
import org.apache.xmpbox.type.PDFASchemaType;
import org.apache.xmpbox.type.PDFATypeType;
import org.apache.xmpbox.type.PropertiesDescription;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.StructuredType;
import org.apache.xmpbox.type.TypeMapping;
import org.apache.xmpbox.type.Types;
import org.apache.xmpbox.xml.XmpParsingException.ErrorType;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
public final class PdfaExtensionHelper
{
public static final String CLOSED_CHOICE = "closed Choice of ";
public static final String OPEN_CHOICE = "open Choice of ";
private PdfaExtensionHelper()
{
}
public static void validateNaming(XMPMetadata meta, Element description) throws XmpParsingException
{
NamedNodeMap nnm = description.getAttributes();
for (int i = 0; i < nnm.getLength(); i++)
{
Attr attr = (Attr) nnm.item(i);
checkNamespaceDeclaration(attr, PDFAExtensionSchema.class);
checkNamespaceDeclaration(attr, PDFAFieldType.class);
checkNamespaceDeclaration(attr, PDFAPropertyType.class);
checkNamespaceDeclaration(attr, PDFASchemaType.class);
checkNamespaceDeclaration(attr, PDFATypeType.class);
}
}
private static void checkNamespaceDeclaration(Attr attr, Class extends AbstractStructuredType> clz)
throws XmpParsingException
{
String prefix = attr.getLocalName();
String namespace = attr.getValue();
String cprefix = clz.getAnnotation(StructuredType.class).preferedPrefix();
String cnamespace = clz.getAnnotation(StructuredType.class).namespace();
// check extension
if (cprefix.equals(prefix) && !cnamespace.equals(namespace))
{
throw new XmpParsingException(ErrorType.InvalidPdfaSchema, "Invalid PDF/A namespace definition");
} // else good match
if (cnamespace.equals(namespace) && !cprefix.equals(prefix))
{
throw new XmpParsingException(ErrorType.InvalidPdfaSchema, "Invalid PDF/A namespace definition");
} // else good match
}
public static void populateSchemaMapping(XMPMetadata meta) throws XmpParsingException
{
List schems = meta.getAllSchemas();
TypeMapping tm = meta.getTypeMapping();
StructuredType stPdfaExt = PDFAExtensionSchema.class.getAnnotation(StructuredType.class);
for (XMPSchema xmpSchema : schems)
{
if (xmpSchema.getNamespace().equals(stPdfaExt.namespace()))
{
// ensure the prefix is the preferred one (cannot use other
// definition)
if (!xmpSchema.getPrefix().equals(stPdfaExt.preferedPrefix()))
{
throw new XmpParsingException(ErrorType.InvalidPrefix,
"Found invalid prefix for PDF/A extension, found '" + xmpSchema.getPrefix()
+ "', should be '" + stPdfaExt.preferedPrefix() + "'");
}
// create schema and types
PDFAExtensionSchema pes = (PDFAExtensionSchema) xmpSchema;
ArrayProperty sp = pes.getSchemasProperty();
for (AbstractField af : sp.getAllProperties())
{
if (af instanceof PDFASchemaType)
{
PDFASchemaType st = (PDFASchemaType) af;
String namespaceUri = st.getNamespaceURI().trim();
String prefix = st.getPrefixValue();
ArrayProperty properties = st.getProperty();
ArrayProperty valueTypes = st.getValueType();
XMPSchemaFactory xsf = tm.getSchemaFactory(namespaceUri);
// retrieve namespaces
if (xsf == null)
{
// create namespace with no field
tm.addNewNameSpace(namespaceUri, prefix);
xsf = tm.getSchemaFactory(namespaceUri);
}
// populate value type
if (valueTypes != null)
{
for (AbstractField af2 : valueTypes.getAllProperties())
{
if (af2 instanceof PDFATypeType)
{
PDFATypeType type = (PDFATypeType) af2;
String ttype = type.getType();
String tns = type.getNamespaceURI();
String tprefix = type.getPrefixValue();
String tdescription = type.getDescription();
ArrayProperty fields = type.getFields();
if (ttype == null || tns == null || tprefix == null || tdescription == null)
{
// all fields are mandatory
throw new XmpParsingException(ErrorType.RequiredProperty,
"Missing field in type definition");
}
// create the structured type
DefinedStructuredType structuredType = new DefinedStructuredType(meta, tns,
tprefix, null); // TODO
// maybe
// a name
// exists
if (fields != null)
{
List definedFields = fields.getAllProperties();
for (AbstractField af3 : definedFields)
{
if (af3 instanceof PDFAFieldType)
{
PDFAFieldType field = (PDFAFieldType) af3;
String fName = field.getName();
String fDescription = field.getDescription();
String fValueType = field.getValueType();
if (fName == null || fDescription == null || fValueType == null)
{
throw new XmpParsingException(ErrorType.RequiredProperty,
"Missing field in field definition");
}
try
{
Types fValue = Types.valueOf(fValueType);
structuredType.addProperty(fName,
TypeMapping.createPropertyType(fValue, Cardinality.Simple));
}
catch (IllegalArgumentException e)
{
throw new XmpParsingException(ErrorType.NoValueType,
"Type not defined : " + fValueType, e);
// TODO could fValueType be
// a structured type ?
}
} // else TODO
}
}
// add the structured type to list
PropertiesDescription pm = new PropertiesDescription();
for (Map.Entry entry : structuredType.getDefinedProperties()
.entrySet())
{
pm.addNewProperty(entry.getKey(), entry.getValue());
}
tm.addToDefinedStructuredTypes(ttype, tns, pm);
}
}
}
// populate properties
if (properties == null)
{
throw new XmpParsingException(ErrorType.RequiredProperty,
"Missing pdfaSchema:property in type definition");
}
for (AbstractField af2 : properties.getAllProperties())
{
if (af2 instanceof PDFAPropertyType)
{
PDFAPropertyType property = (PDFAPropertyType) af2;
String pname = property.getName();
String ptype = property.getValueType();
String pdescription = property.getDescription();
String pCategory = property.getCategory();
// check all mandatory fields are OK
if (pname == null || ptype == null || pdescription == null || pCategory == null)
{
// all fields are mandatory
throw new XmpParsingException(ErrorType.RequiredProperty,
"Missing field in property definition");
}
// check ptype existance
PropertyType pt = transformValueType(tm, ptype);
if (pt.type() == null)
{
throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : " + ptype);
}
else if (pt.type().isSimple() || pt.type().isStructured()
|| pt.type() == Types.DefinedType)
{
xsf.getPropertyDefinition().addNewProperty(pname, pt);
}
else
{
throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : " + ptype);
}
} // TODO unmanaged ?
}
} // TODO unmanaged ?
}
}
}
}
private static PropertyType transformValueType(TypeMapping tm, String valueType) throws XmpParsingException
{
if ("Lang Alt".equals(valueType))
{
return TypeMapping.createPropertyType(Types.LangAlt, Cardinality.Simple);
}
// else all other cases
if (valueType.startsWith(CLOSED_CHOICE))
{
valueType = valueType.substring(CLOSED_CHOICE.length());
}
else if (valueType.startsWith(OPEN_CHOICE))
{
valueType = valueType.substring(OPEN_CHOICE.length());
}
int pos = valueType.indexOf(' ');
Cardinality card = Cardinality.Simple;
if (pos > 0)
{
String scard = valueType.substring(0, pos);
if ("seq".equals(scard))
{
card = Cardinality.Seq;
}
else if ("bag".equals(scard))
{
card = Cardinality.Bag;
}
else if ("alt".equals(scard))
{
card = Cardinality.Alt;
}
else
{
return null;
}
}
String vt = valueType.substring(pos + 1);
Types type = null;
try
{
type = pos < 0 ? Types.valueOf(valueType) : Types.valueOf(vt);
}
catch (IllegalArgumentException e)
{
if (tm.isDefinedType(vt))
{
type = Types.DefinedType;
}
}
return TypeMapping.createPropertyType(type, card);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java 0000644 0000000 0000000 00000024056 12645757426 025352 0 ustar root root /*****************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.xml;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.XmpConstants;
import org.apache.xmpbox.schema.XMPSchema;
import org.apache.xmpbox.type.AbstractComplexProperty;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.AbstractSimpleProperty;
import org.apache.xmpbox.type.AbstractStructuredType;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Attribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
public class XmpSerializer
{
private DocumentBuilder documentBuilder = null;
private boolean parseTypeResourceForLi = true;
public XmpSerializer() throws XmpSerializationException
{
// xml init
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
try
{
documentBuilder = builderFactory.newDocumentBuilder();
}
catch (ParserConfigurationException e)
{
throw new XmpSerializationException("Failed to init XmpSerializer", e);
}
}
public void serialize(XMPMetadata metadata, OutputStream os, boolean withXpacket) throws TransformerException
{
Document doc = documentBuilder.newDocument();
// fill document
Element rdf = createRdfElement(doc, metadata, withXpacket);
for (XMPSchema schema : metadata.getAllSchemas())
{
rdf.appendChild(serializeSchema(doc, schema));
}
// save
save(doc, os, "UTF-8");
}
protected Element serializeSchema(Document doc, XMPSchema schema)
{
// prepare schema
Element selem = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:Description");
selem.setAttributeNS(XmpConstants.RDF_NAMESPACE, "rdf:about", schema.getAboutValue());
selem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + schema.getPrefix(), schema.getNamespace());
// the other attributes
fillElementWithAttributes(selem, schema);
// the content
List fields = schema.getAllProperties();
serializeFields(doc, selem, fields, true);
// return created schema
return selem;
}
public void serializeFields(Document doc, Element parent, List fields, boolean wrapWithProperty)
{
for (AbstractField field : fields)
{
if (field instanceof AbstractSimpleProperty)
{
AbstractSimpleProperty simple = (AbstractSimpleProperty) field;
Element esimple = doc.createElement(simple.getPrefix() + ":" + simple.getPropertyName());
esimple.setTextContent(simple.getStringValue());
parent.appendChild(esimple);
}
else if (field instanceof ArrayProperty)
{
ArrayProperty array = (ArrayProperty) field;
// property
Element asimple = doc.createElement(array.getPrefix() + ":" + array.getPropertyName());
parent.appendChild(asimple);
// attributes
fillElementWithAttributes(asimple, array);
// the array definition
Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + array.getArrayType());
asimple.appendChild(econtainer);
// for each element of the array
List innerFields = array.getAllProperties();
serializeFields(doc, econtainer, innerFields, false);
}
else if (field instanceof AbstractStructuredType)
{
AbstractStructuredType structured = (AbstractStructuredType) field;
List innerFields = structured.getAllProperties();
// property name attribute
Element listParent = parent;
if (wrapWithProperty)
{
Element nstructured = doc
.createElement(structured.getPrefix() + ":" + structured.getPropertyName());
parent.appendChild(nstructured);
listParent = nstructured;
}
// element li
Element estructured = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + XmpConstants.LIST_NAME);
listParent.appendChild(estructured);
if (parseTypeResourceForLi)
{
estructured.setAttribute("rdf:parseType", "Resource");
// all properties
serializeFields(doc, estructured, innerFields, true);
}
else
{
// element description
Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + "Description");
estructured.appendChild(econtainer);
// all properties
serializeFields(doc, econtainer, innerFields, true);
}
}
else
{
// XXX finish serialization classes
System.err.println(">> TODO >> " + field.getClass());
}
}
}
private void fillElementWithAttributes(Element target, AbstractComplexProperty property)
{
List attributes = property.getAllAttributes();
for (Attribute attribute : attributes)
{
if (XmpConstants.RDF_NAMESPACE.equals(attribute.getNamespace()))
{
target.setAttribute(XmpConstants.DEFAULT_RDF_PREFIX + ":" + attribute.getName(), attribute.getValue());
}
else if (target.getNamespaceURI().equals(attribute.getNamespace()))
{
target.setAttribute(attribute.getName(), attribute.getValue());
}
else
{
target.setAttribute(attribute.getName(), attribute.getValue());
}
}
for (Map.Entry ns : property.getAllNamespacesWithPrefix().entrySet())
{
target.setAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + ns.getValue(), ns.getKey());
}
}
protected Element createRdfElement(Document doc, XMPMetadata metadata, boolean withXpacket)
{
// starting xpacket
if (withXpacket)
{
ProcessingInstruction beginXPacket = doc.createProcessingInstruction("xpacket",
"begin=\"" + metadata.getXpacketBegin() + "\" id=\"" + metadata.getXpacketId() + "\"");
doc.appendChild(beginXPacket);
}
// meta element
Element xmpmeta = doc.createElementNS("adobe:ns:meta/", "x:xmpmeta");
xmpmeta.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:x", "adobe:ns:meta/");
doc.appendChild(xmpmeta);
// ending xpacket
if (withXpacket)
{
ProcessingInstruction endXPacket = doc.createProcessingInstruction("xpacket",
"end=\"" + metadata.getEndXPacket() + "\"");
doc.appendChild(endXPacket);
}
// rdf element
Element rdf = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:RDF");
// rdf.setAttributeNS(XMPSchema.NS_NAMESPACE, qualifiedName, value)
xmpmeta.appendChild(rdf);
// return the rdf element where all will be put
return rdf;
}
/**
* Save the XML document to an output stream.
*
* @param doc
* The XML document to save.
* @param outStream
* The stream to save the document to.
* @param encoding
* The encoding to save the file as.
*
* @throws TransformerException
* If there is an error while saving the XML.
*/
private void save(Node doc, OutputStream outStream, String encoding) throws TransformerException
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
// human readable
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// indent elements
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
// encoding
transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
// initialize StreamResult with File object to save to file
Result result = new StreamResult(outStream);
DOMSource source = new DOMSource(doc);
// save
transformer.transform(source, result);
}
}
pdfbox-1.8.11/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java 0000644 0000000 0000000 00000075547 12645757426 025150 0 ustar root root /*****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
package org.apache.xmpbox.xml;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.XmpConstants;
import org.apache.xmpbox.schema.XMPSchema;
import org.apache.xmpbox.schema.XmpSchemaException;
import org.apache.xmpbox.type.AbstractField;
import org.apache.xmpbox.type.AbstractSimpleProperty;
import org.apache.xmpbox.type.AbstractStructuredType;
import org.apache.xmpbox.type.ArrayProperty;
import org.apache.xmpbox.type.Attribute;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.type.Cardinality;
import org.apache.xmpbox.type.ComplexPropertyContainer;
import org.apache.xmpbox.type.PropertiesDescription;
import org.apache.xmpbox.type.PropertyType;
import org.apache.xmpbox.type.TypeMapping;
import org.apache.xmpbox.type.Types;
import org.apache.xmpbox.xml.XmpParsingException.ErrorType;
import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;
public class DomXmpParser
{
private DocumentBuilder dBuilder;
private NamespaceFinder nsFinder;
private boolean strictParsing = true;
public DomXmpParser() throws XmpParsingException
{
try
{
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
dBuilder = dbFactory.newDocumentBuilder();
nsFinder = new NamespaceFinder();
}
catch (ParserConfigurationException e)
{
throw new XmpParsingException(ErrorType.Configuration, "Failed to initilalize", e);
}
}
public boolean isStrictParsing()
{
return strictParsing;
}
public void setStrictParsing(boolean strictParsing)
{
this.strictParsing = strictParsing;
}
public XMPMetadata parse(byte[] xmp) throws XmpParsingException
{
ByteArrayInputStream input = new ByteArrayInputStream(xmp);
return parse(input);
}
public XMPMetadata parse(InputStream input) throws XmpParsingException
{
Document document = null;
try
{
// prevents validation messages polluting the console
dBuilder.setErrorHandler(null);
document = dBuilder.parse(input);
}
catch (SAXException e)
{
throw new XmpParsingException(ErrorType.Undefined, "Failed to parse", e);
}
catch (IOException e)
{
throw new XmpParsingException(ErrorType.Undefined, "Failed to parse", e);
}
// document.normalizeDocument();
XMPMetadata xmp = null;
// Start reading
removeComments(document.getFirstChild());
Node node = document.getFirstChild();
// expect xpacket processing instruction
if (!(node instanceof ProcessingInstruction))
{
throw new XmpParsingException(ErrorType.XpacketBadStart, "xmp should start with a processing instruction");
}
else
{
xmp = parseInitialXpacket((ProcessingInstruction) node);
node = node.getNextSibling();
}
// forget other processing instruction
while (node instanceof ProcessingInstruction)
{
node = node.getNextSibling();
}
// expect root element
Element root = null;
if (!(node instanceof Element))
{
throw new XmpParsingException(ErrorType.NoRootElement, "xmp should contain a root element");
}
else
{
// use this element as root
root = (Element) node;
node = node.getNextSibling();
}
// expect xpacket end
if (!(node instanceof ProcessingInstruction))
{
throw new XmpParsingException(ErrorType.XpacketBadEnd, "xmp should end with a processing instruction");
}
else
{
parseEndPacket(xmp, (ProcessingInstruction) node);
node = node.getNextSibling();
}
// should be null
if (node != null)
{
throw new XmpParsingException(ErrorType.XpacketBadEnd,
"xmp should end after xpacket end processing instruction");
}
// xpacket is OK and the is no more nodes
// Now, parse the content of root
Element rdfRdf = findDescriptionsParent(root);
List descriptions = DomHelper.getElementChildren(rdfRdf);
List dataDescriptions = new ArrayList(descriptions.size());
for (Element description : descriptions)
{
Element first = DomHelper.getFirstChildElement(description);
if (first != null && "pdfaExtension".equals(first.getPrefix()))
{
PdfaExtensionHelper.validateNaming(xmp, description);
parseDescriptionRoot(xmp, description);
}
else
{
dataDescriptions.add(description);
}
}
// find schema description
PdfaExtensionHelper.populateSchemaMapping(xmp);
// parse data description
for (Element description : dataDescriptions)
{
parseDescriptionRoot(xmp, description);
}
return xmp;
}
private void parseDescriptionRoot(XMPMetadata xmp, Element description) throws XmpParsingException
{
nsFinder.push(description);
TypeMapping tm = xmp.getTypeMapping();
try
{
List properties = DomHelper.getElementChildren(description);
// parse attributes as properties
NamedNodeMap nnm = description.getAttributes();
for (int i = 0; i < nnm.getLength(); i++)
{
Attr attr = (Attr) nnm.item(i);
if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix()))
{
// do nothing
}
else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix())
&& XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
{
// do nothing
}
else if (attr.getPrefix() == null && XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
{
// do nothing
}
else
{
String namespace = attr.getNamespaceURI();
XMPSchema schema = xmp.getSchema(namespace);
if (schema == null)
{
schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, attr.getPrefix());
loadAttributes(schema, description);
}
ComplexPropertyContainer container = schema.getContainer();
PropertyType type = checkPropertyDefinition(xmp,
new QName(attr.getNamespaceURI(), attr.getLocalName()));
AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, schema.getPrefix(),
attr.getLocalName(), attr.getValue(), type.type());
container.addProperty(sp);
}
}
// parse children elements as properties
for (Element property : properties)
{
String namespace = property.getNamespaceURI();
PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
// create the container
if (!tm.isDefinedSchema(namespace))
{
throw new XmpParsingException(ErrorType.NoSchema,
"This namespace is not a schema or a structured type : " + namespace);
}
XMPSchema schema = xmp.getSchema(namespace);
if (schema == null)
{
schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, property.getPrefix());
loadAttributes(schema, description);
}
ComplexPropertyContainer container = schema.getContainer();
// create property
createProperty(xmp, property, type, container);
}
}
catch (XmpSchemaException e)
{
throw new XmpParsingException(ErrorType.Undefined, "Parsing failed", e);
}
finally
{
nsFinder.pop();
}
}
private void createProperty(XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer container)
throws XmpParsingException
{
String prefix = property.getPrefix();
String name = property.getLocalName();
String namespace = property.getNamespaceURI();
// create property
nsFinder.push(property);
try
{
if (type == null)
{
if (strictParsing)
{
throw new XmpParsingException(ErrorType.InvalidType, "No type defined for {" + namespace + "}"
+ name);
}
else
{
// use it as string
manageSimpleType(xmp, property, Types.Text, container);
}
}
else if (type.type() == Types.LangAlt)
{
manageLangAlt(xmp, property, container);
}
else if (type.card().isArray())
{
manageArray(xmp, property, type, container);
}
else if (type.type().isSimple())
{
manageSimpleType(xmp, property, type.type(), container);
}
else if (type.type().isStructured())
{
if (DomHelper.isParseTypeResource(property))
{
AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), property);
if (ast != null)
{
ast.setPrefix(prefix);
container.addProperty(ast);
}
}
else
{
Element inner = DomHelper.getFirstChildElement(property);
if (inner != null)
{
AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), inner);
ast.setPrefix(prefix);
container.addProperty(ast);
}
}
}
else if (type.type() == Types.DefinedType)
{
if (DomHelper.isParseTypeResource(property))
{
AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), property);
ast.setPrefix(prefix);
container.addProperty(ast);
}
else
{
Element inner = DomHelper.getFirstChildElement(property);
if (inner == null)
{
throw new XmpParsingException(ErrorType.Format, "property should contain child element : "
+ property);
}
AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property), inner);
ast.setPrefix(prefix);
container.addProperty(ast);
}
}
}
finally
{
nsFinder.pop();
}
}
private void manageSimpleType(XMPMetadata xmp, Element property, Types type, ComplexPropertyContainer container)
throws XmpParsingException
{
TypeMapping tm = xmp.getTypeMapping();
String prefix = property.getPrefix();
String name = property.getLocalName();
String namespace = property.getNamespaceURI();
AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, prefix, name, property.getTextContent(),
type);
loadAttributes(sp, property);
container.addProperty(sp);
}
private void manageArray(XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer container)
throws XmpParsingException
{
TypeMapping tm = xmp.getTypeMapping();
String prefix = property.getPrefix();
String name = property.getLocalName();
String namespace = property.getNamespaceURI();
Element bagOrSeq = DomHelper.getUniqueElementChild(property);
// ensure this is the good type of array
if (bagOrSeq == null)
{
// not an array
throw new XmpParsingException(ErrorType.Format, "Invalid array definition, expecting " + type.card()
+ " and found nothing");
}
if (!bagOrSeq.getLocalName().equals(type.card().name()))
{
// not the good array type
throw new XmpParsingException(ErrorType.Format, "Invalid array type, expecting " + type.card()
+ " and found " + bagOrSeq.getLocalName());
}
ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
container.addProperty(array);
List lis = DomHelper.getElementChildren(bagOrSeq);
for (Element element : lis)
{
QName propertyQName = DomHelper.getQName(property);
AbstractField ast = parseLiElement(xmp, propertyQName, element);
if (ast != null)
{
array.addProperty(ast);
}
}
}
private void manageLangAlt(XMPMetadata xmp, Element property, ComplexPropertyContainer container)
throws XmpParsingException
{
manageArray(xmp, property, TypeMapping.createPropertyType(Types.LangAlt, Cardinality.Alt), container);
}
private void parseDescriptionInner(XMPMetadata xmp, Element description, ComplexPropertyContainer parentContainer)
throws XmpParsingException
{
nsFinder.push(description);
TypeMapping tm = xmp.getTypeMapping();
try
{
List properties = DomHelper.getElementChildren(description);
for (Element property : properties)
{
String name = property.getLocalName();
PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property));
PropertyType ptype = tm.getStructuredPropMapping(dtype.type()).getPropertyType(name);
// create property
createProperty(xmp, property, ptype, parentContainer);
}
}
finally
{
nsFinder.pop();
}
}
private AbstractField parseLiElement(XMPMetadata xmp, QName descriptor, Element liElement)
throws XmpParsingException
{
if (DomHelper.isParseTypeResource(liElement))
{
return parseLiDescription(xmp, descriptor, liElement);
}
// will find rdf:Description
Element liChild = DomHelper.getUniqueElementChild(liElement);
if (liChild != null)
{
return parseLiDescription(xmp, descriptor, liChild);
}
else
{
// no child, so consider as simple text
String text = liElement.getTextContent();
TypeMapping tm = xmp.getTypeMapping();
AbstractSimpleProperty sp = tm.instanciateSimpleProperty(descriptor.getNamespaceURI(),
descriptor.getPrefix(), descriptor.getLocalPart(), text, Types.Text);
loadAttributes(sp, liElement);
return sp;
}
}
private void loadAttributes(AbstractField sp, Element element)
{
NamedNodeMap nnm = element.getAttributes();
for (int i = 0; i < nnm.getLength(); i++)
{
Attr attr = (Attr) nnm.item(i);
if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix()))
{
// do nothing
}
else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix())
&& XmpConstants.ABOUT_NAME.equals(attr.getLocalName()))
{
// set about
if (sp instanceof XMPSchema)
{
((XMPSchema) sp).setAboutAsSimple(attr.getValue());
}
}
else
{
Attribute attribute = new Attribute(XMLConstants.XML_NS_URI, attr.getLocalName(), attr.getValue());
sp.setAttribute(attribute);
}
}
}
private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName descriptor, Element liElement)
throws XmpParsingException
{
TypeMapping tm = xmp.getTypeMapping();
List elements = DomHelper.getElementChildren(liElement);
if (elements.size() == 0)
{
// The list is empty
return null;
}
// Instantiate abstract structured type with hint from first element
Element first = elements.get(0);
PropertyType ctype = checkPropertyDefinition(xmp, DomHelper.getQName(first));
Types tt = ctype.type();
AbstractStructuredType ast = instanciateStructured(tm, tt, descriptor.getLocalPart(), first.getNamespaceURI());
ast.setNamespace(descriptor.getNamespaceURI());
ast.setPrefix(descriptor.getPrefix());
PropertiesDescription pm;
if (tt.isStructured())
{
pm = tm.getStructuredPropMapping(tt);
}
else
{
pm = tm.getDefinedDescriptionByNamespace(first.getNamespaceURI());
}
for (Element element : elements)
{
String prefix = element.getPrefix();
String name = element.getLocalName();
String namespace = element.getNamespaceURI();
PropertyType type = pm.getPropertyType(name);
if (type == null)
{
// not defined
throw new XmpParsingException(ErrorType.NoType, "Type '" + name + "' not defined in "
+ element.getNamespaceURI());
}
else if (type.card().isArray())
{
ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
ast.getContainer().addProperty(array);
Element bagOrSeq = DomHelper.getUniqueElementChild(element);
List lis = DomHelper.getElementChildren(bagOrSeq);
for (Element element2 : lis)
{
AbstractField ast2 = parseLiElement(xmp, descriptor, element2);
if (ast2 != null)
{
array.addProperty(ast2);
}
}
}
else if (type.type().isSimple())
{
AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, prefix, name,
element.getTextContent(), type.type());
loadAttributes(sp, element);
ast.getContainer().addProperty(sp);
}
else if (type.type().isStructured())
{
// create a new structured type
AbstractStructuredType inner = instanciateStructured(tm, type.type(), name, null);
inner.setNamespace(namespace);
inner.setPrefix(prefix);
ast.getContainer().addProperty(inner);
ComplexPropertyContainer cpc = inner.getContainer();
if (DomHelper.isParseTypeResource(element))
{
parseDescriptionInner(xmp, element, cpc);
}
else
{
Element descElement = DomHelper.getFirstChildElement(element);
if (descElement != null)
{
parseDescriptionInner(xmp, descElement, cpc);
}
}
}
else
{
throw new XmpParsingException(ErrorType.NoType, "Unidentified element to parse " + element + " (type="
+ type + ")");
}
}
return ast;
}
private XMPMetadata parseInitialXpacket(ProcessingInstruction pi) throws XmpParsingException
{
if (!"xpacket".equals(pi.getNodeName()))
{
throw new XmpParsingException(ErrorType.XpacketBadStart, "Bad processing instruction name : "
+ pi.getNodeName());
}
String data = pi.getData();
StringTokenizer tokens = new StringTokenizer(data, " ");
String id = null;
String begin = null;
String bytes = null;
String encoding = null;
while (tokens.hasMoreTokens())
{
String token = tokens.nextToken();
if (!token.endsWith("\"") && !token.endsWith("\'"))
{
throw new XmpParsingException(ErrorType.XpacketBadStart, "Cannot understand PI data part : '" + token
+ "'");
}
String quote = token.substring(token.length() - 1);
int pos = token.indexOf("=" + quote);
if (pos <= 0)
{
throw new XmpParsingException(ErrorType.XpacketBadStart, "Cannot understand PI data part : '" + token
+ "'");
}
String name = token.substring(0, pos);
String value = token.substring(pos + 2, token.length() - 1);
if ("id".equals(name))
{
id = value;
}
else if ("begin".equals(name))
{
begin = value;
}
else if ("bytes".equals(name))
{
bytes = value;
}
else if ("encoding".equals(name))
{
encoding = value;
}
else
{
throw new XmpParsingException(ErrorType.XpacketBadStart, "Unknown attribute in xpacket PI : '" + token
+ "'");
}
}
return XMPMetadata.createXMPMetadata(begin, id, bytes, encoding);
}
private void parseEndPacket(XMPMetadata metadata, ProcessingInstruction pi) throws XmpParsingException
{
String xpackData = pi.getData();
// end attribute must be present and placed in first
// xmp spec says Other unrecognized attributes can follow, but
// should be ignored
if (xpackData.startsWith("end="))
{
char end = xpackData.charAt(5);
// check value (5 for end='X')
if (end != 'r' && end != 'w')
{
throw new XmpParsingException(ErrorType.XpacketBadEnd,
"Excepted xpacket 'end' attribute with value 'r' or 'w' ");
}
else
{
metadata.setEndXPacket(Character.toString(end));
}
}
else
{
// should find end='r/w'
throw new XmpParsingException(ErrorType.XpacketBadEnd,
"Excepted xpacket 'end' attribute (must be present and placed in first)");
}
}
private Element findDescriptionsParent(Element root) throws XmpParsingException
{
// always
expectNaming(root, "adobe:ns:meta/", "x", "xmpmeta");
// should only have one child
NodeList nl = root.getChildNodes();
if (nl.getLength() == 0)
{
// empty description
throw new XmpParsingException(ErrorType.Format, "No rdf description found in xmp");
}
else if (nl.getLength() > 1)
{
// only expect one element
throw new XmpParsingException(ErrorType.Format, "More than one element found in x:xmpmeta");
}
else if (!(root.getFirstChild() instanceof Element))
{
// should be an element
throw new XmpParsingException(ErrorType.Format, "x:xmpmeta does not contains rdf:RDF element");
} // else let's parse
Element rdfRdf = (Element) root.getFirstChild();
// always
expectNaming(rdfRdf, XmpConstants.RDF_NAMESPACE, XmpConstants.DEFAULT_RDF_PREFIX,
XmpConstants.DEFAULT_RDF_LOCAL_NAME);
// return description parent
return rdfRdf;
}
private void expectNaming(Element element, String ns, String prefix, String ln) throws XmpParsingException
{
if ((ns != null) && !(ns.equals(element.getNamespaceURI())))
{
throw new XmpParsingException(ErrorType.Format, "Expecting namespace '" + ns + "' and found '"
+ element.getNamespaceURI() + "'");
}
else if ((prefix != null) && !(prefix.equals(element.getPrefix())))
{
throw new XmpParsingException(ErrorType.Format, "Expecting prefix '" + prefix + "' and found '"
+ element.getPrefix() + "'");
}
else if ((ln != null) && !(ln.equals(element.getLocalName())))
{
throw new XmpParsingException(ErrorType.Format, "Expecting local name '" + ln + "' and found '"
+ element.getLocalName() + "'");
} // else OK
}
/**
* Remove all the comments node in the parent element of the parameter
*
* @param node
* the first node of an element or document to clear
*/
private void removeComments(Node root)
{
Node node = root;
while (node != null)
{
Node next = node.getNextSibling();
if (node instanceof Comment)
{
// remove the comment
node.getParentNode().removeChild(node);
}
else if (node instanceof Text)
{
Text t = (Text) node;
if (t.getTextContent().trim().length() == 0)
{
// XXX is there a better way to remove useless Text ?
node.getParentNode().removeChild(node);
}
}
else if (node instanceof Element)
{
// clean child
removeComments(node.getFirstChild());
} // else do nothing
node = next;
}
// end of document
}
private AbstractStructuredType instanciateStructured(TypeMapping tm, Types type, String name,
String structuredNamespace) throws XmpParsingException
{
try
{
if (type.isStructured())
{
return tm.instanciateStructuredType(type, name);
}
else if (type.isDefined())
{
return tm.instanciateDefinedType(name, structuredNamespace);
}
else
{
throw new XmpParsingException(ErrorType.InvalidType, "Type not structured : " + type);
}
}
catch (BadFieldValueException e)
{
throw new XmpParsingException(ErrorType.InvalidType, "Parsing failed", e);
}
}
private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName prop) throws XmpParsingException
{
TypeMapping tm = xmp.getTypeMapping();
// test if namespace is set in xml
if (!nsFinder.containsNamespace(prop.getNamespaceURI()))
{
throw new XmpParsingException(ErrorType.NoSchema, "Schema is not set in this document : "
+ prop.getNamespaceURI());
}
// test if namespace is defined
String nsuri = prop.getNamespaceURI();
if (!tm.isDefinedNamespace(nsuri))
{
throw new XmpParsingException(ErrorType.NoSchema, "Cannot find a definition for the namespace "
+ prop.getNamespaceURI());
}
try
{
return tm.getSpecifiedPropertyType(prop);
}
catch (BadFieldValueException e)
{
throw new XmpParsingException(ErrorType.InvalidType, "Failed to retreive property definition", e);
}
}
protected class NamespaceFinder
{
private Stack