/** * Appends an existing list placeholders to this text run. * @param text optional text to add to the run * @param offset the offset of the placeholders (added to the start / end) * @param propertyTextUnitPlaceholders The existing placeholders to add. */ public void appendWithPropertyTextUnitPlaceholders(String text, int offset, List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders) { if ( text != null ) this.text.append(text); for(PropertyTextUnitPlaceholder p : propertyTextUnitPlaceholders) { p.setMainStartPos(p.getMainStartPos()+offset); p.setMainEndPos(p.getMainEndPos()+offset); p.setValueStartPos(p.getValueStartPos()+offset); p.setValueEndPos(p.getValueEndPos()+offset); if (this.propertyTextUnitPlaceholders==null) this.propertyTextUnitPlaceholders = new ArrayList<PropertyTextUnitPlaceholder>(); this.propertyTextUnitPlaceholders.add(p); } }
private boolean isTextPlaceHoldersOnly(List<PropertyTextUnitPlaceholder> propertyTextUnitPlaceholders) { boolean text = false; boolean nontext = false; for (PropertyTextUnitPlaceholder propOrText : propertyTextUnitPlaceholders) { if (propOrText.getAccessType() == PlaceholderAccessType.TRANSLATABLE) { text = true; } else { nontext = true; } } return (text && !nontext); }
private void embeddedWritableProp(INameable resource, PropertyTextUnitPlaceholder propOrText, String tag, LocaleId locale) { setPropertyBasedOnLocale(resource, locale, new Property(propOrText.getName(), propOrText.getValue(), false)); currentSkeleton.add(tag.substring(propOrText.getMainStartPos(), propOrText.getValueStartPos())); currentSkeleton.addValuePlaceholder(resource, propOrText.getName(), locale); currentSkeleton.add(tag.substring(propOrText.getValueEndPos(), propOrText.getMainEndPos())); }
private void embeddedReadonlyProp(INameable resource, PropertyTextUnitPlaceholder propOrText, String tag, LocaleId locId) { setPropertyBasedOnLocale(resource, locId, new Property(propOrText.getName(), propOrText.getValue(), true)); currentSkeleton.add(tag.substring(propOrText.getMainStartPos(), propOrText.getMainEndPos())); }
private ITextUnit embeddedTextUnit(PropertyTextUnitPlaceholder propOrText, String tag) { ITextUnit tu = new TextUnit(textUnitId.createId(), propOrText.getValue()); tu.setPreserveWhitespaces(this.preserveWhitespace); tu.setMimeType(propOrText.getMimeType()); tu.setIsReferent(true); tu.setType(propOrText.getElementType() == null ? propOrText.getName() : propOrText.getElementType()); GenericSkeleton skel = new GenericSkeleton(); skel.add(tag.substring(propOrText.getMainStartPos(), propOrText.getValueStartPos())); skel.addContentPlaceholder(tu); skel.add(tag.substring(propOrText.getValueEndPos(), propOrText.getMainEndPos())); tu.setSkeleton(skel); postProcessTextUnit(tu); return tu; }
/** * Define equality of state. Equality is based on the MainStartPos of the * attribute. * * @param aThat * the {@link PropertyTextUnitPlaceholder} that is compared to * this object */ @Override public boolean equals(Object aThat) { if (this == aThat) return true; if (!(aThat instanceof PropertyTextUnitPlaceholder)) return false; PropertyTextUnitPlaceholder that = (PropertyTextUnitPlaceholder) aThat; return (this.getMainStartPos() == that.getMainStartPos()); }
return new PropertyTextUnitPlaceholder(type, normalizeAttributeName, v, mainStartPos, mainEndPos, valueStartPos, valueEndPos);
currentSkeleton.add(tag.substring(0, pt.getMainStartPos())); PropertyTextUnitPlaceholder pt1 = propertyTextUnitPlaceholders.get(propOrTextId - 1); PropertyTextUnitPlaceholder pt2 = propertyTextUnitPlaceholders.get(propOrTextId); currentSkeleton.add(tag.substring(pt1.getMainEndPos(), pt2.getMainStartPos())); if (propOrText.getAccessType() == PlaceholderAccessType.TRANSLATABLE) { ITextUnit tu = embeddedTextUnit(propOrText, tag); currentSkeleton.addReference(tu); referencableFilterEvents.add(new Event(EventType.TEXT_UNIT, tu)); } else if (propOrText.getAccessType() == PlaceholderAccessType.WRITABLE_PROPERTY) { embeddedWritableProp(resource, propOrText, tag, locale); } else if (propOrText.getAccessType() == PlaceholderAccessType.READ_ONLY_PROPERTY) { embeddedReadonlyProp(resource, propOrText, tag, locale); } else if (propOrText.getAccessType() == PlaceholderAccessType.NAME) { resource.setName(propOrText.getValue() + "-" + propOrText.getName()); embeddedReadonlyProp(resource, propOrText, tag, locale); } else { currentSkeleton.add(tag.substring(pt.getMainEndPos()));
/** * Compare two {@link PropertyTextUnitPlaceholder}s. Compare is based in * MainStartPos order only. Allows sorting of many * {@link PropertyTextUnitPlaceholder}s in the order they appear in the * input * * @param aThat * the {@link PropertyTextUnitPlaceholder} used to compare to * this object */ public int compareTo(PropertyTextUnitPlaceholder aThat) { final int BEFORE = -1; final int EQUAL = 0; final int AFTER = 1; // this optimization is usually worthwhile, and can // always be added if (this.getMainStartPos() == aThat.getMainStartPos()) return EQUAL; // primitive numbers follow this form if (this.getMainStartPos() < aThat.getMainStartPos()) return BEFORE; if (this.getMainStartPos() > aThat.getMainStartPos()) return AFTER; return EQUAL; }
/** * Create a {@link PropertyTextUnitPlaceholder} given the supplied type, name and Jericho {@link Tag} and * {@link Attribute}. * * @param type * - {@link PlaceholderAccessType} is one of TRANSLATABLE, READ_ONLY_PROPERTY, WRITABLE_PROPERTY * @param name * - attribute name * @param value * - attribute value * @param tag * - Jericho {@link Tag} which contains the attribute * @param attribute * - attribute as a Jericho {@link Attribute} * @return a {@link PropertyTextUnitPlaceholder} representing the attribute */ protected PropertyTextUnitPlaceholder createPropertyTextUnitPlaceholder( PlaceholderAccessType type, String name, String value, Tag tag, Attribute attribute) { // offset of attribute int mainStartPos = attribute.getBegin() - tag.getBegin(); int mainEndPos = attribute.getEnd() - tag.getBegin(); // offset of value of the attribute int valueStartPos = attribute.getValueSegment().getBegin() - tag.getBegin(); int valueEndPos = attribute.getValueSegment().getEnd() - tag.getBegin(); return new PropertyTextUnitPlaceholder(type, normalizeAttributeName(name, value, tag), value, mainStartPos, mainEndPos, valueStartPos, valueEndPos); }
/** * <b>A class that overrides equals must also override hashCode.</b> Return * a hash code based on the MainStartPos only */ @Override public int hashCode() { int result = HashCodeUtil.SEED; result = HashCodeUtil.hash(result, this.getMainStartPos()); return result; }