Example usage for org.w3c.dom Element getPreviousSibling

List of usage examples for org.w3c.dom Element getPreviousSibling

Introduction

In this page you can find the example usage for org.w3c.dom Element getPreviousSibling.

Prototype

public Node getPreviousSibling();

Source Link

Document

The node immediately preceding this node.

Usage

From source file:com.twinsoft.convertigo.engine.localbuild.BuildLocally.java

/***
 * Explore "config.xml", handle plugins and copy needed resources to appropriate platforms folders.
 * @param wwwDir//from w  ww.ja  v  a 2 s .  c om
 * @param platform
 * @param cordovaDir
 */
private void processConfigXMLResources(File wwwDir, File cordovaDir) throws Throwable {
    try {

        File configFile = new File(cordovaDir, "config.xml");
        Document doc = XMLUtils.loadXml(configFile);

        TwsCachedXPathAPI xpathApi = new TwsCachedXPathAPI();

        Element singleElement = (Element) xpathApi.selectSingleNode(doc,
                "/widget/preference[@name='phonegap-version']");

        // Changes icons and splashs src in config.xml file because it was moved to the parent folder
        NodeIterator nodeIterator = xpathApi.selectNodeIterator(doc,
                "//*[local-name()='splash' or local-name()='icon']");
        singleElement = (Element) nodeIterator.nextNode();
        while (singleElement != null) {
            String src = singleElement.getAttribute("src");
            src = "www/" + src;
            File file = new File(cordovaDir, src);
            if (file.exists()) {
                singleElement.setAttribute("src", src);
            }

            singleElement = (Element) nodeIterator.nextNode();
        }

        //ANDROID
        if (mobilePlatform instanceof Android) {
            singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/name");
            if (singleElement != null) {
                String name = singleElement.getTextContent();
                name = name.replace("\\", "\\\\");
                name = name.replace("'", "\\'");
                name = name.replace("\"", "\\\"");
                singleElement.setTextContent(name);
            }
        }

        //iOS
        //         if (mobilePlatform instanceof  IOs) {         
        //         }

        //WINPHONE
        if (mobilePlatform instanceof WindowsPhone8) {

            // Without these width and height the local build doesn't work but with these the remote build doesn't work
            singleElement = (Element) xpathApi.selectSingleNode(doc,
                    "/widget/platform[@name='wp8']/icon[not(@role)]");
            if (singleElement != null) {
                singleElement.setAttribute("width", "99");
                singleElement.setAttribute("height", "99");
            }

            singleElement = (Element) xpathApi.selectSingleNode(doc,
                    "/widget/platform[@name='wp8']/icon[@role='background']");
            if (singleElement != null) {
                singleElement.setAttribute("width", "159");
                singleElement.setAttribute("height", "159");
            }

            // /widget/platform[@name='wp8']/splash
            singleElement = (Element) xpathApi.selectSingleNode(doc, "/widget/platform/splash");
            if (singleElement != null) {
                singleElement.setAttribute("width", "768");
                singleElement.setAttribute("height", "1280");
            }

            singleElement = (Element) xpathApi.selectSingleNode(doc,
                    "/widget/plugin[@name='phonegap-plugin-push']/param[@name='SENDER_ID']");
            if (singleElement != null) {
                // Remote build needs a node named 'param' and local build needs a node named 'variable'
                singleElement.getParentNode().appendChild(cloneNode(singleElement, "variable"));
                singleElement.getParentNode().removeChild(singleElement);
            }
        }

        //         if (mobilePlatform instanceof Windows) {
        // TODO : Add platform Windows 8
        //         }

        // XMLUtils.saveXml(doc, configFile.getAbsolutePath());

        // We have to add the root config.xml all our app's config.xml preferences.
        // Cordova will use this file to generates the platform specific config.xml

        // Get preferences from current config.xml
        NodeIterator preferences = xpathApi.selectNodeIterator(doc, "//preference");
        // File configFile = new File(cordovaDir, "config.xml");

        // doc = XMLUtils.loadXml(configFile);  // The root config.xml

        NodeList preferencesList = doc.getElementsByTagName("preference");

        // Remove old preferences
        while (preferencesList.getLength() > 0) {
            Element pathNode = (Element) preferencesList.item(0);
            // Remove empty lines
            Node prev = pathNode.getPreviousSibling();
            if (prev != null && prev.getNodeType() == Node.TEXT_NODE
                    && prev.getNodeValue().trim().length() == 0) {
                doc.getDocumentElement().removeChild(prev);
            }
            doc.getDocumentElement().removeChild(pathNode);
        }

        for (Element preference = (Element) preferences
                .nextNode(); preference != null; preference = (Element) preferences.nextNode()) {
            String name = preference.getAttribute("name");
            String value = preference.getAttribute("value");

            Element elt = doc.createElement("preference");
            elt.setAttribute("name", name);
            elt.setAttribute("value", value);

            Engine.logEngine.info("Adding preference'" + name + "' with value '" + value + "'");

            doc.getDocumentElement().appendChild(elt);
        }

        Engine.logEngine.trace("New config.xml is: " + XMLUtils.prettyPrintDOM(doc));
        File resXmlFile = new File(cordovaDir, "config.xml");
        // FileUtils.deleteQuietly(resXmlFile);
        XMLUtils.saveXml(doc, resXmlFile.getAbsolutePath());

        // Last part, as all resources has been copied to the correct location, we can remove
        // our "www/res" directory before packaging to save build time and size...
        // FileUtils.deleteDirectory(new File(wwwDir, "res"));

    } catch (Exception e) {
        logException(e, "Unable to process config.xml in your project, check the file's validity");
    }
}

