use of org.omegat.filters3.Attributes in project omegat by omegat-org.
the class XLIFFDialect method constructShortcuts.
@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
protectedParts.clear();
// create shortcuts
InlineTagHandler tagHandler = new InlineTagHandler();
StringBuilder r = new StringBuilder();
for (Element el : elements) {
if (el instanceof XMLContentBasedTag) {
XMLContentBasedTag tag = (XMLContentBasedTag) el;
String shortcut = null;
int shortcutLetter;
int tagIndex;
boolean tagProtected;
if ("bpt".equals(tag.getTag())) {
// XLIFF specification requires 'rid' and 'id' attributes,
// but some tools uses 'i' attribute like for TMX
tagHandler.startBPT(tag.getAttribute("rid"), tag.getAttribute("id"), tag.getAttribute("i"));
shortcutLetter = calcTagShortcutLetter(tag, ignoreTypeForBptTags);
tagHandler.setTagShortcutLetter(shortcutLetter);
tagIndex = tagHandler.endBPT();
shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
tagProtected = false;
} else if ("ept".equals(tag.getTag())) {
tagHandler.startEPT(tag.getAttribute("rid"), tag.getAttribute("id"), tag.getAttribute("i"));
tagIndex = tagHandler.endEPT();
shortcutLetter = tagHandler.getTagShortcutLetter();
shortcut = "</" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
tagProtected = false;
} else if ("it".equals(tag.getTag())) {
tagHandler.startOTHER();
tagHandler.setCurrentPos(tag.getAttribute("pos"));
tagIndex = tagHandler.endOTHER();
// XLIFF specification requires 'open/close' values,
// but some tools may use 'begin/end' values like for TMX
shortcutLetter = calcTagShortcutLetter(tag);
if ("close".equals(tagHandler.getCurrentPos()) || "end".equals(tagHandler.getCurrentPos())) {
// for better compatibility with corresponding TMX files
if (forceShortCutToF) {
shortcutLetter = 'f';
}
shortcut = "</" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
} else {
shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
}
tagProtected = false;
} else if ("ph".equals(tag.getTag())) {
tagHandler.startOTHER();
tagIndex = tagHandler.endOTHER();
shortcutLetter = calcTagShortcutLetter(tag, ignoreTypeForPhTags);
shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + "/>";
tagProtected = false;
} else if ("mrk".equals(tag.getTag())) {
tagHandler.startOTHER();
tagIndex = tagHandler.endOTHER();
shortcutLetter = 'm';
shortcut = "<m" + tagIndex + ">" + tag.getIntactContents().sourceToOriginal() + "</m" + tagIndex + ">";
tagProtected = true;
} else {
shortcutLetter = 'f';
tagIndex = -1;
tagProtected = false;
}
tag.setShortcutLetter(shortcutLetter);
tag.setShortcutIndex(tagIndex);
tag.setShortcut(shortcut);
r.append(shortcut);
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(tag.toOriginal());
if (tagProtected) {
// protected text with related tags, like <m0>Acme</m0>
if (StatisticsSettings.isCountingProtectedText()) {
// Protected texts are counted, but related tags are not counted in the word count
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT + tag.getIntactContents().sourceToOriginal() + StaticUtils.TAG_REPLACEMENT);
} else {
// All protected parts are not counted in the word count(default)
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(tag.getIntactContents().sourceToOriginal());
} else {
// simple tag, like <i0>
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(tag.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
}
protectedParts.add(pp);
} else if (el instanceof Tag) {
Tag tag = (Tag) el;
int tagIndex = tagHandler.paired(tag.getTag(), tag.getType());
tag.setIndex(tagIndex);
String shortcut = tag.toShortcut();
r.append(shortcut);
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(tag.toOriginal());
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(tag.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
protectedParts.add(pp);
} else {
r.append(el.toShortcut());
}
}
return r.toString();
}
use of org.omegat.filters3.Attributes in project omegat by omegat-org.
the class Handler method queueIgnoredTag.
/**
* Queue tag that should be ignored by editor, including content and all subtags.
*/
private void queueIgnoredTag(String tag, Attributes attributes) {
Tag xmltag = null;
setSpacePreservingTag(XMLUtils.convertAttributes(attributes));
if (xmltag == null) {
xmltag = new XMLTag(tag, getShortcut(tag), Tag.Type.BEGIN, attributes, this.translator.getTargetLanguage());
xmlTagName.push(xmltag.getTag());
xmlTagAttributes.push(xmltag.getAttributes());
}
currEntry().add(xmltag);
}
use of org.omegat.filters3.Attributes in project certmgr by hdecarne.
the class StoreController method updateDetailsViewHelper.
private void updateDetailsViewHelper(TreeItem<AttributeModel> parentItem, Attributes attribute, boolean expand) {
TreeItem<AttributeModel> attributeItem = new TreeItem<>(new AttributeModel(attribute));
List<Attributes> attributeChildren = attribute.children();
int childCount = attributeChildren.size();
int childIndex = 0;
for (Attributes child : attributeChildren) {
if (childIndex >= DETAILS_VIEW_ATTRIBUTE_LIMIT) {
attributeItem.getChildren().add(new TreeItem<>(new AttributeModel(StoreI18N.formatSTR_TEXT_DETAILS_OMITTED(childCount - childIndex))));
break;
}
updateDetailsViewHelper(attributeItem, child, false);
childIndex++;
}
parentItem.getChildren().add(attributeItem);
attributeItem.setExpanded(expand);
}
use of org.omegat.filters3.Attributes in project omegat by omegat-org.
the class Handler method queueTag.
private void queueTag(String tag, Attributes attributes) {
Tag xmltag = null;
XMLIntactTag intacttag = null;
setTranslatableTag(tag, XMLUtils.convertAttributes(attributes));
setSpacePreservingTag(XMLUtils.convertAttributes(attributes));
if (!collectingIntactText()) {
if (isContentBasedTag(tag, XMLUtils.convertAttributes(attributes))) {
intacttag = new XMLContentBasedTag(dialect, this, tag, getShortcut(tag), dialect.getContentBasedTags().get(tag), attributes);
xmltag = intacttag;
intacttagName = tag;
intacttagAttributes = XMLUtils.convertAttributes(attributes);
} else if (isIntactTag(tag, XMLUtils.convertAttributes(attributes))) {
intacttag = new XMLIntactTag(dialect, this, tag, getShortcut(tag), attributes);
xmltag = intacttag;
intacttagName = tag;
intacttagAttributes = XMLUtils.convertAttributes(attributes);
}
}
if (xmltag == null) {
xmltag = new XMLTag(tag, getShortcut(tag), Tag.Type.BEGIN, attributes, this.translator.getTargetLanguage());
xmlTagName.push(xmltag.getTag());
xmlTagAttributes.push(xmltag.getAttributes());
}
currEntry().add(xmltag);
if (intacttag != null) {
intacttagEntry = intacttag.getIntactContents();
}
if (!collectingIntactText()) {
for (int i = 0; i < xmltag.getAttributes().size(); i++) {
Attribute attr = xmltag.getAttributes().get(i);
if ((dialect.getTranslatableAttributes().contains(attr.getName()) || dialect.getTranslatableTagAttributes().containsPair(tag, attr.getName())) && dialect.validateTranslatableTagAttribute(tag, attr.getName(), xmltag.getAttributes())) {
attr.setValue(StringUtil.makeValidXML(translator.translate(StringUtil.unescapeXMLEntities(attr.getValue()), null)));
}
}
}
}
use of org.omegat.filters3.Attributes in project omegat by omegat-org.
the class XMLUtils method convertAttributes.
/**
* Converts attributes from org.xml.sax package to OmegaT's.
*/
public static Attributes convertAttributes(org.xml.sax.Attributes attributes) {
Attributes res = new Attributes();
if (attributes == null) {
return res;
}
for (int i = 0; i < attributes.getLength(); i++) {
String name = StringUtil.makeValidXML(attributes.getQName(i));
String value = StringUtil.makeValidXML(attributes.getValue(i));
Attribute attr = new Attribute(name, value);
res.add(attr);
}
return res;
}
Aggregations