use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.
the class MCRTransferPackageUtil method getMCRObjects.
/**
* Gets the list of mycore object identifiers from the given directory.
*
* @param targetDirectory directory where the *.tar was unpacked
* @return list of object which lies within the directory
*/
public static List<String> getMCRObjects(Path targetDirectory) throws JDOMException, IOException {
Path order = targetDirectory.resolve(MCRTransferPackage.IMPORT_CONFIG_FILENAME);
Document xml = new SAXBuilder().build(order.toFile());
Element config = xml.getRootElement();
XPathExpression<Text> exp = MCRConstants.XPATH_FACTORY.compile("order/object/text()", Filters.text());
return exp.evaluate(config).stream().map(Text::getText).collect(Collectors.toList());
}
use of org.omegat.filters3.Text in project mycore by MyCoRe-Org.
the class MCRURNObjectXPathMetadataManager method getIdentifier.
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException {
String xpath = getProperties().get("Xpath");
Document xml = obj.createXML();
XPathFactory xpfac = XPathFactory.instance();
XPathExpression<Text> xp = xpfac.compile(xpath, Filters.text());
List<Text> evaluate = xp.evaluate(xml);
if (evaluate.size() > 1) {
throw new MCRPersistentIdentifierException("Got " + evaluate.size() + " matches for " + obj.getId() + " with xpath " + xpath + "");
}
if (evaluate.size() == 0) {
return Optional.empty();
}
Text identifierText = evaluate.listIterator().next();
String identifierString = identifierText.getTextNormalize();
Optional<MCRDNBURN> parsedIdentifierOptional = PARSER.parse(identifierString);
return parsedIdentifierOptional.map(MCRPersistentIdentifier.class::cast);
}
use of org.omegat.filters3.Text in project omegat by omegat-org.
the class DefaultXMLDialect method constructShortcuts.
/**
* {@inheritDoc}
*/
@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
protectedParts.clear();
StringBuilder r = new StringBuilder();
for (Element el : elements) {
String shortcut = el.toShortcut();
r.append(shortcut);
if (!(el instanceof Text)) {
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(el.toOriginal());
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(el.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
protectedParts.add(pp);
}
}
return r.toString();
}
use of org.omegat.filters3.Text in project omegat by omegat-org.
the class Handler method queueText.
private void queueText(String s) {
if (!translator.isInIgnored()) {
translator.text(s);
}
// knowing here whether we're inside a preformatted tag, etc.
if (internalEntityStarted != null && s.equals(internalEntityStarted.getValue())) {
currEntry().add(new XMLEntityText(internalEntityStarted));
} else {
boolean added = false;
if (!currEntry().isEmpty()) {
Element elem = currEntry().get(currEntry().size() - 1);
if (elem instanceof XMLText) {
XMLText text = (XMLText) elem;
if (text.isInCDATA() == inCDATA) {
currEntry().resetTagDetected();
text.append(s);
added = true;
}
}
}
if (!added) {
currEntry().add(new XMLText(s, inCDATA));
}
}
}
use of org.omegat.filters3.Text in project omegat by omegat-org.
the class Scribus method testParse.
@Test
public void testParse() throws Exception {
List<String> lines = parse(new ScribusFilter(), "test/data/filters/Scribus/Scribus.sla", null);
assertEquals(1, lines.size());
assertEquals("Translatable text", lines.get(0));
}
Aggregations