From source file:org.gvnix.service.roo.addon.addon.ws.WSConfigServiceImpl.java

/**
 * Update web configuration file (web.xml) with CXF configuration.
 * <ul>/*from w  w  w  .  java 2s.  c om*/
 * <li>Add the CXF servlet declaration and mapping with '/services/*' URL to
 * access published web services. All added before forst servlet mapping</li>
 * <li>Configure Spring context to load cxf configuration file</li>
 * </ul>
 * <p>
 * If already installed cxf declaration, nothing to do.
 * </p>
 */
protected void updateWebConfigurationFile() {

    // Get web configuration file document and root XML representation
    MutableFile file = getFileManager().updateFile(getWebConfigFilePath());
    Document web = getInputDocument(file.getInputStream());
    Element root = web.getDocumentElement();

    // If CXF servlet already installed: nothing to do
    if (XmlUtils.findFirstElement(
            "/web-app/servlet[servlet-class='org.apache.cxf.transport.servlet.CXFServlet']", root) != null) {
        return;
    }

    // Get first servlet mapping declaration
    Element firstMapping = XmlUtils.findRequiredElement("/web-app/servlet-mapping", root);

    // Add CXF servlet definition before first mapping
    root.insertBefore(getServletDefinition(web), firstMapping.getPreviousSibling());

    // Add CXF servlet mapping before first mapping
    root.insertBefore(getServletMapping(web), firstMapping);

    // Add CXF configuration file path to Spring context
    Element context = XmlUtils
            .findFirstElement("/web-app/context-param[param-name='contextConfigLocation']/param-value", root);
    context.setTextContent(getCxfConfigRelativeFilePath().concat(" ").concat(context.getTextContent()));

    // Write modified web.xml to disk
    XmlUtils.writeXml(file.getOutputStream(), web);
}

From source file:com.enonic.vertical.adminweb.MenuHandlerServlet.java

private void moveMenuItemUp(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        ExtendedMap formItems) throws VerticalAdminException {

    String menuXML = (String) session.getAttribute("menuxml");
    Document doc = XMLTool.domparse(menuXML);

    String xpath = "//menuitem[@key = '" + formItems.getString("key") + "']";
    Element elem = (Element) XMLTool.selectNode(doc, xpath);

    Element parent = (Element) elem.getParentNode();
    Element previousSibling = (Element) elem.getPreviousSibling();
    elem = (Element) parent.removeChild(elem);
    doc.importNode(elem, true);/*from www. j  av a2  s.  c  om*/

    if (previousSibling == null)
    // This is the top element, move it to the bottom
    {
        parent.appendChild(elem);
    } else {
        parent.insertBefore(elem, previousSibling);
    }

    session.setAttribute("menuxml", XMLTool.documentToString(doc));

    MultiValueMap queryParams = new MultiValueMap();
    queryParams.put("page", formItems.get("page"));
    queryParams.put("op", "browse");
    queryParams.put("keepxml", "yes");
    queryParams.put("highlight", formItems.get("key"));
    queryParams.put("menukey", formItems.get("menukey"));
    queryParams.put("parentmi", formItems.get("parentmi"));
    queryParams.put("subop", "shiftmenuitems");

    queryParams.put("move_menuitem", formItems.getString("move_menuitem", ""));
    queryParams.put("move_from_parent", formItems.getString("move_from_parent", ""));
    queryParams.put("move_to_parent", formItems.getString("move_to_parent", ""));

    redirectClientToAdminPath("adminpage", queryParams, request, response);
}

