本文整理汇总了Java中org.jdom2.Content类的典型用法代码示例。如果您正苦于以下问题:Java Content类的具体用法?Java Content怎么用?Java Content使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Content类属于org.jdom2包,在下文中一共展示了Content类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContent
import org.jdom2.Content; //导入依赖的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();
}
示例2: getLastNodeFromGroup
import org.jdom2.Content; //导入依赖的package包/类
/**
*
* @param iterator
* with hasNext() == true. Iterator position will change
* @return the last node from the current group. i.e. the last <a> element from a consecutive group of <a>
* elements
* @author sholzer (Aug 25, 2015)
*/
private Content getLastNodeFromGroup(ListIterator<Content> iterator) {
Content currentNode = iterator.next();
if (iterator.hasNext()) {
Content nextNode = iterator.next();
if (nextNode.getClass().equals(currentNode.getClass())) {
if (nextNode instanceof Element) {
Element currentElement = (Element) currentNode;
Element nextElement = (Element) nextNode;
if (!nextElement.getName().equals(currentElement.getName())) {
return currentNode;
}
}
iterator.previous();
return getLastNodeFromGroup(iterator);
} else {
return currentNode;
}
} else {
return currentNode;
}
}
示例3: peekFor
import org.jdom2.Content; //导入依赖的package包/类
/**
* Peeks into the list provided by the iterator if an element with the tag ,,name'' exists.
* @param name
* the name to be looking for
* @param iterator
* list iterator of a list to be looked at. next() and previous() will be called multiple
* times. Position of the iterator will be the same as before
* @return true if an element with tag ,,name'' exists in the list of iterator
* @author sholzer (Aug 25, 2015)
*/
private boolean peekFor(String name, ListIterator<Content> iterator) {
if (iterator.hasNext()) {
// take a step forwards
Content currentNode = iterator.next();
boolean result;
// if the current node is an element with the searched name return true
if (currentNode instanceof Element && ((Element) currentNode).getName().equals(name)) {
result = true;
} else { // otherwise look at the next node
result = peekFor(name, iterator);
}
// take a step backwards
iterator.previous();
return result;
} else {// at the end of the list obviously there was no such element
return false;
}
}
示例4: testList
import org.jdom2.Content; //导入依赖的package包/类
@Test
public void testList() throws Exception {
Element child1 = new Element("child").setText("Hallo Welt");
Element child2 = new Element("child").setText("hello world");
Element child3 = new Element("child").setText("Bonjour le monde");
List<Content> l1 = new ArrayList<>();
l1.add(child1);
l1.add(child2);
l1.add(child3);
Element root = new Element("root");
root.addContent(l1);
String formattedXML = "<root>\n<child>Hallo Welt</child>\n" + "<child>hello world</child>"
+ "<child>Bonjour le monde</child>\n</root>";
SAXBuilder b = new SAXBuilder();
Document doc = b.build(new ByteArrayInputStream(formattedXML.getBytes(Charset.forName("UTF-8"))));
assertEquals("Elements should be equal", true, MCRXMLHelper.deepEqual(root, doc.getRootElement()));
}
示例5: process
import org.jdom2.Content; //导入依赖的package包/类
@Override
public Document process(final Map<String, Object> context, final Document document, final Slide slide,
final Resources resources, final Configuration configuration) throws JODTemplateException {
final IteratorIterable<Element> atElements = document.getDescendants(Filters.element(PPTXDocument.T_ELEMENT,
getNamespace()));
final List<Element> atElementsList = new ArrayList<>();
while (atElements.hasNext()) {
atElementsList.add(atElements.next());
}
for (Element at : atElementsList) {
if (at.getContentSize() != 0) {
final Content content = at.getContent(0);
if (content instanceof Comment) {
final Comment comment = (Comment) content;
processComment(comment, at, slide, configuration);
}
}
}
return document;
}
示例6: assertEquals
import org.jdom2.Content; //导入依赖的package包/类
private void assertEquals(Element element1, Element element2) {
Assert.assertEquals(element1.getName(), element2.getName());
Assert.assertEquals(this.getAttributes(element1), this.getAttributes(element2));
List<Content> children1 = element1.getContent();
List<Content> children2 = element2.getContent();
Assert.assertEquals(children1.size(), children2.size());
for (int i = 0; i < children1.size(); i++) {
Content child1 = children1.get(0);
Content child2 = children2.get(0);
if (child1 instanceof Element) {
this.assertEquals((Element) child1, (Element) child2);
} else {
Assert.assertEquals(child1.getValue(), child2.getValue());
}
}
}
示例7: getOriginalHeadContent
import org.jdom2.Content; //导入依赖的package包/类
private List<Content> getOriginalHeadContent(org.jdom2.Document doc)
{
org.jdom2.Element root = doc.getRootElement();
List<Content> contentList = new ArrayList<>();
if (root != null)
{
org.jdom2.Element headElement = root.getChild("head", Constants.NAMESPACE_XHTML);
if (headElement != null)
{
List<Content> contents = headElement.getContent();
contentList.addAll(contents);
}
}
//erst ausserhalb der Schleife detachen
for (Content content : contentList)
{
content.detach();
}
return contentList;
}
示例8: retrieveModifiedEntryElementFromTimestamp
import org.jdom2.Content; //导入依赖的package包/类
/**
* This method retrieves the element of a modified entry. the modified
* entries' content is stored in a separated XML-Document (see
* {@link #modifiedEntries modifiedEntries}. each element of this document
* has a timestamp-attribute that equals the timestamp-attribute of an entry
* in the {@link #desktop desktop}-Document.
* <br><br>
* So, by passing a {@code timestamp} value, this method searches whether we
* have any modified entry that has the same timestamp-attribut, and if so,
* it returns that element which was modified (and thus differs from an
* entry's content as it is stored in the original database).
*
* @param timestamp the timestamp which should match the requested entry's
* timestamp-attribute
* @return the modified entry as element, or {@code null} if no entry was
* found.
*/
private Element retrieveModifiedEntryElementFromTimestamp(String timestamp) {
// retrieve all elements
List<Content> elementList = modifiedEntries.getRootElement().getContent();
// when we have any content, go on...
if (elementList.size() > 0) {
for (Content elementList1 : elementList) {
// retrieve each single element
Element e = (Element) elementList1;
// retrieve timestamp-attribute
String att = e.getAttributeValue(ATTR_TIMESTAMP);
// compare timestamp-attribute-value to timestamp-parameter
if (att != null && att.equals(timestamp)) {
// if they match, return that element
return e;
}
}
}
// else return null
return null;
}
示例9: getChildren
import org.jdom2.Content; //导入依赖的package包/类
private List<Element> getChildren(Element parentElement, String tagName) {
IteratorIterable<Content> iter = parentElement.getDescendants();
List<Element> children = new ArrayList<Element>();
while (iter.hasNext()) {
Element elem;
try {
elem = (Element) iter.next();
} catch (ClassCastException e) {
continue;
}
if (tagName.equalsIgnoreCase(elem.getName())) {
children.add(elem);
}
}
return children;
}
示例10: doFilter
import org.jdom2.Content; //导入依赖的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);
}
}
示例11: replaceVarsRecursive
import org.jdom2.Content; //导入依赖的package包/类
private Content replaceVarsRecursive(TemplateNode node){
Content c = node.xmlNode.clone();
if( c instanceof Element ){
Element e = (Element) c;
e.getContent().clear();
for( TemplateNode n : node.children ) {
Content child = replaceVarsRecursive(n);
e.addContent(child);
}
}
if( node instanceof TemplateVarNode ){
TemplateVarNode tvn = (TemplateVarNode) node;
replace(c, tvn.content);
}
return c;
}
示例12: convert
import org.jdom2.Content; //导入依赖的package包/类
@Override
public Object convert(ConvertContext cxt, Rule rule)
throws ConvertException {
String xpath = (String ) rule.getParams()[0];
logger.debug("xpath: {}",xpath);
XPathExpression<Object> objs = factory.compile(xpath);
List<Object> objList = objs.diagnose(cxt.getSourceDocument(), false).getResult();
logger.debug(">> {}",objList);
if(objList==null){
return null;
}
for(Object obj :objList){
if(obj instanceof Element){
return ((Element) obj).getValue();
}else if(obj instanceof Content){
return ((Content) obj).getValue();
}
}
return "null";
}
示例13: convert
import org.jdom2.Content; //导入依赖的package包/类
@Override
public Object convert(ConvertContext cxt, Rule rule)
throws ConvertException {
String slotName = (String ) rule.getParams()[0];
String xpath = "/SubmitSoapRequest/objective/slot[slotName='"+slotName+"']/slotValue/text()";
logger.trace("xpath: {}",xpath);
XPathExpression<Object> objs = factory.compile(xpath);
List<Object> objList = objs.diagnose(cxt.getSourceDocument(), false).getResult();
logger.trace(">> {}",objList);
if(objList==null){
return null;
}
for(Object obj :objList){
if(obj instanceof Element){
return ((Element) obj).getValue();
}else if(obj instanceof Content){
return ((Content) obj).getValue();
}
}
return "XXXX";
}
示例14: convert
import org.jdom2.Content; //导入依赖的package包/类
@Override
public Object convert(ConvertContext cxt, Rule rule)
throws ConvertException {
String groupName = (String ) rule.getParams()[0];
String itemName = (String ) rule.getParams()[1];
String xpath = "/CdpeRequest/phyExamInfo/examGroup[groupName='"+groupName+"']/groupItem[itemName='"+itemName+"']/itemValue/text()";
logger.debug("xpath: {}",xpath);
XPathExpression<Object> objs = factory.compile(xpath);
List<Object> objList = objs.diagnose(cxt.getSourceDocument(), false).getResult();
logger.trace(">> {}",objList);
if(objList==null){
return null;
}
for(Object obj :objList){
if(obj instanceof Element){
return ((Element) obj).getValue();
}else if(obj instanceof Content){
return ((Content) obj).getValue();
}
}
return "XXXX";
}
示例15: readIncludedDocument
import org.jdom2.Content; //导入依赖的package包/类
private List<Content> readIncludedDocument(@Nullable Path basePath, Path includeFile, @Nullable Element includeElement) throws InvalidXMLException {
final Path fullPath = findIncludeFile(basePath, includeFile, includeElement);
if(fullPath == null) {
throw new InvalidXMLException("Failed to find include: " + includeFile, includeElement);
}
return readIncludedDocument(fullPath, includeElement);
}