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 2015/06/03 08:55:00 UTC
svn commit: r1683241 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf:
FDFCatalog.java FDFDictionary.java FDFDocument.java
Author: msahyoun
Date: Wed Jun 3 06:55:00 2015
New Revision: 1683241
URL: http://svn.apache.org/r1683241
Log:
PDFBOX-2758: ignore invalid element when importing XFDF
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFCatalog.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFCatalog.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFCatalog.java?rev=1683241&r1=1683240&r2=1683241&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFCatalog.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFCatalog.java Wed Jun 3 06:55:00 2015
@@ -58,7 +58,7 @@ public class FDFCatalog implements COSOb
* @param element The XML document that contains the XFDF data.
* @throws IOException If there is an error reading from the dom.
*/
- public FDFCatalog( Element element ) throws IOException
+ public FDFCatalog( Element element )
{
this();
FDFDictionary fdfDict = new FDFDictionary( element );
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java?rev=1683241&r1=1683240&r2=1683241&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java Wed Jun 3 06:55:00 2015
@@ -72,7 +72,7 @@ public class FDFDictionary implements CO
* @param fdfXML The XML document that contains the XFDF data.
* @throws IOException If there is an error reading from the dom.
*/
- public FDFDictionary( Element fdfXML ) throws IOException
+ public FDFDictionary( Element fdfXML )
{
this();
NodeList nodeList = fdfXML.getChildNodes();
@@ -93,8 +93,24 @@ public class FDFDictionary implements CO
COSArray ids = new COSArray();
String original = child.getAttribute( "original" );
String modified = child.getAttribute( "modified" );
- ids.add( COSString.parseHex( original ) );
- ids.add( COSString.parseHex( modified ) );
+ try
+ {
+ ids.add( COSString.parseHex( original ) );
+ }
+ catch (IOException e)
+ {
+ LOG.warn("Error parsing ID entry for attribute 'original' ["
+ + original + "]. ID entry ignored.", e);
+ }
+ try
+ {
+ ids.add( COSString.parseHex( modified ) );
+ }
+ catch (IOException e)
+ {
+ LOG.warn("Error parsing ID entry for attribute 'modified' ["
+ + modified + "]. ID entry ignored.", e);
+ }
setID( ids );
}
else if( child.getTagName().equals( "fields" ) )
@@ -106,7 +122,15 @@ public class FDFDictionary implements CO
Node currentNode = fields.item( f );
if (currentNode instanceof Element && ((Element) currentNode).getTagName().equals("field"))
{
- fieldList.add(new FDFField((Element) fields.item(f)));
+ try
+ {
+ fieldList.add(new FDFField((Element) fields.item(f)));
+ }
+ catch (IOException e)
+ {
+ LOG.warn("Error parsing field entry ["
+ + currentNode.getNodeValue() + "]. Field ignored.", e);
+ }
}
}
setFields( fieldList );
@@ -124,78 +148,85 @@ public class FDFDictionary implements CO
// the node name defines the annotation type
Element annot = (Element)annotNode;
String annotationName = annot.getNodeName();
-
- if (annotationName.equals("text"))
- {
- annotList.add(new FDFAnnotationText(annot));
- }
- else if (annotationName.equals("caret"))
- {
- annotList.add(new FDFAnnotationCaret(annot));
- }
- else if (annotationName.equals("freetext"))
- {
- annotList.add(new FDFAnnotationFreeText(annot));
- }
- else if (annotationName.equals("fileattachment"))
- {
- annotList.add(new FDFAnnotationFileAttachment(annot));
- }
- else if (annotationName.equals("highlight"))
- {
- annotList.add(new FDFAnnotationHighlight(annot));
- }
- else if (annotationName.equals("ink"))
- {
- annotList.add(new FDFAnnotationInk(annot));
- }
- else if (annotationName.equals("line"))
- {
- annotList.add(new FDFAnnotationLine(annot));
- }
- else if (annotationName.equals("link"))
- {
- annotList.add(new FDFAnnotationLink(annot));
- }
- else if (annotationName.equals("circle"))
- {
- annotList.add(new FDFAnnotationCircle(annot));
- }
- else if (annotationName.equals("square"))
- {
- annotList.add(new FDFAnnotationSquare(annot));
- }
- else if (annotationName.equals("polygon"))
- {
- annotList.add(new FDFAnnotationPolygon(annot));
- }
- else if (annotationName.equals("polyline"))
- {
- annotList.add(new FDFAnnotationPolyline(annot));
- }
- else if (annotationName.equals("sound"))
- {
- annotList.add(new FDFAnnotationSound(annot));
- }
- else if (annotationName.equals("squiggly"))
- {
- annotList.add(new FDFAnnotationSquiggly(annot));
- }
- else if (annotationName.equals("stamp"))
- {
- annotList.add(new FDFAnnotationStamp(annot));
- }
- else if (annotationName.equals("strikeout"))
- {
- annotList.add(new FDFAnnotationStrikeOut(annot));
- }
- else if (annotationName.equals("underline"))
+ try
{
- annotList.add(new FDFAnnotationUnderline(annot));
+ if (annotationName.equals("text"))
+ {
+ annotList.add(new FDFAnnotationText(annot));
+ }
+ else if (annotationName.equals("caret"))
+ {
+ annotList.add(new FDFAnnotationCaret(annot));
+ }
+ else if (annotationName.equals("freetext"))
+ {
+ annotList.add(new FDFAnnotationFreeText(annot));
+ }
+ else if (annotationName.equals("fileattachment"))
+ {
+ annotList.add(new FDFAnnotationFileAttachment(annot));
+ }
+ else if (annotationName.equals("highlight"))
+ {
+ annotList.add(new FDFAnnotationHighlight(annot));
+ }
+ else if (annotationName.equals("ink"))
+ {
+ annotList.add(new FDFAnnotationInk(annot));
+ }
+ else if (annotationName.equals("line"))
+ {
+ annotList.add(new FDFAnnotationLine(annot));
+ }
+ else if (annotationName.equals("link"))
+ {
+ annotList.add(new FDFAnnotationLink(annot));
+ }
+ else if (annotationName.equals("circle"))
+ {
+ annotList.add(new FDFAnnotationCircle(annot));
+ }
+ else if (annotationName.equals("square"))
+ {
+ annotList.add(new FDFAnnotationSquare(annot));
+ }
+ else if (annotationName.equals("polygon"))
+ {
+ annotList.add(new FDFAnnotationPolygon(annot));
+ }
+ else if (annotationName.equals("polyline"))
+ {
+ annotList.add(new FDFAnnotationPolyline(annot));
+ }
+ else if (annotationName.equals("sound"))
+ {
+ annotList.add(new FDFAnnotationSound(annot));
+ }
+ else if (annotationName.equals("squiggly"))
+ {
+ annotList.add(new FDFAnnotationSquiggly(annot));
+ }
+ else if (annotationName.equals("stamp"))
+ {
+ annotList.add(new FDFAnnotationStamp(annot));
+ }
+ else if (annotationName.equals("strikeout"))
+ {
+ annotList.add(new FDFAnnotationStrikeOut(annot));
+ }
+ else if (annotationName.equals("underline"))
+ {
+ annotList.add(new FDFAnnotationUnderline(annot));
+ }
+ else
+ {
+ LOG.warn("Unknown or unsupported annotation type '" + annotationName + "'" );
+ }
}
- else
+ catch (IOException e)
{
- LOG.warn("Unknown or unsupported annotation type '" + annotationName + "'" );
+ LOG.warn("Error parsing annotation information ["
+ + annot.getNodeValue() + "]. Annotation ignored", e);
}
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java?rev=1683241&r1=1683240&r2=1683241&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java Wed Jun 3 06:55:00 2015
@@ -51,7 +51,7 @@ public class FDFDocument implements Clos
*
* @throws IOException If there is an error creating this document.
*/
- public FDFDocument() throws IOException
+ public FDFDocument()
{
document = new COSDocument();
document.setVersion( 1.2f );