List of usage examples for org.w3c.dom Element insertBefore
public Node insertBefore(Node newChild, Node refChild) throws DOMException;
newChild
before the existing child node refChild
. From source file:org.gvnix.web.screen.roo.addon.WebScreenOperationsImpl.java
/** * Adds the element dialog:message-box in the right place in default.jspx * layout// w w w . j a v a2 s.c om */ private void addMessageBoxInLayout() { PathResolver pathResolver = projectOperations.getPathResolver(); String defaultJspx = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), "WEB-INF/layouts/default.jspx"); // TODO: Check if it's necessary to add message-box in home-default.jspx // layout (when exists) if (!fileManager.exists(defaultJspx)) { // layouts/default.jspx doesn't exist, so nothing to do return; } InputStream defulatJspxIs = fileManager.getInputStream(defaultJspx); Document defaultJspxXml; try { defaultJspxXml = XmlUtils.getDocumentBuilder().parse(defulatJspxIs); } catch (Exception ex) { throw new IllegalStateException("Could not open default.jspx file", ex); } Element lsHtml = defaultJspxXml.getDocumentElement(); String dialogNsUri = lsHtml.getAttribute("xmlns:dialog"); if (!dialogNsUri.isEmpty() && dialogNsUri.equals("urn:jsptagdir:/WEB-INF/tags/dialog/modal")) { // User has applied modal dialog support, so, don't change anything; return; } // Set dialog tag lib as attribute in html element lsHtml.setAttribute("xmlns:dialog", "urn:jsptagdir:/WEB-INF/tags/dialog/message"); Element messageBoxElement = DomUtils.findFirstElementByName("dialog:message-box", lsHtml); if (messageBoxElement == null) { Element divMain = XmlUtils.findFirstElement("/html/body/div/div[@id='main']", lsHtml); Element insertAttributeBodyElement = XmlUtils .findFirstElement("/html/body/div/div/insertAttribute[@name='body']", lsHtml); Element messageBox = new XmlElementBuilder("dialog:message-box", defaultJspxXml).build(); divMain.insertBefore(messageBox, insertAttributeBodyElement); } writeToDiskIfNecessary(defaultJspx, defaultJspxXml.getDocumentElement()); }
From source file:org.gvnix.web.theme.roo.addon.ThemeOperationsImpl.java
/** * Updates load-scripts.tagx adding in the right position some elements: * <ul>//from w w w .ja va 2s. c o m * <li><code>spring:url</code> elements for JS and CSS</li> * <li><code>link</code> element for CSS</li> * <li><code>script</code> element for JS</li> * </ul> */ private void modifyLoadScriptsTagx() { PathResolver pathResolver = projectOperations.getPathResolver(); String loadScriptsTagx = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), "WEB-INF/tags/util/load-scripts.tagx"); if (!fileManager.exists(loadScriptsTagx)) { // load-scripts.tagx doesn't exist, so nothing to do return; } InputStream loadScriptsIs = fileManager.getInputStream(loadScriptsTagx); Document loadScriptsXml; try { loadScriptsXml = org.springframework.roo.support.util.XmlUtils.getDocumentBuilder() .parse(loadScriptsIs); } catch (Exception ex) { throw new IllegalStateException("Could not open load-scripts.tagx file", ex); } Element lsRoot = loadScriptsXml.getDocumentElement(); // Add new tag namesapces Element jspRoot = org.springframework.roo.support.util.XmlUtils.findFirstElement("/root", lsRoot); jspRoot.setAttribute("xmlns:util", "urn:jsptagdir:/WEB-INF/tags/util"); Node nextSibiling; // spring:url elements Element testElement = org.springframework.roo.support.util.XmlUtils .findFirstElement("/root/url[@var='roo_css-ie_url']", lsRoot); if (testElement == null) { Element urlCitIECss = new XmlElementBuilder(SPRING_URL, loadScriptsXml) .addAttribute(VALUE_ATTRIBUTE, "/resources/styles/cit-IE.css") .addAttribute(VAR_ATTRIBUTE, "roo_css-ie_url").build(); Element urlApplicationCss = new XmlElementBuilder(SPRING_URL, loadScriptsXml) .addAttribute(VALUE_ATTRIBUTE, "/resources/styles/application.css") .addAttribute(VAR_ATTRIBUTE, "application_css_url").build(); Element urlYuiEventJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml) .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/yui/yahoo-dom-event.js") .addAttribute(VAR_ATTRIBUTE, "yui_event").build(); Element urlYuiCoreJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml) .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/yui/container_core-min.js") .addAttribute(VAR_ATTRIBUTE, "yui_core").build(); Element urlYoiMenuJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml) .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/yui/menu-min.js") .addAttribute(VAR_ATTRIBUTE, "yui_menu").build(); Element urlCitJs = new XmlElementBuilder(SPRING_URL, loadScriptsXml) .addAttribute(VALUE_ATTRIBUTE, "/resources/scripts/utils.js") .addAttribute(VAR_ATTRIBUTE, "cit_js_url").build(); List<Element> springUrlElements = org.springframework.roo.support.util.XmlUtils .findElements("/root/url", lsRoot); // Element lastSpringUrl = null; if (!springUrlElements.isEmpty()) { Element lastSpringUrl = springUrlElements.get(springUrlElements.size() - 1); if (lastSpringUrl != null) { nextSibiling = lastSpringUrl.getNextSibling().getNextSibling(); lsRoot.insertBefore(urlCitIECss, nextSibiling); lsRoot.insertBefore(urlApplicationCss, nextSibiling); lsRoot.insertBefore(urlYuiEventJs, nextSibiling); lsRoot.insertBefore(urlYuiCoreJs, nextSibiling); lsRoot.insertBefore(urlYoiMenuJs, nextSibiling); lsRoot.insertBefore(urlCitJs, nextSibiling); } } else { // Add at the end of the document lsRoot.appendChild(urlCitIECss); lsRoot.appendChild(urlApplicationCss); lsRoot.appendChild(urlYuiEventJs); lsRoot.appendChild(urlYuiCoreJs); lsRoot.appendChild(urlYoiMenuJs); lsRoot.appendChild(urlCitJs); } } Element setUserLocale = org.springframework.roo.support.util.XmlUtils.findFirstElement("/root/set/out", lsRoot); setUserLocale.setAttribute("default", "es"); // cit-IE.css stylesheet element testElement = org.springframework.roo.support.util.XmlUtils .findFirstElement("/root/iecondition/link[@href='${roo_css-ie_url}']", lsRoot); if (testElement == null) { Element ifIE = new XmlElementBuilder("util:iecondition", loadScriptsXml).build(); Element linkCitIECss = new XmlElementBuilder("link", loadScriptsXml).addAttribute("rel", "stylesheet") .addAttribute(TYPE_ATTRIBUTE, "text/css").addAttribute(HREF_ATTRIBUTE, "${roo_css-ie_url}") .build(); ifIE.appendChild(linkCitIECss); Node linkFaviconNode = org.springframework.roo.support.util.XmlUtils .findFirstElement("/root/link[@href='${favicon}']", lsRoot); if (linkFaviconNode != null) { nextSibiling = linkFaviconNode.getNextSibling().getNextSibling(); lsRoot.insertBefore(ifIE, linkFaviconNode); } else { // Add ass last link element // Element lastLink = null; List<Element> linkElements = org.springframework.roo.support.util.XmlUtils .findElements("/root/link", lsRoot); if (!linkElements.isEmpty()) { Element lastLink = linkElements.get(linkElements.size() - 1); if (lastLink != null) { nextSibiling = lastLink.getNextSibling().getNextSibling(); lsRoot.insertBefore(ifIE, nextSibiling); } } else { // Add at the end of document lsRoot.appendChild(ifIE); } } } // pattern.css stylesheet element testElement = org.springframework.roo.support.util.XmlUtils .findFirstElement("/root/link[@href='${application_css_url}']", lsRoot); if (testElement == null) { Element linkApplicationCss = new XmlElementBuilder("link", loadScriptsXml) .addAttribute("rel", "stylesheet").addAttribute(TYPE_ATTRIBUTE, "text/css") .addAttribute("media", "screen").addAttribute(HREF_ATTRIBUTE, "${application_css_url}").build(); linkApplicationCss.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA)); Node linkFaviconNode = org.springframework.roo.support.util.XmlUtils .findFirstElement("/root/link[@href='${favicon}']", lsRoot); if (linkFaviconNode != null) { nextSibiling = linkFaviconNode.getNextSibling().getNextSibling(); lsRoot.insertBefore(linkApplicationCss, linkFaviconNode); } else { // Add ass last link element // Element lastLink = null; List<Element> linkElements = org.springframework.roo.support.util.XmlUtils .findElements("/root/link", lsRoot); if (!linkElements.isEmpty()) { Element lastLink = linkElements.get(linkElements.size() - 1); if (lastLink != null) { nextSibiling = lastLink.getNextSibling().getNextSibling(); lsRoot.insertBefore(linkApplicationCss, nextSibiling); } } else { // Add at the end of document lsRoot.appendChild(linkApplicationCss); } } } // utils.js script element testElement = org.springframework.roo.support.util.XmlUtils .findFirstElement("/root/script[@src='${cit_js_url}']", lsRoot); if (testElement == null) { Element scriptYuiEventJs = new XmlElementBuilder(SCRIPT, loadScriptsXml) .addAttribute(SRC, "${yui_event}").addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build(); scriptYuiEventJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA)); Element scriptYuiCoreJs = new XmlElementBuilder(SCRIPT, loadScriptsXml).addAttribute(SRC, "${yui_core}") .addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build(); scriptYuiCoreJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA)); Element scriptYoiMenuJs = new XmlElementBuilder(SCRIPT, loadScriptsXml).addAttribute(SRC, "${yui_menu}") .addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build(); scriptYoiMenuJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA)); Element scriptCitJs = new XmlElementBuilder(SCRIPT, loadScriptsXml).addAttribute(SRC, "${cit_js_url}") .addAttribute(TYPE_ATTRIBUTE, TEXT_JSCRPT).build(); scriptCitJs.appendChild(loadScriptsXml.createComment(FF3_AND_OPERA)); List<Element> scrtiptElements = org.springframework.roo.support.util.XmlUtils .findElements("/root/script", lsRoot); // Element lastScript = null; if (!scrtiptElements.isEmpty()) { Element lastScript = scrtiptElements.get(scrtiptElements.size() - 1); if (lastScript != null) { nextSibiling = lastScript.getNextSibling().getNextSibling(); lsRoot.insertBefore(scriptYuiEventJs, nextSibiling); lsRoot.insertBefore(scriptYuiCoreJs, nextSibiling); lsRoot.insertBefore(scriptYoiMenuJs, nextSibiling); lsRoot.insertBefore(scriptCitJs, nextSibiling); } } else { // Add at the end of document lsRoot.appendChild(scriptYuiEventJs); lsRoot.appendChild(scriptYuiCoreJs); lsRoot.appendChild(scriptYoiMenuJs); lsRoot.appendChild(scriptCitJs); } } writeToDiskIfNecessary(loadScriptsTagx, loadScriptsXml.getDocumentElement()); }
From source file:org.infoglue.calendar.controllers.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 2 s . c om public ContentTypeDefinition validateAndUpdateContentType(Long id, ContentTypeDefinition contentTypeDefinition, Session session) { try { boolean isModified = false; InputSource xmlSource = new InputSource(new StringReader(contentTypeDefinition.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") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { 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, "enableTemplateEditor", "0", "false"); 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") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { 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, "enableTemplateEditor", "0", "false"); 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") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { 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, "enableTemplateEditor", "0", "false"); 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") || inputTypeId.equalsIgnoreCase("select") || inputTypeId.equalsIgnoreCase("radiobutton")) { 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, "enableTemplateEditor", "0", "false"); 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("textarea")) { addParameterElementIfNotExists(paramsElement, "width", "0", "700"); addParameterElementIfNotExists(paramsElement, "height", "0", "150"); addParameterElementIfNotExists(paramsElement, "enableWYSIWYG", "0", "false"); addParameterElementIfNotExists(paramsElement, "enableTemplateEditor", "0", "false"); 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 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); 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); addParameterElementIfNotExists(paramsElement, "enableComponentPropertiesEditor", "0", "false"); isModified = true; } } } } } } if (isModified) { StringBuffer sb = new StringBuffer(); XMLHelper.serializeDom(document.getDocumentElement(), sb); contentTypeDefinition.setSchemaValue(sb.toString()); update(id, contentTypeDefinition, session); } } catch (Exception e) { e.printStackTrace(); } return contentTypeDefinition; }
From source file:org.infoglue.cms.applications.managementtool.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute up one step. *//*from ww w . ja va 2 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 USE_EDITOR; }
From source file:org.infoglue.cms.applications.managementtool.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute down one step. *//*from w ww . j a v a2 s. c o m*/ 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 USE_EDITOR; }
From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java
/** * This method adds a component to the page. *///ww w . j ava2 s . com public String doMoveComponentToSlot() throws Exception { logger.info("************************************************************"); logger.info("* MOVING COMPONENT TO ANOTHER SLOT *"); logger.info("************************************************************"); logger.info("siteNodeId:" + this.siteNodeId); logger.info("languageId:" + this.languageId); logger.info("contentId:" + this.contentId); logger.info("queryString:" + this.getRequest().getQueryString()); logger.info("parentComponentId:" + this.parentComponentId); logger.info("componentId:" + this.componentId); logger.info("slotId:" + this.slotId); logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate); initialize(); logger.info("masterLanguageId:" + this.masterLanguageVO.getId()); ContentVO componentContentVO = null; if (this.specifyBaseTemplate.equalsIgnoreCase("true")) { throw new SystemException("Not possible to move component to base slot"); } else { String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId()); Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8")); String componentXPath = "//component[@id=" + this.componentId + "]"; String parentComponentXPath = "//component[@id=" + this.parentComponentId + "]/components"; logger.info("componentXPath:" + componentXPath); logger.info("parentComponentXPath:" + parentComponentXPath); Node componentNode = org.apache.xpath.XPathAPI.selectSingleNode(document.getDocumentElement(), componentXPath); logger.info("Found componentNode:" + componentNode); Node parentComponentComponentsNode = org.apache.xpath.XPathAPI .selectSingleNode(document.getDocumentElement(), parentComponentXPath); logger.info("Found parentComponentComponentsNode:" + parentComponentComponentsNode); if (componentNode != null && parentComponentComponentsNode != null) { Element component = (Element) componentNode; Element currentParentElement = (Element) componentNode.getParentNode(); Element parentComponentComponentsElement = (Element) parentComponentComponentsNode; Element parentComponentElement = (Element) parentComponentComponentsNode.getParentNode(); Integer componentContentId = new Integer(component.getAttribute("contentId")); Integer parentComponentContentId = new Integer(parentComponentElement.getAttribute("contentId")); logger.info("componentContentId:" + componentContentId); logger.info("parentComponentContentId:" + parentComponentContentId); componentContentVO = ContentController.getContentController() .getContentVOWithId(componentContentId); PageEditorHelper peh = new PageEditorHelper(); List<Slot> slots = peh.getSlots(parentComponentContentId, languageId, this.getInfoGluePrincipal()); boolean allowed = true; Iterator<Slot> slotsIterator = slots.iterator(); while (slotsIterator.hasNext()) { Slot slot = slotsIterator.next(); logger.info(slot.getId() + "=" + slotId); if (slot.getId().equals(slotId)) { String[] allowedComponentNames = slot.getAllowedComponentsArray(); String[] disallowedComponentNames = slot.getDisallowedComponentsArray(); if (allowedComponentNames != null && allowedComponentNames.length > 0) { allowed = false; for (int i = 0; i < allowedComponentNames.length; i++) { if (allowedComponentNames[i].equalsIgnoreCase(componentContentVO.getName())) allowed = true; } } if (disallowedComponentNames != null && disallowedComponentNames.length > 0) { for (int i = 0; i < disallowedComponentNames.length; i++) { if (disallowedComponentNames[i].equalsIgnoreCase(componentContentVO.getName())) allowed = false; } } } break; } logger.info("Should the component:" + componentContentVO + " be allowed to be put in " + slotId + ":" + allowed); logger.info("currentParentElement:" + currentParentElement.getNodeName() + ":" + currentParentElement.hashCode()); logger.info("parentComponentComponentsElement:" + parentComponentComponentsElement.getNodeName() + ":" + parentComponentComponentsElement.hashCode()); logger.info("slotPositionComponentId:" + slotPositionComponentId); if ((component.getParentNode() == parentComponentComponentsElement && slotId.equalsIgnoreCase(component.getAttribute("name")))) { logger.info("Yes..."); component.getParentNode().removeChild(component); component.setAttribute("name", slotId); logger.info("slotPositionComponentId:" + slotPositionComponentId); if (slotPositionComponentId != null && !slotPositionComponentId.equals("")) { logger.info("Moving component to slot: " + slotPositionComponentId); Element afterElement = null; NodeList childNodes = parentComponentComponentsElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getAttribute("id").equals(slotPositionComponentId)) { afterElement = element; break; } } } if (afterElement != null) { logger.info("Inserting component before: " + afterElement); parentComponentComponentsElement.insertBefore(component, afterElement); } else { parentComponentComponentsElement.appendChild(component); } } else { logger.info("Appending component..."); parentComponentComponentsElement.appendChild(component); } String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, this.masterLanguageVO.getId(), contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, this.masterLanguageVO.getId(), 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=" + componentId + "&componentContentId=" + componentContentVO.getId() + "&showSimple=" + this.showSimple; } else if (allowed && (component.getParentNode() != parentComponentComponentsElement || !slotId.equalsIgnoreCase(component.getAttribute("name")))) { logger.info("Moving component..."); component.getParentNode().removeChild(component); component.setAttribute("name", slotId); if (slotPositionComponentId != null && !slotPositionComponentId.equals("")) { NodeList childNodes = parentComponentComponentsElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getAttribute("id").equals(slotPositionComponentId)) { logger.info("Inserting component before: " + element); parentComponentComponentsElement.insertBefore(component, element); break; } } } } else { parentComponentComponentsElement.appendChild(component); } String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString(); ContentVO contentVO = NodeDeliveryController .getNodeDeliveryController(siteNodeId, this.masterLanguageVO.getId(), contentId) .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, this.masterLanguageVO.getId(), 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=" + componentId + "&componentContentId=" + componentContentVO.getId() + "&showSimple=" + this.showSimple; } else { this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&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 creates a parameter for the given input type. * This is to support form steering information later. *///from w ww . ja va 2 s . co m private Element addComponentElementBefore(Element parent, Element beforeElement, Integer id, String name, Integer contentId, boolean isPagePartReference) { Element element = parent.getOwnerDocument().createElement("component"); if (isPagePartReference) element.setAttribute("isPagePartReference", "true"); element.setAttribute("id", id.toString()); element.setAttribute("contentId", contentId.toString()); element.setAttribute("name", name); Element properties = parent.getOwnerDocument().createElement("properties"); element.appendChild(properties); Element subComponents = parent.getOwnerDocument().createElement("components"); element.appendChild(subComponents); parent.insertBefore(element, beforeElement); return element; }
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. *//*from ww w. j a v a 2 s. c om*/ 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.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute up one step. *//*from ww w. j av a 2 s. c o 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; }
From source file:org.infoglue.common.contenttypeeditor.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute down one step. *//* ww w. j a v a 2 s .c o m*/ 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; }