Search in sources :

Example 16 with Text

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());
}
Also used : Path(java.nio.file.Path) MCRPath(org.mycore.datamodel.niofs.MCRPath) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Text(org.jdom2.Text) Document(org.jdom2.Document)

Example 17 with Text

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);
}
Also used : XPathFactory(org.jdom2.xpath.XPathFactory) Text(org.jdom2.Text) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Example 18 with Text

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();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) Element(org.omegat.filters3.Element) Text(org.omegat.filters3.Text)

Example 19 with Text

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));
        }
    }
}
Also used : Element(org.omegat.filters3.Element)

Example 20 with Text

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));
}
Also used : ScribusFilter(org.omegat.filters3.xml.scribus.ScribusFilter) Test(org.junit.Test)

Aggregations

Text (org.jdom2.Text)12 Element (org.jdom2.Element)8 Document (org.jdom2.Document)4 Test (org.junit.Test)4 Content (org.jdom2.Content)3 Element (org.omegat.filters3.Element)3 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ProtectedPart (org.omegat.core.data.ProtectedPart)2 XMLContentBasedTag (org.omegat.filters3.xml.XMLContentBasedTag)2 BaseText (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.BaseText)1 Text (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v1.Text)1 Text (com.adobe.cq.wcm.core.components.it.seljup.util.components.text.v2.Text)1 JsonElement (com.google.gson.JsonElement)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1