List of usage examples for org.w3c.dom Element getParentNode
public Node getParentNode();
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method updates the given property with new values. *///w ww .j ava 2 s.c om public String doUpdateComponentProperty() throws Exception { if (logger.isInfoEnabled()) { logger.info("************************************************************"); logger.info("* doUpdateComponentProperty *"); logger.info("************************************************************"); logger.info("siteNodeId:" + this.siteNodeId); logger.info("languageId:" + this.languageId); logger.info("contentId:" + this.contentId); logger.info("componentId:" + this.componentId); logger.info("slotId:" + this.slotId); logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate); } try { initialize(); Locale locale = LanguageController.getController().getLocaleWithId(languageId); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); //logger.info("componentXML:" + componentXML); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, languageId, contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, languageId, true, "Meta information", DeliveryContext.getDeliveryContext()); ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId()); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String characterEncoding = this.getRequest().getCharacterEncoding(); characterEncoding = this.getResponse().getCharacterEncoding(); String componentContentId = null; String propertyName = this.getRequest().getParameter("propertyName"); String propertyValue = ""; if (propertyName != null && !propertyName.equals("")) { String[] propertyValues = this.getRequest().getParameterValues(propertyName); if (propertyValues != null && propertyValues.length == 1) { propertyValue = propertyValues[0]; } else if (propertyValues != null) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < propertyValues.length; i++) { if (i > 0) sb.append(","); sb.append(propertyValues[i]); } propertyValue = sb.toString(); } logger.info("propertyName:" + propertyName); logger.info("propertyValue:" + propertyValue); String separator = System.getProperty("line.separator"); propertyValue = propertyValue.replaceAll(separator, "igbr"); logger.info("propertyValue1:" + propertyValue); propertyValue = PageEditorHelper.untransformAttribute(propertyValue); logger.info("propertyValue2:" + propertyValue); if (propertyValue != null && !propertyValue.equals("") && !propertyValue.equalsIgnoreCase("undefined")) { String componentPropertyXPath = "//component[@id=" + this.componentId + "]/properties/property[@name='" + propertyName + "']"; //logger.info("componentPropertyXPath:" + componentPropertyXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentPropertyXPath); if (anl.getLength() == 0) { String componentXPath = "//component[@id=" + this.componentId + "]/properties"; //logger.info("componentXPath:" + componentXPath); NodeList componentNodeList = org.apache.xpath.XPathAPI .selectNodeList(document.getDocumentElement(), componentXPath); if (componentNodeList.getLength() > 0) { Element componentProperties = (Element) componentNodeList.item(0); addPropertyElement(componentProperties, propertyName, propertyValue, "textfield", locale); anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentPropertyXPath); } } logger.info("anl:" + anl); if (anl.getLength() > 0) { Element component = (Element) anl.item(0); componentContentId = ((Element) component.getParentNode().getParentNode()) .getAttribute("contentId"); //System.out.println("componentContentId:" + componentContentId); ContentVO componentContentVO = ContentController.getContentController() .getContentVOWithId(new Integer(componentContentId)); LanguageVO componentMasterLanguageVO = LanguageController.getController() .getMasterLanguage(componentContentVO.getRepositoryId()); ContentVersionVO cv = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(new Integer(componentContentId), componentMasterLanguageVO.getId()); String componentProperties = ContentVersionController.getContentVersionController() .getAttributeValue(cv, "ComponentProperties", false); List componentPropertiesList = ComponentPropertyDefinitionController.getController() .parseComponentPropertyDefinitions(componentProperties); Iterator componentPropertiesListIterator = componentPropertiesList.iterator(); boolean allowLanguageVariations = true; while (componentPropertiesListIterator.hasNext()) { ComponentPropertyDefinition componentPropertyDefinition = (ComponentPropertyDefinition) componentPropertiesListIterator .next(); if (componentPropertyDefinition.getName().equalsIgnoreCase(propertyName)) { allowLanguageVariations = componentPropertyDefinition.getAllowLanguageVariations(); break; } } if (allowLanguageVariations) { logger.info("Setting a propertyValue to path_" + locale.getLanguage() + ":" + path); component.setAttribute("path_" + locale.getLanguage(), propertyValue); logger.info("Setting 'path_" + locale.getLanguage() + ":" + propertyValue); } else { logger.info("Setting a propertyValue to path:" + path); component.setAttribute("path", propertyValue); logger.info("Setting 'path:" + propertyValue); component.removeAttribute("path_" + locale.getLanguage()); } } else { logger.warn("No property could be updated... must be wrong."); } } } String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); logger.info("contentVersionVO:" + contentVersionVO.getContentVersionId()); ContentVersionController.getContentVersionController().updateAttributeValue( contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML, this.getInfoGluePrincipal()); String returnStatus = this.getRequest().getParameter("returnStatus"); if (returnStatus != null && returnStatus.equalsIgnoreCase("true")) { this.getResponse().setContentType("text/html"); this.getResponse().getWriter().println( "<html><body>Property " + propertyName + " was set to " + propertyValue + "</body></html>"); } else { this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId=" + this.componentId + (!hideComponentPropertiesOnLoad ? "&activatedComponentId=" + this.componentId : "") + "&componentContentId=" + componentContentId + "&showSimple=" + this.showSimple; //this.getResponse().sendRedirect(url); this.url = this.getResponse().encodeURL(url); this.getResponse().sendRedirect(url); } return NONE; } catch (Exception e) { logger.error("Error setting property:" + e.getMessage()); logger.warn("Error setting property:" + e.getMessage(), e); return ERROR; } }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method updates the given properties with new values. */// ww w . j av a 2 s . c o m public String doUpdateComponentProperties() throws Exception { if (logger.isInfoEnabled()) { logger.info("************************************************************"); logger.info("* doUpdateComponentProperties *"); logger.info("************************************************************"); logger.info("siteNodeId:" + this.siteNodeId); logger.info("languageId:" + this.languageId); logger.info("contentId:" + this.contentId); logger.info("componentId:" + this.componentId); logger.info("slotId:" + this.slotId); logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate); } try { initialize(); Iterator parameterNames = this.getRequest().getParameterMap().keySet().iterator(); while (parameterNames.hasNext()) { String name = (String) parameterNames.next(); String value = (String) this.getRequest().getParameter(name); logger.info(name + "=" + value); } Integer siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId")); Integer languageId = new Integer(this.getRequest().getParameter("languageId")); Locale locale = LanguageController.getController().getLocaleWithId(languageId); String entity = this.getRequest().getParameter("entity"); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); //logger.info("componentXML:" + componentXML); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, languageId, contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, languageId, true, "Meta information", DeliveryContext.getDeliveryContext()); ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId()); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String characterEncoding = this.getRequest().getCharacterEncoding(); characterEncoding = this.getResponse().getCharacterEncoding(); logger.info("siteNodeId:" + siteNodeId); logger.info("languageId:" + languageId); logger.info("entity:" + entity); String componentContentId = null; int propertyIndex = 0; String propertyName = this.getRequest().getParameter(propertyIndex + "_propertyName"); while (propertyName != null && !propertyName.equals("")) { String[] propertyValues = this.getRequest().getParameterValues(propertyName); String propertyValue = ""; if (propertyValues != null && propertyValues.length == 1) propertyValue = propertyValues[0]; else if (propertyValues != null) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < propertyValues.length; i++) { if (i > 0) sb.append(","); sb.append(propertyValues[i]); } propertyValue = sb.toString(); } logger.info("propertyName:" + propertyName); logger.info("propertyValue:" + propertyValue); String separator = System.getProperty("line.separator"); propertyValue = propertyValue.replaceAll(separator, "igbr"); logger.info("propertyValue1:" + propertyValue); propertyValue = PageEditorHelper.untransformAttribute(propertyValue); logger.info("propertyValue2:" + propertyValue); if (propertyValue != null && !propertyValue.equals("") && !propertyValue.equalsIgnoreCase("undefined")) { String componentPropertyXPath = "//component[@id=" + this.componentId + "]/properties/property[@name='" + propertyName + "']"; //logger.info("componentPropertyXPath:" + componentPropertyXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentPropertyXPath); if (anl.getLength() == 0) { String componentXPath = "//component[@id=" + this.componentId + "]/properties"; //logger.info("componentXPath:" + componentXPath); NodeList componentNodeList = org.apache.xpath.XPathAPI .selectNodeList(document.getDocumentElement(), componentXPath); if (componentNodeList.getLength() > 0) { Element componentProperties = (Element) componentNodeList.item(0); addPropertyElement(componentProperties, propertyName, propertyValue, "textfield", locale); anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentPropertyXPath); } } logger.info("anl:" + anl); if (anl.getLength() > 0) { Element component = (Element) anl.item(0); componentContentId = ((Element) component.getParentNode().getParentNode()) .getAttribute("contentId"); //System.out.println("componentContentId:" + componentContentId); ContentVO componentContentVO = ContentController.getContentController() .getContentVOWithId(new Integer(componentContentId)); LanguageVO componentMasterLanguageVO = LanguageController.getController() .getMasterLanguage(componentContentVO.getRepositoryId()); ContentVersionVO cv = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(new Integer(componentContentId), componentMasterLanguageVO.getId()); String componentProperties = ContentVersionController.getContentVersionController() .getAttributeValue(cv, "ComponentProperties", false); List componentPropertiesList = ComponentPropertyDefinitionController.getController() .parseComponentPropertyDefinitions(componentProperties); Iterator componentPropertiesListIterator = componentPropertiesList.iterator(); boolean allowLanguageVariations = true; while (componentPropertiesListIterator.hasNext()) { ComponentPropertyDefinition componentPropertyDefinition = (ComponentPropertyDefinition) componentPropertiesListIterator .next(); if (componentPropertyDefinition.getName().equalsIgnoreCase(propertyName)) { allowLanguageVariations = componentPropertyDefinition.getAllowLanguageVariations(); break; } } if (allowLanguageVariations) { //System.out.println("Setting a propertyValue to path_" + locale.getLanguage() + ":" + path); component.setAttribute("path_" + locale.getLanguage(), propertyValue); logger.info("Setting 'path_" + locale.getLanguage() + ":" + propertyValue); } else { //System.out.println("Setting a propertyValue to path:" + path); component.setAttribute("path", propertyValue); logger.info("Setting 'path:" + propertyValue); component.removeAttribute("path_" + locale.getLanguage()); } } else { logger.warn("No property could be updated... must be wrong."); } } propertyIndex++; propertyName = this.getRequest().getParameter(propertyIndex + "_propertyName"); } String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); logger.info("contentVersionVO:" + contentVersionVO.getContentVersionId()); ContentVersionController.getContentVersionController().updateAttributeValue( contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML, this.getInfoGluePrincipal()); this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId=" + this.componentId + (!hideComponentPropertiesOnLoad ? "&activatedComponentId=" + this.componentId : "") + "&componentContentId=" + componentContentId + "&showSimple=" + this.showSimple; //this.getResponse().sendRedirect(url); this.url = this.getResponse().encodeURL(url); this.getResponse().sendRedirect(url); return NONE; } catch (Exception e) { logger.error("Error setting property:" + e.getMessage()); logger.warn("Error setting property:" + e.getMessage(), e); return ERROR; } }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method shows the user a list of Components(HTML Templates). *//* w w w .j a va2 s . com*/ public String doDeleteComponent() throws Exception { initialize(); //logger.info("************************************************************"); //logger.info("* DELETING COMPONENT *"); //logger.info("************************************************************"); //logger.info("siteNodeId:" + this.siteNodeId); //logger.info("languageId:" + this.languageId); //logger.info("contentId:" + this.contentId); //logger.info("componentId:" + this.componentId); //logger.info("slotId:" + this.slotId); //logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate); logger.info("doDeleteComponent:" + this.getRequest().getQueryString()); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]"; //logger.info("componentXPath:" + componentXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); //logger.info("anl:" + anl.getLength()); if (anl.getLength() > 0) { Element component = (Element) anl.item(0); component.getParentNode().removeChild(component); String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, languageId, contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, languageId, true, "Meta information", DeliveryContext.getDeliveryContext()); ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId()); ContentVersionController.getContentVersionController().updateAttributeValue( contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML, this.getInfoGluePrincipal()); } this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&showSimple=" + this.showSimple; this.url = this.getResponse().encodeURL(url); this.getResponse().sendRedirect(url); return NONE; }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
private void changeComponent(Integer siteNodeId, Boolean recursive, Boolean regardAsCompatible) throws Exception { String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); logger.info("componentXML:" + componentXML); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); if (anl.getLength() > 0 && this.newComponentContentId != null) { Element component = (Element) anl.item(0); ContentVO contentVO = ContentController.getContentController() .getContentVOWithId(this.newComponentContentId); ContentTypeDefinitionVO contentTypeDefinitionVO = ContentTypeDefinitionController.getController() .getContentTypeDefinitionVOWithId(contentVO.getContentTypeDefinitionId()); boolean isPagePartReference = false; if (contentTypeDefinitionVO.getName().equals("PagePartTemplate")) isPagePartReference = true;// w w w . j a va2 s . com ContentVersionVO newComponentContentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(this.newComponentContentId, this.masterLanguageVO.getId()); if (newComponentContentVersionVO == null) { LanguageVO contentMasterLanguageVO = LanguageController.getController() .getMasterLanguage(contentVO.getRepositoryId()); newComponentContentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(this.newComponentContentId, contentMasterLanguageVO.getId()); } if (newComponentContentVersionVO != null && !regardAsCompatible) { String template = ContentVersionController.getContentVersionController() .getAttributeValue(newComponentContentVersionVO, "Template", false); logger.info("template:" + template); String subComponentsXPath = "//component[@id=" + this.componentId + "]//component"; NodeList subComponents = org.apache.xpath.XPathAPI.selectNodeList(component, subComponentsXPath); logger.info("subComponents:" + subComponents.getLength()); for (int i = 0; i < subComponents.getLength(); i++) { Element subComponent = (Element) subComponents.item(i); if (isPagePartReference) { //Removing children if it was a pagePartReference NodeList propertiesNodeList = subComponent.getElementsByTagName("properties"); if (propertiesNodeList.getLength() > 0) { Element propertiesElement = (Element) propertiesNodeList.item(0); NodeList propertyNodeList = propertiesElement.getElementsByTagName("property"); for (int j = 0; j < propertyNodeList.getLength(); j++) { Element property = (Element) propertyNodeList.item(j); Node parentNode = property.getParentNode(); parentNode.removeChild(property); } } Node parentNode = subComponent.getParentNode(); parentNode.removeChild(subComponent); } else { String slotId = subComponent.getAttribute("name"); logger.info("subComponent slotId:" + slotId); if (template.indexOf("id=\"" + slotId + "\"") == -1) { logger.info("deleting subComponent as it was not part of the new template"); Node parentNode = subComponent.getParentNode(); parentNode.removeChild(subComponent); } } } } component.setAttribute("contentId", "" + this.newComponentContentId); if (isPagePartReference) component.setAttribute("isPagePartReference", "true"); String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); logger.info("modifiedXML:" + modifiedXML); ContentVO boundContentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, this.masterLanguageVO.getId(), contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, this.masterLanguageVO.getId(), true, "Meta information", DeliveryContext.getDeliveryContext()); ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(boundContentVO.getId(), this.masterLanguageVO.getId()); ContentVersionController.getContentVersionController().updateAttributeValue( contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML, this.getInfoGluePrincipal()); } if (recursive) { List<SiteNodeVO> childSiteNodeVOList = SiteNodeController.getController() .getSiteNodeChildrenVOList(siteNodeId); for (SiteNodeVO childSiteNodeVO : childSiteNodeVOList) changeComponent(childSiteNodeVO.getId(), recursive, regardAsCompatible); } }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method shows the user a list of Components(HTML Templates). */// w w w . ja v a2s . co m public String doDeleteComponentBinding() throws Exception { initialize(); //logger.info("************************************************************"); //logger.info("* doDeleteComponentBinding *"); //logger.info("************************************************************"); //logger.info("siteNodeId:" + this.siteNodeId); //logger.info("languageId:" + this.languageId); //logger.info("contentId:" + this.contentId); //logger.info("componentId:" + this.componentId); //logger.info("slotId:" + this.slotId); //logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate); Integer siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId")); Integer languageId = new Integer(this.getRequest().getParameter("languageId")); Integer contentId = new Integer(this.getRequest().getParameter("contentId")); Integer bindingId = new Integer(this.getRequest().getParameter("bindingId")); //logger.info("siteNodeId:" + siteNodeId); //logger.info("languageId:" + languageId); //logger.info("contentId:" + contentId); //String templateString = getPageTemplateString(templateController, siteNodeId, languageId, contentId); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); //logger.info("componentXML:" + componentXML); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]/bindings/binding[@id=" + bindingId + "]"; //logger.info("componentXPath:" + componentXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); //logger.info("anl:" + anl.getLength()); if (anl.getLength() > 0) { Element component = (Element) anl.item(0); component.getParentNode().removeChild(component); String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, languageId, contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, languageId, true, "Meta information", DeliveryContext.getDeliveryContext()); ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController() .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId()); ContentVersionController.getContentVersionController().updateAttributeValue( contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML, this.getInfoGluePrincipal()); } this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId=" + this.componentId + "&activatedComponentId=" + this.componentId + "&showSimple=" + this.showSimple; //this.getResponse().sendRedirect(url); this.url = this.getResponse().encodeURL(url); //this.getResponse().sendRedirect(url); return NONE; }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method shows the user a list of Components(HTML Templates). *//*from w ww . jav a2 s. c o m*/ public List getComponentBindings() throws Exception { List bindings = new ArrayList(); try { Integer siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId")); Integer languageId = new Integer(this.getRequest().getParameter("languageId")); Integer contentId = new Integer(this.getRequest().getParameter("contentId")); String supplementingEntityType = this.getRequest().getParameter("supplementingEntityType"); String propertyName = this.getRequest().getParameter("propertyName"); //logger.info("**********************************************************************************"); //logger.info("siteNodeId:" + siteNodeId); //logger.info("languageId:" + languageId); //logger.info("contentId:" + contentId); //logger.info("**********************************************************************************"); //String templateString = getPageTemplateString(templateController, siteNodeId, languageId, contentId); String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); //logger.info("componentXML:" + componentXML); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]/properties/property[@name='" + propertyName + "']/binding"; //logger.info("componentXPath:" + componentXPath); NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath); //logger.info("anl:" + anl.getLength()); // We can not get a fresh path for external bindings to we look at the current path stored on the property. String[] externalBindingPath = null; for (int i = 0; i < anl.getLength(); i++) { Element component = (Element) anl.item(i); String entityName = component.getAttribute("entity"); String entityId = component.getAttribute("entityId"); String assetKey = component.getAttribute("assetKey"); NodeList supplementingEntities = component.getElementsByTagName("supplementing-binding"); try { String path = "Undefined"; if (entityName.equalsIgnoreCase("SiteNode")) { SiteNodeVO siteNodeVO = SiteNodeController.getController() .getSiteNodeVOWithId(new Integer(entityId)); path = siteNodeVO.getName(); } else if (entityName.equalsIgnoreCase("Content")) { ContentVO contentVO = ContentController.getContentController() .getContentVOWithId(new Integer(entityId)); path = contentVO.getName(); } else if (entityName.equalsIgnoreCase("External")) { if (externalBindingPath == null) { Element parent = (Element) component.getParentNode(); String propertyPath = parent.getAttribute("path"); if (propertyPath != null) { externalBindingPath = propertyPath.split(", "); if (externalBindingPath.length != anl.getLength()) { logger.error( "The number of items in the current path value does not match the current number of bindings. This should be fixed! Component id " + this.componentId + " and property: " + propertyName); externalBindingPath = new String[0]; } } } if (externalBindingPath != null && externalBindingPath.length > 0) { path = externalBindingPath[i]; } else { path = "Out of sync"; logger.warn("An external binding was found to be out of sync. SiteNodeId: " + siteNodeId + ". PropertyName" + propertyName); } } Map binding = new HashMap(); binding.put("entityName", entityName); binding.put("entityId", entityId); binding.put("assetKey", assetKey); binding.put("path", path); if (supplementingEntityType != null && !"".equals(supplementingEntityType)) { Map<String, String> supplementingBinding = new HashMap<String, String>(); supplementingBinding.put("entityType", supplementingEntityType); if (supplementingEntities != null && supplementingEntities.getLength() > 0) { Node supplementingEntity = supplementingEntities.item(0); if (supplementingEntity instanceof Element) { String supplementingEntityIdString = null; try { Element supplementingElement = (Element) supplementingEntity; supplementingEntityIdString = supplementingElement.getAttribute("entityId"); Integer supplementingEntityId = Integer.parseInt(supplementingEntityIdString); ContentVO supplementingContentVO = ContentController.getContentController() .getContentVOWithId(supplementingEntityId); if (supplementingContentVO != null) { supplementingBinding.put("entityId", supplementingContentVO.getContentId().toString()); String supplementingAssetKey = supplementingElement .getAttribute("assetKey"); supplementingAssetKey = StringEscapeUtils .unescapeXml(supplementingAssetKey); supplementingBinding.put("assetKey", supplementingAssetKey); } } catch (NumberFormatException ex) { logger.error( "Failed to parse entity id for supplementing entity id. Entity-id: " + supplementingEntityIdString + ". Message: " + ex.getMessage()); logger.warn("Failed to parse entity id for supplementing entity id.", ex); } catch (SystemException ex) { logger.warn( "Exception when verifying existence of supplementing entity. Assuming removed entity, will ignore. Entity-id: " + supplementingEntityIdString + ". Message: " + ex.getMessage()); logger.debug( "Exception when verifying existence of supplementing entity. Entity-id: " + supplementingEntityIdString, ex); } } else { logger.warn( "SupplementingBinding was not of type Element. Really Weired. Node value of component:" + component.getNodeValue()); } } binding.put("supplementingBinding", supplementingBinding); } bindings.add(binding); } catch (Exception e) { logger.warn("There was " + entityName + " bound to property '" + propertyName + "' on siteNode " + siteNodeId + " which appears to have been deleted."); } } } catch (Exception e) { e.printStackTrace(); } return bindings; }
From source file:org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController.java
/** * This method validates the current content type and updates it to be valid in the future. *//* w w w. j a v a 2s . com*/ public ContentTypeDefinitionVO validateAndUpdateContentType(ContentTypeDefinitionVO contentTypeDefinitionVO) { try { boolean isModified = false; InputSource xmlSource = new InputSource(new StringReader(contentTypeDefinitionVO.getSchemaValue())); DOMParser parser = new DOMParser(); parser.parse(xmlSource); Document document = parser.getDocument(); //Set the new versionId String rootXPath = "/xs:schema"; NodeList schemaList = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), rootXPath); for (int i = 0; i < schemaList.getLength(); i++) { Element schemaElement = (Element) schemaList.item(i); if (schemaElement.getAttribute("version") == null || schemaElement.getAttribute("version").equalsIgnoreCase("")) { isModified = true; schemaElement.setAttribute("version", "2.0"); //First check out if the old/wrong definitions are there and delete them String definitionsXPath = "/xs:schema/xs:simpleType"; NodeList definitionList = org.apache.xpath.XPathAPI .selectNodeList(document.getDocumentElement(), definitionsXPath); for (int j = 0; j < definitionList.getLength(); j++) { Element childElement = (Element) definitionList.item(j); if (!childElement.getAttribute("name").equalsIgnoreCase("assetKeys")) childElement.getParentNode().removeChild(childElement); } //Now we create the new definitions Element textFieldDefinition = document.createElement("xs:simpleType"); textFieldDefinition.setAttribute("name", "textfield"); Element restriction = document.createElement("xs:restriction"); restriction.setAttribute("base", "xs:string"); Element maxLength = document.createElement("xs:maxLength"); maxLength.setAttribute("value", "100"); restriction.appendChild(maxLength); textFieldDefinition.appendChild(restriction); schemaElement.insertBefore(textFieldDefinition, schemaElement.getFirstChild()); Element selectDefinition = document.createElement("xs:simpleType"); selectDefinition.setAttribute("name", "select"); restriction = document.createElement("xs:restriction"); restriction.setAttribute("base", "xs:string"); maxLength = document.createElement("xs:maxLength"); maxLength.setAttribute("value", "100"); restriction.appendChild(maxLength); selectDefinition.appendChild(restriction); schemaElement.insertBefore(selectDefinition, schemaElement.getFirstChild()); Element checkboxDefinition = document.createElement("xs:simpleType"); checkboxDefinition.setAttribute("name", "checkbox"); restriction = document.createElement("xs:restriction"); restriction.setAttribute("base", "xs:string"); maxLength = document.createElement("xs:maxLength"); maxLength.setAttribute("value", "100"); restriction.appendChild(maxLength); checkboxDefinition.appendChild(restriction); schemaElement.insertBefore(checkboxDefinition, schemaElement.getFirstChild()); Element radiobuttonDefinition = document.createElement("xs:simpleType"); radiobuttonDefinition.setAttribute("name", "radiobutton"); restriction = document.createElement("xs:restriction"); restriction.setAttribute("base", "xs:string"); maxLength = document.createElement("xs:maxLength"); maxLength.setAttribute("value", "100"); restriction.appendChild(maxLength); radiobuttonDefinition.appendChild(restriction); schemaElement.insertBefore(radiobuttonDefinition, schemaElement.getFirstChild()); Element textareaDefinition = document.createElement("xs:simpleType"); textareaDefinition.setAttribute("name", "textarea"); restriction = document.createElement("xs:restriction"); restriction.setAttribute("base", "xs:string"); maxLength = document.createElement("xs:maxLength"); maxLength.setAttribute("value", "100"); restriction.appendChild(maxLength); textareaDefinition.appendChild(restriction); schemaElement.insertBefore(textareaDefinition, schemaElement.getFirstChild()); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); if (childElement.getAttribute("type").equals("shortString")) { childElement.setAttribute("type", "textfield"); isModified = true; } else if (childElement.getAttribute("type").equals("shortText")) { childElement.setAttribute("type", "textarea"); isModified = true; } else if (childElement.getAttribute("type").equals("fullText")) { childElement.setAttribute("type", "textarea"); isModified = true; } else if (childElement.getAttribute("type").equals("hugeText")) { childElement.setAttribute("type", "textarea"); isModified = true; } String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { Element annotationElement = (Element) annotationNodeList.item(0); NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { Element appinfoElement = (Element) appinfoNodeList.item(0); NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); addParameterElement(paramsElement, "title", "0"); addParameterElement(paramsElement, "description", "0"); addParameterElement(paramsElement, "class", "0"); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElement(paramsElement, "widget", "0"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElement(paramsElement, "dataProviderClass", ""); addParameterElement(paramsElement, "dataProviderParameters", ""); addParameterElement(paramsElement, "values", "1"); } if (inputTypeId.equalsIgnoreCase("textarea")) { addParameterElement(paramsElement, "width", "0", "700"); addParameterElement(paramsElement, "height", "0", "150"); addParameterElement(paramsElement, "enableWYSIWYG", "0", "false"); addParameterElement(paramsElement, "WYSIWYGToolbar", "0", "Default"); addParameterElement(paramsElement, "WYSIWYGExtraConfig", "0", ""); addParameterElement(paramsElement, "enableFormEditor", "0", "false"); addParameterElement(paramsElement, "enableContentRelationEditor", "0", "false"); addParameterElement(paramsElement, "enableStructureRelationEditor", "0", "false"); addParameterElement(paramsElement, "activateExtendedEditorOnLoad", "0", "false"); } } else { Element paramsElement = document.createElement("params"); addParameterElement(paramsElement, "title", "0"); addParameterElement(paramsElement, "description", "0"); addParameterElement(paramsElement, "class", "0"); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElement(paramsElement, "widget", "0"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElement(paramsElement, "dataProviderClass", ""); addParameterElement(paramsElement, "dataProviderParameters", ""); addParameterElement(paramsElement, "values", "1"); } if (inputTypeId.equalsIgnoreCase("textarea")) { addParameterElement(paramsElement, "width", "0", "700"); addParameterElement(paramsElement, "height", "0", "150"); addParameterElement(paramsElement, "enableWYSIWYG", "0", "false"); addParameterElement(paramsElement, "WYSIWYGToolbar", "0", "Default"); addParameterElement(paramsElement, "WYSIWYGExtraConfig", "0", ""); addParameterElement(paramsElement, "enableFormEditor", "0", "false"); addParameterElement(paramsElement, "enableContentRelationEditor", "0", "false"); addParameterElement(paramsElement, "enableStructureRelationEditor", "0", "false"); addParameterElement(paramsElement, "activateExtendedEditorOnLoad", "0", "false"); } appinfoElement.appendChild(paramsElement); isModified = true; } } else { Element appInfo = document.createElement("xs:appinfo"); Element paramsElement = document.createElement("params"); addParameterElement(paramsElement, "title", "0"); addParameterElement(paramsElement, "description", "0"); addParameterElement(paramsElement, "class", "0"); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElement(paramsElement, "widget", "0"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElement(paramsElement, "dataProviderClass", ""); addParameterElement(paramsElement, "dataProviderParameters", ""); addParameterElement(paramsElement, "values", "1"); } if (inputTypeId.equalsIgnoreCase("textarea")) { addParameterElement(paramsElement, "width", "0", "700"); addParameterElement(paramsElement, "height", "0", "150"); addParameterElement(paramsElement, "enableWYSIWYG", "0", "false"); addParameterElement(paramsElement, "WYSIWYGToolbar", "0", "Default"); addParameterElement(paramsElement, "WYSIWYGExtraConfig", "0", ""); addParameterElement(paramsElement, "enableFormEditor", "0", "false"); addParameterElement(paramsElement, "enableContentRelationEditor", "0", "false"); addParameterElement(paramsElement, "enableStructureRelationEditor", "0", "false"); addParameterElement(paramsElement, "activateExtendedEditorOnLoad", "0", "false"); } annotationElement.appendChild(appInfo); appInfo.appendChild(paramsElement); isModified = true; } } else { Element annotation = document.createElement("xs:annotation"); Element appInfo = document.createElement("xs:appinfo"); Element paramsElement = document.createElement("params"); addParameterElement(paramsElement, "title", "0"); addParameterElement(paramsElement, "description", "0"); addParameterElement(paramsElement, "class", "0"); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElement(paramsElement, "widget", "0"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElement(paramsElement, "dataProviderClass", ""); addParameterElement(paramsElement, "dataProviderParameters", ""); addParameterElement(paramsElement, "values", "1"); } if (inputTypeId.equalsIgnoreCase("textarea")) { addParameterElement(paramsElement, "width", "0", "700"); addParameterElement(paramsElement, "height", "0", "150"); addParameterElement(paramsElement, "enableWYSIWYG", "0", "false"); addParameterElement(paramsElement, "WYSIWYGToolbar", "0", "Default"); addParameterElement(paramsElement, "WYSIWYGExtraConfig", "0", ""); addParameterElement(paramsElement, "enableFormEditor", "0", "false"); addParameterElement(paramsElement, "enableContentRelationEditor", "0", "false"); addParameterElement(paramsElement, "enableStructureRelationEditor", "0", "false"); addParameterElement(paramsElement, "activateExtendedEditorOnLoad", "0", "false"); } childElement.appendChild(annotation); annotation.appendChild(appInfo); appInfo.appendChild(paramsElement); isModified = true; } } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.0")) { isModified = true; schemaElement.setAttribute("version", "2.1"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } if (inputTypeId.equalsIgnoreCase("textarea")) { addParameterElementIfNotExists(paramsElement, "width", "0", "700"); addParameterElementIfNotExists(paramsElement, "height", "0", "150"); addParameterElementIfNotExists(paramsElement, "enableWYSIWYG", "0", "false"); addParameterElementIfNotExists(paramsElement, "WYSIWYGToolbar", "0", "Default"); addParameterElementIfNotExists(paramsElement, "WYSIWYGExtraConfig", "0", ""); addParameterElementIfNotExists(paramsElement, "enableFormEditor", "0", "false"); addParameterElementIfNotExists(paramsElement, "enableContentRelationEditor", "0", "false"); addParameterElementIfNotExists(paramsElement, "enableStructureRelationEditor", "0", "false"); addParameterElementIfNotExists(paramsElement, "activateExtendedEditorOnLoad", "0", "false"); isModified = true; } } } } } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.1")) { isModified = true; schemaElement.setAttribute("version", "2.2"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } } } } } //Now we deal with adding the validation part if not existent String validatorsXPath = "/xs:schema/xs:complexType[@name = 'Validation']"; Node formNode = org.apache.xpath.XPathAPI.selectSingleNode(document.getDocumentElement(), validatorsXPath); if (formNode == null) { String schemaXPath = "/xs:schema"; Node schemaNode = org.apache.xpath.XPathAPI.selectSingleNode(document.getDocumentElement(), schemaXPath); Element element = (Element) schemaNode; String validationXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xs:complexType name=\"Validation\" xmlns:xi=\"http://www.w3.org/2001/XInclude\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:annotation><xs:appinfo><form-validation><global><validator name=\"required\" classname=\"org.infoglue.cms.util.validators.CommonsValidator\" method=\"validateRequired\" methodParams=\"java.lang.Object,org.apache.commons.validator.Field\" msg=\"300\"/><validator name=\"requiredif\" classname=\"org.infoglue.cms.util.validators.CommonsValidator\" method=\"validateRequiredIf\" methodParams=\"java.lang.Object,org.apache.commons.validator.Field,org.apache.commons.validator.Validator\" msg=\"315\"/><validator name=\"matchRegexp\" classname=\"org.infoglue.cms.util.validators.CommonsValidator\" method=\"validateRegexp\" methodParams=\"java.lang.Object,org.apache.commons.validator.Field\" msg=\"300\"/></global><formset><form name=\"requiredForm\"></form></formset></form-validation></xs:appinfo></xs:annotation></xs:complexType>"; InputSource validationXMLSource = new InputSource(new StringReader(validationXML)); DOMParser parser2 = new DOMParser(); parser2.parse(validationXMLSource); Document document2 = parser2.getDocument(); Node node = document.importNode(document2.getDocumentElement(), true); element.appendChild(node); } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.2")) { isModified = true; schemaElement.setAttribute("version", "2.3"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } addParameterElementIfNotExists(paramsElement, "initialData", "0", ""); isModified = true; } } } } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.3")) { isModified = true; schemaElement.setAttribute("version", "2.4"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } addParameterElementIfNotExists(paramsElement, "enableComponentPropertiesEditor", "0", "false"); isModified = true; } } } } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.4")) { isModified = true; schemaElement.setAttribute("version", "2.5"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } addParameterElementIfNotExists(paramsElement, "WYSIWYGToolbar", "0", "Default"); addParameterElementIfNotExists(paramsElement, "WYSIWYGExtraConfig", "0", ""); isModified = true; } } } } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.5")) { isModified = true; schemaElement.setAttribute("version", "2.5.1"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } addParameterElementIfNotExists(paramsElement, "WYSIWYGExtraConfig", "0", ""); isModified = true; } } } } } else if (schemaElement.getAttribute("version") != null && schemaElement.getAttribute("version").equalsIgnoreCase("2.5.1")) { isModified = true; schemaElement.setAttribute("version", "2.5.2"); //Now we deal with the individual attributes and parameters 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); for (int k = 0; k < anl.getLength(); k++) { Element childElement = (Element) anl.item(k); String inputTypeId = childElement.getAttribute("type"); NodeList annotationNodeList = childElement.getElementsByTagName("xs:annotation"); if (annotationNodeList != null && annotationNodeList.getLength() > 0) { NodeList appinfoNodeList = childElement.getElementsByTagName("xs:appinfo"); if (appinfoNodeList != null && appinfoNodeList.getLength() > 0) { NodeList paramsNodeList = childElement.getElementsByTagName("params"); if (paramsNodeList != null && paramsNodeList.getLength() > 0) { Element paramsElement = (Element) paramsNodeList.item(0); if (inputTypeId.equalsIgnoreCase("checkbox")) addParameterElementIfNotExists(paramsElement, "widget", "0", "default"); if (inputTypeId.equalsIgnoreCase("checkbox") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { addParameterElementIfNotExists(paramsElement, "dataProviderClass", "", ""); addParameterElementIfNotExists(paramsElement, "dataProviderParameters", "", ""); } isModified = true; } } } } } } if (isModified) { StringBuffer sb = new StringBuffer(); org.infoglue.cms.util.XMLHelper.serializeDom(document.getDocumentElement(), sb); contentTypeDefinitionVO.setSchemaValue(sb.toString()); update(contentTypeDefinitionVO); } } catch (Exception e) { e.printStackTrace(); } return contentTypeDefinitionVO; }
From source file:org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController.java
private boolean addElement(Document document, String attributeName, String nodeTemplateAsString, String siblingName) throws Exception { Document nodeTemplateDocument = createDocumentFromDefinition(nodeTemplateAsString); logger.info("modelClassNameNodeDocument:" + nodeTemplateDocument); String componentLabelsXPath = "//xs:element[@name='" + siblingName + "']"; NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentLabelsXPath);/*from w w w .j av a 2s . com*/ logger.info("anl:" + anl); if (anl.getLength() > 0) { Element childElement = (Element) anl.item(0); Element parent = (Element) childElement.getParentNode(); Node node = document.importNode( nodeTemplateDocument.getDocumentElement().getElementsByTagName("xs:element").item(0), true); parent.appendChild(node); return true; } return false; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
public String doDeleteAttribute() throws Exception { log.debug("Deleting attribute...."); this.initialize(getContentTypeDefinitionId()); try {/*from w ww .j a va 2 s. co m*/ Document document = createDocumentFromDefinition(); String attributesXPath = "/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(), attributesXPath); if (anl != null && anl.getLength() > 0) { Element element = (Element) anl.item(0); element.getParentNode().removeChild(element); } String validatorsXPath = "/xs:schema/xs:complexType[@name = 'Validation']/xs:annotation/xs:appinfo/form-validation/formset/form/field[@property = '" + attributeName + "']"; NodeList anl2 = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), validatorsXPath); for (int i = 0; i < anl2.getLength(); i++) { Element element = (Element) anl2.item(i); 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
/** * This method moves an content type attribute up one step. *///w ww . ja va2 s . co m public String doMoveAttributeUp() 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 previousElement = null; for (int i = 0; i < anl.getLength(); i++) { Element element = (Element) anl.item(i); if (element.getAttribute("name").equalsIgnoreCase(this.attributeName) && previousElement != null) { Element parent = (Element) element.getParentNode(); parent.removeChild(element); parent.insertBefore(element, previousElement); } previousElement = element; } saveUpdatedDefinition(document); } catch (Exception e) { e.printStackTrace(); } this.initialize(getContentTypeDefinitionId()); return UPDATED; }