org.jdom2.Content Java Examples
The following examples show how to use
org.jdom2.Content.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DesktopData.java From Zettelkasten with GNU General Public License v3.0 | 6 votes |
/** * 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; }
Example #2
Source File: MCRWCMSDefaultSectionProvider.java From mycore with GNU General Public License v3.0 | 6 votes |
/** * 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 (!"".equals(trimmedText)) { Text newText = new Text(trimmedText); out.output(newText, writer); } } } return writer.toString(); }
Example #3
Source File: MCRXMLHelperTest.java From mycore with GNU General Public License v3.0 | 6 votes |
@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(StandardCharsets.UTF_8))); assertEquals("Elements should be equal", true, MCRXMLHelper.deepEqual(root, doc.getRootElement())); }
Example #4
Source File: MCRMetaEnrichedLinkID.java From mycore with GNU General Public License v3.0 | 6 votes |
@Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } MCRMetaEnrichedLinkID that = (MCRMetaEnrichedLinkID) o; final List<Content> myContentList = getContentList(); final List<Content> theirContentList = that.getContentList(); final int listSize = myContentList.size(); if (listSize != theirContentList.size()) { return false; } for (int i = 0; i < listSize; i++) { Content myContent = myContentList.get(i); Content theirContent = theirContentList.get(i); if (!myContent.equals(theirContent) || (myContent instanceof Element && theirContent instanceof Element && !MCRXMLHelper.deepEqual((Element) myContent, (Element) theirContent))) { return false; } } return true; }
Example #5
Source File: MapFilePreprocessor.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private List<Content> readIncludedDocument(Path fullPath, @Nullable Element includeElement) throws InvalidXMLException { if(includeStack.contains(fullPath)) { throw new InvalidXMLException("Circular include: " + Joiner.on(" --> ").join(includeStack), includeElement); } includeStack.push(fullPath); try { return readDocument(fullPath).getRootElement().cloneContent(); } finally { includeStack.pop(); } }
Example #6
Source File: BaseWireFeedParser.java From rome with Apache License 2.0 | 5 votes |
protected String getStyleSheet(final Document doc) { String styleSheet = null; for (final Content c : doc.getContent(new ContentFilter(ContentFilter.PI))) { final ProcessingInstruction pi = (ProcessingInstruction) c; if ("text/xsl".equals(pi.getPseudoAttributeValue("type"))) { styleSheet = pi.getPseudoAttributeValue("href"); break; } } return styleSheet; }
Example #7
Source File: RSS092Parser.java From rome with Apache License 2.0 | 5 votes |
@Override protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { final Description desc = new Description(); final StringBuilder sb = new StringBuilder(); final XMLOutputter xmlOut = new XMLOutputter(); for (final Content c : eDesc.getContent()) { switch (c.getCType()) { case Text: case CDATA: sb.append(c.getValue()); break; case EntityRef: LOG.debug("Entity: {}", c.getValue()); sb.append(c.getValue()); break; case Element: sb.append(xmlOut.outputString((Element) c)); break; default: // ignore break; } } desc.setValue(sb.toString()); String att = eDesc.getAttributeValue("type"); if (att == null) { att = "text/html"; } desc.setType(att); return desc; }
Example #8
Source File: SSEParserTest.java From rome with Apache License 2.0 | 5 votes |
private void asserEqualContent(final Element one, final Element two) { final List<Content> oneContent = one.getContent(); final List<Content> twoContent = two.getContent(); if (bothNull(oneContent, twoContent)) { return; } assertNullEqual("missing compare content", oneContent, twoContent); assertEqualAttributes(one, two); // scan through the content to make sure each element is equal for (final Object content1 : oneContent) { if (content1 instanceof Element) { final Element e1 = (Element) content1; boolean foundEqual = false; final ArrayList<String> messages = new ArrayList<String>(); for (final Object o : twoContent) { if (o instanceof Element) { final Element e2 = (Element) o; try { // have to check all elements to be order insensitive if (e1.getName().equals(e2.getName()) && equalAttributes(e1, e2, false)) { assertEqualElements(e1, e2); foundEqual = true; messages.clear(); break; } } catch (final Error e) { messages.add(e.getMessage()); } } } // look for the content in the other tree assertTrue("could not find matching element for: " + one.getName(), foundEqual); } } }
Example #9
Source File: ContentModuleParser.java From rome with Apache License 2.0 | 5 votes |
protected String getXmlInnerText(final Element e) { final StringBuffer sb = new StringBuffer(); final XMLOutputter xo = new XMLOutputter(); final List<Content> children = e.getContent(); sb.append(xo.outputString(children)); return sb.toString(); }
Example #10
Source File: ITunesParser.java From rome with Apache License 2.0 | 5 votes |
protected String getXmlInnerText(final Element e) { final StringBuffer sb = new StringBuffer(); final XMLOutputter xo = new XMLOutputter(); final List<Content> children = e.getContent(); sb.append(xo.outputString(children)); return sb.toString(); }
Example #11
Source File: SaxonUtil.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
/** * Evaluates an XQuery against a data document * @param query the XQuery to evaluate * @param dataElem a JDOM Element containing the data tree * @return a List containing the Element(s) resulting from the evaluation * @throws SaxonApiException if there's a problem with the XQuery or Element */ public static List<Content> evaluateListQuery(String query, Element dataElem) throws SaxonApiException { // put the element in a jdom document Document dataDoc = new Document(dataElem.clone()); String result = evaluateQuery(query, dataDoc); // use the string result to create a doc to get it expressed as an element list Document resultDoc = JDOMUtil.stringToDocument(StringUtil.wrap(result, "root")); return resultDoc.getRootElement().cloneContent(); }
Example #12
Source File: MCRXMLHelper.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * This method is capable of serializing Elements and Text nodes. * Return null otherwise. * * @param content the content to serialize * @return the serialized content, or null if the type is not supported */ public static JsonElement serialize(Content content) { if (content instanceof Element) { return serializeElement((Element) content); } if (content instanceof Text) { return serializeText((Text) content); } return null; }
Example #13
Source File: MCRXMLHelper.java From mycore with GNU General Public License v3.0 | 5 votes |
public static boolean equivalentContent(List<Content> l1, List<Content> l2) { if (l1.size() != l2.size()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Number of content list elements differ {}!={}", l1.size(), l2.size()); } return false; } boolean result = true; Iterator<Content> i1 = l1.iterator(); Iterator<Content> i2 = l2.iterator(); while (result && i1.hasNext() && i2.hasNext()) { Object o1 = i1.next(); Object o2 = i2.next(); if (o1 instanceof Element && o2 instanceof Element) { result = equivalent((Element) o1, (Element) o2); } else if (o1 instanceof Text && o2 instanceof Text) { result = equivalent((Text) o1, (Text) o2); } else if (o1 instanceof Comment && o2 instanceof Comment) { result = equivalent((Comment) o1, (Comment) o2); } else if (o1 instanceof ProcessingInstruction && o2 instanceof ProcessingInstruction) { result = equivalent((ProcessingInstruction) o1, (ProcessingInstruction) o2); } else if (o1 instanceof DocType && o2 instanceof DocType) { result = equivalent((DocType) o1, (DocType) o2); } else { result = false; } } return result; }
Example #14
Source File: MCRXSL2XMLTransformer.java From mycore with GNU General Public License v3.0 | 5 votes |
private Document getDocument(JDOMResult result) { Document resultDoc = result.getDocument(); if (resultDoc == null) { //Sometimes a transformation produces whitespace strings //JDOM would produce a empty document if it detects those //So we remove them, if they exists. List<Content> transformResult = result.getResult(); int origSize = transformResult.size(); Iterator<Content> iterator = transformResult.iterator(); while (iterator.hasNext()) { Content content = iterator.next(); if (content instanceof Text) { String trimmedText = ((Text) content).getTextTrim(); if (trimmedText.length() == 0) { iterator.remove(); } } } if (transformResult.size() < origSize) { JDOMFactory f = result.getFactory(); if (f == null) { f = new DefaultJDOMFactory(); } resultDoc = f.document(null); resultDoc.setContent(transformResult); } } return resultDoc; }
Example #15
Source File: MyCoReWebPageProvider.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * Adds a section to the MyCoRe webpage * @param title the title of the section * @param content list of content added to the section * @param lang the language of the section specified by a language key. * @return added section */ public Element addSection(String title, List<Content> content, String lang) { Element section = new Element(XML_SECTION); if (lang != null) { section.setAttribute(XML_LANG, lang, Namespace.XML_NAMESPACE); } if (title != null && !title.equals("")) { section.setAttribute(XML_TITLE, title); } section.addContent(content); this.xml.getRootElement().addContent(section); return section; }
Example #16
Source File: MCRMetaXML.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * This method create a XML stream for all data in this class, defined by * the MyCoRe XML MCRMetaLangText definition for the given subtag. * * @exception MCRException * if the content of this class is not valid * @return a JDOM Element with the XML MCRMetaLangText part */ @Override public Element createXML() throws MCRException { Element elm = super.createXML(); List<Content> addedContent = new ArrayList<>(content.size()); cloneListContent(addedContent, content); elm.addContent(addedContent); return elm; }
Example #17
Source File: MCRMODSWrapper.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * @return the mods:mods Element at /metadata/def.modsContainer/modsContainer */ public Element getMODS() { try { MCRMetaXML mx = (MCRMetaXML) (object.getMetadata().getMetadataElement(DEF_MODS_CONTAINER).getElement(0)); for (Content content : mx.getContent()) { if (content instanceof Element) { return (Element) content; } } } catch (NullPointerException | IndexOutOfBoundsException e) { //do nothing } return null; }
Example #18
Source File: MapFilePreprocessor.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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); }
Example #19
Source File: MapFilePreprocessor.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private List<Content> processConditional(Element el, boolean invert) throws InvalidXMLException { for(Node attr : Node.fromAttrs(el)) { boolean expected = XMLUtils.parseBoolean(attr); boolean actual = getEnvironment(attr.getName(), Boolean.class, attr); if(expected != actual) { return invert ? el.cloneContent() : Collections.<Content>emptyList(); } } return invert ? Collections.<Content>emptyList() : el.cloneContent(); }
Example #20
Source File: MapFilePreprocessor.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void processChildren(Path file, Element parent) throws InvalidXMLException { for(int i = 0; i < parent.getContentSize(); i++) { Content content = parent.getContent(i); if(!(content instanceof Element)) continue; Element child = (Element) content; List<Content> replacement = null; switch(child.getName()) { case "include": replacement = processIncludeElement(file, child); break; case "if": replacement = processConditional(child, false); break; case "unless": replacement = processConditional(child, true); break; } if(replacement != null) { parent.removeContent(i); parent.addContent(i, replacement); i--; // Process replacement content } else { processChildren(file, child); } } }
Example #21
Source File: MCRSwapElements.java From mycore with GNU General Public License v3.0 | 5 votes |
public static MCRChangeData swap(Element parent, int posA, Content a, int posB, Content b) { if (posA > posB) { return swap(parent, posB, b, posA, a); } b.detach(); // x a x x x parent.addContent(posA, b); // x b a x x x a.detach(); // x b x x x parent.addContent(posB, a); // x b x x a x return new MCRChangeData("swapped-elements", posA + " " + posB, posB, parent); }
Example #22
Source File: MCRMetaEnrichedLinkID.java From mycore with GNU General Public License v3.0 | 5 votes |
@Override public Element createXML() throws MCRException { final Element xml = super.createXML(); contentList.stream().map(Content::clone).forEach(xml::addContent); xml.sortChildren( Comparator.comparingInt(MCRMetaEnrichedLinkID::getElementPosition) .thenComparing(contentList::indexOf)); return xml; }
Example #23
Source File: MCRMetaXML.java From mycore with GNU General Public License v3.0 | 5 votes |
public void addContent(Content content) { if (this.content == null) { this.content = new ArrayList<>(); } this.content.add(content); }
Example #24
Source File: MCRMetaEnrichedLinkID.java From mycore with GNU General Public License v3.0 | 4 votes |
@JsonIgnore public List<Content> getContentList() { return contentList; }
Example #25
Source File: MCRMetaEnrichedLinkID.java From mycore with GNU General Public License v3.0 | 4 votes |
public void setContentList(List<Content> contentList) { this.contentList = Objects.requireNonNull(contentList); }
Example #26
Source File: MCRMetaEnrichedLinkID.java From mycore with GNU General Public License v3.0 | 4 votes |
@Override public void setFromDOM(Element element) { super.setFromDOM(element); contentList = element.getContent().stream().map(Content::clone).collect(Collectors.toList()); }
Example #27
Source File: MCRMetaXML.java From mycore with GNU General Public License v3.0 | 4 votes |
public List<Content> getContent() { return content; }
Example #28
Source File: MCREditableMetaEnrichedLinkID.java From mycore with GNU General Public License v3.0 | 4 votes |
protected Element createNewElement(String name) { final List<Content> contentList = getContentList(); Element orderElement = new Element(name); contentList.add(orderElement); return orderElement; }
Example #29
Source File: AOI.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private boolean load(final File file) { Document doc; try { doc = XMLSupport.LoadXML(file.getAbsolutePath()); final Element root = doc.getRootElement(); final Attribute nameAttrib = root.getAttribute("name"); if (nameAttrib != null) this.name = nameAttrib.getValue(); final List<GeoPos> geoPosList = new ArrayList<GeoPos>(); final List<Content> children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element child = (Element) aChild; if (child.getName().equals("param")) { inputFolder = XMLSupport.getAttrib(child, "inputFolder"); outputFolder = XMLSupport.getAttrib(child, "outputFolder"); processingGraph = XMLSupport.getAttrib(child, "graph"); lastProcessed = XMLSupport.getAttrib(child, "lastProcessed"); final Attribute findSlavesAttrib = child.getAttribute("findSlaves"); if (findSlavesAttrib != null) findSlaves = Boolean.parseBoolean(findSlavesAttrib.getValue()); final Attribute maxSlavesAttrib = child.getAttribute("maxSlaves"); if (maxSlavesAttrib != null) maxSlaves = Integer.parseInt(maxSlavesAttrib.getValue()); } else if (child.getName().equals("points")) { final List<Content> pntsList = child.getContent(); for (Object o : pntsList) { if (o instanceof Element) { final Element pntElem = (Element) o; final String latStr = XMLSupport.getAttrib(pntElem, "lat"); final String lonStr = XMLSupport.getAttrib(pntElem, "lon"); if (!latStr.isEmpty() && !lonStr.isEmpty()) { final float lat = Float.parseFloat(latStr); final float lon = Float.parseFloat(lonStr); geoPosList.add(new GeoPos(lat, lon)); } } } } else if (child.getName().equals(DBQuery.DB_QUERY)) { slaveDBQuery = new DBQuery(); //todo slaveDBQuery.fromXML(child); } } } aoiPoints = geoPosList.toArray(new GeoPos[geoPosList.size()]); } catch (IOException e) { SnapApp.getDefault().handleError("Unable to load AOI", e); return false; } return true; }
Example #30
Source File: MCRSwapElements.java From mycore with GNU General Public License v3.0 | 4 votes |
public static MCRChangeData swap(Element parent, int posA, int posB) { Content a = parent.getContent().get(posA); Content b = parent.getContent().get(posB); return swap(parent, posA, a, posB, b); }