Author: tilman
Date: Mon Apr 7 07:30:24 2025
New Revision: 1924887
URL: http://svn.apache.org/viewvc?rev=1924887&view=rev
Log:
PDFBOX-5660: refactor
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java?rev=1924887&r1=1924886&r2=1924887&view=diff
==============================================================================
---
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
(original)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
Mon Apr 7 07:30:24 2025
@@ -164,16 +164,17 @@ public class FDFAnnotationStamp extends
if (node instanceof Element)
{
Element child = (Element) node;
- if ("STREAM".equalsIgnoreCase(child.getTagName()))
+ String childTagName = child.getTagName();
+ if ("STREAM".equalsIgnoreCase(childTagName))
{
LOG.debug("{} => Process {} item in the dictionary after
processing the {}",
- parentAttrKey, child.getAttribute("KEY"),
child.getTagName());
+ parentAttrKey, child.getAttribute("KEY"),
childTagName);
dictionary.setItem(child.getAttribute("KEY"),
parseStreamElement(child));
LOG.debug("{} => Set {}", parentAttrKey,
child.getAttribute("KEY"));
}
else
{
- LOG.warn("{} => Not handling element: {}", parentAttrKey,
child.getTagName());
+ LOG.warn("{} => Not handling element: {}", parentAttrKey,
childTagName);
}
}
}
@@ -196,77 +197,75 @@ public class FDFAnnotationStamp extends
Element child = (Element) node;
String childAttrKey = child.getAttribute("KEY");
String childAttrVal = child.getAttribute("VAL");
- LOG.debug("{} => reading child: {} with key: {}", () ->
parentAttrKey, () -> child.getTagName(),
- () -> childAttrKey);
- if ("INT".equalsIgnoreCase(child.getTagName()))
- {
- if (!"Length".equals(childAttrKey))
- {
- stream.setInt(COSName.getPDFName(childAttrKey),
Integer.parseInt(childAttrVal));
- LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
- }
- }
- else if ("FIXED".equalsIgnoreCase(child.getTagName()))
- {
- stream.setFloat(COSName.getPDFName(childAttrKey),
Float.parseFloat(childAttrVal));
- LOG.debug("{} => Set {}: {}", parentAttrKey, childAttrKey,
childAttrVal);
- }
- else if ("NAME".equalsIgnoreCase(child.getTagName()))
- {
- stream.setName(COSName.getPDFName(childAttrKey),
childAttrVal);
- LOG.debug("{} => Set {}: {}", parentAttrKey, childAttrKey,
childAttrVal);
- }
- else if ("BOOL".equalsIgnoreCase(child.getTagName()))
- {
- stream.setBoolean(COSName.getPDFName(childAttrKey),
Boolean.parseBoolean(childAttrVal));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrVal);
- }
- else if ("ARRAY".equalsIgnoreCase(child.getTagName()))
- {
- stream.setItem(COSName.getPDFName(childAttrKey),
parseArrayElement(child));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
- }
- else if ("DICT".equalsIgnoreCase(child.getTagName()))
- {
- stream.setItem(COSName.getPDFName(childAttrKey),
parseDictElement(child));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
- }
- else if ("STREAM".equalsIgnoreCase(child.getTagName()))
+ String childTagName = child.getTagName();
+ LOG.debug("{} => reading child: {} with key: {}",
parentAttrKey, childTagName, childAttrKey);
+ if (childTagName == null)
{
- stream.setItem(COSName.getPDFName(childAttrKey),
parseStreamElement(child));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
+ LOG.warn("{} => Not handling child element: null",
parentAttrKey);
+ continue;
}
- else if ("DATA".equalsIgnoreCase(child.getTagName()))
+ switch (childTagName.toUpperCase())
{
- LOG.debug("{} => Handling DATA with encoding: {}",
parentAttrKey,
- child.getAttribute("ENCODING"));
- if ("HEX".equals(child.getAttribute("ENCODING")))
- {
- try (OutputStream os = stream.createRawOutputStream())
+ case "INT":
+ if (!"Length".equals(childAttrKey))
{
- os.write(Hex.decodeHex(child.getTextContent()));
- LOG.debug("{} => Data was streamed",
parentAttrKey);
+ stream.setInt(COSName.getPDFName(childAttrKey),
Integer.parseInt(childAttrVal));
+ LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
}
- }
- else if ("ASCII".equals(child.getAttribute("ENCODING")))
- {
- try (OutputStream os = stream.createOutputStream())
+ break;
+ case "FIXED":
+ stream.setFloat(COSName.getPDFName(childAttrKey),
Float.parseFloat(childAttrVal));
+ LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
+ break;
+ case "NAME":
+ stream.setName(COSName.getPDFName(childAttrKey),
childAttrVal);
+ LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
+ break;
+ case "BOOL":
+ stream.setBoolean(COSName.getPDFName(childAttrKey),
Boolean.parseBoolean(childAttrVal));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrVal);
+ break;
+ case "ARRAY":
+ stream.setItem(COSName.getPDFName(childAttrKey),
parseArrayElement(child));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
+ break;
+ case "DICT":
+ stream.setItem(COSName.getPDFName(childAttrKey),
parseDictElement(child));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
+ break;
+ case "STREAM":
+ stream.setItem(COSName.getPDFName(childAttrKey),
parseStreamElement(child));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
+ break;
+ case "DATA":
+ String childEncodingAttr =
child.getAttribute("ENCODING");
+ LOG.debug("{} => Handling DATA with encoding: {}",
parentAttrKey, childEncodingAttr);
+ if ("HEX".equals(childEncodingAttr))
{
- // not sure about charset
- os.write(child.getTextContent().getBytes());
- LOG.debug("{} => Data was streamed",
parentAttrKey);
+ try (OutputStream os =
stream.createRawOutputStream())
+ {
+
os.write(Hex.decodeHex(child.getTextContent()));
+ LOG.debug("{} => Data was streamed",
parentAttrKey);
+ }
}
- }
- else
- {
- LOG.warn("{} => Not handling element DATA encoding:
{}", parentAttrKey,
- child.getAttribute("ENCODING"));
- }
- }
- else
- {
- LOG.warn("{} => Not handling child element: {}",
parentAttrKey,
- child.getTagName());
+ else if ("ASCII".equals(childEncodingAttr))
+ {
+ try (OutputStream os = stream.createOutputStream())
+ {
+ // not sure about charset
+ os.write(child.getTextContent().getBytes());
+ LOG.debug("{} => Data was streamed",
parentAttrKey);
+ }
+ }
+ else
+ {
+ LOG.warn("{} => Not handling element DATA
encoding: {}", parentAttrKey,
+ childEncodingAttr);
+ }
+ break;
+ default:
+ LOG.warn("{} => Not handling child element: {}",
parentAttrKey, childTagName);
+ break;
}
}
}
@@ -301,42 +300,44 @@ public class FDFAnnotationStamp extends
Element child = (Element) node;
String childAttrKey = child.getAttribute("KEY");
String childAttrVal = child.getAttribute("VAL");
- LOG.debug("{} => reading child: {} with key: {}",
parentAttrKey, child.getTagName(),
+ String childTagName = child.getTagName();
+ LOG.debug("{} => reading child: {} with key: {}",
parentAttrKey, childTagName,
childAttrKey);
- if ("INT".equalsIgnoreCase(child.getTagName()) ||
"FIXED".equalsIgnoreCase(child.getTagName()))
- {
- LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
- array.add(COSNumber.get(childAttrVal));
- }
- else if ("NAME".equalsIgnoreCase(child.getTagName()))
- {
- LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
- array.add(COSName.getPDFName(childAttrVal));
- }
- else if ("BOOL".equalsIgnoreCase(child.getTagName()))
- {
- LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
-
array.add(COSBoolean.getBoolean(Boolean.parseBoolean(childAttrVal)));
- }
- else if ("DICT".equalsIgnoreCase(child.getTagName()))
- {
- LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
- array.add(parseDictElement(child));
- }
- else if ("STREAM".equalsIgnoreCase(child.getTagName()))
- {
- LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
- array.add(parseStreamElement(child));
- }
- else if ("ARRAY".equalsIgnoreCase(child.getTagName()))
+ if (null == childTagName)
{
- LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
- array.add(parseArrayElement(child));
+ LOG.warn("{} => Not handling child element: null",
parentAttrKey);
+ continue;
}
- else
+ switch (childTagName.toUpperCase())
{
- LOG.warn("{} => Not handling child element: {}",
parentAttrKey,
- child.getTagName());
+ case "INT":
+ case "FIXED":
+ LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
+ array.add(COSNumber.get(childAttrVal));
+ break;
+ case "NAME":
+ LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
+ array.add(COSName.getPDFName(childAttrVal));
+ break;
+ case "BOOL":
+ LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
+
array.add(COSBoolean.getBoolean(Boolean.parseBoolean(childAttrVal)));
+ break;
+ case "DICT":
+ LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
+ array.add(parseDictElement(child));
+ break;
+ case "STREAM":
+ LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
+ array.add(parseStreamElement(child));
+ break;
+ case "ARRAY":
+ LOG.debug("{} value({}): {}", parentAttrKey, i,
childAttrVal);
+ array.add(parseArrayElement(child));
+ break;
+ default:
+ LOG.warn("{} => Not handling child element: {}",
parentAttrKey, childTagName);
+ break;
}
}
}
@@ -360,51 +361,51 @@ public class FDFAnnotationStamp extends
Element child = (Element) node;
String childAttrKey = child.getAttribute("KEY");
String childAttrVal = child.getAttribute("VAL");
+ String childTagName = child.getTagName();
- if ("DICT".equals(child.getTagName()))
- {
- LOG.debug("{} => Handling DICT element with key: {}",
parentAttrKey,
- childAttrKey);
- dict.setItem(COSName.getPDFName(childAttrKey),
parseDictElement(child));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
- }
- else if ("STREAM".equals(child.getTagName()))
- {
- LOG.debug("{} => Handling STREAM element with key: {}",
parentAttrKey,
- childAttrKey);
- dict.setItem(COSName.getPDFName(childAttrKey),
parseStreamElement(child));
- }
- else if ("NAME".equals(child.getTagName()))
+ if (childTagName == null)
{
- LOG.debug("{} => Handling NAME element with key: {}",
parentAttrKey,
- childAttrKey);
- dict.setName(COSName.getPDFName(childAttrKey),
childAttrVal);
- LOG.debug("{} => Set {}: {}", parentAttrKey, childAttrKey,
childAttrVal);
+ LOG.warn("{} => NOT handling child element: null",
parentAttrKey);
+ continue;
}
- else if ("INT".equalsIgnoreCase(child.getTagName()))
+ switch (childTagName)
{
- dict.setInt(COSName.getPDFName(childAttrKey),
Integer.parseInt(childAttrVal));
- LOG.debug("{} => Set {}: {}", parentAttrKey, childAttrKey,
childAttrVal);
- }
- else if ("FIXED".equalsIgnoreCase(child.getTagName()))
- {
- dict.setFloat(COSName.getPDFName(childAttrKey),
Float.parseFloat(childAttrVal));
- LOG.debug("{} => Set {}: {}", parentAttrKey, childAttrKey,
childAttrVal);
- }
- else if ("BOOL".equalsIgnoreCase(child.getTagName()))
- {
- dict.setBoolean(COSName.getPDFName(childAttrKey),
Boolean.parseBoolean(childAttrVal));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrVal);
- }
- else if ("ARRAY".equalsIgnoreCase(child.getTagName()))
- {
- dict.setItem(COSName.getPDFName(childAttrKey),
parseArrayElement(child));
- LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
- }
- else
- {
- LOG.warn("{} => NOT handling child element: {}",
parentAttrKey,
- child.getTagName());
+ case "DICT":
+ LOG.debug("{} => Handling DICT element with key: {}",
parentAttrKey,
+ childAttrKey);
+ dict.setItem(COSName.getPDFName(childAttrKey),
parseDictElement(child));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
+ break;
+ case "STREAM":
+ LOG.debug("{} => Handling STREAM element with key:
{}", parentAttrKey,
+ childAttrKey);
+ dict.setItem(COSName.getPDFName(childAttrKey),
parseStreamElement(child));
+ break;
+ case "NAME":
+ LOG.debug("{} => Handling NAME element with key: {}",
parentAttrKey,
+ childAttrKey);
+ dict.setName(COSName.getPDFName(childAttrKey),
childAttrVal);
+ LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
+ break;
+ case "INT":
+ dict.setInt(COSName.getPDFName(childAttrKey),
Integer.parseInt(childAttrVal));
+ LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
+ break;
+ case "FIXED":
+ dict.setFloat(COSName.getPDFName(childAttrKey),
Float.parseFloat(childAttrVal));
+ LOG.debug("{} => Set {}: {}", parentAttrKey,
childAttrKey, childAttrVal);
+ break;
+ case "BOOL":
+ dict.setBoolean(COSName.getPDFName(childAttrKey),
Boolean.parseBoolean(childAttrVal));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrVal);
+ break;
+ case "ARRAY":
+ dict.setItem(COSName.getPDFName(childAttrKey),
parseArrayElement(child));
+ LOG.debug("{} => Set {}", parentAttrKey, childAttrKey);
+ break;
+ default:
+ LOG.warn("{} => NOT handling child element: {}",
parentAttrKey, childTagName);
+ break;
}
}
}