List of usage examples for org.w3c.dom Node getParentNode
public Node getParentNode();
From source file:com.netscape.cms.servlet.csadmin.ConfigurationUtils.java
public static boolean updateConfigEntries(String hostname, int port, boolean https, String servlet, MultivaluedMap<String, String> content, IConfigStore config) throws Exception { logger.debug("updateConfigEntries start"); String c = post(hostname, port, https, servlet, content, null, null); if (c != null) { ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes()); XMLObject parser = null;// w w w. j av a 2s . com parser = new XMLObject(bis); String status = parser.getValue("Status"); logger.debug("updateConfigEntries: status=" + status); if (status.equals(SUCCESS)) { String cstype = ""; cstype = config.getString("cs.type", ""); logger.debug("Master's configuration:"); Document doc = parser.getDocument(); NodeList list = doc.getElementsByTagName("name"); int len = list.getLength(); for (int i = 0; i < len; i++) { Node n = list.item(i); NodeList nn = n.getChildNodes(); String name = nn.item(0).getNodeValue(); logger.debug(" - " + name); Node parent = n.getParentNode(); nn = parent.getChildNodes(); int len1 = nn.getLength(); String v = ""; for (int j = 0; j < len1; j++) { Node nv = nn.item(j); String val = nv.getNodeName(); if (val.equals("value")) { NodeList n2 = nv.getChildNodes(); if (n2.getLength() > 0) v = n2.item(0).getNodeValue(); break; } } if (name.equals("internaldb.basedn")) { config.putString(name, v); config.putString("preop.internaldb.master.basedn", v); } else if (name.startsWith("internaldb")) { config.putString(name.replaceFirst("internaldb", "preop.internaldb.master"), v); } else if (name.equals("instanceId")) { config.putString("preop.master.instanceId", v); } else if (name.equals("cloning.signing.nickname")) { config.putString("preop.master.signing.nickname", v); config.putString("preop.cert.signing.nickname", v); } else if (name.equals("cloning.ocsp_signing.nickname")) { config.putString("preop.master.ocsp_signing.nickname", v); config.putString("preop.cert.ocsp_signing.nickname", v); } else if (name.equals("cloning.subsystem.nickname")) { config.putString("preop.master.subsystem.nickname", v); config.putString("preop.cert.subsystem.nickname", v); } else if (name.equals("cloning.transport.nickname")) { config.putString("preop.master.transport.nickname", v); config.putString("kra.transportUnit.nickName", v); config.putString("preop.cert.transport.nickname", v); } else if (name.equals("cloning.storage.nickname")) { config.putString("preop.master.storage.nickname", v); config.putString("kra.storageUnit.nickName", v); config.putString("preop.cert.storage.nickname", v); } else if (name.equals("cloning.audit_signing.nickname")) { config.putString("preop.master.audit_signing.nickname", v); config.putString("preop.cert.audit_signing.nickname", v); config.putString(name, v); } else if (name.startsWith("cloning.ca")) { config.putString(name.replaceFirst("cloning", "preop"), v); } else if (name.equals("cloning.signing.keyalgorithm")) { config.putString(name.replaceFirst("cloning", "preop.cert"), v); if (cstype.equals("CA")) { config.putString("ca.crl.MasterCRL.signingAlgorithm", v); config.putString("ca.signing.defaultSigningAlgorithm", v); } else if (cstype.equals("OCSP")) { config.putString("ocsp.signing.defaultSigningAlgorithm", v); } } else if (name.equals("cloning.transport.keyalgorithm")) { config.putString(name.replaceFirst("cloning", "preop.cert"), v); config.putString("kra.transportUnit.signingAlgorithm", v); } else if (name.equals("cloning.ocsp_signing.keyalgorithm")) { config.putString(name.replaceFirst("cloning", "preop.cert"), v); if (cstype.equals("CA")) { config.putString("ca.ocsp_signing.defaultSigningAlgorithm", v); } } else if (name.startsWith("cloning")) { config.putString(name.replaceFirst("cloning", "preop.cert"), v); } else { config.putString(name, v); } } // set master ldap password (if it exists) temporarily in password store // in case it is needed for replication. Not stored in password.conf. String master_pwd = config.getString("preop.internaldb.master.ldapauth.password", ""); if (!master_pwd.equals("")) { config.putString("preop.internaldb.master.ldapauth.bindPWPrompt", "master_internaldb"); String passwordFile = config.getString("passwordFile"); IConfigStore psStore = CMS.createFileConfigStore(passwordFile); psStore.putString("master_internaldb", master_pwd); psStore.commit(false); } return true; } else if (status.equals(AUTH_FAILURE)) { throw new EAuthException(AUTH_FAILURE); } else { String error = parser.getValue("Error"); throw new IOException(error); } } return false; }
From source file:com.gargoylesoftware.htmlunit.html.DomNode.java
/** * <p>Returns <tt>true</tt> if this node is displayed and can be visible to the user * (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).</p> * * <p><b>NOTE:</b> If CSS is {@link WebClient#setCssEnabled(boolean) disabled}, this method * does <b>not</b> take this element's style into consideration!</p> * * @see <a href="http://www.w3.org/TR/CSS2/visufx.html#visibility">CSS2 Visibility</a> * @see <a href="http://www.w3.org/TR/CSS2/visuren.html#propdef-display">CSS2 Display</a> * @see <a href="http://msdn.microsoft.com/en-us/library/ms531180.aspx">MSDN Documentation</a> * @return <tt>true</tt> if the node is visible to the user, <tt>false</tt> otherwise * @see #mayBeDisplayed()//from w w w. j av a2 s .co m */ public boolean isDisplayed() { if (!mayBeDisplayed()) { return false; } final Page page = getPage(); if (page instanceof HtmlPage && page.getEnclosingWindow().getWebClient().isCssEnabled()) { // display: iterate top to bottom, because if a parent is display:none, // there's nothing that a child can do to override it for (final Node node : getAncestors(true)) { final ScriptableObject scriptableObject = ((DomNode) node).getScriptObject(); if (scriptableObject instanceof HTMLElement) { final CSSStyleDeclaration style = ((HTMLElement) scriptableObject).jsxGet_currentStyle(); final String display = style.jsxGet_display(); if ("none".equals(display)) { return false; } } } // visibility: iterate bottom to top, because children can override // the visibility used by parent nodes final boolean collapseInvisible = ((HtmlPage) page).getWebClient().getBrowserVersion() .hasFeature(BrowserVersionFeatures.DISPLAYED_COLLAPSE); DomNode node = this; do { final ScriptableObject scriptableObject = node.getScriptObject(); if (scriptableObject instanceof HTMLElement) { final CSSStyleDeclaration style = ((HTMLElement) scriptableObject).jsxGet_currentStyle(); final String visibility = style.jsxGet_visibility(); if (visibility.length() > 0) { if (visibility.equals("visible")) { return true; } else if (visibility.equals("hidden") || (collapseInvisible && visibility.equals("collapse"))) { return false; } } } node = node.getParentNode(); } while (node != null); } return true; }
From source file:com.enonic.vertical.adminweb.MenuHandlerServlet.java
private void menuItemForm(HttpServletRequest request, HttpServletResponse response, HttpSession session, AdminService admin, ExtendedMap formItems) throws VerticalAdminException { int menuKey = formItems.getInt("menukey"); User user = securityService.getLoggedInAdminConsoleUser(); String menuXML = admin.getAdminMenu(user, menuKey); boolean forwardData = formItems.getBoolean("forward_data", false); boolean create; String menuItemXML = null;//from ww w . j av a2 s. c om String categoryXML = null; String pageTemplatesXML; String pageTemplateParamsXML = null; String defaultAccessRightXML = null; // menuitem key: String key = formItems.getString("key", null); try { if (key != null && !key.startsWith("f") && !key.equals("none")) { create = false; menuItemXML = admin.getMenuItem(user, Integer.parseInt(key), false, true); } else { create = true; String insertBelow = formItems.getString("insertbelow", null); if (insertBelow != null && !"-1".equals(insertBelow)) { defaultAccessRightXML = admin.getAccessRights(user, AccessRight.MENUITEM, Integer.parseInt(insertBelow), true); } else { defaultAccessRightXML = admin.getAccessRights(user, AccessRight.MENUITEM_DEFAULT, menuKey, true); } } int[] excludeTypeKeys = null; // before we excluded page-tempales of type newsletter, but not anymore. pageTemplatesXML = admin.getPageTemplatesByMenu(menuKey, excludeTypeKeys); Document doc1 = XMLTool.domparse(menuXML); Element menuElem = XMLTool.selectElement(doc1.getDocumentElement(), "//menu[@key = '" + menuKey + "']"); int pageTemplateKey = formItems.getInt("selpagetemplatekey", -1); if (pageTemplateKey < 0 && create) { // selpagetemplatekey has not been set... set it to parent or default // pagetemplatekey (if appliccable) int insertBelow = -1; if (formItems.containsKey("insertbelow") /* && formItems.get("insertbelow") instanceof Integer */ ) { insertBelow = formItems.getInt("insertbelow"); } pageTemplateKey = findParentPagetemplateKey(doc1, insertBelow); formItems.putInt("selpagetemplatekey", pageTemplateKey); } if (pageTemplateKey >= 0) { pageTemplateParamsXML = admin.getPageTemplParams(pageTemplateKey); } else if (menuItemXML != null && XMLTool.getElementText(menuItemXML, "//page/@pagetemplatekey") != null) { pageTemplateKey = Integer.parseInt(XMLTool.getElementText(menuItemXML, "//page/@pagetemplatekey")); pageTemplateParamsXML = admin.getPageTemplParams(pageTemplateKey); } else { String tmp = menuElem.getAttribute("defaultpagetemplate"); if (tmp != null && tmp.length() > 0) { pageTemplateKey = Integer.parseInt(tmp); pageTemplateParamsXML = admin.getPageTemplParams(pageTemplateKey); } } // insert correct menuitem XML: Element menuitemElem = null; if (menuItemXML != null) { Document miDoc = XMLTool.domparse(menuItemXML); Element tmpElem = miDoc.getDocumentElement(); tmpElem = XMLTool.getFirstElement(tmpElem); if (tmpElem != null) { // add read count // int readCount = admin.getReadCount(LogHandler.TABLE_TMENUITEM, Integer.parseInt(key)); // Element elem = XMLTool.createElement(miDoc, tmpElem, "logentries"); // elem.setAttribute("totalread", String.valueOf(readCount)); if (tmpElem != null) { String xpath = "//menuitem[@key = '" + key + "']"; Element oldElem = (Element) XMLTool.selectNode(doc1.getDocumentElement(), xpath); if (oldElem != null) { Element menuitemsElem = (Element) oldElem.getParentNode(); menuitemElem = (Element) doc1.importNode(tmpElem, true); menuitemsElem.replaceChild(menuitemElem, oldElem); } } } } Document pageTemplateDoc = XMLTool.domparse(pageTemplatesXML); XMLTool.mergeDocuments(doc1, pageTemplateDoc, true); if (defaultAccessRightXML != null) { XMLTool.mergeDocuments(doc1, XMLTool.domparse(defaultAccessRightXML), true); } ExtendedMap parameters = new ExtendedMap(); if (forwardData) { // get accessrights element Node nodeAccessRights; if (create) { nodeAccessRights = XMLTool.selectNode(doc1.getDocumentElement(), "/menus/accessrights"); } else { nodeAccessRights = XMLTool.selectNode(doc1.getDocumentElement(), "//menuitem[@key=" + key + "]/accessrights"); } // get new accessrights xml from parameters String xmlAccessRights = buildAccessRightsXML(formItems); if (xmlAccessRights != null) { Document docAccessRights = XMLTool.domparse(xmlAccessRights); if (docAccessRights.getDocumentElement().hasChildNodes()) // replace accessrights element with the generated accessrights { nodeAccessRights.getParentNode().replaceChild( doc1.importNode(docAccessRights.getDocumentElement(), true), nodeAccessRights); } } // get custom parameters // get parameters element Node nodeParameters; if (create) { Node nodeMenu = XMLTool.selectNode(doc1.getDocumentElement(), "/menus"); nodeParameters = XMLTool.createElement(doc1, (Element) nodeMenu, "parameters"); nodeMenu.appendChild(nodeParameters); } else { nodeParameters = XMLTool.selectNode(doc1.getDocumentElement(), "//menuitem[@key=" + key + "]/parameters"); } XMLTool.removeChildNodes((Element) nodeParameters, false); if (isArrayFormItem(formItems, "paramname")) { String[] paramName = (String[]) formItems.get("paramname"); String[] paramValue = (String[]) formItems.get("paramval"); for (int i = 0; i < paramName.length; i++) { final String currParamName = paramName[i]; if (currParamName == null || !currParamName.trim().equals("")) { Element newElem = XMLTool.createElement(doc1, (Element) nodeParameters, "parameter", paramValue[i]); newElem.setAttribute("name", currParamName); nodeParameters.appendChild(newElem); } } } else { // ingen sideparametre finnes, vi lager en String paramName = formItems.getString("paramname", ""); String paramValue = formItems.getString("paramval", ""); if (paramName.length() > 0) { Element newElem = XMLTool.createElement(doc1, (Element) nodeParameters, "parameter", paramValue); newElem.setAttribute("name", paramName); nodeParameters.appendChild(newElem); } } parameters.put("referer", formItems.getString("referer")); } if (pageTemplateParamsXML == null) { Element nameElem = (Element) XMLTool.selectNode(doc1, "//menuitem[@key = '" + key + "']/page"); if (nameElem != null) { pageTemplateKey = Integer.parseInt(nameElem.getAttribute("pagetemplatekey")); pageTemplateParamsXML = admin.getPageTemplParams(pageTemplateKey); } } Document doc8; if (pageTemplateParamsXML != null) { doc8 = XMLTool.domparse(pageTemplateParamsXML); XMLTool.mergeDocuments(doc1, doc8, true); } String xpath = "/pagetemplates/pagetemplate[@key=" + pageTemplateKey + "]"; Element pagetemplateElem = (Element) XMLTool.selectNode(pageTemplateDoc, xpath); if (pagetemplateElem != null) { String pageTemplateType = pagetemplateElem.getAttribute("type"); if ("form".equals(pageTemplateType)) { Element dataElem = XMLTool.getElement(menuitemElem, "data"); Element formElem = XMLTool.getElement(dataElem, "form"); if (formElem != null) { String keyStr = formElem.getAttribute("categorykey"); if (keyStr.length() > 0) { int categoryKey = Integer.parseInt(keyStr); categoryXML = admin.getCategoryNameXML(categoryKey); } } } } if (categoryXML != null) { Document doc5 = XMLTool.domparse(categoryXML); XMLTool.mergeDocuments(doc1, doc5, true); } // Get content types for this site XMLTool.mergeDocuments(doc1, admin.getContentTypes(false).getAsDOMDocument(), true); // Append languages Document langs = XMLTool.domparse(admin.getLanguages()); XMLTool.mergeDocuments(doc1, langs, true); DOMSource xmlSource = new DOMSource(doc1); // Stylesheet Source xslSource = AdminStore.getStylesheet(session, "menu_item_form.xsl"); // Parameters addCommonParameters(admin, user, request, parameters, -1, menuKey); parameters.put("page", String.valueOf(request.getParameter("page"))); if ((key == null || key.length() == 0 || key.equals("none"))) { parameters.put("key", "none"); } else { parameters.put("key", key); } String type = formItems.getString("type", null); if ((type == null || "page".equals(type)) && pageTemplateKey >= 0) { if (pagetemplateElem != null) { type = pagetemplateElem.getAttribute("type"); } } if ("document".equals(type) || "form".equals(type)) { type = "content"; } parameters.put("type", type); parameters.put("insertbelow", formItems.getString("insertbelow", null)); parameters.put("selpagetemplatekey", String.valueOf(pageTemplateKey)); parameters.put("name", formItems.getString("name", null)); if ("on".equals(formItems.getString("visibility", null))) { parameters.put("visibility", "on"); } parameters.put("forward_data", formItems.get("forward_data", Boolean.FALSE)); parameters.put("menu-name", formItems.getString("menu-name", null)); parameters.put("displayname", formItems.getString("displayname", null)); parameters.put("description", formItems.getString("description", null)); parameters.put("keywords", formItems.getString("keywords", null)); parameters.put("alias", formItems.getString("alias", null)); parameters.put("document", formItems.getString("contentdata_body", null)); if (formItems.getString("noauth", null) != null) { if ("on".equals(formItems.getString("noauth", null))) { parameters.put("noauth", "false"); } else { parameters.put("noauth", "true"); } } parameters.put("catselkey", formItems.getString("catsel", null)); parameters.put("catkey", formItems.getString("category_key", null)); parameters.put("catname", formItems.getString("viewcategory_key", null)); parameters.put("menukey", String.valueOf(menuKey)); // find content title if contentkey is specified if (menuitemElem != null) { String contentKeyStr = menuitemElem.getAttribute("contentkey"); if (contentKeyStr.length() > 0) { int contentKey = Integer.parseInt(contentKeyStr); int versionKey = admin.getCurrentVersionKey(contentKey); String contentTitle = admin.getContentTitle(versionKey); parameters.put("contenttitle", contentTitle); } } // Adds accessrights values, so that these can be remembered until next page for (Object formItemKey : formItems.keySet()) { String paramName = (String) formItemKey; if (paramName.startsWith("accessright[key=")) { parameters.put(paramName, formItems.getString(paramName)); } } parameters.put("selectedtabpageid", formItems.getString("selectedtabpageid", null)); // Get form categories int[] contentTypeKeys = admin.getContentTypesByHandlerClass( "com.enonic.vertical.adminweb.handlers.ContentFormHandlerServlet"); if (contentTypeKeys != null && contentTypeKeys.length > 0) { StringBuffer contentTypeString = new StringBuffer(); for (int i = 0; i < contentTypeKeys.length; i++) { if (i > 0) { contentTypeString.append(','); } contentTypeString.append(contentTypeKeys[i]); } parameters.put("contenttypestring", contentTypeString.toString()); } else { parameters.put("contenttypestring", "99999"); } addAccessLevelParameters(user, parameters); UserEntity defaultRunAsUser = siteDao.findByKey(formItems.getInt("menukey")).resolveDefaultRunAsUser(); String defaultRunAsUserName = "NA"; if (defaultRunAsUser != null) { defaultRunAsUserName = defaultRunAsUser.getDisplayName(); } parameters.put("defaultRunAsUser", defaultRunAsUserName); transformXML(session, response.getWriter(), xmlSource, xslSource, parameters); } catch (IOException ioe) { String msg = "I/O error: %t"; VerticalAdminLogger.errorAdmin(this.getClass(), 0, msg, ioe); } catch (TransformerException te) { String msg = "XSL transformer error: %t"; VerticalAdminLogger.errorAdmin(this.getClass(), 0, msg, te); } }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Substitute the element selected by the xPath in the given node with the new node. * /*from w ww . j av a 2 s .c o m*/ * @param node * The node. * @param xPath * The xPath. * @param newNode * The new node. * @return The resulting node after the substitution. * @throws Exception * If anything fails. */ public static Node substitute(final Node node, final String xPath, final Node newNode) throws Exception { Node result = node; Node replace = selectSingleNode(result, xPath); assertNotNull("No node selected for substitute. ", replace); Node parent = replace.getParentNode(); parent.replaceChild(newNode, replace); return result; }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Adds the provided new node before the element selected by the xPath in the given node. * /*from ww w. java 2 s.com*/ * @param node * The node. * @param xPath * The xPath. * @param newNode * The new node. * @return The resulting node after the substitution. * @throws Exception * If anything fails. */ public static Node addBefore(final Node node, final String xPath, final Node newNode) throws Exception { Node result = node; Node after = selectSingleNode(result, xPath); assertNotNull("No node for xpath found [" + xPath + "]", after); Node parent = after.getParentNode(); parent.insertBefore(newNode, after); return result; }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Adds the provided new node after the element selected by the xPath in the given node. * /* w w w .j a v a2 s .co m*/ * @param node * The node. * @param xPath * The xPath. * @param newNode * The new node. * @return The resulting node after the substitution. * @throws Exception * If anything fails. */ public static Node addAfter(final Node node, final String xPath, final Node newNode) throws Exception { Node result = node; Node before = selectSingleNode(result, xPath); assertNotNull("No node for xpath [" + xPath + "] found", before); Node parent = before.getParentNode(); parent.insertBefore(newNode, before.getNextSibling()); return result; }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Delete an Element from a Node.//from w w w. j av a 2 s . c om * * @param node * the node. * @param xPath * The xPath selecting the element. * @return The resulting node. * @throws Exception * If anything fails. */ public static Node deleteElement(final Node node, final String xPath) throws Exception { Node delete = selectSingleNode(node, xPath); assertNotNull("No node found for provided xpath [" + xPath + "]", delete); if (delete instanceof AttrImpl) { throw new Exception("Removal of Element not successful! " + "xPath selects an Attribute!"); } else { delete.getParentNode().removeChild(delete); } return node; }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Deletes the node selected by the given XPath from the provided node. * /* ww w. ja va 2s .com*/ * @param node * The Node to delete the selected nodes from. * @param xPath * The XPath selecting the sub nodes in the provided node. * @return returns the provided <code>Node</code> object. This <code>Node</code> object may be changed. * @throws Exception * Thrown if anything fails. */ public static Node deleteNodes(final Node node, final String xPath) throws Exception { NodeList nodes = selectNodeList(node, xPath); if (nodes == null || nodes.getLength() == 0) { return node; } for (int i = 0; i < nodes.getLength(); ++i) { Node delete = nodes.item(i); if (delete.getNodeType() == Node.ATTRIBUTE_NODE) { final int index = xPath.lastIndexOf('/'); String attribute = delete.getNodeName(); attribute = attribute.substring(attribute.lastIndexOf(':') + 1); String elementXpath = xPath.substring(0, index); elementXpath += "[@" + attribute + "=\"" + delete.getTextContent().trim() + "\"]"; Node parent = selectSingleNode(node, elementXpath); if (parent.hasAttributes()) { parent.getAttributes().removeNamedItem(delete.getNodeName()); } } else { delete.getParentNode().removeChild(delete); } } return node; }
From source file:com.enonic.vertical.engine.handlers.MenuHandler.java
private void tagParents(Element menuItemsElement) { Node tmpNode = menuItemsElement.getParentNode(); while (tmpNode != null && tmpNode.getNodeType() == Node.ELEMENT_NODE && !((Element) tmpNode).getTagName().equals("menu")) { ((Element) tmpNode).setAttribute("path", "true"); tmpNode = tmpNode.getParentNode().getParentNode(); }/*from www . j ava2 s .c o m*/ }