Example usage for org.w3c.dom Node getParentNode

List of usage examples for org.w3c.dom Node getParentNode

Introduction

In this page you can find the example usage for org.w3c.dom Node getParentNode.

Prototype

public Node getParentNode();

Source Link

Document

The parent of this node.

Usage

From source file:org.glom.web.server.libglom.Document.java

/**
 * getElementsByTagName() is recursive, but we do not want that.
 * /* w w  w  .jav a2 s  . c om*/
 * @param node
 * @param
 * @return
 */
private List<Node> getChildrenByTagName(final Element parentNode, final String tagName) {
    final List<Node> result = new ArrayList<Node>();

    final NodeList list = parentNode.getElementsByTagName(tagName);
    final int num = list.getLength();
    for (int i = 0; i < num; i++) {
        final Node node = list.item(i);
        if (node == null) {
            continue;
        }

        final Node itemParentNode = node.getParentNode();
        if (itemParentNode.equals(parentNode)) {
            result.add(node);
        }
    }

    return result;
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternJspMetadataListener.java

/**
 * Modifies create.jspx or update.jspx generate by Roo based on
 * {@link RooJspx} param./*from  w w w  .  j a v a  2  s.  com*/
 * <p>
 * It wraps field element into ul/li elements and add a hidden param
 * <code>gvnixpattern</code> and a button
 * 
 * @param rooJspx
 */
private void modifyRooJsp(RooJspx rooJspx) {
    String controllerPath = webScaffoldAnnotationValues.getPath();
    Validate.notNull(controllerPath,
            PATH_IS_NOT_SPECIFIED + webScaffoldAnnotationValues.getGovernorTypeDetails().getName() + "'");
    if (!controllerPath.startsWith("/")) {
        controllerPath = "/".concat(controllerPath);
    }

    PathResolver pathResolver = getProjectOperations().getPathResolver();
    String docJspx = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""),
            "WEB-INF/views" + controllerPath + "/" + rooJspx.name() + ".jspx");

    if (!getFileManager().exists(docJspx)) {
        // create.jspx doesn't exist, so nothing to do
        return;
    }

    InputStream docJspxIs = getFileManager().getInputStream(docJspx);

    Document docJspXml;
    try {
        docJspXml = XmlUtils.getDocumentBuilder().parse(docJspxIs);
    } catch (Exception ex) {
        throw new IllegalStateException("Could not open " + rooJspx.name() + ".jspx file", ex);
    }

    Element docRoot = docJspXml.getDocumentElement();
    // Add new tag namesapces
    Element divMain = XmlUtils.findFirstElement("/div", docRoot);

    if (rooJspx.equals(RooJspx.create) || rooJspx.equals(RooJspx.update)) {
        divMain.setAttribute("xmlns:pattern", "urn:jsptagdir:/WEB-INF/tags/pattern");
    }

    String divContPaneId = XmlUtils
            .convertId(DIV_ID_PREFIX + formbackingType.getFullyQualifiedTypeName() + "_contentPane");
    Element divContentPane = XmlUtils
            .findFirstElement("/div/" + rooJspx.name() + "/div[@id='" + divContPaneId + "']", docRoot);
    if (null == divContentPane) {
        divContentPane = new XmlElementBuilder(DIV_ELEMENT, docJspXml).addAttribute(ID_ATTRIBUTE, divContPaneId)
                .addAttribute(CLASS_ATTRIBUTE, "patternContentPane").build();
    }

    String divFormId = XmlUtils
            .convertId(DIV_ID_PREFIX + formbackingType.getFullyQualifiedTypeName() + "_formNoedit");
    Element divForm = XmlUtils.findFirstElement("/div/" + rooJspx.name() + "/div/div[@id='" + divFormId + "']",
            docRoot);
    if (null == divForm) {
        divForm = new XmlElementBuilder(DIV_ELEMENT, docJspXml).addAttribute(ID_ATTRIBUTE, divFormId)
                .addAttribute(CLASS_ATTRIBUTE, "formularios boxNoedit").build();
        divContentPane.appendChild(divForm);
    }

    String idPrefix = rooJspx.equals(RooJspx.create) ? "fc:" : rooJspx.equals(RooJspx.update) ? "fu:" : "ps:";

    Element form = XmlUtils.findFirstElement(
            "/div/" + rooJspx.name() + "[@id='"
                    + XmlUtils.convertId(idPrefix + formbackingType.getFullyQualifiedTypeName()) + "']",
            docRoot);

    if (form != null) {
        // Wrap fields into <ul><li/></ul>
        NodeList fields = form.getChildNodes();
        if (fields.getLength() > 0) {
            Node thisField;
            for (int i = 0; i < fields.getLength(); i++) {
                thisField = fields.item(i);

                if (thisField.getNodeName().startsWith("field:")
                        && !thisField.getParentNode().getNodeName().equalsIgnoreCase("li")) {
                    if (null != thisField.getAttributes()
                    /*
                     * && null != thisField.getAttributes().getNamedItem(
                     * "type") &&
                     * !thisField.getAttributes().getNamedItem("type")
                     * .getNodeValue().equalsIgnoreCase("hidden")
                     */) {
                        Node thisNodeCpy = thisField.cloneNode(true);
                        String fieldAttValue = thisNodeCpy.getAttributes().getNamedItem(FIELD_ATTRIBUTE)
                                .getNodeValue();
                        Element li = new XmlElementBuilder("li", docJspXml)
                                .addAttribute(CLASS_ATTRIBUTE, "size120")
                                .addAttribute(ID_ATTRIBUTE,
                                        XmlUtils.convertId(
                                                "li:".concat(formbackingType.getFullyQualifiedTypeName())
                                                        .concat(".").concat(fieldAttValue)))
                                .addChild(thisNodeCpy).build();
                        Element ul = new XmlElementBuilder("ul", docJspXml)
                                .addAttribute(CLASS_ATTRIBUTE, "formInline")
                                .addAttribute(ID_ATTRIBUTE,
                                        XmlUtils.convertId(
                                                "ul:".concat(formbackingType.getFullyQualifiedTypeName())
                                                        .concat(".").concat(fieldAttValue)))
                                .addChild(li).build();
                        divForm.appendChild(ul);
                        form.removeChild(thisField);
                        // form.replaceChild(ul, thisField);
                    }
                }
            }
        }
        if (rooJspx.equals(RooJspx.create) || rooJspx.equals(RooJspx.update)) {
            // Add a hidden field holding gvnixpattern parameter if exists
            String hiddenFieldId = XmlUtils
                    .convertId("c:" + formbackingType.getFullyQualifiedTypeName() + "_gvnixpattern");
            Element hiddenField = XmlUtils.findFirstElement(
                    "/div/" + rooJspx.name() + "/div/div/hiddengvnixpattern[@id='" + hiddenFieldId + "']",
                    docRoot);
            if (null == hiddenField) {
                hiddenField = new XmlElementBuilder("pattern:hiddengvnixpattern", docJspXml)
                        .addAttribute(ID_ATTRIBUTE, hiddenFieldId)
                        .addAttribute("value", "${param.gvnixpattern}")
                        .addAttribute(RENDER_ATTRIBUTE, "${not empty param.gvnixpattern}").build();
                divForm.appendChild(hiddenField);
            }
            // Add a cancel button
            String cancelId = XmlUtils
                    .convertId(idPrefix + formbackingType.getFullyQualifiedTypeName() + "_cancel");
            Element cancelButton = XmlUtils.findFirstElement(
                    "/div/" + rooJspx.name() + "/div/div/cancelbutton[@id='" + cancelId + "']", docRoot);
            if (null == cancelButton) {
                cancelButton = new XmlElementBuilder("pattern:cancelbutton", docJspXml)
                        .addAttribute(ID_ATTRIBUTE, cancelId)
                        .addAttribute(RENDER_ATTRIBUTE, "${not empty param.gvnixpattern}").build();
                divForm.appendChild(cancelButton);
            }
        }
        form.appendChild(divContentPane);
    }
    DomUtils.removeTextNodes(docJspXml);
    getFileManager().createOrUpdateTextFileIfRequired(docJspx, XmlUtils.nodeToString(docJspXml), true);
    // writeToDiskIfNecessary(docJspx, docJspXml);
}