From source file:org.apache.rampart.util.RampartUtil.java

public static Element insertSiblingBeforeOrPrepend(RampartMessageData rmd, Element child, Element elem) {
    Element retElem = null;/*from   w  w  w .j a  va  2 s  .  c  om*/
    if (child != null && child.getPreviousSibling() != null) {
        retElem = RampartUtil.insertSiblingBefore(rmd, child, elem);
    } else { //Prepend
        retElem = prependSecHeader(rmd, elem);
    }

    return retElem;
}

From source file:org.apache.ws.security.processor.EncryptedDataProcessor.java

public List<WSSecurityEngineResult> handleToken(Element elem, RequestData request, WSDocInfo wsDocInfo)
        throws WSSecurityException {
    if (log.isDebugEnabled()) {
        log.debug("Found EncryptedData element");
    }/*from   www . ja v  a 2s.  c  o m*/
    Element kiElem = WSSecurityUtil.getDirectChildElement(elem, "KeyInfo", WSConstants.SIG_NS);
    // KeyInfo cannot be null
    if (kiElem == null) {
        throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, "noKeyinfo");
    }

    String symEncAlgo = X509Util.getEncAlgo(elem);
    // Check BSP compliance
    if (request.getWssConfig().isWsiBSPCompliant()) {
        checkBSPCompliance(symEncAlgo);
    }

    // Get the Key either via a SecurityTokenReference or an EncryptedKey
    Element secRefToken = WSSecurityUtil.getDirectChildElement(kiElem, "SecurityTokenReference",
            WSConstants.WSSE_NS);
    Element encryptedKeyElement = WSSecurityUtil.getDirectChildElement(kiElem, WSConstants.ENC_KEY_LN,
            WSConstants.ENC_NS);

    if (elem != null && request.isRequireSignedEncryptedDataElements()) {
        WSSecurityUtil.verifySignedElement(elem, elem.getOwnerDocument(), wsDocInfo.getSecurityHeader());
    }

    SecretKey key = null;
    List<WSSecurityEngineResult> encrKeyResults = null;
    Principal principal = null;
    if (secRefToken != null) {
        STRParser strParser = new SecurityTokenRefSTRParser();
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put(SecurityTokenRefSTRParser.SIGNATURE_METHOD, symEncAlgo);
        strParser.parseSecurityTokenReference(secRefToken, request, wsDocInfo, parameters);
        byte[] secretKey = strParser.getSecretKey();
        principal = strParser.getPrincipal();
        key = WSSecurityUtil.prepareSecretKey(symEncAlgo, secretKey);
    } else if (encryptedKeyElement != null) {
        EncryptedKeyProcessor encrKeyProc = new EncryptedKeyProcessor();
        encrKeyResults = encrKeyProc.handleToken(encryptedKeyElement, request, wsDocInfo);
        byte[] symmKey = (byte[]) encrKeyResults.get(0).get(WSSecurityEngineResult.TAG_SECRET);
        key = WSSecurityUtil.prepareSecretKey(symEncAlgo, symmKey);
    } else {
        throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, "noEncKey");
    }

    // Check for compliance against the defined AlgorithmSuite
    AlgorithmSuite algorithmSuite = request.getAlgorithmSuite();
    if (algorithmSuite != null) {
        AlgorithmSuiteValidator algorithmSuiteValidator = new AlgorithmSuiteValidator(algorithmSuite);

        if (principal instanceof WSDerivedKeyTokenPrincipal) {
            algorithmSuiteValidator
                    .checkDerivedKeyAlgorithm(((WSDerivedKeyTokenPrincipal) principal).getAlgorithm());
            algorithmSuiteValidator
                    .checkEncryptionDerivedKeyLength(((WSDerivedKeyTokenPrincipal) principal).getLength());
        }
        algorithmSuiteValidator.checkSymmetricKeyLength(key.getEncoded().length);
        algorithmSuiteValidator.checkSymmetricEncryptionAlgorithm(symEncAlgo);
    }

    // initialize Cipher ....
    XMLCipher xmlCipher = null;
    try {
        xmlCipher = XMLCipher.getInstance(symEncAlgo);
        xmlCipher.setSecureValidation(true);
        xmlCipher.init(XMLCipher.DECRYPT_MODE, key);
    } catch (XMLEncryptionException ex) {
        throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, ex);
    }
    Node previousSibling = elem.getPreviousSibling();
    Node parent = elem.getParentNode();
    try {
        xmlCipher.doFinal(elem.getOwnerDocument(), elem, false);
    } catch (Exception e) {
        throw new WSSecurityException(WSSecurityException.FAILED_CHECK, null, null, e);
    }

    WSDataRef dataRef = new WSDataRef();
    dataRef.setWsuId(elem.getAttributeNS(null, "Id"));
    dataRef.setAlgorithm(symEncAlgo);
    dataRef.setContent(false);

    Node decryptedNode;
    if (previousSibling == null) {
        decryptedNode = parent.getFirstChild();
    } else {
        decryptedNode = previousSibling.getNextSibling();
    }
    if (decryptedNode != null && Node.ELEMENT_NODE == decryptedNode.getNodeType()) {
        dataRef.setProtectedElement((Element) decryptedNode);
    }
    dataRef.setXpath(ReferenceListProcessor.getXPath(decryptedNode));

    WSSecurityEngineResult result = new WSSecurityEngineResult(WSConstants.ENCR,
            Collections.singletonList(dataRef));
    result.put(WSSecurityEngineResult.TAG_ID, elem.getAttributeNS(null, "Id"));
    wsDocInfo.addResult(result);
    wsDocInfo.addTokenElement(elem);

    WSSConfig wssConfig = request.getWssConfig();
    if (wssConfig != null) {
        // Get hold of the plain text element
        Element decryptedElem;
        if (previousSibling == null) {
            decryptedElem = (Element) parent.getFirstChild();
        } else {
            decryptedElem = (Element) previousSibling.getNextSibling();
        }
        QName el = new QName(decryptedElem.getNamespaceURI(), decryptedElem.getLocalName());
        Processor proc = request.getWssConfig().getProcessor(el);
        if (proc != null) {
            if (log.isDebugEnabled()) {
                log.debug("Processing decrypted element with: " + proc.getClass().getName());
            }
            List<WSSecurityEngineResult> results = proc.handleToken(decryptedElem, request, wsDocInfo);
            List<WSSecurityEngineResult> completeResults = new ArrayList<WSSecurityEngineResult>();
            if (encrKeyResults != null) {
                completeResults.addAll(encrKeyResults);
            }
            completeResults.add(result);
            completeResults.addAll(0, results);
            return completeResults;
        }
    }
    encrKeyResults.add(result);
    return encrKeyResults;
}

