Example usage for org.w3c.dom Element getAttributes

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

Introduction

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

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:org.firesoa.common.schema.DOMInitializer.java

private static String getQualifiedName(Document doc, QName qName) {
    Element rootElement = (Element) doc.getDocumentElement();

    if (rootElement != null && !equalStrings(qName.getNamespaceURI(), rootElement.getNamespaceURI())) {
        //         Attr attrTmp = rootElement.getAttributeNodeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "ns0");
        //         System.out.println("===========found attrTmp=="+attrTmp);

        String nsPrefix = null;//from www . j a  v  a2  s  .co  m
        nsPrefix = rootElement.lookupPrefix(qName.getNamespaceURI());
        if (nsPrefix == null || nsPrefix.trim().equals("")) {
            int nsNumber = 1;
            NamedNodeMap attrMap = rootElement.getAttributes();
            int length = attrMap.getLength();

            for (int i = 0; i < length; i++) {
                Attr attr = (Attr) attrMap.item(i);
                String name = attr.getName();
                if (name.startsWith(Constants.XMLNS_ATTRIBUTE)) {
                    if (attr.getValue().equals(qName.getNamespaceURI())) {
                        // Namespace?
                        nsPrefix = attr.getLocalName();
                        break;
                    }
                    nsNumber++;
                }
            }
            if (nsPrefix == null) {
                nsPrefix = "ns" + nsNumber;
            }
        }

        Attr attr = doc.createAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI,
                Constants.XMLNS_ATTRIBUTE + ":" + nsPrefix);
        attr.setValue(qName.getNamespaceURI());
        rootElement.setAttributeNode(attr);

        return nsPrefix + ":" + qName.getLocalPart();
    } else {
        return "ns0:" + qName.getLocalPart();
    }

}

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

/**
 * Create a base 64 encoded SHA1 hash key for a given XML element. The key
 * is based on the element name, the attribute names and their values. Child
 * elements are ignored. Attributes named 'z' are not concluded since they
 * contain the hash key itself./*from w w  w.j av  a2 s.  com*/
 * 
 * @param element The element to create the base 64 encoded hash key for
 * @return the unique key
 */
public static String calculateUniqueKeyFor(Element element) {
    StringBuilder sb = new StringBuilder();
    sb.append(element.getTagName());
    NamedNodeMap attributes = element.getAttributes();
    SortedMap<String, String> attrKVStore = Collections.synchronizedSortedMap(new TreeMap<String, String>());
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attr = attributes.item(i);
        if (!"z".equals(attr.getNodeName()) && !attr.getNodeName().startsWith("_")) {
            attrKVStore.put(attr.getNodeName(), attr.getNodeValue());
        }
    }
    for (Entry<String, String> entry : attrKVStore.entrySet()) {
        sb.append(entry.getKey()).append(entry.getValue());
    }
    return base64(sha1(sb.toString().getBytes()));
}

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

private static boolean equalElements(Element a, Element b) {
    if (!a.getTagName().equals(b.getTagName())) {
        return false;
    }// w ww.  j  a  v a2  s.  c om
    if (a.getAttributes().getLength() != b.getAttributes().getLength()) {
        return false;
    }
    NamedNodeMap attributes = a.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node node = attributes.item(i);
        if (!node.getNodeName().equals("z") && !node.getNodeName().startsWith("_")) {
            if (b.getAttribute(node.getNodeName()).length() == 0
                    || !b.getAttribute(node.getNodeName()).equals(node.getNodeValue())) {
                return false;
            }
        }
    }
    return true;
}

From source file:org.infoglue.calendar.controllers.ContentTypeDefinitionController.java

/**
 * This method returns the attributes in the content type definition for generation.
 *//* w w w.  ja  v  a 2s .  c  o  m*/

