public class EventBuilder extends Object implements Iterator<Event>
EventBuilder allows filter writers to think in terms of start and end calls. For example, to produce a
non-translatable Event you would use startDocumentPart() and endDocumentPart(). For a text-based
Event you would use startTextUnit() and endTextUnit().
More complex cases such as tags with embedded translatable text can also be handled. See the AbstractMarkupFilter, HtmlFilter and OpenXmlFilter for examples of using EventBuilder.
| Constructor and Description |
|---|
EventBuilder()
Instantiates a new EventBuilder.
|
EventBuilder(String rootId,
IFilter filter)
Instantiates a new EventBuilder with a root ID.
|
| Modifier and Type | Method and Description |
|---|---|
DocumentPart |
addDocumentPart(String part)
|
void |
addFilterEvent(Event event)
|
void |
addFilterEvents(List<Event> events)
|
void |
addTextUnit(String text)
Start and end a
TextUnit. |
void |
addToDocumentPart(String part)
Add to the current
DocumentPart. |
void |
addToTextUnit(Code code)
|
void |
addToTextUnit(Code code,
boolean endCodeNow)
|
void |
addToTextUnit(Code code,
boolean endCodeNow,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
|
void |
addToTextUnit(Code code,
boolean endCodeNow,
LocaleId locale,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
|
void |
addToTextUnit(String text)
Adds text to the current
TextUnit |
void |
appendCodeInlineExcludedData(String data)
append to the current
Code's data |
void |
appendCodeOuterData(String outerData)
append to the current
Code's outerData |
void |
appendToFirstSkeletonPart(String text)
Appends text to the first data part of the skeleton.
|
void |
appendToSkeleton(GenericSkeleton part)
Appends text to the first data part of the skeleton.
|
void |
cancel()
Cancel current processing and add the CANCELED
Event to the event queue. |
boolean |
canStartNewTextUnit()
|
void |
convertTempTextUnitToDocumentPart()
Convert the skeleton attached to an in-progress
TextUnit into
a DocumentPart. |
void |
endCode() |
void |
endCode(String tag) |
void |
endDocumentPart()
End the
DocumentPart and finalize the Event. |
void |
endDocumentPart(String part)
End the current
DocumentPart and finalize the Event. |
Ending |
endGroup(GenericSkeleton endMarker)
|
Ending |
endGroup(GenericSkeleton endMarker,
LocaleId locale,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
|
void |
endSubDocument()
Add the END_SUBDOCUMENT
Event to the event queue. |
ITextUnit |
endTextUnit()
|
ITextUnit |
endTextUnit(GenericSkeleton endMarker)
|
ITextUnit |
endTextUnit(GenericSkeleton endMarker,
LocaleId locale,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
|
String |
findMostRecentParentId() |
String |
findMostRecentParentName() |
String |
findMostRecentTextUnitName()
Find in our buffered queue the most recent TextUnit
that has an assigned name
|
void |
flushRemainingTempEvents()
Flush all remaining events from the
Event temp queue |
Code |
getCurrentCode()
Get the current
Code. |
long |
getDocumentPartId()
Gets the current custom
DocumentPart id. |
IdGenerator |
getGroupId()
Get the
IdGenerator for Groups |
long |
getGroupIdSequence() |
String |
getRootId()
Get the current root id
|
IdGenerator |
getSubDocumentId()
Get the
IdGenerator for SubDocuments |
long |
getTextUnitId()
Gets the custom textUnitId set by the caller.
|
boolean |
hasNext()
Are we finished parsing the input document?
|
boolean |
hasParentTextUnit()
Does the current
TextUnit have a parent? |
boolean |
hasQueuedEvents()
Are there any queued events? We queue events in the correct order as expected by the Okapi filter writers
(IWriter).
|
boolean |
hasUnfinishedSkeleton()
Is there an unfinished
DocumentPart (aka skeleton)? |
boolean |
isCurrentComplexTextUnit()
|
boolean |
isCurrentGroup()
Is the current buffered
Event a StartGroup? |
boolean |
isCurrentSubfilter()
Is the current buffered
Event a StartSubfilter? |
boolean |
isCurrentTextUnit()
|
boolean |
isInsideTextRun()
Is the filter is inside text run?
|
boolean |
isPreserveWhitespace()
What is the current preserve whitespace state?
|
boolean |
isTextUnitWithSameType(String type)
Is the current TextUnit of the specified type?
|
Event |
next()
Return the next filter event waiting in the event queue.
|
Code |
peekMostRecentCode()
Peek at the most recently created
StartGroup. |
StartGroup |
peekMostRecentGroup()
Peek at the most recently created
StartGroup or StartSubfilter. |
StartSubDocument |
peekMostRecentSubDocument()
Peek at the most recently created
StartSubDocument |
ITextUnit |
peekMostRecentTextUnit()
Peek At the most recently created
TextUnit. |
Event |
peekTempEvent() |
Event |
popTempEvent() |
protected ITextUnit |
postProcessTextUnit(ITextUnit textUnit)
Do any required post-processing on the TextUnit after endTextUnit is called.
|
void |
reset(String rootId,
IFilter filter) |
void |
setDocumentPartId(long id)
Set the current custom
DocumentPart id. |
void |
setGroupIdSequence(long id) |
void |
setMimeType(String mimeType)
Sets the input document mime type.
|
void |
setPreserveWhitespace(boolean preserveWhitespace)
Tell the
IFilter what to do with whitespace. |
void |
setTextUnitId(long id)
Set the current textUnitId.
|
void |
setTextUnitMimeType(String mimeType)
Set the mime type on the current
TextUnit |
void |
setTextUnitName(String name)
Set the current
TextUnit name. |
void |
setTextUnitPreserveWhitespace(boolean preserveWhitespace)
Set preserve whitespace flag on current
TextUnit |
void |
setTextUnitTranslatable(boolean translatable)
Set the current
TextUnit translatable flag. |
void |
setTextUnitType(String type)
Set the current
TextUnit type. |
void |
startCode(Code code) |
DocumentPart |
startDocumentPart(String part)
Create a
DocumentPart and store it for later processing. |
void |
startDocumentPart(String part,
String name,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Create a
DocumentPart that references actionable (i.e., translatable, localizable) properties and store
it for later processing. |
void |
startDocumentPart(String part,
String name,
LocaleId locale,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Create a
DocumentPart that references actionable (i.e., translatable, localizable) properties and store
it for later processing. |
StartGroup |
startGroup(GenericSkeleton startMarker,
String commonTagType)
Create a
StartGroup Event and add it to the event queue. |
StartGroup |
startGroup(GenericSkeleton startMarker,
String commonTagType,
LocaleId locale,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Create a
StartGroup Event and add it to the event queue. |
StartSubDocument |
startSubDocument()
Add the START_SUBDOCUMENT
Event to the event queue. |
void |
startTextUnit()
Start a
TextUnit. |
void |
startTextUnit(GenericSkeleton startMarker)
Start a complex
TextUnit. |
void |
startTextUnit(GenericSkeleton startMarker,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Start a complex
TextUnit with actionable (translatable, writable or read-only) attributes. |
void |
startTextUnit(String text)
Start a
TextUnit. |
void |
startTextUnit(String text,
GenericSkeleton startMarker,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Start a complex
TextUnit with actionable (translatable, writable or read-only) attributes. |
void |
startTextUnit(String text,
GenericSkeleton startMarker,
LocaleId locale,
List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Start a complex
TextUnit with actionable (translatable, writable or read-only) attributes. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemaining, removepublic boolean hasNext()
public Event next()
public void addFilterEvent(Event event)
Event at the end of the current Event queue.
Assume all child events have already been added in case of an IReferenceable Event
as all children events must come before their parent reference.event - The Event to be addedpublic void addFilterEvents(List<Event> events)
Event at the end of the current Event queue.
Assume all child events have already been added in case of an IReferenceable Event
as all children events must come before their parent reference.events - The list of Event to be addedpublic void cancel()
Event to the event queue.public Event peekTempEvent()
public Event popTempEvent()
public void flushRemainingTempEvents()
Event temp queuepublic boolean isCurrentTextUnit()
public boolean isCurrentComplexTextUnit()
Event a complex TextUnit? A complex TextUnit is one which carries along
with it it's surrounding formatting or skeleton such <p> text </p> or <title> text </title>Event is a complex text unit, false otherwise.public boolean isCurrentGroup()
Event a StartGroup?Event is a StartGrouppublic boolean isCurrentSubfilter()
Event a StartSubfilter?Event is a StartSubfilterpublic boolean isInsideTextRun()
public boolean canStartNewTextUnit()
TextUnit? A new TextUnit can only be started if the current one has been ended
with endTextUnit. Or no TextUnit has been created yet.TextUnitpublic boolean hasQueuedEvents()
public String findMostRecentParentId()
public String findMostRecentParentName()
public String findMostRecentTextUnitName()
public StartGroup peekMostRecentGroup()
StartGroup or StartSubfilter.public StartSubDocument peekMostRecentSubDocument()
StartSubDocumentpublic ITextUnit peekMostRecentTextUnit()
TextUnit.public Code peekMostRecentCode()
StartGroup.public boolean hasUnfinishedSkeleton()
DocumentPart (aka skeleton)?public boolean hasParentTextUnit()
TextUnit have a parent?public void reset(String rootId, IFilter filter)
rootId - new root id (can be null or empty)filter - subfilter to use (can be null)
Reset IFilter for a new input. Callers should reset the EventBuilder for each input.public StartSubDocument startSubDocument()
Event to the event queue.StartSubDocument created and added,
or null if there is no subFilterpublic void endSubDocument()
Event to the event queue.public void addTextUnit(String text)
text - the text used to prime the TextUnitpublic void startTextUnit(String text)
text - the text used to prime the TextUnitpublic void startTextUnit()
public void startTextUnit(GenericSkeleton startMarker)
startMarker - the tag that begins the complex TextUnitpublic void startTextUnit(GenericSkeleton startMarker, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
public void startTextUnit(String text, GenericSkeleton startMarker, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
public void startTextUnit(String text, GenericSkeleton startMarker, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
public void convertTempTextUnitToDocumentPart()
TextUnit into
a DocumentPart. This is used when a TextUnit has been started
but then is immediately ended without any content. The final skeleton
part in the TU is always a self-reference, which is stripped during
the conversion.public ITextUnit endTextUnit(GenericSkeleton endMarker)
public ITextUnit endTextUnit(GenericSkeleton endMarker, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
endMarker - the tag that ends the complex TextUnitlocale - the locale of the textpropertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.TextUnitOkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void addToTextUnit(String text)
TextUnittext - the textOkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void addToTextUnit(Code code)
Code to the current TextUnit. Nothing is actionable within the tag (i.e., no properties or
translatable, localizable text)code - the code typeOkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void addToTextUnit(Code code, boolean endCodeNow)
Code to the current TextUnit. Nothing is actionable within the tag (i.e., no properties or
translatable, localizable text)code - the code typeendCodeNow - do we end the code now or delay?OkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void addToTextUnit(Code code, boolean endCodeNow, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Code to the current TextUnit. The Code contains actionable (i.e., translatable,
localizable) attributes.code - the codeendCodeNow - do we end the code now or delay?propertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.public void addToTextUnit(Code code, boolean endCodeNow, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
Code to the current TextUnit. The Code contains actionable (i.e., translatable,
localizable) attributes.code - the codeendCodeNow - do we end the code now or delay?locale - the language of the textpropertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.OkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void appendToFirstSkeletonPart(String text)
text - the text to happend.OkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void appendToSkeleton(GenericSkeleton part)
text - the text to happend.OkapiIllegalFilterOperationException - if we try to perform an invalid operation.public StartGroup startGroup(GenericSkeleton startMarker, String commonTagType)
StartGroup Event and add it to the event queue.startMarker - the tag which starts the groupcommonTagType - the tag name or abstract type for this group.public StartGroup startGroup(GenericSkeleton startMarker, String commonTagType, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
StartGroup Event and add it to the event queue.startMarker - the tag which starts the group.commonTagType - the tag name or abstract type for this group.locale - the language of any actionable itemspropertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.public Ending endGroup(GenericSkeleton endMarker)
endMarker - the tags that ends the group.public Ending endGroup(GenericSkeleton endMarker, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
endMarker - the tags that ends the group.locale - the language of any actionable itemspropertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.OkapiIllegalFilterOperationException - if we try to perform an invalid operation.public void startCode(Code code)
public void endCode()
public void endCode(String tag)
public void appendCodeOuterData(String outerData)
Code's outerDataouterData - the outerData to appendpublic void appendCodeInlineExcludedData(String data)
Code's datadata - the data to appendpublic DocumentPart addDocumentPart(String part)
part - the DocumentPart (aka skeleton)public DocumentPart startDocumentPart(String part)
DocumentPart and store it for later processing.part - the DocumentPart (aka skeleton)public void startDocumentPart(String part, String name, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
DocumentPart that references actionable (i.e., translatable, localizable) properties and store
it for later processing.part - the DocumentPart (aka skeleton)name - the namepropertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.public void startDocumentPart(String part, String name, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders)
DocumentPart that references actionable (i.e., translatable, localizable) properties and store
it for later processing.part - the DocumentPart (aka skeleton)name - the namelocale - the language of any actionable itemspropertyTextUnitPlaceholders - the list of actionable TextUnit or Properties with offset information into the tag.public void endDocumentPart(String part)
part - the DocumentPart (aka skeleton)public void endDocumentPart()
public void addToDocumentPart(String part)
DocumentPart.part - the DocumentPart as a String.public void setMimeType(String mimeType)
mimeType - the new mime typepublic void setTextUnitMimeType(String mimeType)
TextUnitmimeType - - mime typepublic void setPreserveWhitespace(boolean preserveWhitespace)
IFilter what to do with whitespace.preserveWhitespace - the preserveWhitespace as boolean.public void setTextUnitPreserveWhitespace(boolean preserveWhitespace)
TextUnitpreserveWhitespace - the preserveWhitespace as boolean.public boolean isPreserveWhitespace()
public long getTextUnitId()
public void setTextUnitId(long id)
id - the initial value for the textUnitIdpublic void setTextUnitName(String name)
TextUnit name.name - the name (resname in XLIFF) of the TextUnitNullPointerException - if there is no current TextUnitpublic void setTextUnitType(String type)
TextUnit type. If there is no defined type the type is the element name.type - - the TextUnit type.public void setTextUnitTranslatable(boolean translatable)
TextUnit translatable flag.translatable - - the TextUnit translatable flag.public long getDocumentPartId()
DocumentPart id.public void setDocumentPartId(long id)
DocumentPart id. Note that using this method overrides the built-in id creation
algorithm. Useful for some callers that wish to create custom ids.id - the initial value for the textUnitIdpublic String getRootId()
protected ITextUnit postProcessTextUnit(ITextUnit textUnit)
public boolean isTextUnitWithSameType(String type)
public IdGenerator getGroupId()
IdGenerator for GroupsIdGeneratorpublic long getGroupIdSequence()
public void setGroupIdSequence(long id)
public IdGenerator getSubDocumentId()
IdGenerator for SubDocumentsIdGeneratorCopyright © 2022. All rights reserved.