From source file:org.apache.ws.security.processor.ReferenceListProcessor.java

/**
 * Decrypt the EncryptedData argument using a SecretKey.
 * @param doc The (document) owner of EncryptedData
 * @param dataRefURI The URI of EncryptedData
 * @param encData The EncryptedData element
 * @param symmetricKey The SecretKey with which to decrypt EncryptedData
 * @param symEncAlgo The symmetric encryption algorithm to use
 * @throws WSSecurityException//from   w w  w . j  a v  a2s . c  o m
 */
public static WSDataRef decryptEncryptedData(Document doc, String dataRefURI, Element encData,
        SecretKey symmetricKey, String symEncAlgo) throws WSSecurityException {
    XMLCipher xmlCipher = null;
    try {
        xmlCipher = XMLCipher.getInstance(symEncAlgo);
        xmlCipher.init(XMLCipher.DECRYPT_MODE, symmetricKey);
    } catch (XMLEncryptionException ex) {
        throw new WSSecurityException(WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, ex);
    }

    WSDataRef dataRef = new WSDataRef(dataRefURI);
    dataRef.setWsuId(dataRefURI);
    dataRef.setAlgorithm(symEncAlgo);
    boolean content = X509Util.isContent(encData);
    dataRef.setContent(content);

    Node parent = encData.getParentNode();
    Node previousSibling = encData.getPreviousSibling();
    if (content) {
        encData = (Element) encData.getParentNode();
        parent = encData.getParentNode();
    }

    try {
        xmlCipher.doFinal(doc, encData, content);
    } catch (Exception ex) {
        throw new WSSecurityException(WSSecurityException.FAILED_CHECK, null, null, ex);
    }

    if (parent.getLocalName().equals(WSConstants.ENCRYPTED_HEADER)
            && parent.getNamespaceURI().equals(WSConstants.WSSE11_NS)) {

        Node decryptedHeader = parent.getFirstChild();
        Element decryptedHeaderClone = (Element) decryptedHeader.cloneNode(true);
        parent.getParentNode().appendChild(decryptedHeaderClone);
        parent.getParentNode().removeChild(parent);
        dataRef.setProtectedElement(decryptedHeaderClone);
        dataRef.setXpath(getXPath(decryptedHeaderClone));
    } else if (content) {
        dataRef.setProtectedElement(encData);
        dataRef.setXpath(getXPath(encData));
    } else {
        Node decryptedNode;
        if (previousSibling == null) {
            decryptedNode = parent.getFirstChild();
        } else {
            decryptedNode = previousSibling.getNextSibling();
        }
        if (decryptedNode != null && Node.ELEMENT_NODE == decryptedNode.getNodeType()) {
            dataRef.setProtectedElement((Element) decryptedNode);
        }
        dataRef.setXpath(getXPath(decryptedNode));
    }

    return dataRef;
}

