List of usage examples for org.jdom2 Element cloneContent
@Override
public List<Content> cloneContent()
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 ww .ja v a 2s. 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
/** * Replaces editor elements in static webpage with complete editor * definition.//w ww.j a v a 2 s.c om * * @param request * the current MCRServletJob * @param uri * the uri of the static XML file containing the editor * @param xml * the complete XML document of the static webpage */ public static void replaceEditorElements(HttpServletRequest request, String uri, Document xml) { String sessionID = request.getParameter("XSL.editor.session.id"); List<Element> editors = new ArrayList<Element>(); Iterator it = xml.getDescendants(new ElementFilter("editor")); while (it.hasNext()) { editors.add((Element) it.next()); } for (Element editor : editors) { Element editorResolved = null; if (sessionID != null) { MCREditorSession editorSession = MCREditorSessionCache.instance().getEditorSession(sessionID); if (editorSession == null) { throw new MCRException("Editor session is invalid:" + sessionID); } editorResolved = editorSession.getXML(); } if (sessionID == null || editorResolved == null) { Map parameters = request.getParameterMap(); boolean validate = "true".equals(editor.getAttributeValue("validate", "false")); String ref = editor.getAttributeValue("id"); editorResolved = startSession(parameters, ref, uri, validate); } String clazz1 = editor.getAttributeValue("class"); String clazz2 = editorResolved.getAttributeValue("class"); editor.removeContent(); editor.addContent(editorResolved.cloneContent()); editor.setAttribute("session", editorResolved.getAttributeValue("session")); editor.setAttribute("class", (clazz1 == null ? clazz2 : clazz1)); } }
From source file:org.yawlfoundation.yawl.digitalSignature.DigitalSignature.java
License:Open Source License
public String PrepareDocumentToBeSign(Element element) { try {// w ww . j a va 2 s . c o m //extract the Document to sign and transform it in a valid XML DOM Element rootElement = new Element(element.getName()); rootElement.setContent(element.cloneContent()); //convert the Element in a JDOM Document Document xdoc = new Document(rootElement); //create a DOMOutputter to write the content of the JDOM document in a DOM document DOMOutputter outputter = new DOMOutputter(); org.w3c.dom.Document Doctosign = outputter.output(xdoc); // Show the document before being sign System.out.println("xml to Sign:"); XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); sortie.output(xdoc, System.out); //Transform the XML DOM in a String using the xml transformer DOMSource domSource = new DOMSource(Doctosign); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); String StringTobeSign = writer.toString(); return StringTobeSign; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.yawlfoundation.yawl.resourcing.ResourceManager.java
License:Open Source License
/** * updates the input datalist with the changed data in the output datalist * * @param in - the JDOM Element containing the input params * @param out - the JDOM Element containing the output params * @return a JDOM Element with the data updated *//*from w w w . j av a 2 s . c om*/ private Element updateOutputDataList(Element in, Element out) { // get a copy of the 'in' list Element result = in.clone(); // for each child in 'out' list, get its value and copy to 'in' list for (Element e : out.getChildren()) { // if there's a matching 'in' data item, update its value Element resData = result.getChild(e.getName()); if (resData != null) { if (resData.getContentSize() > 0) resData.setContent(e.cloneContent()); else resData.setText(e.getText()); } else { result.addContent(e.clone()); } } return result; }
From source file:org.yawlfoundation.yawl.worklet.WorkletService.java
License:Open Source License
/** * updates the input datalist with the changed data in the output datalist * * @param in - the JDOM Element containing the input params * @param out - the JDOM Element containing the output params * @return a JDOM Element with the data updated *///w ww. jav a 2 s.co m public Element updateDataList(Element in, Element out) { // get a copy of the 'in' list Element result = in.clone(); // for each child in 'out' list, get its value and copy to 'in' list for (Element e : out.getChildren()) { // if there's a matching 'in' data item, update its value Element resData = result.getChild(e.getName()); if (resData != null) { if (resData.getContentSize() > 0) resData.setContent(e.cloneContent()); else resData.setText(e.getText()); } else { // if the item is not in the 'in' list, add it. result.getChildren().add(e.clone()); } } return result; }