List of usage examples for org.w3c.dom Element getParentNode
public Node getParentNode();
From source file:org.etudes.tool.melete.ViewSectionsPage.java
private Node getParentsNextSibling(Element secElement) { if (secElement.getParentNode().getNodeName().equals("module")) { return null; }//from ww w.j av a2 s .c o m if (secElement.getParentNode().getNextSibling() == null) { return getParentsNextSibling((Element) secElement.getParentNode()); } else { if (secElement != null) { if (secElement.getParentNode() != null) { return secElement.getParentNode().getNextSibling(); } } } return null; }
From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java
private static boolean addOrUpdateElements(Element original, Element proposed, boolean originalDocumentChanged) { NodeList proposedChildren = proposed.getChildNodes(); for (int i = 0; i < proposedChildren.getLength(); i++) { // check // proposed // elements and // compare to // originals to // find out if // we need to // add or // replace // elements Node node = proposedChildren.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element proposedElement = (Element) node; String proposedId = proposedElement.getAttribute("id"); if (proposedId.length() != 0) { // only proposed elements with // an id will be considered Element originalElement = XmlUtils.findFirstElement("//*[@id='" + proposedId + "']", original); if (null == originalElement) { // insert proposed element // given the original // document has no element // with a matching id Element placeHolder = XmlUtils.findFirstElementByName("util:placeholder", original); if (placeHolder != null) { // insert right before place // holder if we can find it placeHolder.getParentNode().insertBefore( original.getOwnerDocument().importNode(proposedElement, false), placeHolder); } else { // find the best place to insert the element if (proposed.getAttribute("id").length() != 0 || proposed.getTagName().substring(2).matches(":[a-z].*") || proposed.getTagName().equals("fx:Declarations")) { // try to find // the id of // the // proposed // element's // parent id // in // the // original // document Element originalParent = XmlUtils.findFirstElement( "//*[@id='" + proposed.getAttribute("id") + "']", original); if (originalParent != null) { // found parent // with the same // id, so we can // just add it as // new child originalParent.appendChild( original.getOwnerDocument().importNode(proposedElement, false)); } else if (proposed.getTagName().equals("fx:Declarations")) { originalParent = XmlUtils.findFirstElementByName("fx:Declarations", original); originalParent.appendChild( original.getOwnerDocument().importNode(proposedElement, true)); } else if (proposed.getTagName().substring(2).matches(":[a-z].*")) { // Likely an attribute tag rather than a // component, thus not allowed to have an // id, // so we must match on the next level up Element proposedParent = proposed.getParentNode() .getNodeType() == Node.ELEMENT_NODE ? (Element) proposed.getParentNode() : null; if (proposedParent != null && proposedParent.getAttribute("id").length() != 0) { String attrTag = proposed.getTagName() .substring(proposed.getTagName().indexOf(":") + 1); originalParent = XmlUtils.findFirstElement( "//*[@id='" + proposedParent.getAttribute("id") + "']/" + attrTag, original); if (originalParent != null) { // found a // matching // parent, // so we // can // just // add it // as new // child originalParent.appendChild( original.getOwnerDocument().importNode(proposedElement, false)); }/*from w w w .j a va 2 s . c om*/ } } } } originalDocumentChanged = true; } else { // we found an element in the original document with // a matching id String originalElementHashCode = originalElement.getAttribute("z"); if (originalElementHashCode.length() > 0) { // only act // if a hash // code // exists if ("?".equals(originalElementHashCode) || originalElementHashCode .equals(MxmlRoundTripUtils.calculateUniqueKeyFor(originalElement))) { // only // act // if // hash // codes // match // (no // user // changes // in // the // element) // or // the // user // requests // for // the // hash // code // to // be // regenerated if (!equalElements(originalElement, proposedElement)) { // check if the // elements have // equal contents originalElement.getParentNode().replaceChild( original.getOwnerDocument().importNode(proposedElement, false), originalElement); // replace // the // original // with // the // proposed // element originalDocumentChanged = true; } if ("?".equals(originalElementHashCode)) { // replace // z // if // the // user // sets // its // value // to // '?' // as // an // indication // that // roo // should // take // over // the // management // of // this // element // again originalElement.setAttribute("z", MxmlRoundTripUtils.calculateUniqueKeyFor(proposedElement)); originalDocumentChanged = true; } } else { // if hash codes don't match we will mark the // element as z="user-managed" if (!originalElementHashCode.equals("user-managed")) { originalElement.setAttribute("z", "user-managed"); // mark the element // as // 'user-managed' // if the hash // codes don't // match any more originalDocumentChanged = true; } } } } } originalDocumentChanged = addOrUpdateElements(original, proposedElement, originalDocumentChanged); // walk // through // the // document // tree // recursively } } return originalDocumentChanged; }
From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java
private static boolean removeElements(Element original, Element proposed, boolean originalDocumentChanged) { NodeList originalChildren = original.getChildNodes(); for (int i = 0; i < originalChildren.getLength(); i++) { // check // original // elements and // compare to // proposed to // find out if // we need to // remove // elements Node node = originalChildren.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element originalElement = (Element) node; String originalId = originalElement.getAttribute("id"); if (originalId.length() != 0) { // only proposed elements with // an id will be considered Element proposedElement = XmlUtils.findFirstElement("//*[@id='" + originalId + "']", proposed); if (null == proposedElement && (originalElement.getAttribute("z") .equals(MxmlRoundTripUtils.calculateUniqueKeyFor(originalElement)) || originalElement.getAttribute("z").equals("?"))) { // remove // original // element // given // the // proposed // document // has no // element // with a // matching // id originalElement.getParentNode().removeChild(originalElement); originalDocumentChanged = true; }/*from w w w . j ava 2 s. c o m*/ } originalDocumentChanged = removeElements(originalElement, proposed, originalDocumentChanged); // walk // through // the // document // tree // recursively } } return originalDocumentChanged; }
From source file:org.hisp.dhis.webwork.configuration.UrlXmlConfigurationProvider.java
protected List buildExternalRefs(Element element, PackageConfig context) throws ConfigurationException { List refs = new ArrayList(); NodeList externalRefList = element.getElementsByTagName("external-ref"); String refName;/*from ww w. j a v a 2 s . c o m*/ String refValue = null; String requiredTemp; boolean required; for (int i = 0; i < externalRefList.getLength(); i++) { Element refElement = (Element) externalRefList.item(i); if (refElement.getParentNode().equals(element)) { refName = refElement.getAttribute("name"); // If the external ref is not declared explicitly, we can // introspect the // reference type using it's name and try resolving the // reference using it's class type if (refElement.getChildNodes().getLength() > 0) { refValue = refElement.getChildNodes().item(0).getNodeValue(); } requiredTemp = refElement.getAttribute("required"); if ((requiredTemp == null) || "".equals(requiredTemp)) { required = true; } else { required = Boolean.valueOf(requiredTemp).booleanValue(); } refs.add(new ExternalReference(refName, refValue, required)); } } return refs; }
From source file:org.hisp.dhis.webwork.configuration.UrlXmlConfigurationProvider.java
protected List buildInterceptorList(Element element, PackageConfig context) throws ConfigurationException { List interceptorList = new ArrayList(); NodeList interceptorRefList = element.getElementsByTagName("interceptor-ref"); for (int i = 0; i < interceptorRefList.getLength(); i++) { Element interceptorRefElement = (Element) interceptorRefList.item(i); if (interceptorRefElement.getParentNode().equals(element)) { List interceptors = lookupInterceptorReference(context, interceptorRefElement); interceptorList.addAll(interceptors); }/* w ww . jav a 2s . com*/ } return interceptorList; }
From source file:org.hisp.dhis.webwork.configuration.UrlXmlConfigurationProvider.java
/** * Build a map of ResultConfig objects from below a given XML element. *//*from w w w .j ava2 s . c om*/ protected Map buildResults(Element element, PackageConfig packageContext) { NodeList resultEls = element.getElementsByTagName("result"); Map results = new LinkedHashMap(); for (int i = 0; i < resultEls.getLength(); i++) { Element resultElement = (Element) resultEls.item(i); if (resultElement.getParentNode().equals(element)) { String resultName = resultElement.getAttribute("name"); String resultType = resultElement.getAttribute("type"); // if you don't specify a name on <result/>, it defaults to // "success" if (!TextUtils.stringSet(resultName)) { resultName = Action.SUCCESS; } // there is no result type, so let's inherit from the parent // package if (!TextUtils.stringSet(resultType)) { resultType = packageContext.getFullDefaultResultType(); // now check if there is a result type now if (!TextUtils.stringSet(resultType)) { // uh-oh, we have a problem LOG.error("No result type specified for result named '" + resultName + "', perhaps the parent package does not specify the result type?"); } } ResultTypeConfig config = (ResultTypeConfig) packageContext.getAllResultTypeConfigs() .get(resultType); if (config == null) { throw new ConfigurationException("There is no result type defined for type '" + resultType + "' mapped with name '" + resultName + "'", resultElement); } String resultClass = config.getClazz(); // invalid result type specified in result definition if (resultClass == null) { LOG.error("Result type '" + resultType + "' is invalid. Modify your xwork.xml file."); } Map resultParams = XmlHelper.getParams(resultElement); if (resultParams.size() == 0) // maybe we just have a body - // therefore a default parameter { // if <result ...>something</result> then we add a parameter // of 'something' as this is the most used result param if ((resultElement.getChildNodes().getLength() == 1) && (resultElement.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE)) { resultParams = new LinkedHashMap(); String paramName = config.getDefaultResultParam(); if (paramName != null) { String paramValue = resultElement.getChildNodes().item(0).getNodeValue(); if (paramValue != null) { paramValue = paramValue.trim(); } resultParams.put(paramName, paramValue); } else { LOG.warn("no default parameter defined for result of type " + config.getName()); } } } // create new param map, so that the result param can override // the config param Map params = new LinkedHashMap(); Map configParams = config.getParams(); if (configParams != null) { params.putAll(configParams); } params.putAll(resultParams); ResultConfig resultConfig = new ResultConfig(resultName, resultClass, params); resultConfig.setLocation(DomHelper.getLocationObject(element)); results.put(resultConfig.getName(), resultConfig); } } return results; }
From source file:org.hisp.dhis.webwork.configuration.UrlXmlConfigurationProvider.java
/** * Build a map of ResultConfig objects from below a given XML element. *//* ww w . j ava 2 s . co m*/ protected List buildExceptionMappings(Element element, PackageConfig packageContext) { NodeList exceptionMappingEls = element.getElementsByTagName("exception-mapping"); List exceptionMappings = new ArrayList(); for (int i = 0; i < exceptionMappingEls.getLength(); i++) { Element ehElement = (Element) exceptionMappingEls.item(i); if (ehElement.getParentNode().equals(element)) { String emName = ehElement.getAttribute("name"); String exceptionClassName = ehElement.getAttribute("exception"); String exceptionResult = ehElement.getAttribute("result"); Map params = XmlHelper.getParams(ehElement); if (!TextUtils.stringSet(emName)) { emName = exceptionResult; } ExceptionMappingConfig ehConfig = new ExceptionMappingConfig(emName, exceptionClassName, exceptionResult, params); ehConfig.setLocation(DomHelper.getLocationObject(ehElement)); exceptionMappings.add(ehConfig); } } return exceptionMappings; }
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. *//*from w w w. ja 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
public String doDeleteAttribute() throws Exception { this.initialize(getContentTypeDefinitionId()); try {/*from w w w . j a v a 2s . c o 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 USE_EDITOR; }
From source file:org.infoglue.cms.applications.managementtool.actions.ViewContentTypeDefinitionAction.java
/** * This method moves an content type attribute up one step. *///from www.j a va 2s . 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 USE_EDITOR; }