You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2016/08/25 05:17:37 UTC
svn commit: r1757605 - in /pdfbox/branches/2.0/xmpbox: ./
src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Author: msahyoun
Date: Thu Aug 25 05:17:37 2016
New Revision: 1757605
URL: http://svn.apache.org/viewvc?rev=1757605&view=rev
Log:
PDFBOX-3471: ensure that all nodes are visited when removing; ignore comments
Modified:
pdfbox/branches/2.0/xmpbox/ (props changed)
pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Propchange: pdfbox/branches/2.0/xmpbox/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Aug 25 05:17:37 2016
@@ -0,0 +1,3 @@
+/pdfbox/branches/no-awt/xmpbox:1618517-1621410
+/pdfbox/no-awt/xmpbox:1618514-1618516
+/pdfbox/trunk/xmpbox:1736223,1736227,1736615,1737043,1737130,1737599-1737600,1738755,1740160,1742437,1742442,1745595,1745606,1745772,1745774,1745776,1745779,1746032,1746151,1749162,1749165,1749432,1757604
Modified: pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java?rev=1757605&r1=1757604&r2=1757605&view=diff
==============================================================================
--- pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java (original)
+++ pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java Thu Aug 25 05:17:37 2016
@@ -789,25 +789,32 @@ public class DomXmpParser
*/
private void removeComments(Node root)
{
- if (root.getChildNodes().getLength()<=1)
+ // will hold the nodes which are to be deleted
+ List<Node> forDeletion = new ArrayList<Node>();
+
+ NodeList nl = root.getChildNodes();
+
+ if (nl.getLength()<=1)
{
// There is only one node so we do not remove it
return;
}
- NodeList nl = root.getChildNodes();
- for (int i=0; i < nl.getLength(); i++)
+
+ for (int i = 0; i < nl.getLength(); i++)
{
Node node = nl.item(i);
if (node instanceof Comment)
{
- // remove the comment
- root.removeChild(node);
+ // comments to be deleted
+ forDeletion.add(node);
}
else if (node instanceof Text)
{
if (node.getTextContent().trim().isEmpty())
{
- root.removeChild(node);
+ // TODO: verify why this is necessary
+ // empty text nodes to be deleted
+ forDeletion.add(node);
}
}
else if (node instanceof Element)
@@ -816,6 +823,12 @@ public class DomXmpParser
removeComments(node);
} // else do nothing
}
+
+ // now remove the child nodes
+ for (Node node : forDeletion)
+ {
+ root.removeChild(node);
+ }
}
private AbstractStructuredType instanciateStructured(TypeMapping tm, Types type, String name,