From source file:org.iish.visualmets.services.TocDaoImp.java

private ArrayList<TocFolderItem> findBreadCrumbs(ArrayList<TocFolderItem> breadCrumbs, Node breadNode) {

    // maak extract item
    try {//from www.  jav  a  2 s. c  om
        TocFolderItem breadCrumbItem = new TocFolderItem();
        breadCrumbItem.setIndex(String.valueOf(breadNode.getAttributes().getNamedItem("ID").getNodeValue()));
        breadCrumbItem.setTitle(breadNode.getAttributes().getNamedItem("LABEL").getNodeValue());

        // voeg extract toe aan lijst van breadcrumbs
        breadCrumbs.add(breadCrumbItem);
    } catch (NullPointerException e) {

    }

    // try to find parentNode
    Node parentNode = breadNode.getParentNode();
    if (parentNode.getNodeName().equals(namespaceName + "div")) {

        // recursive: try fo find parents parentnode
        breadCrumbs = findBreadCrumbs(breadCrumbs, parentNode);
    }

    return breadCrumbs;
}

From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java

/**
 * This method adds a component to the page. 
 *///from w  w  w.  j  a  v  a 2s.c  o m

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 shows the user a list of Components(HTML Templates). 
 *///from w  ww .j  a v a2s .co m