From source file:org.apereo.portal.layout.dlm.DistributedLayoutManager.java

public String getPreviousSiblingId(String nodeId) throws PortalException {
    Document uld = this.getUserLayoutDOM();
    Element nelement = uld.getElementById(nodeId);
    if (nelement != null) {
        Node nsibling = nelement.getPreviousSibling();
        // scroll to the next element node
        while (nsibling != null && nsibling.getNodeType() != Node.ELEMENT_NODE) {
            nsibling = nsibling.getNextSibling();
        }//from ww  w  .j a v a2 s . co  m
        if (nsibling != null) {
            Element e = (Element) nsibling;
            return e.getAttribute("ID");
        }
        return null;
    }
    throw new PortalException("Node with id=\"" + nodeId + "\" doesn't exist. Occurred in layout for "
            + owner.getAttribute(IPerson.USERNAME) + ".");
}

From source file:org.dita.dost.writer.TestConrefPushParser.java

@Test
public void testWrite() throws DITAOTException, ParserConfigurationException, SAXException, IOException {
    /*//  w w w .ja  v  a2  s .com
     * the part of content of conrefpush_stub2.xml is
     * <ol>
     *    <li id="A">A</li>
     *    <li id="B">B</li>
     *    <li id="C">C</li>
     * </ol>
     * 
     * the part of content of conrefpush_stup.xml is
     *  <steps>
     *     <step conaction="pushbefore"><cmd>before</cmd></step>
     *   <step conref="conrefpush_stub2.xml#X/A" conaction="mark"/>
     *   <step conref="conrefpush_stub2.xml#X/B" conaction="mark"/>
     *    <step conaction="pushafter"><cmd>after</cmd></step>
     *    <step conref="conrefpush_stub2.xml#X/C" conaction="pushreplace"><cmd>replace</cmd></step>
     *   </steps>
     *
     * after conrefpush the part of conrefpush_stub2.xml should be like this
     * <ol class="- topic/ol ">
     *  <li class="- topic/li task/step ">
     *     <ph class="- topic/ph task/cmd ">
     *     before
     *     </ph>
     *  </li>
     *  <li id="A" class="- topic/li ">A</li>
     *   <li id="B" class="- topic/li ">B</li>
     *   <li class="- topic/li task/step ">
     *      <ph class="- topic/ph task/cmd ">
     *      after
     *      </ph>
     *   </li>
     *   <li class="- topic/li task/step ">
     *      <ph class="- topic/ph task/cmd ">
     *      replace
     *      </ph>
     *   </li>
     * </ol>
     */
    final ConrefPushParser parser = new ConrefPushParser();
    parser.setLogger(new TestUtils.TestLogger());
    parser.setJob(new Job(tempDir));
    final ConrefPushReader reader = new ConrefPushReader();

    reader.read(inputFile.getAbsoluteFile());
    final Map<File, Hashtable<MoveKey, DocumentFragment>> pushSet = reader.getPushMap();
    final Iterator<Map.Entry<File, Hashtable<MoveKey, DocumentFragment>>> iter = pushSet.entrySet().iterator();
    if (iter.hasNext()) {
        final Map.Entry<File, Hashtable<MoveKey, DocumentFragment>> entry = iter.next();
        // initialize the parsed file
        copyFile(new File(srcDir, "conrefpush_stub2_backup.xml"), entry.getKey());
        //            final Content content = new ContentImpl();
        //            content.setValue(entry.getValue());
        //            parser.setContent(content);
        parser.setMoveTable(entry.getValue());
        parser.write(entry.getKey());
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document document = builder.parse(entry.getKey());
        final Element elem = document.getDocumentElement();
        NodeList nodeList = elem.getChildNodes();
        // according to the structure, it comes to the <li> after 2 iterations.
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < nodeList.getLength(); j++) {
                if (nodeList.item(j).getNodeType() == Node.ELEMENT_NODE) {
                    nodeList = nodeList.item(j).getChildNodes();
                    break;
                }
            }
        }
        Element element;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                element = (Element) node;
                if (element.getAttributes().getNamedItem("id") != null
                        && element.getAttributes().getNamedItem("id").getNodeValue().equals("A")) {
                    // get node of before
                    node = element.getPreviousSibling();
                    while (node.getNodeType() != Node.ELEMENT_NODE) {
                        node = node.getPreviousSibling();
                    }
                    assertEquals(
                            "<li class=\"- topic/li task/step \"><ph class=\"- topic/ph task/cmd \">before</ph></li>",
                            nodeToString((Element) node));
                } else if (element.getAttributes().getNamedItem("id") != null
                        && element.getAttributes().getNamedItem("id").getNodeValue().equals("B")) {
                    // get node of after
                    node = element.getNextSibling();
                    while (node.getNodeType() != Node.ELEMENT_NODE) {
                        node = node.getNextSibling();
                    }
                    assertEquals(
                            "<li class=\"- topic/li task/step \"><ph class=\"- topic/ph task/cmd \">after</ph></li>",
                            nodeToString((Element) node));

                    // get node of replacement
                    node = node.getNextSibling();
                    while (node.getNodeType() != Node.ELEMENT_NODE) {
                        node = node.getNextSibling();
                    }
                    assertEquals(
                            "<li class=\"- topic/li task/step \" id=\"C\"><ph class=\"- topic/ph task/cmd \">replace</ph></li>",
                            nodeToString((Element) node));
                }
            }
        }

    }
}

