List of usage examples for org.jdom2 Element clone
@Override
public Element clone()
This returns a deep clone of this element.
From source file:org.lendingclub.mercator.ucs.UCSClient.java
License:Apache License
public void logDebug(String message, Element element) { if (logger.isDebugEnabled()) { XMLOutputter out = new XMLOutputter(); out.setFormat(Format.getPrettyFormat()); element = element.clone(); if (!Strings.isNullOrEmpty(element.getAttributeValue("outCookie"))) { element.setAttribute("outCookie", "**********"); }// w w w . j av a2s . c o m if (!Strings.isNullOrEmpty(element.getAttributeValue("cookie"))) { element.setAttribute("cookie", "**********"); } logger.debug(message + "\n{}", out.outputString(element)); } }
From source file:org.mycore.common.content.MCRSourceContent.java
License:Open Source License
public MCRSourceContent(Source source) { if (source == null) { throw new NullPointerException("Source cannot be null"); }/* w ww . jav a2s.co m*/ this.source = source; MCRContent baseContent = null; if (source instanceof JDOMSource) { JDOMSource src = (JDOMSource) source; Document xml = src.getDocument(); if (xml != null) { baseContent = new MCRJDOMContent(xml); } else { for (Object node : src.getNodes()) { if (node instanceof Element) { Element element = (Element) node; Document doc = element.getDocument(); if (doc == null) { baseContent = new MCRJDOMContent(element); } else { if (doc.getRootElement() == element) { baseContent = new MCRJDOMContent(doc); } else { baseContent = new MCRJDOMContent((Element) element.clone()); } } break; } else if (node instanceof Document) { baseContent = new MCRJDOMContent((Document) node); break; } } } } else if (source instanceof SAXSource) { SAXSource src = (SAXSource) source; baseContent = new MCRSAXContent(src.getXMLReader(), src.getInputSource()); } else if (source instanceof DOMSource) { Node node = ((DOMSource) source).getNode(); baseContent = new MCRDOMContent(node.getOwnerDocument()); } else if (source instanceof StreamSource) { InputStream inputStream = ((StreamSource) source).getInputStream(); if (inputStream != null) { baseContent = new MCRStreamContent(inputStream); } else { try { URL url = new URL(source.getSystemId()); baseContent = new MCRURLContent(url); } catch (MalformedURLException e) { throw new MCRException( "Could not create instance of MCRURLContent for SYSTEMID: " + source.getSystemId(), e); } } } if (baseContent == null) { throw new MCRException("Could not get MCRContent from " + source.getClass().getCanonicalName() + ", systemId:" + source.getSystemId()); } baseContent.setSystemId(getSystemId()); this.setBaseContent(baseContent); }
From source file:org.mycore.datamodel.ifs.MCRFilesystemNode.java
License:Open Source License
/** * Stores additional XML data for this node. The name of the data element is * used as unique key for storing data. If data with this name already * exists, it is overwritten./*from www .ja v a 2 s . co m*/ * * @param data * the additional XML data to be saved * @throws IOException * if the XML data can not be retrieved * @throws JDOMException * if the XML data can not be parsed */ public void setAdditionalData(Element data) throws IOException, JDOMException { MCRFile dataFile = MCRFile.getRootFile(ID); Document doc; if (dataFile == null) { String name = "MCRFilesystemNode.additionalData"; dataFile = new MCRFile(name, ID); doc = new Document(new Element("additionalData")); } else { doc = dataFile.getContentAsJDOM(); } Element child = doc.getRootElement().getChild(data.getName()); if (child != null) { child.detach(); } doc.getRootElement().addContent((Element) data.clone()); dataFile.setContentFrom(doc); }
From source file:org.mycore.datamodel.metadata.MCRMetaAccessRule.java
License:Open Source License
/** * This method set the condition./*from w w w . j ava 2 s. c om*/ * * @param set_condition * the JDOM Element included the condition tree * @exception MCRException * if the set_condition is null or empty */ public final void setCondition(org.jdom2.Element set_condition) throws MCRException { if (set_condition == null || !set_condition.getName().equals("condition")) { throw new MCRException("The condition Element of MCRMetaAccessRule is null."); } condition = (Element) set_condition.clone(); }
From source file:org.mycore.datamodel.metadata.MCRMetaISO8601Date.java
License:Open Source License
@Override public void setFromDOM(org.jdom2.Element element) { super.setFromDOM(element); setFormat(element.getAttributeValue("format")); setDate(element.getTextTrim());/*from w w w .j a va 2s. c o m*/ export = (Element) element.clone(); }
From source file:org.mycore.frontend.basket.MCRBasketEntry.java
License:Open Source License
/** * Sets the XML data of the object in the basket entry. *//* w w w . java 2s . c o m*/ public void setContent(Element content) { this.content = (Element) (content.clone()); }
From source file:org.mycore.frontend.basket.MCRBasketXMLBuilder.java
License:Open Source License
/** * Builds an XML representation of a basket entry. * Note that setContent() or resolveContent() must have been called before * if XML content of the basket entry's object should be included. *//*from ww w .j a va 2 s .com*/ public Element buildXML(MCRBasketEntry entry) { Element xml = new Element("entry"); xml.setAttribute("id", entry.getID()); xml.setAttribute("uri", entry.getURI()); if (addContent) { Element content = entry.getContent(); if (content != null) xml.addContent((Element) (content.clone())); } String comment = entry.getComment(); if (comment != null) xml.addContent(new Element("comment").setText(comment)); return xml; }
From source file:org.mycore.frontend.cli.MCRCommandLineInterface.java
License:Open Source License
/** * Reads XML content from URIResolver and sends output to a local file. *//*from w w w.ja v a 2s . c om*/ public static void getURI(String uri, String file) throws Exception { Element resolved = MCRURIResolver.instance().resolve(uri); Element cloned = (Element) resolved.clone(); new MCRJDOMContent(cloned).sendTo(new File(file)); }
From source file:org.mycore.frontend.editor.MCREditorDefReader.java
License:Open Source License
/** * Recursively resolves references by the @ref attribute and * replaces them with the referenced component. *///from w w w .ja v a 2 s.c o m private void resolveReferences() { for (Iterator<Element> it = referencing2ref.keySet().iterator(); it.hasNext();) { Element referencing = it.next(); String id = referencing2ref.get(referencing); LOGGER.debug("Resolving reference to " + id); Element found = id2component.get(id); if (found == null) { String msg = "Reference to component " + id + " could not be resolved"; throw new MCRConfigurationException(msg); } String name = referencing.getName(); referencing.removeAttribute("ref"); it.remove(); if (name.equals("cell") || name.equals("repeater")) { if (found.getParentElement().getName().equals("components")) { referencing.addContent(0, found.detach()); } else { referencing.addContent(0, (Element) found.clone()); } } else if (name.equals("panel")) { if (referencing2ref.containsValue(id)) { referencing.addContent(0, found.cloneContent()); } else { found.detach(); List<Content> content = found.getContent(); for (int i = 0; !content.isEmpty(); i++) { Content child = content.remove(0); referencing.addContent(i, child); } } } else if (name.equals("include")) { Element parent = referencing.getParentElement(); int pos = parent.indexOf(referencing); referencing.detach(); if (referencing2ref.containsValue(id)) { parent.addContent(pos, found.cloneContent()); } else { found.detach(); List<Content> content = found.getContent(); for (int i = pos; !content.isEmpty(); i++) { Content child = content.remove(0); parent.addContent(i, child); } } } } Element components = editor.getChild("components"); String root = components.getAttributeValue("root"); for (int i = 0; i < components.getContentSize(); i++) { Content child = components.getContent(i); if (!(child instanceof Element)) { continue; } if (((Element) child).getName().equals("headline")) { continue; } if (!root.equals(((Element) child).getAttributeValue("id"))) { components.removeContent(i--); } } }
From source file:org.mycore.frontend.editor.MCREditorServlet.java
License:Open Source License
private void includeEditorFromXSL(MCRServletJob job) throws IOException { HttpServletRequest req = job.getRequest(); HttpServletResponse res = job.getResponse(); String sessionID = job.getRequest().getParameter("XSL.editor.session.id"); Element editorResolved = null; if (sessionID != null) { editorResolved = MCREditorSessionCache.instance().getEditorSession(sessionID).getXML(); }//ww w . j av a 2 s .c om if (editorResolved == null || sessionID == null) { Map parameters = job.getRequest().getParameterMap(); String ref = req.getParameter("_ref"); String uri = req.getParameter("_uri"); boolean validate = "true".equals(req.getParameter("_validate")); editorResolved = startSession(parameters, ref, uri, validate); } getLayoutService().sendXML(req, res, new MCRJDOMContent((Element) editorResolved.clone())); }