private void handleDocumentPart(String part) { eventBuilder.addDocumentPart(part); }
/** * Add a {@link Code} to the current {@link TextUnit}. Nothing is actionable within the tag (i.e., no properties or * translatable, localizable text) * * @param code * the code type * * @throws OkapiIllegalFilterOperationException if we try to perform an invalid operation. */ public void addToTextUnit(Code code) { addToTextUnit(code, true); }
/** * Start and end a {@link TextUnit}. Also create a TextUnit {@link Event} and add it to the event queue. * * @param text * the text used to prime the {@link TextUnit} */ public void addTextUnit(String text) { startTextUnit(text, null, null, null); endTextUnit(); }
/** * Create a {@link DocumentPart} and store it for later processing. * * @param part * the {@link DocumentPart} (aka skeleton) * @return the newly created DocumentPart */ public DocumentPart startDocumentPart(String part) { if (hasUnfinishedSkeleton()) { endDocumentPart(); } else if (isCurrentTextUnit()) { endTextUnit(); } currentSkeleton = new GenericSkeleton(part); currentDocumentPart = new DocumentPart(documentPartId.createId(), false); currentDocumentPart.setSkeleton(currentSkeleton); return currentDocumentPart; }
if (hasUnfinishedSkeleton()) { endDocumentPart(); Event e = peekTempEvent(); if (e != null && e.getEventType() == EventType.TEXT_UNIT) { ITextUnit parentTu = e.getTextUnit(); if (parentTu.getSource().isEmpty()) { convertTempTextUnitToDocumentPart(); processAllEmbedded(startMarker.toString(), locale, propertyTextUnitPlaceholders, false, tu); tu.setSkeleton(currentSkeleton); currentSkeleton.addContentPlaceholder(tu);
/** * Flush all remaining events from the {@link Event} queues */ public void flushRemainingTempEvents() { if (hasUnfinishedSkeleton()) { endDocumentPart(); } else if (!tempFilterEventStack.isEmpty()) { // go through filtered object stack and close them one by one while (!tempFilterEventStack.isEmpty()) { Event fe = tempFilterEventStack.peek(); if (fe.getEventType() == EventType.START_GROUP) { StartGroup sg = (StartGroup) fe.getResource(); endGroup((GenericSkeleton) sg.getSkeleton()); } else if (fe.getEventType() == EventType.START_SUBFILTER) { StartSubfilter sf = (StartSubfilter) fe.getResource(); endGroup((GenericSkeleton) sf.getSkeleton()); } else if (fe.getEventType() == EventType.TEXT_UNIT) { endTextUnit(); } } } }
/** * Convert the skeleton attached to an in-progress {@link TextUnit} into * a {@link 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 void convertTempTextUnitToDocumentPart() { if (peekTempEvent().getEventType() != EventType.TEXT_UNIT) { return; } Event e = popTempEvent(); ITextUnit textUnit = (e.getTextUnit()); GenericSkeleton oldTuSkeleton = (GenericSkeleton)textUnit.getSkeleton(); if (oldTuSkeleton != null) { List<GenericSkeletonPart> parts = oldTuSkeleton.getParts(); // Skip the trailing [$$self$] reference StringBuilder sb = new StringBuilder(); for (int i = 0; i < parts.size() - 1; i++) { sb.append(parts.get(i).toString()); } addToDocumentPart(sb.toString()); endDocumentPart(); } }
/** * Is the current buffered {@link Event} a {@link StartGroup}? * * @return true, if current {@link Event} is a {@link StartGroup} */ public boolean isCurrentGroup() { Event e = peekTempEvent(); if (e != null && e.getEventType() == EventType.START_GROUP) { return true; } return false; }
if (!isCurrentGroup()) { if (endMarker != null) { addDocumentPart(endMarker.toString()); processAllEmbedded(endMarker.toString(), locale, propertyTextUnitPlaceholders, false); popTempEvent(); Ending eg = new Ending(groupId.getLastId()); filterEvents.add(new Event(EventType.END_GROUP, eg, skel));
while (eventBuilder.hasQueuedEvents()) { return eventBuilder.next(); currentBook = currentLine.substring(2); setDocumentName(currentBook); eventBuilder.addFilterEvent(createStartFilterEvent()); handleDocumentPart(currentLine + newline); this.foundBook = true; currentChapter = currentLine.substring(2); if (startSubDocument != null) { eventBuilder.endSubDocument(); if (eventBuilder.hasQueuedEvents()) { break; eventBuilder.endSubDocument(); eventBuilder.flushRemainingTempEvents(); eventBuilder.addFilterEvent(createStartFilterEvent()); LOGGER.warn("Missing book marker at start of document: |b"); eventBuilder.addFilterEvent(createEndFilterEvent()); return eventBuilder.next();
Event tempTextUnit; if (!isCurrentTextUnit()) { if (endMarker != null) { addDocumentPart(endMarker.toString()); tempTextUnit = popTempEvent(); tempTextUnit.setResource(postProcessTextUnit(tempTextUnit.getTextUnit())); filterEvents.add(tempTextUnit);
/** * Start a {@link TextUnit}. Also create a TextUnit {@link Event} and add it to the event queue. * * @param text * the text used to prime the {@link TextUnit} */ public void startTextUnit(String text) { startTextUnit(text, null, null, null); }
private void buildTextUnitForNonTrados(String text, boolean source) { if (TRADOS_LEAVINGS_COMPILED.matcher(text).find()) { throw new OkapiBadFilterInputException("Trados segment markers found in source or target text: " + text); } if (source) { eventBuilder.setTargetLocale(null); } else { eventBuilder.setTargetLocale(getTrgLoc()); } Matcher m = PLACEHOLDER_PATTERN.matcher(text); if (m.find()) { m.reset(); String[] chunks = PLACEHOLDER_PATTERN.split(text); for (int i = 0; i < chunks.length; i++) { eventBuilder.addToTextUnit(chunks[i]); if (m.find()) { String ph = text.substring(m.start(), m.end()); Code c = new Code(TagType.PLACEHOLDER, ph, ph); c.setId(Integer.parseInt(m.group(2))); eventBuilder.addToTextUnit(c); } } } else { // no placeholders found - treat is text only eventBuilder.addToTextUnit(text); } }
eventBuilder = new EventBuilder(); } else { eventBuilder.reset(null, this);
/** * End the current {@link TextUnit} and place the {@link Event} on the event queue. * * @return the ended {@link TextUnit} */ public ITextUnit endTextUnit() { return endTextUnit(null, null, null); }
/** * Instantiates a new EventBuilder. */ public EventBuilder() { reset(null, null); }
@Override public boolean hasNext() { return eventBuilder.hasNext(); }
/** * Create a {@link DocumentPart} that references actionable (i.e., translatable, localizable) properties and store * it for later processing. * * @param part * the {@link DocumentPart} (aka skeleton) * @param name * the name * @param locale * the language of any actionable items * @param propertyTextUnitPlaceholders * the list of actionable {@link TextUnit} or {@link Properties} with offset information into the tag. */ public void startDocumentPart(String part, String name, LocaleId locale, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders) { if (hasUnfinishedSkeleton()) { endDocumentPart(); } else if (isCurrentTextUnit()) { endTextUnit(); } currentSkeleton = new GenericSkeleton(); currentDocumentPart = new DocumentPart(documentPartId.createId(), false); currentDocumentPart.setSkeleton(currentSkeleton); processAllEmbedded(part, locale, propertyTextUnitPlaceholders, false); }
/** * Is the current buffered {@link Event} a {@link StartSubfilter}? * * @return true, if current {@link Event} is a {@link StartSubfilter} */ public boolean isCurrentSubfilter() { Event e = peekTempEvent(); if (e != null && e.getEventType() == EventType.START_SUBFILTER) { return true; } return false; }
/** * Start a {@link TextUnit}. Also create a TextUnit {@link Event} and add it to the event queue. */ public void startTextUnit() { startTextUnit(null, null, null, null); }