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.mycore.frontend.editor.MCREditorServlet.java
License:Open Source License
/** * Shows a help popup window// w w w. j a va2s . c om */ private void processShowPopup(MCRServletJob job) throws IOException, TransformerException, SAXException { String sessionID = job.getRequest().getParameter("_session"); String ref = job.getRequest().getParameter("_ref"); LOGGER.debug("Editor session " + sessionID + " show popup " + ref); Element editor = MCREditorSessionCache.instance().getEditorSession(sessionID).getXML(); Element popup = MCREditorDefReader.findElementByID(ref, editor); Element clone = (Element) popup.clone(); getLayoutService().doLayout(job.getRequest(), job.getResponse(), new MCRJDOMContent(clone)); }
From source file:org.mycore.frontend.export.MCRExportCollection.java
License:Open Source License
/** * Adds the given XML element, making a clone. */// w w w .j a va2 s . c o m public void add(Element element) { collection.addContent((Element) (element.clone())); }
From source file:org.mycore.frontend.xeditor.MCRBinding.java
License:Open Source License
public Element cloneBoundElement(int index) { Element template = (Element) (boundNodes.get(index)); Element newElement = template.clone(); Element parent = template.getParentElement(); int indexInParent = parent.indexOf(template) + 1; parent.addContent(indexInParent, newElement); boundNodes.add(index + 1, newElement); trackNodeCreated(newElement);//w w w . jav a2 s . c om return newElement; }
From source file:org.mycore.mir.authorization.MirSelfRegistrationServlet.java
License:Open Source License
private void register(final HttpServletRequest req, final HttpServletResponse res) throws Exception { final Document doc = (Document) (req.getAttribute("MCRXEditorSubmission")); if (doc == null) { res.sendRedirect(MCRFrontendUtil.getBaseURL() + "authorization/new-author.xed"); }// w ww .j av a2s . co m final Element u = doc.getRootElement(); final MCRUser user = MCRUserTransformer.buildMCRUser(u); final boolean userExists = MCRUserManager.exists(user.getUserID(), user.getRealm().getID()); if (!userExists) { try { MCRMailer.sendMail(MCRUserTransformer.buildExportableSafeXML(user), "e-mail-new-author"); MCRMailer.sendMail(MCRUserTransformer.buildExportableSafeXML(user), "e-mail-new-author-registered"); } catch (final Exception ex) { LOGGER.error(ex); res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg("mailError")); return; } LOGGER.info("create new user " + user.getUserID() + " " + user.getRealm().getID()); final String password = doc.getRootElement().getChildText("password"); user.setDisabled(true); // remove all roles set by editor user.getSystemRoleIDs().clear(); user.setHashType(MCRPasswordHashType.md5); user.setPassword(MCRUtils.asMD5String(1, null, password)); MCRUserManager.createUser(user); final Element root = new Element("new-author-created"); root.addContent(u.clone()); getLayoutService().doLayout(req, res, new MCRJDOMContent(root)); } else { LOGGER.error("User " + user.getUserID() + " already exists!"); res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg("userExists")); } }
From source file:org.mycore.mir.authorization.MirSelfRegistrationServlet.java
License:Open Source License
private void verify(final HttpServletRequest req, final HttpServletResponse res) throws Exception { final String userName = req.getParameter("user"); final String realmId = req.getParameter("realm"); final String mailToken = req.getParameter("token"); if (userName != null && realmId != null && mailToken != null) { final MCRUser user = MCRUserManager.getUser(userName, realmId); if (user != null) { final String umt = user.getUserAttribute("mailtoken"); if (umt != null) { if (umt.equals(mailToken)) { user.setDisabled(false); if (DEFAULT_ROLE != null && !DEFAULT_ROLE.isEmpty()) user.assignRole(DEFAULT_ROLE); user.getAttributes().remove("mailtoken"); MCRUserManager.updateUser(user); final Element root = new Element("new-author-verified"); final Element u = MCRUserTransformer.buildExportableSafeXML(user).getRootElement(); root.addContent(u.clone()); getLayoutService().doLayout(req, res, new MCRJDOMContent(root)); } else { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg("missingParameter")); }// w w w. j a v a 2 s.c o m } else { LOGGER.warn("No \"mailtoken\" attribute for user " + user.getUserID() + "."); res.sendRedirect(MCRFrontendUtil.getBaseURL()); } } else { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg("userNotFound")); } } else { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMsg("missingParameter")); } }
From source file:org.mycore.mods.MCRExtractRelatedItemsEventHandler.java
License:Open Source License
private Element cloneRelatedItem(Element relatedItem) { Element mods = (Element) (relatedItem.clone()); mods.setName("mods"); mods.removeAttribute("type"); mods.removeAttribute("href", MCRConstants.XLINK_NAMESPACE); mods.removeAttribute("type", MCRConstants.XLINK_NAMESPACE); mods.removeChildren("part", MCRConstants.MODS_NAMESPACE); return mods;/*w ww. j a v a 2 s . co m*/ }
From source file:org.rometools.feed.module.content.io.ContentModuleParser.java
License:Open Source License
public com.sun.syndication.feed.module.Module parse(org.jdom2.Element element) { boolean foundSomething = false; ContentModule cm = new ContentModuleImpl(); List encodeds = element.getChildren("encoded", CONTENT_NS); ArrayList contentStrings = new ArrayList(); ArrayList encodedStrings = new ArrayList(); if (encodeds.size() > 0) { foundSomething = true;//w w w . ja va 2s . c om for (int i = 0; i < encodeds.size(); i++) { Element encodedElement = (Element) encodeds.get(i); encodedStrings.add(encodedElement.getText()); contentStrings.add(encodedElement.getText()); } } ArrayList contentItems = new ArrayList(); List items = element.getChildren("items", CONTENT_NS); for (int i = 0; i < items.size(); i++) { foundSomething = true; List lis = ((Element) items.get(i)).getChild("Bag", RDF_NS).getChildren("li", RDF_NS); for (int j = 0; j < lis.size(); j++) { ContentItem ci = new ContentItem(); Element li = (Element) lis.get(j); Element item = li.getChild("item", CONTENT_NS); Element format = item.getChild("format", CONTENT_NS); Element encoding = item.getChild("encoding", CONTENT_NS); Element value = item.getChild("value", RDF_NS); if (value != null) { if (value.getAttributeValue("parseType", RDF_NS) != null) { ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS)); } if ((ci.getContentValueParseType() != null) && ci.getContentValueParseType().equals("Literal")) { ci.setContentValue(getXmlInnerText(value)); contentStrings.add(getXmlInnerText(value)); ci.setContentValueNamespaces(value.getAdditionalNamespaces()); } else { ci.setContentValue(value.getText()); contentStrings.add(value.getText()); } ci.setContentValueDOM(((Element) value.clone()).getContent()); } if (format != null) { ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue()); } if (encoding != null) { ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue()); } if (item != null) { Attribute about = item.getAttribute("about", RDF_NS); if (about != null) { ci.setContentAbout(about.getValue()); } } contentItems.add(ci); } } cm.setEncodeds(encodedStrings); cm.setContentItems(contentItems); cm.setContents(contentStrings); return (foundSomething) ? cm : null; }
From source file:org.shaman.rpg.editor.level.LevelBuildFileExtender.java
private Element createExportLevelsTarget() { Element target = new Element("target"); Element mkdir = new Element("mkdir"); mkdir.setAttribute("dir", "${" + Extender.OUTPUT_LEVELS + "}"); target.addContent(mkdir);//from w w w. j a v a2 s . c o m Element mkdir2 = new Element("mkdir"); mkdir2.setAttribute("dir", "${" + Extender.INPUT_ROOT + "}" + Levels.LEVELS_FOLDER + "/"); target.addContent(mkdir2); Element delEntries = new Element("delete"); delEntries.setAttribute("file", "${" + Extender.OUTPUT_ENTRY_FILE + "}"); target.addContent(delEntries); Element sync = new Element("sync"); sync.setAttribute("todir", "${" + Extender.OUTPUT_LEVELS + "}"); sync.setAttribute("verbose", "true"); Element fileset = new Element("fileset"); fileset.setAttribute("dir", "${" + Extender.INPUT_ROOT + "}" + Levels.LEVELS_FOLDER + "/"); fileset.setAttribute("includes", "**/*.level"); sync.addContent(fileset); target.addContent(sync); //add entries to the entry-file Element f = new Element("for"); f.setAttribute("param", "filename"); Element path = new Element("path"); path.addContent(fileset.clone()); f.addContent(path); Element sequential = new Element("sequential"); Element path2 = new Element("path"); path2.setAttribute("id", "engine.level.path-raw"); path2.addContent(new Element("pathelement").setAttribute("location", "@{filename}")); sequential.addContent(path2); Element local = new Element("local"); local.setAttribute("name", "engine.level.path"); sequential.addContent(local); Element prop = new Element("pathconvert"); prop.setAttribute("property", "engine.level.path"); prop.setAttribute("dirsep", "/"); prop.setAttribute("refid", "engine.level.path-raw"); Element map = new Element("map"); map.setAttribute("from", "${" + Extender.INPUT_ROOT + "}" + Levels.LEVELS_FOLDER + "/"); map.setAttribute("to", ""); prop.addContent(map); sequential.addContent(prop); Element echo = new Element("echo"); echo.setAttribute("file", "${" + Extender.OUTPUT_ENTRY_FILE + "}"); echo.setAttribute("append", "true"); echo.setAttribute("message", "${engine.level.path}\n"); sequential.addContent(echo); f.addContent(sequential); target.addContent(f); return target; }
From source file:org.xflatdb.xflat.db.ElementTable.java
License:Apache License
@Override public void insert(Element data) throws DuplicateKeyException { String id = getId(data);/*from w w w. j a v a 2s. c om*/ if (id == null) { id = generateNewId(); setId(id, data); } //always clone incoming data final Element cData = data.clone(); final String sId = id; this.doWithEngine(new EngineActionEx<Object, DuplicateKeyException>() { @Override public Object act(Engine engine) throws DuplicateKeyException { engine.insertRow(sId, cData); return null; } }); }
From source file:org.xflatdb.xflat.db.ElementTable.java
License:Apache License
@Override public void replace(Element newValue) throws KeyNotFoundException { final String id = getId(newValue); if (id == null) { throw new KeyNotFoundException("Element has no ID"); }/* w ww .j a v a2 s . c om*/ //always clone incoming data final Element data = newValue.clone(); this.doWithEngine(new EngineActionEx<Object, KeyNotFoundException>() { @Override public Object act(Engine engine) throws KeyNotFoundException { engine.replaceRow(id, data); return null; } }); }