public String doAddComponentPropertyBindingWithQualifyer() throws Exception {
    initialize();
    //logger.info("************************************************************");
    //logger.info("* doAddComponentPropertyBindingWithQualifyer               *");
    //logger.info("************************************************************");
    //logger.info("siteNodeId:" + this.siteNodeId);
    //logger.info("languageId:" + this.languageId);
    //logger.info("contentId:" + this.contentId);
    //logger.info("componentId:" + this.componentId);
    //logger.info("slotId:" + this.slotId);
    //logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate);

    Integer siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId"));
    Integer languageId = new Integer(this.getRequest().getParameter("languageId"));
    Integer contentId = new Integer(this.getRequest().getParameter("contentId"));

    Locale locale = LanguageController.getController().getLocaleWithId(languageId);

    String qualifyerXML = this.getRequest().getParameter("qualifyerXML");
    String propertyName = this.getRequest().getParameter("propertyName");

    //logger.info("siteNodeId:" + siteNodeId);
    //logger.info("languageId:" + languageId);
    //logger.info("contentId:" + contentId);
    //logger.info("qualifyerXML:" + qualifyerXML);
    //logger.info("propertyName:" + propertyName);

    NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId,
            languageId, contentId);

    String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId());
    //logger.info("componentXML:" + componentXML);

    Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));
    String componentPropertyXPath = "//component[@id=" + this.componentId + "]/properties/property[@name='"
            + propertyName + "']";
    //logger.info("componentPropertyXPath:" + componentPropertyXPath);
    NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
            componentPropertyXPath);
    if (anl.getLength() > 0) {
        Node propertyNode = anl.item(0);
        propertyNode.getParentNode().removeChild(propertyNode);
    }

    String componentXPath = "//component[@id=" + this.componentId + "]/properties";
    //logger.info("componentXPath:" + componentXPath);
    NodeList componentNodeList = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
            componentXPath);
    if (componentNodeList.getLength() > 0) {
        Element componentProperties = (Element) componentNodeList.item(0);
        addPropertyElement(componentProperties, propertyName, path, "contentBinding", locale);
        anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentPropertyXPath);
    }
    //}

    if (anl.getLength() > 0) {
        Element component = (Element) anl.item(0);
        component.setAttribute("path", path);
        component.setAttribute("path_" + locale.getLanguage(), path);

        addBindingElement(component, qualifyerXML);
        String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString();

        ContentVO contentVO = NodeDeliveryController
                .getNodeDeliveryController(siteNodeId, languageId, contentId)
                .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, languageId, true, "Meta information",
                        DeliveryContext.getDeliveryContext());
        ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController()
                .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId());

        ContentVersionController.getContentVersionController().updateAttributeValue(
                contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML,
                this.getInfoGluePrincipal());
    }

    if (showDecorated == null || showDecorated.equalsIgnoreCase("true"))
        this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId
                + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId="
                + this.componentId + "&activatedComponentId=" + this.componentId + "&showSimple="
                + this.showSimple;
    else
        this.url = getComponentRendererUrl() + "ViewPage.action?siteNodeId=" + this.siteNodeId + "&languageId="
                + this.languageId + "&contentId=" + this.contentId + "&focusElementId=" + this.componentId
                + "&activatedComponentId=" + this.componentId + "&showSimple=" + this.showSimple;

    this.url = this.getResponse().encodeURL(url);
    this.getResponse().sendRedirect(url);
    return NONE;
}

