Example usage for org.w3c.dom Element removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name) throws DOMException;

Source Link

Document

Removes an attribute by name.

Usage

From source file:org.eclipse.ecr.runtime.model.persistence.fs.FileSystemStorage.java

@Override
public Contribution updateContribution(Contribution contribution) throws Exception {
    File file = new File(root, contribution.getName() + ".xml");
    String content = safeRead(file);
    DocumentBuilder docBuilder = factory.newDocumentBuilder();
    Document doc = docBuilder.parse(new ByteArrayInputStream(content.getBytes()));
    Element root = doc.getDocumentElement();
    if (contribution.isDisabled()) {
        root.setAttribute("disabled", "true");
    } else {/*w w  w .  jav a2  s. c om*/
        root.removeAttribute("disabled");
    }
    Node node = root.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE && "documentation".equals(node.getNodeName())) {
            break;
        }
        node = node.getNextSibling();
    }
    String description = contribution.getDescription();
    if (description == null) {
        description = "";
    }
    if (node != null) {
        root.removeChild(node);
    }
    Element el = doc.createElement("documentation");
    el.appendChild(doc.createTextNode(description));
    root.appendChild(el);

    safeWrite(file, DOMSerializer.toString(doc));
    return getContribution(contribution.getName());
}

From source file:org.exoplatform.services.jcr.ext.artifact.ArtifactManagingServiceImpl.java

/**
 * Set attribute value. If value is null the attribute will be removed.
 * /*w w  w.j  a va  2  s .co  m*/
 * @param element
 *          The element to set attribute value
 * @param attr
 *          The attribute name
 * @param value
 *          The value of attribute
 */
private void setAttributeSmart(Element element, String attr, String value) {
    if (value == null) {
        element.removeAttribute(attr);
    } else {
        element.setAttribute(attr, value);
    }
}

From source file:org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoader.java

/**
 * Set attribute value. If value is null the attribute will be removed.
 * // w ww .j av  a  2 s  .  c om
 * @param element The element to set attribute value
 * @param attr The attribute name
 * @param value The value of attribute
 */
protected void setAttributeSmart(Element element, String attr, String value) {
    if (value == null) {
        element.removeAttribute(attr);
    } else {
        element.setAttribute(attr, value);
    }
}

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

/**
 * This method updates the given property with new values. 
 *///from www . j a v  a  2  s.  c o m