From source file:org.etudes.tool.melete.ViewSectionsPage.java

private Node getPreviousNode(Element secElement) {

    if (secElement.getPreviousSibling() != null) {
        if (secElement.getPreviousSibling().hasChildNodes() == false) {
            return secElement.getPreviousSibling();
        } else {/*from ww  w.j  a  v a  2s .c om*/
            return getInnerLastChild((Element) secElement.getPreviousSibling());
        }
    } else {
        if (secElement.getParentNode() != null) {

            if (secElement.getParentNode().getNodeName().equals("module")) {
                return null;
            } else {
                return secElement.getParentNode();
            }
        } else {
            return null;
        }
    }
}

From source file:org.infoglue.cms.applications.managementtool.actions.ViewContentTypeDefinitionAction.java

/**
 * This method moves an content type assetKey up one step.
 *///ww  w . j a v  a  2  s  .  co  m

public String doMoveAssetKeyUp() throws Exception {
    this.initialize(getContentTypeDefinitionId());

    try {
        Document document = createDocumentFromDefinition();

        String attributesXPath = "/xs:schema/xs:simpleType[@name = '"
                + ContentTypeDefinitionController.ASSET_KEYS + "']/xs:restriction/xs:enumeration[@value='"
                + this.assetKey + "']";
        NodeList anl = XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath);
        if (anl != null && anl.getLength() > 0) {
            Element element = (Element) anl.item(0);
            Node parentElement = element.getParentNode();
            Node previuosSibling = element.getPreviousSibling();
            if (previuosSibling != null) {
                parentElement.removeChild(element);
                parentElement.insertBefore(element, previuosSibling);
            }
        }

        saveUpdatedDefinition(document);
    } catch (Exception e) {
        e.printStackTrace();
    }

    this.initialize(getContentTypeDefinitionId());

    return USE_EDITOR;
}