From source file:org.infoglue.cms.applications.structuretool.actions.ViewSiteNodePageComponentsAction.java

/**
 * This method deletes a component property value. This is to enable users to quickly remove a property value no matter what type.
 *//*from w ww.  j  av a  2  s.co  m*/

public String doDeleteComponentPropertyValue() throws Exception {
    initialize();

    Integer siteNodeId = new Integer(this.getRequest().getParameter("siteNodeId"));
    Integer languageId = new Integer(this.getRequest().getParameter("languageId"));
    Integer contentId = new Integer(this.getRequest().getParameter("contentId"));
    String propertyName = this.getRequest().getParameter("propertyName");

    Locale locale = LanguageController.getController().getLocaleWithId(languageId);

    //logger.info("siteNodeId:" + siteNodeId);
    //logger.info("languageId:" + languageId);
    //logger.info("contentId:" + contentId);
    //logger.info("propertyName:" + propertyName);

    String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId());
    //logger.info("componentXML:" + componentXML);

    Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));
    String componentPropertyXPath = "//component[@id=" + this.componentId + "]/properties/property[@name='"
            + propertyName + "']";
    //logger.info("componentPropertyXPath:" + componentPropertyXPath);
    NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
            componentPropertyXPath);
    if (anl.getLength() > 0) {
        Node propertyNode = anl.item(0);
        Element propertyElement = (Element) propertyNode;

        propertyElement.removeAttribute("path");
        propertyElement.removeAttribute("path_" + locale.getLanguage());
        if (propertyElement.getAttributes().getLength() == 0)
            ;
        {
            propertyNode.getParentNode().removeChild(propertyNode);
        }
    }

    String detailSiteNodeIdPropertyXPath = "//component[@id=" + this.componentId
            + "]/properties/property[@name='" + propertyName + "_detailSiteNodeId']";
    //logger.info("componentPropertyXPath:" + componentPropertyXPath);
    NodeList anl2 = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
            detailSiteNodeIdPropertyXPath);
    if (anl2.getLength() > 0) {
        Node propertyNode = anl2.item(0);
        Element propertyElement = (Element) propertyNode;

        propertyElement.removeAttribute("path");
        propertyElement.removeAttribute("path_" + locale.getLanguage());
        if (propertyElement.getAttributes().getLength() == 0)
            ;
        {
            propertyNode.getParentNode().removeChild(propertyNode);
        }
    }

    String modifiedXML = XMLHelper.serializeDom(document, new StringBuffer()).toString();
    //logger.info("modifiedXML:" + modifiedXML);

    ContentVO contentVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId)
            .getBoundContent(this.getInfoGluePrincipal(), siteNodeId, languageId, true, "Meta information",
                    DeliveryContext.getDeliveryContext());
    ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController()
            .getLatestActiveContentVersionVO(contentVO.getId(), this.masterLanguageVO.getId());

    ContentVersionController.getContentVersionController().updateAttributeValue(
            contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML,
            this.getInfoGluePrincipal());

    this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId
            + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId="
            + this.componentId + "&activatedComponentId=" + this.componentId + "&showSimple=" + this.showSimple;
    //this.getResponse().sendRedirect(url);      

    this.url = this.getResponse().encodeURL(url);
    this.getResponse().sendRedirect(url);
    return NONE;
}

From source file:org.infoscoop.service.AdminServiceUtil.java

/**
 * delete a Node which was appointed in an argument.
 * //  w  ww. j a  v a 2 s . c o m
 * @param node
 * @return Node
 */