public String doUpdateComponentProperty() throws Exception {
    if (logger.isInfoEnabled()) {
        logger.info("************************************************************");
        logger.info("* doUpdateComponentProperty                                 *");
        logger.info("************************************************************");
        logger.info("siteNodeId:" + this.siteNodeId);
        logger.info("languageId:" + this.languageId);
        logger.info("contentId:" + this.contentId);
        logger.info("componentId:" + this.componentId);
        logger.info("slotId:" + this.slotId);
        logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate);
    }

    try {
        initialize();

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

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

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

        Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));

        String characterEncoding = this.getRequest().getCharacterEncoding();
        characterEncoding = this.getResponse().getCharacterEncoding();

        String componentContentId = null;

        String propertyName = this.getRequest().getParameter("propertyName");
        String propertyValue = "";
        if (propertyName != null && !propertyName.equals("")) {
            String[] propertyValues = this.getRequest().getParameterValues(propertyName);

            if (propertyValues != null && propertyValues.length == 1) {
                propertyValue = propertyValues[0];
            } else if (propertyValues != null) {
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < propertyValues.length; i++) {
                    if (i > 0)
                        sb.append(",");
                    sb.append(propertyValues[i]);
                }
                propertyValue = sb.toString();
            }

            logger.info("propertyName:" + propertyName);
            logger.info("propertyValue:" + propertyValue);
            String separator = System.getProperty("line.separator");
            propertyValue = propertyValue.replaceAll(separator, "igbr");
            logger.info("propertyValue1:" + propertyValue);
            propertyValue = PageEditorHelper.untransformAttribute(propertyValue);
            logger.info("propertyValue2:" + propertyValue);

            if (propertyValue != null && !propertyValue.equals("")
                    && !propertyValue.equalsIgnoreCase("undefined")) {
                String componentPropertyXPath = "//component[@id=" + this.componentId
                        + "]/properties/property[@name='" + propertyName + "']";
                //logger.info("componentPropertyXPath:" + componentPropertyXPath);
                NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                        componentPropertyXPath);
                if (anl.getLength() == 0) {
                    String componentXPath = "//component[@id=" + this.componentId + "]/properties";
                    //logger.info("componentXPath:" + componentXPath);
                    NodeList componentNodeList = org.apache.xpath.XPathAPI
                            .selectNodeList(document.getDocumentElement(), componentXPath);
                    if (componentNodeList.getLength() > 0) {
                        Element componentProperties = (Element) componentNodeList.item(0);
                        addPropertyElement(componentProperties, propertyName, propertyValue, "textfield",
                                locale);
                        anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                                componentPropertyXPath);
                    }
                }

                logger.info("anl:" + anl);
                if (anl.getLength() > 0) {
                    Element component = (Element) anl.item(0);
                    componentContentId = ((Element) component.getParentNode().getParentNode())
                            .getAttribute("contentId");

                    //System.out.println("componentContentId:" + componentContentId);
                    ContentVO componentContentVO = ContentController.getContentController()
                            .getContentVOWithId(new Integer(componentContentId));
                    LanguageVO componentMasterLanguageVO = LanguageController.getController()
                            .getMasterLanguage(componentContentVO.getRepositoryId());
                    ContentVersionVO cv = ContentVersionController.getContentVersionController()
                            .getLatestActiveContentVersionVO(new Integer(componentContentId),
                                    componentMasterLanguageVO.getId());
                    String componentProperties = ContentVersionController.getContentVersionController()
                            .getAttributeValue(cv, "ComponentProperties", false);
                    List componentPropertiesList = ComponentPropertyDefinitionController.getController()
                            .parseComponentPropertyDefinitions(componentProperties);
                    Iterator componentPropertiesListIterator = componentPropertiesList.iterator();
                    boolean allowLanguageVariations = true;
                    while (componentPropertiesListIterator.hasNext()) {
                        ComponentPropertyDefinition componentPropertyDefinition = (ComponentPropertyDefinition) componentPropertiesListIterator
                                .next();
                        if (componentPropertyDefinition.getName().equalsIgnoreCase(propertyName)) {
                            allowLanguageVariations = componentPropertyDefinition.getAllowLanguageVariations();
                            break;
                        }
                    }

                    if (allowLanguageVariations) {
                        logger.info("Setting a propertyValue to path_" + locale.getLanguage() + ":" + path);
                        component.setAttribute("path_" + locale.getLanguage(), propertyValue);
                        logger.info("Setting 'path_" + locale.getLanguage() + ":" + propertyValue);
                    } else {
                        logger.info("Setting a propertyValue to path:" + path);
                        component.setAttribute("path", propertyValue);
                        logger.info("Setting 'path:" + propertyValue);
                        component.removeAttribute("path_" + locale.getLanguage());
                    }
                } else {
                    logger.warn("No property could be updated... must be wrong.");
                }
            }
        }

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

        logger.info("contentVersionVO:" + contentVersionVO.getContentVersionId());
        ContentVersionController.getContentVersionController().updateAttributeValue(
                contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML,
                this.getInfoGluePrincipal());

        String returnStatus = this.getRequest().getParameter("returnStatus");
        if (returnStatus != null && returnStatus.equalsIgnoreCase("true")) {
            this.getResponse().setContentType("text/html");
            this.getResponse().getWriter().println(
                    "<html><body>Property " + propertyName + " was set to " + propertyValue + "</body></html>");
        } else {
            this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId="
                    + this.siteNodeId + "&languageId=" + this.languageId + "&contentId=" + this.contentId
                    + "&focusElementId=" + this.componentId
                    + (!hideComponentPropertiesOnLoad ? "&activatedComponentId=" + this.componentId : "")
                    + "&componentContentId=" + componentContentId + "&showSimple=" + this.showSimple;
            //this.getResponse().sendRedirect(url);      

            this.url = this.getResponse().encodeURL(url);
            this.getResponse().sendRedirect(url);
        }
        return NONE;
    } catch (Exception e) {
        logger.error("Error setting property:" + e.getMessage());
        logger.warn("Error setting property:" + e.getMessage(), e);
        return ERROR;
    }
}

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