public List getContentTypeAttributes(String schemaValue) {
    List attributes = new ArrayList();

    try {
        InputSource xmlSource = new InputSource(new StringReader(schemaValue));

        DOMParser parser = new DOMParser();
        parser.parse(xmlSource);
        Document document = parser.getDocument();

        String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element";
        NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath);
        for (int i = 0; i < anl.getLength(); i++) {
            Element child = (Element) anl.item(i);
            String attributeName = child.getAttribute("name");
            String attributeType = child.getAttribute("type");

            ContentTypeAttribute contentTypeAttribute = new ContentTypeAttribute();
            contentTypeAttribute.setPosition(i);
            contentTypeAttribute.setName(attributeName);
            contentTypeAttribute.setInputType(attributeType);

            String validatorsXPath = "/xs:schema/xs:complexType[@name = 'Validation']/xs:annotation/xs:appinfo/form-validation/formset/form/field[@property = '"
                    + attributeName + "']";

            // Get validators
            NodeList validatorNodeList = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                    validatorsXPath);
            for (int j = 0; j < validatorNodeList.getLength(); j++) {
                Element validatorNode = (Element) validatorNodeList.item(j);
                if (validatorNode != null) {
                    Map arguments = new HashMap();

                    NodeList varNodeList = validatorNode.getElementsByTagName("var");
                    for (int k = 0; k < varNodeList.getLength(); k++) {
                        Element varNode = (Element) varNodeList.item(k);

                        String varName = getElementValue(varNode, "var-name");
                        String varValue = getElementValue(varNode, "var-value");

                        arguments.put(varName, varValue);
                    }

                    String attribute = ((Element) validatorNode).getAttribute("depends");
                    String[] depends = attribute.split(",");
                    for (int dependsIndex = 0; dependsIndex < depends.length; dependsIndex++) {
                        String name = depends[dependsIndex];

                        ContentTypeAttributeValidator contentTypeAttributeValidator = new ContentTypeAttributeValidator();
                        contentTypeAttributeValidator.setName(name);
                        contentTypeAttributeValidator.setArguments(arguments);
                        contentTypeAttribute.getValidators().add(contentTypeAttributeValidator);
                    }

                }
            }

            // Get extra parameters
            Node paramsNode = org.apache.xpath.XPathAPI.selectSingleNode(child,
                    "xs:annotation/xs:appinfo/params");
            if (paramsNode != null) {
                NodeList childnl = ((Element) paramsNode).getElementsByTagName("param");
                for (int ci = 0; ci < childnl.getLength(); ci++) {
                    Element param = (Element) childnl.item(ci);
                    String paramId = param.getAttribute("id");
                    String paramInputTypeId = param.getAttribute("inputTypeId");

                    ContentTypeAttributeParameter contentTypeAttributeParameter = new ContentTypeAttributeParameter();
                    contentTypeAttributeParameter.setId(paramId);
                    if (paramInputTypeId != null && paramInputTypeId.length() > 0)
                        contentTypeAttributeParameter.setType(Integer.parseInt(paramInputTypeId));

                    contentTypeAttribute.putContentTypeAttributeParameter(paramId,
                            contentTypeAttributeParameter);

                    NodeList valuesNodeList = param.getElementsByTagName("values");
                    for (int vsnli = 0; vsnli < valuesNodeList.getLength(); vsnli++) {
                        NodeList valueNodeList = param.getElementsByTagName("value");
                        for (int vnli = 0; vnli < valueNodeList.getLength(); vnli++) {
                            Element value = (Element) valueNodeList.item(vnli);
                            String valueId = value.getAttribute("id");

                            ContentTypeAttributeParameterValue contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
                            contentTypeAttributeParameterValue.setId(valueId);

                            NamedNodeMap nodeMap = value.getAttributes();
                            for (int nmi = 0; nmi < nodeMap.getLength(); nmi++) {
                                Node attribute = (Node) nodeMap.item(nmi);
                                String valueAttributeName = attribute.getNodeName();
                                String valueAttributeValue = attribute.getNodeValue();

                                contentTypeAttributeParameterValue.addAttribute(valueAttributeName,
                                        valueAttributeValue);
                            }

                            contentTypeAttributeParameter.addContentTypeAttributeParameterValue(valueId,
                                    contentTypeAttributeParameterValue);
                        }
                    }
                }
            }
            // End extra parameters

            attributes.add(contentTypeAttribute);
        }

    } catch (Exception e) {
        log.error(
                "An error occurred when we tried to get the attributes of the content type: " + e.getMessage(),
                e);
    }

    return attributes;
}

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