public static Node removeSelf(Node node) {
    if (node == null)
        return null;

    Node pNode = node.getParentNode();

    if (pNode != null) {
        return pNode.removeChild(node);
    }

    return null;
}

From source file:org.infoscoop.service.ProxyConfService.java

/**
 * @param id/*from w  ww .j a  v a 2 s  .  c  om*/
 * @param siblingId
 * @throws Exception
 */
public synchronized void replaceSort(String id, String siblingId) throws Exception {

    try {

        // Obtain data and transfer the result to Document.
        Proxyconf entity = this.proxyConfDAO.select();
        Document document = entity.getElement().getOwnerDocument();

        // Search for default
        Node defaultNode = AdminServiceUtil.getNodeById(document, "/proxy-config/default", null);

        // Search for node matches id
        Node targetNode = AdminServiceUtil.getNodeById(document, "/proxy-config/case", id);

        // Error
        if (targetNode == null)
            throw new Exception("targetNode not found [/proxy-config/case/@" + id + "]");

        if (siblingId != null && siblingId.length() != 0) {
            // Search for node matches siblingId
            Node siblingNode = AdminServiceUtil.getNodeById(document, "/proxy-config/case", siblingId);

            // Error
            if (siblingNode == null)
                throw new Exception("siblingNode not found [/proxy-config/case/@" + siblingId + "]");

            // Insert before siblingNode
            siblingNode.getParentNode().insertBefore(targetNode, siblingNode);
        } else {
            if (defaultNode != null) {
                // Insert before defaultNode
                targetNode.getParentNode().insertBefore(targetNode, defaultNode);
            } else {
                // Added at last
                targetNode.getParentNode().appendChild(targetNode);
            }
        }

        entity.setElement(document.getDocumentElement());
        // Update
        proxyConfDAO.update(entity);

    } catch (Exception e) {
        log.error("Unexpected error occurred.", e);
        throw e;
    }
}

From source file:org.infoscoop.service.SearchEngineService.java

/**
 * @param engineId//w  w  w. j ava 2s  .c  o m
 * @param siblingId
 * @throws Exception
 */
public synchronized void replaceSort(String engineId, String siblingId) throws Exception {

    // Obtain data and transfer the result to Document.
    Searchengine temp = (Searchengine) this.searchEngineDAO.selectTemp();
    Document document = temp.getDocument();

    // Search for node matches engineId
    Node engineNode = AdminServiceUtil.getNodeById(document, "//searchEngine", engineId);

    // Error
    if (engineNode == null)
        throw new Exception("engineNode not found [//searchEngine]");

    if (siblingId != null && siblingId.length() != 0) {
        // Search for node matches siblingId
        Node siblingNode = AdminServiceUtil.getNodeById(document, "//searchEngine", siblingId);

        // Error
        if (siblingNode == null)
            throw new Exception("siblingNode not found [//searchEngine]");

        // Insert before siblingNode
        siblingNode.getParentNode().insertBefore(engineNode, siblingNode);

    } else {
        engineNode.getParentNode().appendChild(engineNode);
    }

    temp.setDocument(document);
    // Update
    this.searchEngineDAO.update(temp);

}

From source file:org.jahia.services.importexport.ExternalUsersImportUpdater.java

private boolean clean(InputStream inputStream, OutputStream outputStream, Map<String, String> pathMapping)
        throws IOException, ParserConfigurationException, SAXException, XPathExpressionException,
        TransformerException {//w w  w . j  a  v a2  s .  c o m
    Document doc = JahiaDocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(new InputSource(inputStream));

    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList nodes = (NodeList) xpath.evaluate("//*[@*[name()='jcr:primaryType'] = 'jnt:usersFolder']", doc,
            XPathConstants.NODESET);

    for (int i = 0; i < nodes.getLength(); i++) {
        Node legacyExtUser = nodes.item(i);
        Node parent = legacyExtUser.getParentNode();
        if (!getNodePath(parent).startsWith("/sites/")) {
            parent.removeChild(legacyExtUser);
        }
    }

    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.transform(new DOMSource(doc), new StreamResult(outputStream));

    return nodes.getLength() > 0;
}