/**
 * This method updates the given properties with new values. 
 *//*from w  w w .  j  a va2  s.  c om*/

public String doUpdateComponentProperties() throws Exception {
    if (logger.isInfoEnabled()) {
        logger.info("************************************************************");
        logger.info("* doUpdateComponentProperties                              *");
        logger.info("************************************************************");
        logger.info("siteNodeId:" + this.siteNodeId);
        logger.info("languageId:" + this.languageId);
        logger.info("contentId:" + this.contentId);
        logger.info("componentId:" + this.componentId);
        logger.info("slotId:" + this.slotId);
        logger.info("specifyBaseTemplate:" + this.specifyBaseTemplate);
    }

    try {
        initialize();

        Iterator parameterNames = this.getRequest().getParameterMap().keySet().iterator();
        while (parameterNames.hasNext()) {
            String name = (String) parameterNames.next();
            String value = (String) this.getRequest().getParameter(name);
            logger.info(name + "=" + value);
        }

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

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

        String entity = this.getRequest().getParameter("entity");

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

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

        Document document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));

        String characterEncoding = this.getRequest().getCharacterEncoding();
        characterEncoding = this.getResponse().getCharacterEncoding();

        logger.info("siteNodeId:" + siteNodeId);
        logger.info("languageId:" + languageId);
        logger.info("entity:" + entity);

        String componentContentId = null;

        int propertyIndex = 0;
        String propertyName = this.getRequest().getParameter(propertyIndex + "_propertyName");
        while (propertyName != null && !propertyName.equals("")) {
            String[] propertyValues = this.getRequest().getParameterValues(propertyName);
            String propertyValue = "";

            if (propertyValues != null && propertyValues.length == 1)
                propertyValue = propertyValues[0];
            else if (propertyValues != null) {
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < propertyValues.length; i++) {
                    if (i > 0)
                        sb.append(",");
                    sb.append(propertyValues[i]);
                }
                propertyValue = sb.toString();
            }

            logger.info("propertyName:" + propertyName);
            logger.info("propertyValue:" + propertyValue);
            String separator = System.getProperty("line.separator");
            propertyValue = propertyValue.replaceAll(separator, "igbr");
            logger.info("propertyValue1:" + propertyValue);
            propertyValue = PageEditorHelper.untransformAttribute(propertyValue);
            logger.info("propertyValue2:" + propertyValue);

            if (propertyValue != null && !propertyValue.equals("")
                    && !propertyValue.equalsIgnoreCase("undefined")) {
                String componentPropertyXPath = "//component[@id=" + this.componentId
                        + "]/properties/property[@name='" + propertyName + "']";
                //logger.info("componentPropertyXPath:" + componentPropertyXPath);
                NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                        componentPropertyXPath);
                if (anl.getLength() == 0) {
                    String componentXPath = "//component[@id=" + this.componentId + "]/properties";
                    //logger.info("componentXPath:" + componentXPath);
                    NodeList componentNodeList = org.apache.xpath.XPathAPI
                            .selectNodeList(document.getDocumentElement(), componentXPath);
                    if (componentNodeList.getLength() > 0) {
                        Element componentProperties = (Element) componentNodeList.item(0);
                        addPropertyElement(componentProperties, propertyName, propertyValue, "textfield",
                                locale);
                        anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                                componentPropertyXPath);
                    }
                }

                logger.info("anl:" + anl);
                if (anl.getLength() > 0) {
                    Element component = (Element) anl.item(0);
                    componentContentId = ((Element) component.getParentNode().getParentNode())
                            .getAttribute("contentId");

                    //System.out.println("componentContentId:" + componentContentId);
                    ContentVO componentContentVO = ContentController.getContentController()
                            .getContentVOWithId(new Integer(componentContentId));
                    LanguageVO componentMasterLanguageVO = LanguageController.getController()
                            .getMasterLanguage(componentContentVO.getRepositoryId());
                    ContentVersionVO cv = ContentVersionController.getContentVersionController()
                            .getLatestActiveContentVersionVO(new Integer(componentContentId),
                                    componentMasterLanguageVO.getId());
                    String componentProperties = ContentVersionController.getContentVersionController()
                            .getAttributeValue(cv, "ComponentProperties", false);
                    List componentPropertiesList = ComponentPropertyDefinitionController.getController()
                            .parseComponentPropertyDefinitions(componentProperties);
                    Iterator componentPropertiesListIterator = componentPropertiesList.iterator();
                    boolean allowLanguageVariations = true;
                    while (componentPropertiesListIterator.hasNext()) {
                        ComponentPropertyDefinition componentPropertyDefinition = (ComponentPropertyDefinition) componentPropertiesListIterator
                                .next();
                        if (componentPropertyDefinition.getName().equalsIgnoreCase(propertyName)) {
                            allowLanguageVariations = componentPropertyDefinition.getAllowLanguageVariations();
                            break;
                        }
                    }

                    if (allowLanguageVariations) {
                        //System.out.println("Setting a propertyValue to path_" + locale.getLanguage() + ":" + path);
                        component.setAttribute("path_" + locale.getLanguage(), propertyValue);
                        logger.info("Setting 'path_" + locale.getLanguage() + ":" + propertyValue);
                    } else {
                        //System.out.println("Setting a propertyValue to path:" + path);
                        component.setAttribute("path", propertyValue);
                        logger.info("Setting 'path:" + propertyValue);
                        component.removeAttribute("path_" + locale.getLanguage());
                    }
                } else {
                    logger.warn("No property could be updated... must be wrong.");
                }
            }

            propertyIndex++;

            propertyName = this.getRequest().getParameter(propertyIndex + "_propertyName");
        }

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

        logger.info("contentVersionVO:" + contentVersionVO.getContentVersionId());
        ContentVersionController.getContentVersionController().updateAttributeValue(
                contentVersionVO.getContentVersionId(), "ComponentStructure", modifiedXML,
                this.getInfoGluePrincipal());
        this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId
                + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId="
                + this.componentId
                + (!hideComponentPropertiesOnLoad ? "&activatedComponentId=" + this.componentId : "")
                + "&componentContentId=" + componentContentId + "&showSimple=" + this.showSimple;
        //this.getResponse().sendRedirect(url);      

        this.url = this.getResponse().encodeURL(url);
        this.getResponse().sendRedirect(url);
        return NONE;
    } catch (Exception e) {
        logger.error("Error setting property:" + e.getMessage());
        logger.warn("Error setting property:" + e.getMessage(), e);
        return ERROR;
    }
}

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