/**
 * This method shows the user a list of Components(HTML Templates). 
 *//*  www  .j a  v a2  s . c  o 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.
 *//*ww  w . ja  va2  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.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController.java

private List getAttributesWithXalan(String schemaValue, boolean addPriorityAttribute) {
    List attributes = new ArrayList();

    int i = 0;/*  w w  w  . j a  va2  s  .  c  o m*/
    try {
        InputSource xmlSource = new InputSource(new StringReader(schemaValue));

        DOMParser parser = new DOMParser();
        parser.parse(xmlSource);
        Document document = parser.getDocument();

        String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element";
        NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath);

        for (i = 0; i < anl.getLength(); i++) {
            Element child = (Element) anl.item(i);
            String attributeName = child.getAttribute("name");
            String attributeType = child.getAttribute("type");

            ContentTypeAttribute contentTypeAttribute = new ContentTypeAttribute();
            contentTypeAttribute.setPosition(i);
            contentTypeAttribute.setName(attributeName);
            contentTypeAttribute.setInputType(attributeType);

            String validatorsXPath = "/xs:schema/xs:complexType[@name = 'Validation']/xs:annotation/xs:appinfo/form-validation/formset/form/field[@property = '"
                    + attributeName + "']";

            // Get validators
            NodeList validatorNodeList = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(),
                    validatorsXPath);
            for (int j = 0; j < validatorNodeList.getLength(); j++) {
                Element validatorNode = (Element) validatorNodeList.item(j);
                if (validatorNode != null) {
                    Map arguments = new HashMap();

                    NodeList varNodeList = validatorNode.getElementsByTagName("var");
                    for (int k = 0; k < varNodeList.getLength(); k++) {
                        Element varNode = (Element) varNodeList.item(k);

                        String varName = getElementValue(varNode, "var-name");
                        String varValue = getElementValue(varNode, "var-value");

                        arguments.put(varName, varValue);
                    }

                    String attribute = ((Element) validatorNode).getAttribute("depends");
                    String[] depends = attribute.split(",");
                    for (int dependsIndex = 0; dependsIndex < depends.length; dependsIndex++) {
                        String name = depends[dependsIndex];

                        ContentTypeAttributeValidator contentTypeAttributeValidator = new ContentTypeAttributeValidator();
                        contentTypeAttributeValidator.setName(name);
                        contentTypeAttributeValidator.setArguments(arguments);
                        contentTypeAttribute.getValidators().add(contentTypeAttributeValidator);
                    }

                }
            }

            // Get extra parameters
            Node paramsNode = org.apache.xpath.XPathAPI.selectSingleNode(child,
                    "xs:annotation/xs:appinfo/params");
            if (paramsNode != null) {
                NodeList childnl = ((Element) paramsNode).getElementsByTagName("param");
                Map existingParams = new HashMap();
                for (int ci = 0; ci < childnl.getLength(); ci++) {
                    Element param = (Element) childnl.item(ci);
                    String paramId = param.getAttribute("id");
                    String paramInputTypeId = param.getAttribute("inputTypeId");

                    ContentTypeAttributeParameter contentTypeAttributeParameter = new ContentTypeAttributeParameter();
                    contentTypeAttributeParameter.setId(paramId);
                    if (paramInputTypeId != null && paramInputTypeId.length() > 0)
                        contentTypeAttributeParameter.setType(Integer.parseInt(paramInputTypeId));

                    contentTypeAttribute.putContentTypeAttributeParameter(paramId,
                            contentTypeAttributeParameter);
                    existingParams.put(paramId, contentTypeAttributeParameter);

                    NodeList valuesNodeList = param.getElementsByTagName("values");
                    for (int vsnli = 0; vsnli < valuesNodeList.getLength(); vsnli++) {
                        NodeList valueNodeList = param.getElementsByTagName("value");
                        for (int vnli = 0; vnli < valueNodeList.getLength(); vnli++) {
                            Element value = (Element) valueNodeList.item(vnli);
                            String valueId = value.getAttribute("id");

                            ContentTypeAttributeParameterValue contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
                            contentTypeAttributeParameterValue.setId(valueId);

                            NamedNodeMap nodeMap = value.getAttributes();
                            for (int nmi = 0; nmi < nodeMap.getLength(); nmi++) {
                                Node attribute = (Node) nodeMap.item(nmi);
                                String valueAttributeName = attribute.getNodeName();
                                String valueAttributeValue = attribute.getNodeValue();
                                contentTypeAttributeParameterValue.addAttribute(valueAttributeName,
                                        valueAttributeValue);
                            }

                            contentTypeAttributeParameter.addContentTypeAttributeParameterValue(valueId,
                                    contentTypeAttributeParameterValue);
                        }
                    }
                }

                //
                if ((attributeType.equals("select") || attributeType.equals("radiobutton")
                        || attributeType.equals("checkbox")) && !existingParams.containsKey("widget")) {
                    ContentTypeAttributeParameter contentTypeAttributeParameter = new ContentTypeAttributeParameter();
                    contentTypeAttributeParameter.setId("widget");
                    contentTypeAttributeParameter.setType(0);
                    contentTypeAttribute.putContentTypeAttributeParameter("widget",
                            contentTypeAttributeParameter);

                    ContentTypeAttributeParameterValue contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
                    contentTypeAttributeParameterValue.setId("0");
                    contentTypeAttributeParameterValue.addAttribute("id", "default");
                    contentTypeAttributeParameterValue.addAttribute("label", "Default");
                    contentTypeAttributeParameter.addContentTypeAttributeParameterValue("0",
                            contentTypeAttributeParameterValue);
                }
            }

            // End extra parameters
            attributes.add(contentTypeAttribute);
        }

        if (addPriorityAttribute) {
            ContentTypeAttribute contentTypeAttribute = new ContentTypeAttribute();
            contentTypeAttribute.setPosition(i);
            contentTypeAttribute.setName("PropertyPriority");
            contentTypeAttribute.setInputType("select");

            ContentTypeAttributeParameter contentTypeAttributeParameter = new ContentTypeAttributeParameter();
            contentTypeAttributeParameter.setId("title");
            contentTypeAttributeParameter.setType(0);
            contentTypeAttribute.putContentTypeAttributeParameter("title", contentTypeAttributeParameter);
            ContentTypeAttributeParameterValue contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("title");
            contentTypeAttributeParameterValue.addAttribute("title", "PropertyPriority");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("title",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameter = new ContentTypeAttributeParameter();
            contentTypeAttributeParameter.setId("description");
            contentTypeAttributeParameter.setType(0);
            contentTypeAttribute.putContentTypeAttributeParameter("description", contentTypeAttributeParameter);
            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("description");
            contentTypeAttributeParameterValue.addAttribute("description", "What prio should this have");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("description",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameter = new ContentTypeAttributeParameter();
            contentTypeAttributeParameter.setId("initialData");
            contentTypeAttributeParameter.setType(0);
            contentTypeAttribute.putContentTypeAttributeParameter("initialData", contentTypeAttributeParameter);
            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("initialData");
            contentTypeAttributeParameterValue.addAttribute("initialData", "");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("initialData",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameter = new ContentTypeAttributeParameter();
            contentTypeAttributeParameter.setId("class");
            contentTypeAttributeParameter.setType(0);
            contentTypeAttribute.putContentTypeAttributeParameter("class", contentTypeAttributeParameter);
            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("class");
            contentTypeAttributeParameterValue.addAttribute("class", "longtextfield");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("class",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameter = new ContentTypeAttributeParameter();
            contentTypeAttributeParameter.setId("values");
            contentTypeAttributeParameter.setType(1);
            contentTypeAttribute.putContentTypeAttributeParameter("values", contentTypeAttributeParameter);

            contentTypeAttribute.getOptions().add(new ContentTypeAttributeOptionDefinition("Lowest", "1"));
            contentTypeAttribute.getOptions().add(new ContentTypeAttributeOptionDefinition("Low", "2"));
            contentTypeAttribute.getOptions().add(new ContentTypeAttributeOptionDefinition("Medium", "3"));
            contentTypeAttribute.getOptions().add(new ContentTypeAttributeOptionDefinition("High", "4"));
            contentTypeAttribute.getOptions().add(new ContentTypeAttributeOptionDefinition("Highest", "5"));

            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("1");
            contentTypeAttributeParameterValue.addAttribute("id", "1");
            contentTypeAttributeParameterValue.addAttribute("label", "Lowest");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("1",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("2");
            contentTypeAttributeParameterValue.addAttribute("id", "2");
            contentTypeAttributeParameterValue.addAttribute("label", "Low");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("2",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("3");
            contentTypeAttributeParameterValue.addAttribute("id", "3");
            contentTypeAttributeParameterValue.addAttribute("label", "Medium");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("3",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("4");
            contentTypeAttributeParameterValue.addAttribute("id", "4");
            contentTypeAttributeParameterValue.addAttribute("label", "High");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("4",
                    contentTypeAttributeParameterValue);

            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
            contentTypeAttributeParameterValue.setId("5");
            contentTypeAttributeParameterValue.addAttribute("id", "5");
            contentTypeAttributeParameterValue.addAttribute("label", "Highest");
            contentTypeAttributeParameter.addContentTypeAttributeParameterValue("5",
                    contentTypeAttributeParameterValue);
            // End extra parameters

            attributes.add(contentTypeAttribute);
        }
    } catch (Exception e) {
        logger.error(
                "An error occurred when we tried to get the attributes of the content type: " + e.getMessage(),
                e);
    }

    return attributes;
}

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

public static JSONArray createAuthsJson(Element authsEl) throws DOMException, JSONException {
    if (authsEl == null)
        return null;
    JSONArray authArray = new JSONArray();
    NodeList authList = authsEl.getElementsByTagName("auth");
    for (int i = 0; i < authList.getLength(); i++) {
        JSONObject authJson = new JSONObject();
        Element authEl = (Element) authList.item(i);
        NamedNodeMap attMap = authEl.getAttributes();
        for (int j = 0; j < attMap.getLength(); j++) {
            Node attr = attMap.item(j);
            if ("actions".equals(attr.getNodeName())) {
                authJson.put(attr.getNodeName(), new JSONArray(attr.getNodeValue()));
            } else {
                authJson.put(attr.getNodeName(), attr.getNodeValue());
            }//from  www. jav  a 2 s.  c  o  m
        }
        authArray.put(authJson);
    }
    return authArray;
}

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

/**
 * Create JSONObject of site/*w  w w.j  a v  a  2  s  .c  o  m*/
 * 
 * @param siteEl
 * @return
 * @throws DOMException
 * @throws JSONException
 * @throws TransformerException
 */
private static JSONObject siteToJSON(String sitetopId, Element siteEl, boolean isEditMode)
        throws DOMException, JSONException, TransformerException {
    JSONObject json = new JSONObject();

    // attrs
    NamedNodeMap attMap = siteEl.getAttributes();
    Node attr;
    for (int i = 0; i < attMap.getLength(); i++) {
        attr = attMap.item(i);
        if ("link_disabled".equalsIgnoreCase(attr.getNodeName())) {
            json.put("linkDisabled", new Boolean(attr.getNodeValue()));
        } else if ("directory_title".equalsIgnoreCase(attr.getNodeName())) {
            json.put("directoryTitle", attr.getNodeValue());
        } else {
            json.put(attr.getNodeName(), attr.getNodeValue());
        }
    }

    // parentId
    if (!sitetopId.equals(siteEl.getAttribute("id"))) {
        Element parentEl = (Element) siteEl.getParentNode();
        if (parentEl != null && (parentEl.getNodeName().equalsIgnoreCase("site")
                || parentEl.getNodeName().equalsIgnoreCase("site-top"))) {
            json.put("parentId", parentEl.getAttribute("id"));
        }
    }

    // properties
    JSONObject propsJson = new JSONObject();
    Element propEl = (Element) XPathAPI.selectSingleNode(siteEl, "properties");
    if (propEl != null) {
        NodeList propertyList = propEl.getElementsByTagName("property");
        Element propertyEl;
        for (int i = 0; i < propertyList.getLength(); i++) {
            propertyEl = (Element) propertyList.item(i);
            propsJson.put(propertyEl.getAttribute("name"),
                    (propertyEl.getFirstChild() != null) ? propertyEl.getFirstChild().getNodeValue() : "");
        }
    }
    json.put("properties", propsJson);

    // auths
    Element authsEl = (Element) XPathAPI.selectSingleNode(siteEl, "auths");
    if (authsEl != null) {
        json.put("auths", MenuAuthorization.createAuthsJson(authsEl));
    }

    // admins
    JSONArray adminsArray = new JSONArray();
    Element adminsEl = (Element) XPathAPI.selectSingleNode(siteEl, "menuTreeAdmins");
    if (adminsEl != null) {
        NodeList adminList = adminsEl.getElementsByTagName("admin");
        Element adminEl;
        for (int i = 0; i < adminList.getLength(); i++) {
            adminEl = (Element) adminList.item(i);
            if (adminEl.getFirstChild() != null) {
                adminsArray.put(adminEl.getFirstChild().getNodeValue());
            }
        }
    }
    json.put("menuTreeAdmins", adminsArray);

    if (isEditMode)
        json.put("isEditMode", true);

    return json;
}

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

private static void buildAuthorizedMenuXml(Element siteNode, StringBuffer buf, boolean noAuth)
        throws ClassNotFoundException {

    NodeList childNodes = siteNode.getChildNodes();
    Collection childSites = new ArrayList();
    Element propertiesNode = null;
    boolean accessible = true;

    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if ("auths".equals(node.getNodeName()) && !noAuth) {
            accessible = false;// ww w .j  a v  a2 s . com
            Element rolesEl = (Element) node;
            NodeList roles = rolesEl.getElementsByTagName("auth");
            for (int j = 0; j < roles.getLength(); j++) {
                Element auth = (Element) roles.item(j);
                String type = auth.getAttribute("type");
                String regx = auth.getAttribute("regx");
                if (RoleUtil.isPermitted(type, regx)) {
                    accessible = true;
                }
            }
        }
        if ("site".equals(node.getNodeName())) {
            childSites.add(node);
        }
        if ("properties".equals(node.getNodeName())) {
            propertiesNode = (Element) node;
        }
    }
    if (!accessible) {
        return;
    }

    buf.append("<").append(siteNode.getNodeName());
    NamedNodeMap attrs = siteNode.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        buf.append(" ").append(attr.getName()).append("=\"").append(XmlUtil.escapeXmlEntities(attr.getValue()))
                .append("\"");
    }
    buf.append(">\n");

    if (propertiesNode != null) {
        NodeList properties = propertiesNode.getElementsByTagName("property");
        buf.append("<properties>\n");
        for (int i = 0; i < properties.getLength(); i++) {
            Element property = (Element) properties.item(i);
            setElement2Buf(property, buf);
        }
        buf.append("</properties>\n");
    }

    for (Iterator it = childSites.iterator(); it.hasNext();) {
        Element site = (Element) it.next();
        buildAuthorizedMenuXml(site, buf, noAuth);
    }

    buf.append("</").append(siteNode.getNodeName()).append(">\n");

}