Skip to content

Commit 61e2b9b

Browse files
committed
PDFBOX-6073: Add option to implement custom ICOSVisitor behaviour for COSObject as suggested by jp-db; closes #255
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1928645 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7990cb8 commit 61e2b9b

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

pdfbox/src/main/java/org/apache/pdfbox/cos/COSObject.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,7 @@ public String toString()
160160
@Override
161161
public void accept( ICOSVisitor visitor ) throws IOException
162162
{
163-
COSBase object = getObject();
164-
if (object != null)
165-
{
166-
object.accept(visitor);
167-
}
168-
else
169-
{
170-
COSNull.NULL.accept(visitor);
171-
}
163+
visitor.visitFromObject(this);
172164
}
173165

174166
/**

pdfbox/src/main/java/org/apache/pdfbox/cos/ICOSVisitor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,12 @@ public interface ICOSVisitor
104104
* @throws IOException If there is an error while visiting this object.
105105
*/
106106
void visitFromString(COSString obj) throws IOException;
107+
108+
/**
109+
* Notification of visit to object.
110+
*
111+
* @param obj The Object that is being visited.
112+
* @throws IOException If there is an error while visiting this object.
113+
*/
114+
void visitFromObject(COSObject obj) throws IOException;
107115
}

pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,20 @@ public void visitFromString(COSString obj) throws IOException
14471447
}
14481448
}
14491449

1450+
@Override
1451+
public void visitFromObject(COSObject obj) throws IOException
1452+
{
1453+
COSBase base = obj.getObject();
1454+
if (base == null)
1455+
{
1456+
visitFromNull(COSNull.NULL);
1457+
}
1458+
else
1459+
{
1460+
base.accept(this);
1461+
}
1462+
}
1463+
14501464
/**
14511465
* This will write the pdf document.
14521466
*

0 commit comments

Comments
 (0)