/**
 * This method shows the user a list of Components(HTML Templates). 
 *///from   w  w w .  ja  v  a2  s .  co m

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

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

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

    String entity = this.getRequest().getParameter("entity");
    Integer entityId = new Integer(this.getRequest().getParameter("entityId"));
    String propertyName = this.getRequest().getParameter("propertyName");

    String componentXML = getPageComponentsString(siteNodeId, this.masterLanguageVO.getId());

    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) {
        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);
            if (entity.equalsIgnoreCase("SiteNode"))
                addPropertyElement(componentProperties, propertyName, path, "siteNodeBinding", locale);
            else if (entity.equalsIgnoreCase("Content"))
                addPropertyElement(componentProperties, propertyName, path, "contentBinding", locale);
            else if (entity.equalsIgnoreCase("Category"))
                addPropertyElement(componentProperties, propertyName, path, "categoryBinding", locale);

            anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                    componentPropertyXPath);
        }
    }

    //logger.info("anl:" + anl);
    if (anl.getLength() > 0) {
        Element component = (Element) anl.item(0);
        if (entity.equalsIgnoreCase("SiteNode")) {
            SiteNodeVO siteNodeVO = SiteNodeController.getController().getSiteNodeVOWithId(entityId);
            path = siteNodeVO.getName();
        } else if (entity.equalsIgnoreCase("Content")) {
            ContentVO contentVO = ContentController.getContentController().getContentVOWithId(entityId);
            path = contentVO.getName();
        } else if (entity.equalsIgnoreCase("Category")) {
            CategoryVO categoryVO = CategoryController.getController().findById(entityId);
            path = categoryVO.getDisplayName();
        }

        component.setAttribute("path", path);
        NamedNodeMap attributes = component.getAttributes();
        logger.debug("NumberOfAttributes:" + attributes.getLength() + ":" + attributes);

        List removableAttributes = new ArrayList();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node node = attributes.item(i);
            logger.debug("Node:" + node.getNodeName());
            if (node.getNodeName().startsWith("path_")) {
                removableAttributes.add("" + node.getNodeName());
            }
        }

        Iterator removableAttributesIterator = removableAttributes.iterator();
        while (removableAttributesIterator.hasNext()) {
            String attributeName = (String) removableAttributesIterator.next();
            logger.debug("Removing node:" + attributeName);
            component.removeAttribute(attributeName);
        }

        NodeList children = component.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            component.removeChild(node);
        }

        if (assetKey != null) {
            logger.debug("assetKey:" + assetKey);
            String fromEncoding = CmsPropertyHandler.getUploadFromEncoding();
            if (fromEncoding == null)
                fromEncoding = "iso-8859-1";

            String toEncoding = CmsPropertyHandler.getUploadToEncoding();
            if (toEncoding == null)
                toEncoding = "utf-8";

            this.assetKey = new String(this.assetKey.getBytes(fromEncoding), toEncoding);
            logger.debug("assetKey:" + assetKey);
        }

        Element newComponent = addBindingElement(component, entity, entityId, assetKey);
        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());
    }

    Boolean hideComponentPropertiesOnLoad = (Boolean) getHttpSession()
            .getAttribute("" + siteNodeId + "_hideComponentPropertiesOnLoad");
    if (hideComponentPropertiesOnLoad == null)
        hideComponentPropertiesOnLoad = false;
    else
        getHttpSession().removeAttribute("" + siteNodeId + "_hideComponentPropertiesOnLoad");

    if (showDecorated == null || !showDecorated.equalsIgnoreCase("false"))
        this.url = getComponentRendererUrl() + getComponentRendererAction() + "?siteNodeId=" + this.siteNodeId
                + "&languageId=" + this.languageId + "&contentId=" + this.contentId + "&focusElementId="
                + this.componentId
                + (!hideComponentPropertiesOnLoad ? "&activatedComponentId=" + this.componentId : "")
                + "&showSimple=" + this.showSimple;
    else
        this.url = getComponentRendererUrl() + "ViewPage.action?siteNodeId=" + this.siteNodeId + "&languageId="
                + this.languageId + "&contentId=" + this.contentId + "&focusElementId=" + this.componentId
                + (!hideComponentPropertiesOnLoad ? "&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.
 *//* w w w  .  j a v  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.GadgetService.java

private void updateUserPrefNodes(Document doc, JSONObject json) throws JSONException {
    String prefType = "UserPref";
    if (!json.has(prefType))
        return;//from  w w w. ja v  a  2  s.c om

    JSONObject prefs = json.getJSONObject(prefType);

    Map<String, Element> prefNodes = new HashMap<String, Element>();
    NodeList prefNodeList = doc.getElementsByTagName(prefType);
    for (int i = 0; i < prefNodeList.getLength(); i++) {
        Element prefNode = (Element) prefNodeList.item(i);

        prefNodes.put(prefNode.getAttribute("name"), prefNode);
    }

    // update the userPref
    for (Iterator<String> prefNames = prefs.keys(); prefNames.hasNext();) {
        String prefName = prefNames.next();
        JSONObject pref = prefs.getJSONObject(prefName);
        if (!pref.has("default_value"))
            continue;

        String value = pref.getString("default_value");
        Element prefNode = prefNodes.get(prefName);
        if (prefNode == null)
            continue;

        if (log.isInfoEnabled())
            log.info("Modify Gadget's " + prefType + " name=" + prefName + " to " + value + ".");

        String datatype = "";
        if (pref.has("datatype"))
            datatype = pref.getString("datatype");

        if ("xml".equals(datatype) || "json".equals(datatype)) {
            prefNode.removeAttribute("default_value");
            while (prefNode.getFirstChild() != null)
                prefNode.removeChild(prefNode.getFirstChild());

            prefNode.appendChild(doc.createTextNode(value));
        } else {
            prefNode.setAttribute("default_value", value);
        }
    }
}

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

public synchronized void updateMenuItem(String menuId, String title, String href, String display, String type,
        String serviceURL, String serviceAuthType, Map props, String alert, String menuType, Collection auths,
        Collection<String> menuTreeAdmins, Boolean linkDisabled, String directoryTitle, String sitetopId,
        boolean multi) throws Exception {

    href = StringUtil.getTruncatedString(href, 1024, "UTF-8");

    if (log.isInfoEnabled()) {
        log.info("UpdateMenuItem: menuId=" + menuId + ", title=" + title + ", " + title + ", href=" + href
                + ", display=" + display + ", alert" + alert + ", properties=" + props);
    }//from   w  w w.  j a va  2 s  .c o  m
    // Obtain data and transfer the result to Document.
    Siteaggregationmenu_temp entity = this.siteAggregationMenuTempDAO.selectBySitetopId(menuType, sitetopId);
    Node node = getTargetElement(entity, menuId);

    // Error
    if (node == null)
        throw new Exception("element not found [//site],[//site-top]");

    Document document = node.getOwnerDocument();

    // Create element to be updated
    Element element;
    element = (Element) node;
    element.setAttribute("title", title);
    element.setAttribute("href", href);
    element.setAttribute("display", display);
    element.setAttribute("link_disabled", linkDisabled.toString());
    if (serviceURL != null)
        element.setAttribute("serviceURL", serviceURL);
    if (serviceAuthType != null)
        element.setAttribute("serviceAuthType", serviceAuthType);
    if (alert != null && !"".equals(alert))
        element.setAttribute("alert", alert);

    element.setAttribute("multi", String.valueOf(multi));

    element.setAttribute("type", type);

    if (directoryTitle != null && !"".equals(directoryTitle)) {
        element.setAttribute("directory_title", directoryTitle);
    } else if (element.hasAttribute("directory_title")) {
        element.removeAttribute("directory_title");
    }

    element.insertBefore(recreatePropertiesNode(document, element, props), element.getFirstChild());

    Element oldAuths = getFirstChildElementByName(element, "auths");
    if (oldAuths != null) {
        element.removeChild(oldAuths);
    }
    if (auths != null) {
        element.insertBefore(MenuAuthorization.createAuthsElement(document, auths),
                getFirstChildElementByName(element, "site"));
    }

    NodeList oldAdmins = element.getElementsByTagName("menuTreeAdmins");
    if (oldAdmins != null) {
        while (oldAdmins.getLength() != 0) {
            oldAdmins.item(0).getParentNode().removeChild(oldAdmins.item(0));
        }
    }
    if (menuTreeAdmins != null) {
        element.insertBefore(createAdminsElement(document, menuTreeAdmins),
                getFirstChildElementByName(element, "site"));
    }

    // Update
    entity.setElement(document.getDocumentElement());
    this.siteAggregationMenuTempDAO.update(entity);
}

From source file:org.intellij.xquery.runner.rt.vendor.exist.ExistRunnerApp.java

private String getEvaluationResult(String response)
        throws ParserConfigurationException, SAXException, IOException, XPathExpressionException,
        TransformerException, IllegalAccessException, ClassNotFoundException, InstantiationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(false);/*w  w w .j a  v  a  2  s . c om*/
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(response)));
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();
    XPathExpression expr = xpath.compile("/result/value/text()");
    String textValue = expr.evaluate(doc);
    if (!"".equals(textValue))
        return textValue;
    expr = xpath.compile("/result/text()");
    String resultingXmlAsText = expr.evaluate(doc);
    if (!"".equals(resultingXmlAsText.trim()))
        return resultingXmlAsText;
    expr = xpath.compile("/result/child::*");
    Element node = (Element) expr.evaluate(doc, NODE);
    if (node != null) {
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            String nodeName = attribute.getNodeName();
            String nodeValue = attribute.getNodeValue();
            if (XMLNS.equals(nodeName) && SERIALIZED_NAMESPACE.equals(nodeValue)) {
                node.removeAttribute(XMLNS);
            }
        }
        return prettyPrint(node, builder.getDOMImplementation());
    } else {
        return response;
    }
}