当前位置: 首页>>代码示例>>Java>>正文


Java Text类代码示例

本文整理汇总了Java中org.jdom2.Text的典型用法代码示例。如果您正苦于以下问题:Java Text类的具体用法?Java Text怎么用?Java Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Text类属于org.jdom2包,在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContent

import org.jdom2.Text; //导入依赖的package包/类
/**
 * Returns the content of an element as string. The element itself
 * is ignored.
 * 
 * @param e the element to get the content from
 * @return the content as string
 */
protected String getContent(Element e) throws IOException {
    XMLOutputter out = new XMLOutputter();
    StringWriter writer = new StringWriter();
    for (Content child : e.getContent()) {
        if (child instanceof Element) {
            out.output((Element) child, writer);
        } else if (child instanceof Text) {
            Text t = (Text) child;
            String trimmedText = t.getTextTrim();
            if (!trimmedText.equals("")) {
                Text newText = new Text(trimmedText);
                out.output(newText, writer);
            }
        }
    }
    return writer.toString();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:25,代码来源:MCRWCMSDefaultSectionProvider.java

示例2: objectToString

import org.jdom2.Text; //导入依赖的package包/类
/**
 * Returns the string value of the given XML node object, depending on its type.
 * 
 * @param object
 * @return String
 */
public static String objectToString(Object object) {
    if (object instanceof Element) {
        return ((Element) object).getText();
    } else if (object instanceof Attribute) {
        return ((Attribute) object).getValue();
    } else if (object instanceof Text) {
        return ((Text) object).getText();
    } else if (object instanceof CDATA) {
        return ((CDATA) object).getText();
    } else if (object instanceof Comment) {
        return ((Comment) object).getText();
    } else if (object instanceof Double) {
        return String.valueOf(object);
    } else if (object instanceof Boolean) {
        return String.valueOf(object);
    } else if (object instanceof String) {
        return (String) object;
    } else if (object != null) {
        logger.error("Unknown object type: {}", object.getClass().getName());
        return null;
    } else {
        return null;
    }

}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:32,代码来源:JDomXP.java

示例3: parseString

import org.jdom2.Text; //导入依赖的package包/类
/**
 * Parses a JDom2 Object into a string
 * @param e
 *            Object (Element, Text, Document or Attribute)
 * @return String
 * @author sholzer (11.05.2015)
 */
public String parseString(Object e) {
    XMLOutputter element2String = new XMLOutputter();
    if (e instanceof Element) {
        return element2String.outputString((Element) e);
    }
    if (e instanceof Text) {
        return element2String.outputString((Text) e);
    }
    if (e instanceof Document) {
        return element2String.outputString((Document) e);
    }
    if (e instanceof org.jdom2.Attribute) {
        Attribute a = (org.jdom2.Attribute) e;
        return a.getName() + "=\"" + a.getValue() + "\"";
    }
    return e.toString();
}
 
开发者ID:maybeec,项目名称:lexeme,代码行数:25,代码来源:JDom2Util.java

示例4: testCompareElementWithTextNodeMismatch

import org.jdom2.Text; //导入依赖的package包/类
/**
 * Test method for {@link ElementComparatorImpl#compare(Element, Element)}
 * <p>
 * Compares two Elements through their text content. Expects mismatch
 * @throws Exception
 *             when something somewhere goes wrong
 * @author sholzer (23.03.2015)
 */
@Test
public void testCompareElementWithTextNodeMismatch() throws Exception {
    String rootName = "A";
    String textValue1 = "0";
    String textValue2 = "1";

    String xpath = "./text()";

    Element root1 = new Element(rootName);
    Text child1 = new Text(textValue1);
    root1.addContent(child1);
    Element root2 = new Element(rootName);
    Text child2 = new Text(textValue2);
    root2.addContent(child2);
    assertFalse("Expected false", getComparatorFromXpath(xpath).compare(root1, root2));

}
 
开发者ID:maybeec,项目名称:lexeme,代码行数:26,代码来源:ElementComparatorImplTest.java

示例5: extractModsMetadata

import org.jdom2.Text; //导入依赖的package包/类
@Override
public List<MCRIIIFMetadata> extractModsMetadata(Element xmlData) {
    Map<String, String> elementLabelMap = new HashMap<>();

    elementLabelMap.put("title", "mods:mods/mods:titleInfo/mods:title/text()");
    elementLabelMap.put("genre", "mods:mods/mods:genre/text()");
    // TODO: add some more metadata

    return elementLabelMap.entrySet().stream().map(entry -> {
        XPathExpression<Text> pathExpression = XPathFactory.instance().compile(entry.getValue(), Filters.text(),
            null, MCRConstants.MODS_NAMESPACE);
        List<Text> texts = pathExpression.evaluate(xmlData);
        if (texts.size() == 0) {
            return null;
        }
        return new MCRIIIFMetadata(entry.getKey(),
            texts.stream().map(Text::getText).collect(Collectors.joining(", ")));
    }).filter(Objects::nonNull)
        .collect(Collectors.toList());
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:21,代码来源:MCRMetsIIIFModsMetadataExtractor.java

示例6: getIdentifier

import org.jdom2.Text; //导入依赖的package包/类
@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);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRURNObjectXPathMetadataManager.java

示例7: convertSuppressConsistency

import org.jdom2.Text; //导入依赖的package包/类
private void convertSuppressConsistency(Element repo) {
    Element type = repo.getChild("type", repo.getNamespace());
    RepoType repoType = RepoType.fromType(type.getText());
    if (repoType.isMavenGroup()) {
        Element suppress= repo.getChild("suppressPomConsistencyChecks", repo.getNamespace());
        String pomConsistencyValue = repo.getChildText("suppressPomConsistencyChecks", repo.getNamespace());
        if (suppress==null ){
            suppress=new Element("suppressPomConsistencyChecks", repo.getNamespace());
            int lastLocation = findSuppressLocation(repo);
            repo.addContent(lastLocation + 1, new Text("\n            "));
            repo.addContent(lastLocation + 2, suppress);
        }
        if(StringUtils.isBlank(suppress.getText())) {
            pomConsistencyValue = "false";
        }
        suppress.setText(pomConsistencyValue);
    }
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:19,代码来源:SuppressConsitencyConverter.java

示例8: replaceExcludedWithIncluded

import org.jdom2.Text; //导入依赖的package包/类
private void replaceExcludedWithIncluded(Element rootElement, Namespace namespace, Element indexer,
        Element excludedRepositories) {
    List<String> excluded = excludedRepositories.getChildren()
            .stream()
            .map(Element::getText)
            .collect(Collectors.toList());


    if (StringUtils.equals(indexer.getChildText("enabled", namespace), "true")) {
        Element includedRepositories = new Element("includedRepositories", namespace);
        collectRepositories(rootElement, namespace)
                .stream()
                .filter(repo -> !excluded.contains(repo))
                .forEach(repo -> {
                    Element repositoryRef = new Element("repositoryRef", namespace);
                    repositoryRef.setText(repo);
                    includedRepositories.addContent(repositoryRef);
                });
        indexer.addContent(new Text("\n        "));
        indexer.addContent(includedRepositories);
    }

    indexer.removeContent(excludedRepositories);
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:25,代码来源:MavenIndexerConverter.java

示例9: getAnnotations

import org.jdom2.Text; //导入依赖的package包/类
protected List<AnnotationFS> getAnnotations(JCas jCas) {
  int makeInstanceOffset = jCas.getDocumentText().length();
  List<AnnotationFS> annotations = new ArrayList<AnnotationFS>();
  FSIterator<Annotation> iterator = jCas.getAnnotationIndex().iterator();
  while (iterator.isValid() && iterator.hasNext()) {
    Annotation annotation = iterator.next();
    if (annotation instanceof DocumentAnnotation || annotation instanceof org.cleartk.timeml.type.Text || annotation instanceof Event || annotation instanceof Time  || annotation instanceof TemporalLink) {
      annotations.add(annotation);
      if (annotation instanceof DocumentCreationTime) {
        annotations.add(new DCT((DocumentCreationTime) annotation));
      }
      if (annotation instanceof Event) {
        annotations.add(new MakeInstance((Event) annotation, makeInstanceOffset));
      }
    }
  }
  return annotations;
}
 
开发者ID:ClearTK,项目名称:cleartk,代码行数:19,代码来源:TempEval2013Writer.java

示例10: doFilter

import org.jdom2.Text; //导入依赖的package包/类
private LinkedList<String> doFilter(String in, Set<String> xpaths) throws IOException {
    LinkedList<String> result = new LinkedList<String>();
    try {
        Document doc = new SAXBuilder(XMLReaders.NONVALIDATING).build(new StringReader(in));
        XMLOutputter out = new XMLOutputter();

        for (String xp : xpaths) {
            XPathExpression<Content> xpath = XPathFactory.instance().compile(xp, Filters.content());
            for (Content node : xpath.evaluate(doc)) {
                if(node instanceof Element) {
                    result.add(out.outputString((Element) node));
                } else if(node instanceof Text) {
                    result.add(out.outputString((Text) node));
                }
            }
        }
        return result;
    } catch (JDOMException xpe) {
        throw new IllegalArgumentException("error while processing xpath expressions: '" + xpaths + "'", xpe);
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:22,代码来源:XPathFunction.java

示例11: getTextNodes

import org.jdom2.Text; //导入依赖的package包/类
/**
 * @param element
 *            {@link org.jdom2.Element}
 * @return {@link List}&lt;{@link String}>
 * @author sholzer (05.05.2015)
 */
public List<Text> getTextNodes(Element element) {
    List<Text> result = new LinkedList<>();

    for (Content content : element.getContent()) {
        if (content instanceof Text) {
            result.add((Text) content);
        }
    }

    return result;
}
 
开发者ID:maybeec,项目名称:lexeme,代码行数:18,代码来源:JDom2Util.java

示例12: transform

import org.jdom2.Text; //导入依赖的package包/类
public MCRJDOMContent transform(MCRContent source) throws IOException {
    try {
        Element root = source.asXML().getRootElement().clone();
        for (Text text : root.getDescendants(Filters.text())) {
            text.setText(MCRXMLFunctions.normalizeUnicode(text.getText()));
        }
        return new MCRJDOMContent(root);
    } catch (JDOMException | SAXException ex) {
        throw new IOException(ex);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:12,代码来源:MCRPostProcessorXSL.java

示例13: getProcessingInstruction

import org.jdom2.Text; //导入依赖的package包/类
public ProcessingInstruction getProcessingInstruction() {
    if (pi == null) {
        String data = RAW_OUTPUTTER.outputString(new Text(text));
        this.pi = new ProcessingInstruction(type, data);
    }
    return pi;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRChangeData.java

示例14: getMCRObjects

import org.jdom2.Text; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:14,代码来源:MCRTransferPackageUtil.java

示例15: equivalent

import org.jdom2.Text; //导入依赖的package包/类
public static boolean equivalent(Text t1, Text t2) {
    String v1 = t1.getValue();
    String v2 = t2.getValue();
    boolean equals = v1.equals(v2);
    if (!equals && LOGGER.isDebugEnabled()) {
        LOGGER.debug("Text differs \"{}\"!=\"{}\"", t1, t2);
    }
    return equals;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:10,代码来源:MCRXMLHelper.java


注:本文中的org.jdom2.Text类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。