List of usage examples for org.w3c.dom Element getParentNode
public Node getParentNode();
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute down one step. *//* w ww. j a va 2 s .c om*/ public String doMoveAttributeDown() throws Exception { this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); Element parent = null; Element elementToMove = null; boolean isInserted = false; int position = 0; for (int i = 0; i < anl.getLength(); i++) { Element element = (Element) anl.item(i); parent = (Element) element.getParentNode(); if (elementToMove != null) { if (position == 2) { parent.insertBefore(elementToMove, element); isInserted = true; break; } else position++; } if (element.getAttribute("name").equalsIgnoreCase(this.attributeName)) { elementToMove = element; parent.removeChild(elementToMove); position++; } } if (!isInserted && elementToMove != null) parent.appendChild(elementToMove); saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type assetKey up one step. *//*from w ww .ja v a2 s . c o m*/ public String doMoveAssetKeyUp() throws Exception { this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:simpleType[@name = '" + ContentTypeDefinitionController.ASSET_KEYS + "']/xs:restriction/xs:enumeration[@value='" + this.assetKey + "']"; NodeList anl = XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); if (anl != null && anl.getLength() > 0) { Element element = (Element) anl.item(0); Node parentElement = element.getParentNode(); Node previuosSibling = element.getPreviousSibling(); if (previuosSibling != null) { parentElement.removeChild(element); parentElement.insertBefore(element, previuosSibling); } } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type asset key down one step. *///from w ww. j a v a 2s. c o m public String doMoveAssetKeyDown() throws Exception { this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:simpleType[@name = '" + ContentTypeDefinitionController.ASSET_KEYS + "']/xs:restriction/xs:enumeration[@value='" + this.assetKey + "']"; NodeList anl = XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); if (anl != null && anl.getLength() > 0) { Element element = (Element) anl.item(0); Node parentElement = element.getParentNode(); Node nextSibling = element.getNextSibling(); if (nextSibling != null) { parentElement.removeChild(nextSibling); parentElement.insertBefore(nextSibling, element); } } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
public String doDeleteAttributeParameterValue() throws Exception { this.initialize(getContentTypeDefinitionId()); try {//from w w w .j a v a 2 s . com Document document = createDocumentFromDefinition(); String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element[@name='" + this.attributeName + "']/xs:annotation/xs:appinfo/params/param[@id='" + this.attributeParameterId + "']/values/value[@id='" + this.attributeParameterValueId + "']"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); if (anl != null && anl.getLength() > 0) { Element element = (Element) anl.item(0); element.getParentNode().removeChild(element); } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * We validate that ' ', '.', ''', '"' is not used in the attribute name as that will break the javascripts later. *///from w w w . j a v a2s . c om public String doUpdateAttribute() throws Exception { ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer(); if (this.newAttributeName.indexOf(" ") > -1 || this.newAttributeName.indexOf(".") > -1 || this.newAttributeName.indexOf("'") > -1 || this.newAttributeName.indexOf("\"") > -1) { ceb.add(new ConstraintException("ContentTypeAttribute.updateAction", "3500")); } ceb.throwIfNotEmpty(); this.initialize(getContentTypeDefinitionId()); try { Document document = createDocumentFromDefinition(); //Updating the content attribute String[] extraParameterNames = ServletActionContext.getRequest().getParameterValues("parameterNames"); if (extraParameterNames != null) { for (int i = 0; i < extraParameterNames.length; i++) { String extraParameterName = extraParameterNames[i]; String value = ServletActionContext.getRequest().getParameter(extraParameterName); String extraParametersXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element[@name='" + this.attributeName + "']/xs:annotation/xs:appinfo/params/param[@id='" + extraParameterName + "']/values/value"; NodeList extraParamsNodeList = org.apache.xpath.XPathAPI .selectNodeList(document.getDocumentElement(), extraParametersXPath); if (extraParamsNodeList != null && extraParamsNodeList.getLength() > 0) { Element element = (Element) extraParamsNodeList.item(0); if (extraParameterName.equalsIgnoreCase("values") && (this.inputTypeId.equalsIgnoreCase("select") || this.inputTypeId.equalsIgnoreCase("checkbox") || this.inputTypeId.equalsIgnoreCase("radiobutton"))) { ((Element) element.getParentNode().getParentNode()).setAttribute("inputTypeId", "1"); } else { ((Element) element.getParentNode().getParentNode()).setAttribute("inputTypeId", "0"); } if (((Element) element.getParentNode().getParentNode()).getAttribute("inputTypeId") .equals("0")) { if (this.currentContentTypeEditorViewLanguageCode != null && this.currentContentTypeEditorViewLanguageCode.length() > 0) { element.setAttribute("label_" + this.currentContentTypeEditorViewLanguageCode, value); } else { element.setAttribute("label", value); } } } } } //Updating the name and type String attributeXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element[@name='" + this.attributeName + "']"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributeXPath); if (anl != null && anl.getLength() > 0) { Element element = (Element) anl.item(0); element.setAttribute("name", this.newAttributeName); element.setAttribute("type", this.inputTypeId); } try { //Updating the validation part String validationXPath = "//xs:complexType[@name='Validation']/xs:annotation/xs:appinfo/form-validation/formset/form/field[@property='" + this.attributeName + "']"; NodeList fieldNodeList = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), validationXPath); if (fieldNodeList != null && fieldNodeList.getLength() > 0) { Element element = (Element) fieldNodeList.item(0); element.setAttribute("property", this.newAttributeName); } //Updating the dependent part String validationDependentXPath = "//xs:complexType[@name='Validation']/xs:annotation/xs:appinfo/form-validation/formset/form/field[@depends='requiredif']/var/var-value"; NodeList requiredIfValueNodeList = org.apache.xpath.XPathAPI .selectNodeList(document.getDocumentElement(), validationDependentXPath); if (requiredIfValueNodeList != null && requiredIfValueNodeList.getLength() > 0) { for (int i = 0; i < requiredIfValueNodeList.getLength(); i++) { Element element = (Element) requiredIfValueNodeList.item(0); if (element.getFirstChild() != null && element.getFirstChild().getNodeValue() != null && element.getFirstChild().getNodeValue().equals(this.attributeName)) element.getFirstChild().setNodeValue(this.newAttributeName); } } } catch (Exception ve) { ve.printStackTrace(); } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
public String doDeleteAttributeValidator() throws Exception { this.initialize(getContentTypeDefinitionId()); try {/*from w w w. j a va2 s. co m*/ Document document = createDocumentFromDefinition(); int i = 0; String attributeValidatorName = ServletActionContext.getRequest() .getParameter("attributeValidatorName"); if (attributeValidatorName != null && !attributeValidatorName.equalsIgnoreCase("")) { String validatorsXPath = "/xs:schema/xs:complexType[@name = 'Validation']/xs:annotation/xs:appinfo/form-validation/formset/form/field[@property = '" + attributeName + "'][@depends = '" + attributeValidatorName + "']"; Node fieldNode = org.apache.xpath.XPathAPI.selectSingleNode(document.getDocumentElement(), validatorsXPath); if (fieldNode != null) { Element element = (Element) fieldNode; element.getParentNode().removeChild(element); } } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }
From source file:org.infoscoop.request.filter.GadgetViewFilter.java
private byte[] processViewTransform(Document module, String viewType) throws Exception { NodeList nodeList = module.getElementsByTagName("Maximize"); while (nodeList.getLength() > 0) { nodeList.item(0).getParentNode().removeChild(nodeList.item(0)); nodeList = module.getElementsByTagName("Maximize"); }//ww w.j a v a 2s . com nodeList = module.getElementsByTagName("Content"); Collection contents = new ArrayList(); for (int i = 0; i < nodeList.getLength(); i++) contents.add(nodeList.item(i)); Element matches = null; for (Iterator ite = contents.iterator(); ite.hasNext();) { Element content = (Element) ite.next(); if ("Maximize".equals(((Element) content.getParentNode()).getTagName())) continue; if (matches == null) matches = content; if (content.hasAttribute("view") && !"".equals(content.getAttribute("view"))) { if (content.getAttribute("view").toLowerCase().indexOf(viewType) >= 0) { matches = content; break; } else if ("home".equalsIgnoreCase(content.getAttribute("view"))) { matches = content; } } else { matches = content; } } contents.remove(matches); for (Iterator ite = contents.iterator(); ite.hasNext();) { Element content = (Element) ite.next(); content.getParentNode().removeChild(content); } ByteArrayOutputStream respOut = new ByteArrayOutputStream(); try { Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.transform(new DOMSource(module), new StreamResult(respOut)); } catch (Exception ex) { throw ex; } finally { respOut.close(); } return respOut.toByteArray(); }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
public synchronized void replaceTopOrder(String menuType, String menuId, String siblingId) throws Exception { if (log.isInfoEnabled()) { log.info("MoveMenuItem: menuId=" + menuId + ", siblingId=" + siblingId + ", menuType=" + menuType); }//from ww w . java 2s. c om // Obtain data and transfer the result to Document. Siteaggregationmenu_temp orderEntity = this.siteAggregationMenuTempDAO.selectBySitetopId(menuType, SiteAggregationMenuTempDAO.SITEMENU_ORDER_TEMP_ID); Element orderEl = orderEntity.getElement(); Element siteTopEl = (Element) AdminServiceUtil.getNodeById(orderEl.getOwnerDocument(), "//site-top", menuId); Element targetEl = getTargetElement(siteTopEl, orderEntity.getWorkinguid(), menuId, false); // Error if (targetEl == null) throw new Exception("targetElement not found [//site],[//site-top]"); // Search for node matches siblingId from <site-top>. Element siblingSiteTopEl = (Element) AdminServiceUtil.getNodeById(orderEl.getOwnerDocument(), "//site-top", siblingId); Element siblingEl = getTargetElement(siblingSiteTopEl, orderEntity.getWorkinguid(), siblingId, false); if (siblingEl == null) { targetEl.getParentNode().appendChild(targetEl); } else { targetEl.getParentNode().insertBefore(targetEl, siblingEl); } // Update orderEntity.setElement(orderEl); this.siteAggregationMenuTempDAO.update(orderEntity); }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
/** * Create JSONObject of site/*from w w w. ja va2 s . c om*/ * * @param siteEl * @return * @throws DOMException * @throws JSONException * @throws TransformerException */ private static JSONObject siteToJSON(String sitetopId, Element siteEl, boolean isEditMode) throws DOMException, JSONException, TransformerException { JSONObject json = new JSONObject(); // attrs NamedNodeMap attMap = siteEl.getAttributes(); Node attr; for (int i = 0; i < attMap.getLength(); i++) { attr = attMap.item(i); if ("link_disabled".equalsIgnoreCase(attr.getNodeName())) { json.put("linkDisabled", new Boolean(attr.getNodeValue())); } else if ("directory_title".equalsIgnoreCase(attr.getNodeName())) { json.put("directoryTitle", attr.getNodeValue()); } else { json.put(attr.getNodeName(), attr.getNodeValue()); } } // parentId if (!sitetopId.equals(siteEl.getAttribute("id"))) { Element parentEl = (Element) siteEl.getParentNode(); if (parentEl != null && (parentEl.getNodeName().equalsIgnoreCase("site") || parentEl.getNodeName().equalsIgnoreCase("site-top"))) { json.put("parentId", parentEl.getAttribute("id")); } } // properties JSONObject propsJson = new JSONObject(); Element propEl = (Element) XPathAPI.selectSingleNode(siteEl, "properties"); if (propEl != null) { NodeList propertyList = propEl.getElementsByTagName("property"); Element propertyEl; for (int i = 0; i < propertyList.getLength(); i++) { propertyEl = (Element) propertyList.item(i); propsJson.put(propertyEl.getAttribute("name"), (propertyEl.getFirstChild() != null) ? propertyEl.getFirstChild().getNodeValue() : ""); } } json.put("properties", propsJson); // auths Element authsEl = (Element) XPathAPI.selectSingleNode(siteEl, "auths"); if (authsEl != null) { json.put("auths", MenuAuthorization.createAuthsJson(authsEl)); } // admins JSONArray adminsArray = new JSONArray(); Element adminsEl = (Element) XPathAPI.selectSingleNode(siteEl, "menuTreeAdmins"); if (adminsEl != null) { NodeList adminList = adminsEl.getElementsByTagName("admin"); Element adminEl; for (int i = 0; i < adminList.getLength(); i++) { adminEl = (Element) adminList.item(i); if (adminEl.getFirstChild() != null) { adminsArray.put(adminEl.getFirstChild().getNodeValue()); } } } json.put("menuTreeAdmins", adminsArray); if (isEditMode) json.put("isEditMode", true); return json; }
From source file:org.infoscoop.service.SiteAggregationMenuService.java
/** * Commiting temporary data./* www . j a v a 2s . c o m*/ * @param menuType topmenu|sidemenu * @param forceUpdateMap * @throws Exception */ public synchronized void commitMenu(String menuType, Map<String, List<ForceUpdateUserPref>> forceUpdateMap, List<String> forceDeleteList, List<String> editSitetopIdList) throws Exception { ISPrincipal p = SecurityController.getPrincipalByType("UIDPrincipal"); String myUid = p.getName(); Siteaggregationmenu currentEntity = this.siteAggregationMenuDAO.select(menuType); Element currentMenuEl = currentEntity.getElement(); Document currentDoc = currentMenuEl.getOwnerDocument(); // Get the tree that the user edited List<Siteaggregationmenu_temp> myTempList = this.siteAggregationMenuTempDAO.selectByTypeAndUser(menuType, myUid); checkError(myTempList, editSitetopIdList, menuType); // Merge Element siteTop; WidgetDAO dao = WidgetDAO.newInstance(); List<Element> deleteSiteTopList = new ArrayList<Element>(); Siteaggregationmenu_temp orderTemp = null; for (Siteaggregationmenu_temp tempEntity : myTempList) { if (tempEntity.getId().getSitetopid().equals(SiteAggregationMenuTempDAO.SITEMENU_ORDER_TEMP_ID)) { orderTemp = tempEntity; continue; } // Update last modified time tempEntity.setLastmodified(new Date()); this.siteAggregationMenuTempDAO.update(tempEntity); siteTop = tempEntity.getElement(); String siteTopId = tempEntity.getId().getSitetopid(); Node currentSiteTopEl = XPathAPI.selectSingleNode(currentMenuEl, "site-top[@id=\"" + siteTopId + "\"]"); // Import Node mergeEl = currentDoc.importNode(siteTop.cloneNode(true), true); if (siteTop.getAttributeNode("deleteFlag") != null) { // If the tree is deleted if (currentSiteTopEl != null) deleteSiteTopList.add((Element) currentSiteTopEl); continue; } else { if (currentSiteTopEl != null) { currentDoc.getDocumentElement().replaceChild(mergeEl, currentSiteTopEl); } else { currentDoc.getDocumentElement().appendChild(mergeEl); } } // Properties should not be updated if existing data is not changed. if (currentSiteTopEl == null) continue; //Properties of url and authType in current menu is added to Map. NodeList sites = siteTop.getElementsByTagName("site"); for (int i = 0; i < sites.getLength(); i++) { Element site = (Element) sites.item(i); String type = site.getAttribute("type"); if (type == null) continue; String menuId = site.getAttribute("id"); List<ForceUpdateUserPref> updatePropList = forceUpdateMap.get(menuId); if (updatePropList == null || updatePropList.isEmpty()) continue; NodeList properties = XPathAPI.selectNodeList(site, "properties/property"); Map<String, String> propMap = new HashMap<String, String>(); for (int j = 0; j < properties.getLength(); j++) { Element property = (Element) properties.item(j); String name = property.getAttribute("name"); String value = property.getFirstChild() != null ? property.getFirstChild().getNodeValue() : ""; propMap.put(name, value); } String title = null; String href = null; Map<String, ForceUpdateUserPref> upPropMap = new HashMap<String, ForceUpdateUserPref>(); Set<ForceUpdateUserPref> removePropNames = new HashSet<ForceUpdateUserPref>(); for (ForceUpdateUserPref prop : updatePropList) { if ("__MENU_TITLE__".equals(prop.name)) { title = site.getAttribute("title"); } else if ("__MENU_HREF__".equals(prop.name)) { href = site.getAttribute("href"); } else { String value = propMap.get(prop.name); prop.value = value; if (value != null) { upPropMap.put(prop.name, prop); } else { removePropNames.add(prop); } } } if (title != null || href != null || upPropMap.size() > 0 || removePropNames.size() > 0) dao.updateWidgetProperties(menuId, title, href, upPropMap, removePropNames); } } for (String menuId : forceDeleteList) { dao.deleteWidgetByMenuId(menuId); } // Deleting tree for (Element deleteSiteTop : deleteSiteTopList) { AdminServiceUtil.removeSelf(deleteSiteTop); } // Changing order of tree if (orderTemp != null) { Element orderEl = orderTemp.getElement(); NodeList orderSiteTopList = orderEl.getElementsByTagName("site-top"); for (int i = 0; i < orderSiteTopList.getLength(); i++) { Element orderSiteTop = (Element) orderSiteTopList.item(i); Element targetNode = (Element) XPathAPI.selectSingleNode(currentMenuEl, "site-top[@id=\"" + orderSiteTop.getAttribute("id") + "\"]"); if (targetNode != null) targetNode.getParentNode().appendChild(targetNode); } } //Apply the change of menu to widget. currentEntity.setElement(currentMenuEl); this.siteAggregationMenuDAO.update(currentEntity); }