You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Lindberg, Chris J." <li...@llnl.gov> on 2011/09/08 18:37:19 UTC
Error from XMPSchemaMediaManagement createDerivedFrom() method
Hello,
my goal is to create an updated set of XMP metadata but when I try to use the XMPSchemaMediaManagement createDerivedFrom() method I get an error:
Exception in thread "Thread-1" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
when I use:
ResourceRef derivedFromRef = destXmpMM.createDerivedFrom();
to create the DerivedFrom element as seen in the my method (source below)
/**
* Create new XMP Media Management schema from existing XMP Media Management schema data.
*
* @param xmpMM XMP Media Management schema extracted from original PDF
*/
public void loadDestMediaManagmentSchema(XMPSchemaMediaManagement xmpMM) {
// add XMPSchemaMediaManagment to destination XMP metadata
XMPSchemaMediaManagement destXmpMM = destXmpMetadata.addMediaManagementSchema();
// create DerivedFrom ResourceRef element from XMPSchemaMediaManagement object
ResourceRef derivedFromRef = destXmpMM.createDerivedFrom();
loadDerivedFromResourceRef(derivedFromRef, xmpMM.getTextProperty("xmpMM:InstanceID")));
destXmpMM.setDerivedFrom(derivedFromRef);
// add History ResourceEvents
destXmpMM.addHistory(loadResourceEvent(destXmpMM, ResourceEvent.ACTION_EDITED, PLMLoader.AGENT_NAME));
destXmpMM.addHistory(loadResourceEvent(destXmpMM, ResourceEvent.ACTION_MANAGED, PLMLoader.MANAGED_AGENT_NAME));
destXmpMM.setDocumentID(xmpMM.getDocumentID());
}
Watching the debugger I believe the error is caused because the new destination XMP Media Management element returns "rdf" as its prefix (from rdf:Description element that wraps the xmpMM content).
<rdf:Description xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
How can I correct this and generate a DerivedFrom element?
Thanks in advance,
Chris
RE: Error from XMPSchemaMediaManagement createDerivedFrom() method
Posted by "Lindberg, Chris J." <li...@llnl.gov>.
Hello,
I have found that the jempbox ResourceRef constructor is failing a DOM namespace check.
After attaching the jempbox source code to the IDE I'm using I find that the error is occurring in the jempbox ResourceRef constructor when it sets the name space attribute (parent.setAttributeNS()).
public ResourceRef( Element parentElement )
{
parent = parentElement;
if( !parent.hasAttribute( "xmlns:stRef" ) )
{
parent.setAttributeNS(
"http://ns.adobe.com/xap/1.0/sType/ResourceRef#",
"xmlns:stRef",
"http://ns.adobe.com/xap/1.0/sType/ResourceRef#" );
}
}
setAttributesNS ultimately runs a DOM namespace error check in CoreDocumentImpl where it fails:
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr(CoreDocumentImpl.java:2547)
...
else if (
prefix.equals("xmlns")
&& !namespace.equals(NamespaceContext.XMLNS_URI)
|| (!prefix.equals("xmlns")
&& namespace.equals(NamespaceContext.XMLNS_URI))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
when I run in debugger
prefix equals "xmlns" and
namespace equals "http://nsadobe.com/xap/1.0/sType/ResourceRef#"
The error is thrown because the checkDOMNSErr expects namespace to be equal to
"http://www.w3.0rg/2000/xmlns/"
Is this a bug?
Thanks,
Chris
-----Original Message-----
From: Lindberg, Chris J. [mailto:lindberg4@llnl.gov]
Sent: Thursday, September 08, 2011 9:37 AM
To: users@pdfbox.apache.org
Subject: Error from XMPSchemaMediaManagement createDerivedFrom() method
Hello,
my goal is to create an updated set of XMP metadata but when I try to use the XMPSchemaMediaManagement createDerivedFrom() method I get an error:
Exception in thread "Thread-1" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
when I use:
ResourceRef derivedFromRef = destXmpMM.createDerivedFrom();
to create the DerivedFrom element as seen in the my method (source below)
/**
* Create new XMP Media Management schema from existing XMP Media Management schema data.
*
* @param xmpMM XMP Media Management schema extracted from original PDF
*/
public void loadDestMediaManagmentSchema(XMPSchemaMediaManagement xmpMM) {
// add XMPSchemaMediaManagment to destination XMP metadata
XMPSchemaMediaManagement destXmpMM = destXmpMetadata.addMediaManagementSchema();
// create DerivedFrom ResourceRef element from XMPSchemaMediaManagement object
ResourceRef derivedFromRef = destXmpMM.createDerivedFrom();
loadDerivedFromResourceRef(derivedFromRef, xmpMM.getTextProperty("xmpMM:InstanceID")));
destXmpMM.setDerivedFrom(derivedFromRef);
// add History ResourceEvents
destXmpMM.addHistory(loadResourceEvent(destXmpMM, ResourceEvent.ACTION_EDITED, PLMLoader.AGENT_NAME));
destXmpMM.addHistory(loadResourceEvent(destXmpMM, ResourceEvent.ACTION_MANAGED, PLMLoader.MANAGED_AGENT_NAME));
destXmpMM.setDocumentID(xmpMM.getDocumentID());
}
Watching the debugger I believe the error is caused because the new destination XMP Media Management element returns "rdf" as its prefix (from rdf:Description element that wraps the xmpMM content).
<rdf:Description xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
How can I correct this and generate a DerivedFrom element?
Thanks in advance,
Chris