Skip to content

Commit c81c2ab

Browse files
introfogUbuntu
authored andcommitted
Add javadocs to tagutils classes
DEVSIX-6057
1 parent 5dbe948 commit c81c2ab

File tree

3 files changed

+104
-6
lines changed

3 files changed

+104
-6
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/tagutils/DefaultAccessibilityProperties.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.kernel.pdf.tagutils;
4545

4646
import com.itextpdf.kernel.pdf.tagging.PdfNamespace;
47+
import com.itextpdf.kernel.pdf.tagging.PdfStructElem;
4748
import com.itextpdf.kernel.pdf.tagging.PdfStructureAttributes;
49+
4850
import java.util.ArrayList;
4951
import java.util.Collections;
5052
import java.util.List;
5153

54+
/**
55+
* The class represents a default accessibility properties which correspond specified role. Accessibility
56+
* properties are used to define properties of {@link PdfStructElem structure elements} in Tagged PDF documents.
57+
*/
5258
public class DefaultAccessibilityProperties extends AccessibilityProperties {
53-
54-
5559
protected String role;
5660
protected String language;
5761
protected String actualText;
@@ -64,6 +68,11 @@ public class DefaultAccessibilityProperties extends AccessibilityProperties {
6468
protected PdfNamespace namespace;
6569
protected List<TagTreePointer> refs = new ArrayList<>();
6670

71+
/**
72+
* Instantiates a new {@link DefaultAccessibilityProperties} instance based on structure element role.
73+
*
74+
* @param role the structure element role
75+
*/
6776
public DefaultAccessibilityProperties(String role) {
6877
this.role = role;
6978
}

kernel/src/main/java/com/itextpdf/kernel/pdf/tagutils/TagReference.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.kernel.pdf.PdfDictionary;
4747
import com.itextpdf.kernel.pdf.PdfName;
4848
import com.itextpdf.kernel.pdf.PdfObject;
49+
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
4950
import com.itextpdf.kernel.pdf.tagging.PdfStructElem;
5051

52+
/**
53+
* The class is used to provide connection between structure element of
54+
* Tagged PDF document and marked content sequence in PDF stream.
55+
*
56+
* <p>
57+
* See {@link TagTreePointer#getTagReference(int)} and {@link PdfCanvas#openTag(TagReference)}.
58+
*/
5159
public class TagReference {
5260
protected TagTreePointer tagPointer;
5361
protected int insertIndex;
@@ -56,21 +64,48 @@ public class TagReference {
5664
protected PdfName role;
5765
protected PdfDictionary properties;
5866

67+
/**
68+
* Creates a {@link TagReference} instance which represents a reference to {@link PdfStructElem}.
69+
*
70+
* @param referencedTag a structure element to which marked content will link (if insertIndex is -1,
71+
* otherwise to MC will link to kid with insertIndex of passed structure element)
72+
* @param tagPointer the tag pointer to structure element
73+
* @param insertIndex if insertIndex is -1, the referencedTag will be used as a
74+
* source of reference, otherwise the kid will be used
75+
*/
5976
protected TagReference(PdfStructElem referencedTag, TagTreePointer tagPointer, int insertIndex) {
6077
this.role = referencedTag.getRole();
6178
this.referencedTag = referencedTag;
6279
this.tagPointer = tagPointer;
6380
this.insertIndex = insertIndex;
6481
}
6582

83+
/**
84+
* Gets role of structure element.
85+
*
86+
* @return the role of structure element
87+
*/
6688
public PdfName getRole() {
6789
return role;
6890
}
6991

92+
/**
93+
* Creates next marked content identifier, which will be used to mark content in PDF stream.
94+
*
95+
* @return the marked content identifier
96+
*/
7097
public int createNextMcid() {
7198
return tagPointer.createNextMcidForStructElem(referencedTag, insertIndex);
7299
}
73100

101+
/**
102+
* Adds property, which will be associated with marked-content sequence.
103+
*
104+
* @param name the name of the property
105+
* @param value the value of the property
106+
*
107+
* @return the {@link TagReference} instance
108+
*/
74109
public TagReference addProperty(PdfName name, PdfObject value) {
75110
if (properties == null) {
76111
properties = new PdfDictionary();
@@ -80,20 +115,39 @@ public TagReference addProperty(PdfName name, PdfObject value) {
80115
return this;
81116
}
82117

118+
/**
119+
* Removes property. The property will not be associated with marked-content sequence.
120+
*
121+
* @param name the name of property to be deleted
122+
*
123+
* @return the {@link TagReference} instance
124+
*/
83125
public TagReference removeProperty(PdfName name) {
84126
if (properties != null) {
85127
properties.remove(name);
86128
}
87129
return this;
88130
}
89131

132+
/**
133+
* Gets property which related to specified name.
134+
*
135+
* @param name the name of the property
136+
*
137+
* @return the value of the property
138+
*/
90139
public PdfObject getProperty(PdfName name) {
91140
if (properties == null) {
92141
return null;
93142
}
94143
return properties.get(name);
95144
}
96145

146+
/**
147+
* Gets properties, which will be associated with marked-content sequence as {@link PdfDictionary}.
148+
*
149+
* @return the properties
150+
*/
97151
public PdfDictionary getProperties() {
98152
return properties;
99153
}

kernel/src/main/java/com/itextpdf/kernel/pdf/tagutils/TagStructureContext.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ This file is part of the iText (R) project.
4444
package com.itextpdf.kernel.pdf.tagutils;
4545

4646
import com.itextpdf.io.logs.IoLogMessageConstant;
47-
import com.itextpdf.kernel.exceptions.PdfException;
4847
import com.itextpdf.kernel.exceptions.KernelExceptionMessageConstant;
48+
import com.itextpdf.kernel.exceptions.PdfException;
4949
import com.itextpdf.kernel.pdf.PdfArray;
5050
import com.itextpdf.kernel.pdf.PdfDictionary;
5151
import com.itextpdf.kernel.pdf.PdfDocument;
@@ -64,7 +64,6 @@ This file is part of the iText (R) project.
6464
import com.itextpdf.kernel.pdf.tagging.StandardNamespaces;
6565
import com.itextpdf.kernel.pdf.tagging.StandardRoles;
6666

67-
6867
import java.text.MessageFormat;
6968
import java.util.ArrayList;
7069
import java.util.Collection;
@@ -119,6 +118,7 @@ public class TagStructureContext {
119118
* <br>
120119
* Creates {@code TagStructureContext} for document. There shall be only one instance of this
121120
* class per {@code PdfDocument}.
121+
*
122122
* @param document the document which tag structure will be manipulated with this class.
123123
*/
124124
public TagStructureContext(PdfDocument document) {
@@ -128,9 +128,11 @@ public TagStructureContext(PdfDocument document) {
128128
/**
129129
* Do not use this constructor, instead use {@link PdfDocument#getTagStructureContext()}
130130
* method.
131+
*
131132
* <p>
132133
* Creates {@code TagStructureContext} for document. There shall be only one instance of this
133134
* class per {@code PdfDocument}.
135+
*
134136
* @param document the document which tag structure will be manipulated with this class.
135137
* @param tagStructureTargetVersion the version of the pdf standard to which the tag structure shall adhere.
136138
*/
@@ -156,14 +158,21 @@ public TagStructureContext(PdfDocument document, PdfVersion tagStructureTargetVe
156158
* If forbidUnknownRoles is set to true, then if you would try to add new tag which has not a standard role and
157159
* it's role is not mapped through RoleMap, an exception will be raised.
158160
* Default value - true.
161+
*
159162
* @param forbidUnknownRoles new value of the flag
163+
*
160164
* @return current {@link TagStructureContext} instance.
161165
*/
162166
public TagStructureContext setForbidUnknownRoles(boolean forbidUnknownRoles) {
163167
this.forbidUnknownRoles = forbidUnknownRoles;
164168
return this;
165169
}
166170

171+
/**
172+
* Gets the version of the PDF standard to which the tag structure shall adhere.
173+
*
174+
* @return the tag structure target version
175+
*/
167176
public PdfVersion getTagStructureTargetVersion() {
168177
return tagStructureTargetVersion;
169178
}
@@ -174,6 +183,7 @@ public PdfVersion getTagStructureTargetVersion() {
174183
* Typically it points at the root tag. This pointer also could be used to tweak auto tagging process
175184
* (e.g. move this pointer to the Section tag, which would result in placing all automatically tagged content
176185
* under Section tag).
186+
*
177187
* @return the {@code TagTreePointer} which is used for all automatic tagging of the document.
178188
*/
179189
public TagTreePointer getAutoTaggingPointer() {
@@ -186,6 +196,7 @@ public TagTreePointer getAutoTaggingPointer() {
186196
/**
187197
* Gets {@link WaitingTagsManager} for the current document. It allows to mark tags as waiting,
188198
* which would indicate that they are incomplete and are not ready to be flushed.
199+
*
189200
* @return document's {@link WaitingTagsManager} class instance.
190201
*/
191202
public WaitingTagsManager getWaitingTagsManager() {
@@ -199,8 +210,10 @@ public WaitingTagsManager getWaitingTagsManager() {
199210
* <p>
200211
* By default, this value is defined based on the PDF document version and the existing tag structure inside
201212
* a document. For the new empty PDF 2.0 documents this namespace is set to {@link StandardNamespaces#PDF_2_0}.
213+
*
202214
* <p>
203215
* This value has meaning only for the PDF documents of version <b>2.0 and higher</b>.
216+
*
204217
* @return a {@link PdfNamespace} which is used as a default value for the document tagging.
205218
*/
206219
public PdfNamespace getDocumentDefaultNamespace() {
@@ -210,16 +223,19 @@ public PdfNamespace getDocumentDefaultNamespace() {
210223
/**
211224
* Sets a namespace that will be used as a default value for the tagging for any new {@link TagTreePointer} created.
212225
* See {@link #getDocumentDefaultNamespace()} for more info.
226+
*
213227
* <p>
214228
* Be careful when changing this property value. It is most recommended to do it right after the {@link PdfDocument} was
215229
* created, before any content was added. Changing this value after any content was added might result in the mingled
216230
* tag structure from the namespaces point of view. So in order to maintain the document consistent but in the namespace
217231
* different from default, set this value before any modifications to the document were made and before
218232
* {@link #getAutoTaggingPointer()} method was called for the first time.
233+
*
219234
* <p>
220235
* This value has meaning only for the PDF documents of version <b>2.0 and higher</b>.
221236
*
222237
* @param namespace a {@link PdfNamespace} which is to be used as a default value for the document tagging.
238+
*
223239
* @return current {@link TagStructureContext} instance.
224240
*/
225241
public TagStructureContext setDocumentDefaultNamespace(PdfNamespace namespace) {
@@ -229,6 +245,7 @@ public TagStructureContext setDocumentDefaultNamespace(PdfNamespace namespace) {
229245

230246
/**
231247
* This method defines a recommended way to obtain {@link PdfNamespace} class instances.
248+
*
232249
* <p>
233250
* Returns either a wrapper over an already existing namespace dictionary in the document or over a new one
234251
* if such namespace wasn't encountered before. Calling this method is considered as encountering a namespace,
@@ -239,6 +256,7 @@ public TagStructureContext setDocumentDefaultNamespace(PdfNamespace namespace) {
239256
* {@link PdfName#Namespaces /Namespaces} array unless they were set to the certain element of the tag structure.
240257
*
241258
* @param namespaceName a {@link String} defining the namespace name (conventionally a uniform resource identifier, or URI).
259+
*
242260
* @return {@link PdfNamespace} wrapper over either already existing namespace object or over the new one.
243261
*/
244262
public PdfNamespace fetchNamespace(String namespaceName) {
@@ -254,7 +272,9 @@ public PdfNamespace fetchNamespace(String namespaceName) {
254272
/**
255273
* Gets an instance of the {@link IRoleMappingResolver} corresponding to the current tag structure target version.
256274
* This method implies that role is in the default standard structure namespace.
275+
*
257276
* @param role a role in the default standard structure namespace which mapping is to be resolved.
277+
*
258278
* @return a {@link IRoleMappingResolver} instance, with the giving role as current.
259279
*/
260280
public IRoleMappingResolver getRoleMappingResolver(String role) {
@@ -263,8 +283,10 @@ public IRoleMappingResolver getRoleMappingResolver(String role) {
263283

264284
/**
265285
* Gets an instance of the {@link IRoleMappingResolver} corresponding to the current tag structure target version.
286+
*
266287
* @param role a role in the given namespace which mapping is to be resolved.
267288
* @param namespace a {@link PdfNamespace} which this role belongs to.
289+
*
268290
* @return a {@link IRoleMappingResolver} instance, with the giving role in the given {@link PdfNamespace} as current.
269291
*/
270292
public IRoleMappingResolver getRoleMappingResolver(String role, PdfNamespace namespace) {
@@ -278,9 +300,11 @@ public IRoleMappingResolver getRoleMappingResolver(String role, PdfNamespace nam
278300
/**
279301
* Checks if the given role and namespace are specified to be obligatory mapped to the standard structure namespace
280302
* in order to be a valid role in the Tagged PDF.
303+
*
281304
* @param role a role in the given namespace which mapping necessity is to be checked.
282305
* @param namespace a {@link PdfNamespace} which this role belongs to, null value refers to the default standard
283306
* structure namespace.
307+
*
284308
* @return true, if the given role in the given namespace is either mapped to the standard structure role or doesn't
285309
* have to; otherwise false.
286310
*/
@@ -290,10 +314,13 @@ public boolean checkIfRoleShallBeMappedToStandardRole(String role, PdfNamespace
290314

291315
/**
292316
* Gets an instance of the {@link IRoleMappingResolver} which is already in the "resolved" state: it returns
293-
* role in the standard or domain-specific namespace for the {@link IRoleMappingResolver#getRole()} and {@link IRoleMappingResolver#getNamespace()}
294-
* methods calls which correspond to the mapping of the given role; or null if the given role is not mapped to the standard or domain-specific one.
317+
* role in the standard or domain-specific namespace for the {@link IRoleMappingResolver#getRole()} and
318+
* {@link IRoleMappingResolver#getNamespace()} methods calls which correspond to the mapping of the given role;
319+
* or null if the given role is not mapped to the standard or domain-specific one.
320+
*
295321
* @param role a role in the given namespace which mapping is to be resolved.
296322
* @param namespace a {@link PdfNamespace} which this role belongs to.
323+
*
297324
* @return an instance of the {@link IRoleMappingResolver} which returns false
298325
* for the {@link IRoleMappingResolver#currentRoleShallBeMappedToStandard()} method call; if mapping cannot be resolved
299326
* to this state, this method returns null, which means that the given role
@@ -323,6 +350,7 @@ public IRoleMappingResolver resolveMappingToStandardOrDomainSpecificRole(String
323350
* If annotation is not added to the document or is not tagged, nothing will happen.
324351
*
325352
* @param annotation the {@link PdfAnnotation} that will be removed from the tag structure
353+
*
326354
* @return {@link TagTreePointer} instance which points at annotation tag parent if annotation was removed,
327355
* otherwise returns null
328356
*/
@@ -353,8 +381,10 @@ public TagTreePointer removeAnnotationTag(PdfAnnotation annotation) {
353381
* Removes content item from the tag structure.
354382
* <br>
355383
* Nothing happens if there is no such mcid on given page.
384+
*
356385
* @param page page, which contains this content item
357386
* @param mcid marked content id of this content item
387+
*
358388
* @return {@code TagTreePointer} which points at the parent of the removed content item, or null if there is no
359389
* such mcid on given page.
360390
*/
@@ -374,6 +404,7 @@ public TagTreePointer removeContentItem(PdfPage page, int mcid) {
374404
* at {@link #flushPageTags(PdfPage)}.
375405
*
376406
* @param page page that defines which tags are to be removed
407+
*
377408
* @return current {@link TagStructureContext} instance
378409
*/
379410
public TagStructureContext removePageTags(PdfPage page) {
@@ -402,6 +433,7 @@ public TagStructureContext removePageTags(PdfPage page) {
402433
* as not yet finished ones, and they and their children won't be flushed.
403434
*
404435
* @param page a page which tags will be flushed
436+
*
405437
* @return current {@link TagStructureContext} instance
406438
*/
407439
public TagStructureContext flushPageTags(PdfPage page) {
@@ -474,6 +506,7 @@ public void prepareToDocumentClosing() {
474506
* especially in conjunction with high level {@link TagTreePointer} and {@link TagStructureContext} classes.
475507
*
476508
* @param pointer a {@link TagTreePointer} which points at desired {@link PdfStructElem}.
509+
*
477510
* @return a {@link PdfStructElem} at which given {@link TagTreePointer} points.
478511
*/
479512
public PdfStructElem getPointerStructElem(TagTreePointer pointer) {
@@ -482,7 +515,9 @@ public PdfStructElem getPointerStructElem(TagTreePointer pointer) {
482515

483516
/**
484517
* Creates a new {@link TagTreePointer} which points at given {@link PdfStructElem}.
518+
*
485519
* @param structElem a {@link PdfStructElem} for which {@link TagTreePointer} will be created.
520+
*
486521
* @return a new {@link TagTreePointer}.
487522
*/
488523
public TagTreePointer createPointerForStructElem(PdfStructElem structElem) {

0 commit comments

Comments
 (0)