Example usage for org.dom4j Element attributes

List of usage examples for org.dom4j Element attributes

Introduction

In this page you can find the example usage for org.dom4j Element attributes.

Prototype

List<Attribute> attributes();

Source Link

Document

Returns the Attribute instances this element contains as a backed List so that the attributes may be modified directly using the List interface.

Usage

From source file:org.craftercms.core.xml.mergers.impl.cues.impl.MergeCueResolverImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
protected Map<String, String> getMergeCueParams(Element element, Attribute mergeCueAttribute) {
    Map<String, String> params = new HashMap<String, String>();
    String paramsPrefix = mergeCueAttribute.getQualifiedName() + "-";
    List<Attribute> attributes = element.attributes();

    for (Iterator<Attribute> i = attributes.iterator(); i.hasNext();) {
        Attribute attribute = i.next();
        String attributeQualifiedName = attribute.getQualifiedName();
        if (attributeQualifiedName.startsWith(paramsPrefix)) {
            i.remove();/*from  ww w .  j a v  a 2s  . co  m*/

            String paramName = attributeQualifiedName.substring(paramsPrefix.length());
            String paramValue = attribute.getValue();

            params.put(paramName, paramValue);
        }
    }

    return params;
}

From source file:org.craftercms.core.xml.mergers.impl.cues.impl.MergeParentAndChildMergeCue.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public Element merge(Element parent, Element child, Map<String, String> params) throws XmlMergeException {
    Element merged = DocumentHelper.createElement(child.getQName());
    org.craftercms.core.util.CollectionUtils.move(child.attributes(), merged.attributes());

    if (parent.isTextOnly() && child.isTextOnly()) {
        String parentText = parent.getText();
        String childText = child.getText();

        if (getMergeOrder(params).equalsIgnoreCase("after")) {
            merged.setText(parentText + childText);
        } else {/* w w  w.  ja  va2 s . c  o m*/
            merged.setText(childText + parentText);
        }
    } else {
        List<Element> parentElements = parent.elements();
        List<Element> childElements = child.elements();
        List<Element> mergedElements = merged.elements();

        if (CollectionUtils.isNotEmpty(parentElements) && CollectionUtils.isNotEmpty(childElements)) {
            for (Iterator<Element> i = parentElements.iterator(); i.hasNext();) {
                Element parentElement = i.next();
                boolean elementsMerged = false;

                for (Iterator<Element> j = childElements.iterator(); !elementsMerged && j.hasNext();) {
                    Element childElement = j.next();
                    if (elementMergeMatcher.matchForMerge(parentElement, childElement)) {
                        MergeCueContext context = mergeCueResolver.getMergeCue(parentElement, childElement);
                        if (context != null) {
                            i.remove();
                            j.remove();

                            Element mergedElement = context.doMerge();
                            mergedElements.add(mergedElement);

                            elementsMerged = true;
                        } else {
                            throw new XmlMergeException("No merge cue was resolved for matching elements "
                                    + parentElement + " (parent) and " + childElement + " (child)");
                        }
                    }
                }
            }
        }

        if (getMergeOrder(params).equalsIgnoreCase("after")) {
            org.craftercms.core.util.CollectionUtils.move(parentElements, mergedElements);
            org.craftercms.core.util.CollectionUtils.move(childElements, mergedElements);
        } else {
            org.craftercms.core.util.CollectionUtils.move(childElements, mergedElements);
            org.craftercms.core.util.CollectionUtils.move(parentElements, mergedElements);
        }
    }

    return merged;
}

From source file:org.craftercms.cstudio.alfresco.dm.service.impl.DmContentTypeServiceImpl.java

License:Open Source License

/**
 * copy the given element to the target node
 *
 * @param site// w w w.jav  a  2  s  . co m
 * @param parentPath
 * @param element
 * @param targetNode
 */
protected void copyContent(String site, String parentPath, Element element, Node targetNode) {
    if (targetNode != null) {
        String name = element.getName();
        String currentPath = parentPath + name;
        boolean noCopyOnConvert = DmUtils.getBooleanValue(targetNode.valueOf("@no-copy"), false);
        if (!this.getExcludedPaths(site).contains(currentPath) && !noCopyOnConvert) {
            Element targetElement = (Element) targetNode;
            boolean multiValued = DmUtils.getBooleanValue(targetNode.valueOf("@copy-children"), false);
            List<Element> childElements = element.elements();
            if (childElements != null && childElements.size() > 0) {
                for (Element childElement : childElements) {
                    Node targetChildNode = null;
                    if (this.getMultiValuedPaths(site).contains(currentPath) || multiValued) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("[CHANGE-TEMPLATE] " + currentPath + " is multi-valued.");
                        }
                        targetChildNode = (Node) targetElement.addElement(childElement.getName());
                    } else {
                        String uniquePath = childElement.getUniquePath(element);
                        targetChildNode = targetElement.selectSingleNode(uniquePath);
                    }
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("[CHANGE-TEMPLATE] copying child node of " + currentPath + " : "
                                + childElement.getUniquePath(element));
                    }
                    copyContent(site, currentPath + "/", childElement, targetChildNode);
                }
            }
            targetElement.setText(element.getText());
            targetElement.setAttributes(element.attributes());
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("[CHANGE-TEMPLATE] " + currentPath
                        + " is not being copied since it is in exlcudedPaths or no copy on convert node.");
            }
        }
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(
                    "[CHANGE-TEMPLATE] " + element.getUniquePath() + " does not exist in target location.");
        }
    }

}

From source file:org.hightides.annotations.util.SpringXMLUtil.java

License:Apache License

/**
 * Method to add a bean to a spring configuration.
 * @param xmlFilename/* w w w . j  ava 2s . c o  m*/
 * @param bean
 * @param backup
 * @return
 */
@SuppressWarnings("unchecked")
public static Element addBean(String xmlFilename, Element bean, boolean backup, String syncMode) {
    String filename = FileUtil.getFilename(xmlFilename);
    // some checking first
    if (StringUtil.isEmpty(bean.attributeValue("id"))) {
        _log.warn("Attempt to insert empty bean id on [" + filename + "].");
        return null;
    }
    Document doc = readXMLDocument(xmlFilename);
    if (doc == null)
        return null;
    Element root = doc.getRootElement();
    // beans
    List<Element> elements = root.elements();
    List<Element> backupBeans = new ArrayList<Element>();
    boolean found = false;
    for (Element element : elements) {
        // check if bean already exist
        if (bean.attributeValue("id").equals(element.attributeValue("id"))) {
            if (syncMode.equals("UPDATE")) {
                // copy all the attributes
                bean.setAttributes(element.attributes());
                // inside bean (property)
                List<Element> properties = element.elements();
                List<Element> beanProperties = bean.elements();
                for (Element property : properties) {
                    found = false;
                    for (Element beanProperty : beanProperties) {
                        // check if property already exists in bean
                        if (beanProperty.attributeValue("name").equals(property.attributeValue("name"))) {
                            // remove existing property in bean
                            bean.remove(beanProperty);
                            cloneChildElement(bean, property);
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        // add property to bean
                        cloneChildElement(bean, property);
                    }
                }
            }
            root.remove(element);
            found = true;
        } else if (found) {
            backupBeans.add(element);
            root.remove(element);
        }
    }
    cloneChildElement(root, bean);
    if (backupBeans != null) {
        for (Element backUpBean : backupBeans) {
            cloneChildElement(root, backUpBean);
        }
    }
    if (saveXMLDocument(xmlFilename, doc, backup)) {
        if (found)
            _log.info("Updated bean [" + bean.attributeValue("id") + "] on [" + filename + "].");
        else
            _log.info("Added bean [" + bean.attributeValue("id") + "] on [" + filename + "].");
    }
    return bean;
}

From source file:org.hightides.annotations.util.SpringXMLUtil.java

License:Apache License

/**
 * Copies the node to target. This is necessary because
 * DOM4J appends xmlns when bean is inserted as addElement().
 * @param target/* w ww .ja v  a  2  s.c  o  m*/
 * @param node
 */
@SuppressWarnings("unchecked")
private static void cloneChildElement(Element target, Element node) {
    // create new element
    Element newBean = target.addElement(node.getName());
    // copy all attributes
    newBean.setAttributes(node.attributes());
    // copy text elements
    if (!StringUtil.isEmpty(node.getText()))
        newBean.addText(node.getText());
    List<Element> elements = node.elements();
    // copy all elements
    for (Element elem : elements) {
        cloneChildElement(newBean, elem);
    }
}

From source file:org.hlc.demo.mybatis.mapper.DocumentAppender.java

License:Apache License

@SuppressWarnings("unchecked")
public void send(Element xml) {

    XmlElement element = new XmlElement(xml.getName());
    List<org.dom4j.Attribute> attributes = xml.attributes();
    for (org.dom4j.Attribute temp : attributes) {
        Attribute att = new Attribute(temp.getName(), temp.getValue());
        element.addAttribute(att);//from   w w w  .  j a  v  a 2  s.  c  om
    }
    // System.out.println(xml.getText());
    element.addElement(new TextElement(xml.asXML()));
    this.document.getRootElement().addElement(element);
}

From source file:org.infoglue.deliver.controllers.kernel.impl.simple.PageEditorHelper.java

License:Open Source License

/**
 * This method gets the component structure on the page.
 *
 * @author mattias/*from w w  w  .  ja  v  a  2s. co  m*/
 */

protected List getPageComponents(Database db, String componentXML, Element element, String slotName,
        Slot containerSlot, InfoGlueComponent parentComponent, Integer siteNodeId, Integer languageId,
        InfoGluePrincipal principal) throws Exception {
    //List components = new ArrayList();

    Locale locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(db, languageId);

    String key = "" + componentXML.hashCode() + "_" + languageId + "_" + slotName;
    if (parentComponent != null)
        key = "" + componentXML.hashCode() + "_" + languageId + "_" + slotName + "_" + parentComponent.getId()
                + "_" + parentComponent.getName() + "_" + parentComponent.getIsInherited();

    Object componentsCandidate = CacheController.getCachedObjectFromAdvancedCache("pageComponentsCache", key);
    List components = new ArrayList();
    String[] groups = null;

    if (componentsCandidate != null) {
        if (componentsCandidate instanceof NullObject)
            components = null;
        else
            components = (List) componentsCandidate;
    } else {
        String componentXPath = "component[@name='" + slotName + "']";
        //logger.info("componentXPath:" + componentXPath);
        List componentElements = element.selectNodes(componentXPath);
        //logger.info("componentElements:" + componentElements.size());
        //logger.info("componentElements:" + componentElements.size());

        Iterator componentIterator = componentElements.iterator();
        int slotPosition = 0;
        while (componentIterator.hasNext()) {
            Element componentElement = (Element) componentIterator.next();

            Integer id = new Integer(componentElement.attributeValue("id"));
            Integer contentId = new Integer(componentElement.attributeValue("contentId"));
            String name = componentElement.attributeValue("name");
            String isInherited = componentElement.attributeValue("isInherited");
            String pagePartTemplateContentId = componentElement.attributeValue("pagePartTemplateContentId");

            try {
                ContentVO contentVO = ContentDeliveryController.getContentDeliveryController().getContentVO(db,
                        contentId, null);
                //logger.info("contentVO for current component:" + contentVO.getName());
                //logger.info("slotName:" + slotName + " should get connected with content_" + contentVO.getId());

                groups = new String[] { CacheController.getPooledString(1, contentVO.getId()) };

                InfoGlueComponent component = new InfoGlueComponent();
                component.setPositionInSlot(new Integer(slotPosition));
                component.setId(id);
                component.setContentId(contentId);
                component.setName(contentVO.getName());
                component.setSlotName(name);
                component.setParentComponent(parentComponent);
                if (containerSlot != null) {
                    //logger.info("Adding component to container slot:" + component.getId() + ":" + containerSlot.getId());
                    //containerSlot.getComponents().add(component);
                    component.setContainerSlot(containerSlot);
                    //logger.info("containerSlot:" + containerSlot);
                    //logger.info("containerSlot:" + containerSlot);
                }
                if (isInherited != null && isInherited.equals("true"))
                    component.setIsInherited(true);
                else if (parentComponent != null)
                    component.setIsInherited(parentComponent.getIsInherited());

                if (pagePartTemplateContentId != null && !pagePartTemplateContentId.equals("")
                        && !pagePartTemplateContentId.equals("-1")) {
                    Integer pptContentId = new Integer(pagePartTemplateContentId);
                    ContentVO pptContentIdContentVO = ContentDeliveryController.getContentDeliveryController()
                            .getContentVO(db, pptContentId, null);

                    InfoGlueComponent partTemplateReferenceComponent = new InfoGlueComponent();
                    partTemplateReferenceComponent.setPositionInSlot(new Integer(slotPosition));
                    partTemplateReferenceComponent.setId(id);
                    //logger.info("Setting component:" + partTemplateReferenceComponent.getId() + " - " + partTemplateReferenceComponent.getPositionInSlot());
                    partTemplateReferenceComponent.setContentId(pptContentId);
                    partTemplateReferenceComponent.setName(pptContentIdContentVO.getName());
                    partTemplateReferenceComponent.setSlotName(name);
                    partTemplateReferenceComponent.setParentComponent(parentComponent);
                    if (containerSlot != null) {
                        //logger.info("Adding component to container slot:" + partTemplateReferenceComponent.getId() + ":" + containerSlot.getId());
                        partTemplateReferenceComponent.setContainerSlot(containerSlot);
                        //containerSlot.getComponents().add(partTemplateReferenceComponent);
                    }
                    partTemplateReferenceComponent.setIsInherited(true);

                    component.setPagePartTemplateContentId(pptContentId);
                    component.setPagePartTemplateComponent(partTemplateReferenceComponent);
                }

                //Use this later
                //getComponentProperties(componentElement, component, locale, templateController);
                List propertiesNodeList = componentElement.selectNodes("properties");
                if (propertiesNodeList.size() > 0) {
                    Element propertiesElement = (Element) propertiesNodeList.get(0);

                    List propertyNodeList = propertiesElement.selectNodes("property");
                    Iterator propertyNodeListIterator = propertyNodeList.iterator();
                    while (propertyNodeListIterator.hasNext()) {
                        Element propertyElement = (Element) propertyNodeListIterator.next();

                        String propertyName = propertyElement.attributeValue("name");
                        String type = propertyElement.attributeValue("type");
                        String path = propertyElement.attributeValue("path");

                        if (path == null) {
                            LanguageVO langaugeVO = LanguageDeliveryController.getLanguageDeliveryController()
                                    .getMasterLanguageForSiteNode(db, siteNodeId);
                            if (propertyElement.attributeValue("path_" + langaugeVO.getLanguageCode()) != null)
                                path = propertyElement.attributeValue("path_" + langaugeVO.getLanguageCode());
                        }

                        if (propertyElement.attributeValue("path_" + locale.getLanguage()) != null)
                            path = propertyElement.attributeValue("path_" + locale.getLanguage());

                        if (path == null || path.equals("")) {
                            logger.info(
                                    "Falling back to content master language 1 for property:" + propertyName);
                            LanguageVO contentMasterLangaugeVO = LanguageDeliveryController
                                    .getLanguageDeliveryController()
                                    .getMasterLanguageForRepository(db, contentVO.getRepositoryId());
                            if (propertyElement.attributeValue(
                                    "path_" + contentMasterLangaugeVO.getLanguageCode()) != null)
                                path = propertyElement
                                        .attributeValue("path_" + contentMasterLangaugeVO.getLanguageCode());
                        }

                        Map property = new HashMap();
                        property.put("name", propertyName);
                        property.put("path", path);
                        property.put("type", type);

                        List attributes = propertyElement.attributes();
                        Iterator attributesIterator = attributes.iterator();
                        while (attributesIterator.hasNext()) {
                            Attribute attribute = (Attribute) attributesIterator.next();
                            if (attribute.getName().startsWith("path_"))
                                property.put(attribute.getName(), attribute.getValue());
                        }

                        if (propertyName.equals(InfoGlueComponent.CACHE_RESULT_PROPERTYNAME)
                                && (path.equalsIgnoreCase("true") || path.equalsIgnoreCase("yes"))) {
                            component.setCacheResult(true);
                        }
                        if (propertyName.equals(InfoGlueComponent.UPDATE_INTERVAL_PROPERTYNAME)
                                && !path.equals("")) {
                            try {
                                component.setUpdateInterval(Integer.parseInt(path));
                            } catch (Exception e) {
                                logger.warn("The component " + component.getName() + " "
                                        + InfoGlueComponent.UPDATE_INTERVAL_PROPERTYNAME
                                        + " with a faulty value on page with siteNodeId=" + siteNodeId + ":"
                                        + e.getMessage());
                            }
                        }
                        if (propertyName.equals(InfoGlueComponent.CACHE_KEY_PROPERTYNAME) && !path.equals("")) {
                            component.setCacheKey(path);
                        }
                        if (propertyName.equals(InfoGlueComponent.PREPROCESSING_ORDER_PROPERTYNAME)
                                && !path.equals("")) {
                            component.setPreProcessingOrder(path);
                        }

                        List<ComponentBinding> bindings = new ArrayList<ComponentBinding>();
                        List bindingNodeList = propertyElement.selectNodes("binding");
                        Iterator bindingNodeListIterator = bindingNodeList.iterator();
                        while (bindingNodeListIterator.hasNext()) {
                            Element bindingElement = (Element) bindingNodeListIterator.next();
                            String entity = bindingElement.attributeValue("entity");
                            String entityId = bindingElement.attributeValue("entityId");
                            String assetKey = bindingElement.attributeValue("assetKey");
                            Element supplementingBindingElement = bindingElement
                                    .element("supplementingBinding");

                            ComponentBinding componentBinding;
                            if (supplementingBindingElement == null) {
                                componentBinding = new ComponentBinding();
                            } else {
                                String supplementingEntityIdString = null;
                                try {
                                    supplementingEntityIdString = supplementingBindingElement
                                            .attributeValue("entityId");
                                    String supplementingEntityId = null;
                                    if (supplementingEntityIdString != null
                                            && !supplementingEntityIdString.equals("")) {
                                        supplementingEntityId = supplementingEntityIdString;
                                    }
                                    String supplementingAssetKey = supplementingBindingElement
                                            .attributeValue("assetKey");
                                    componentBinding = new SupplementedComponentBinding(supplementingEntityId,
                                            supplementingAssetKey);
                                } catch (NumberFormatException ex) {
                                    logger.error("Could not make Integer from supplementing entity id [id: "
                                            + supplementingEntityIdString
                                            + "]. Will ignore it!. Property name: " + propertyName);
                                    componentBinding = new ComponentBinding();
                                }
                            }
                            //componentBinding.setId(new Integer(id));
                            //componentBinding.setComponentId(componentId);
                            componentBinding.setEntityClass(entity);
                            componentBinding.setEntityId(entityId);
                            componentBinding.setAssetKey(assetKey);
                            componentBinding.setBindingPath(path);

                            bindings.add(componentBinding);
                        }

                        property.put("bindings", bindings);

                        component.getProperties().put(propertyName, property);
                    }
                }

                getComponentRestrictions(componentElement, component, locale);

                //Getting slots for the component
                try {
                    String componentString = getComponentTemplateString(contentId, languageId, db, principal);

                    int offset = 0;
                    int slotStartIndex = componentString.indexOf("<ig:slot", offset);
                    while (slotStartIndex > -1) {
                        int slotStopIndex = componentString.indexOf("</ig:slot>", slotStartIndex);
                        String slotString = componentString.substring(slotStartIndex, slotStopIndex + 10);
                        String slotId = slotString.substring(slotString.indexOf("id") + 4,
                                slotString.indexOf("\"", slotString.indexOf("id") + 4));

                        boolean inherit = true;
                        int inheritIndex = slotString.indexOf("inherit");
                        if (inheritIndex > -1) {
                            String inheritString = slotString.substring(inheritIndex + 9,
                                    slotString.indexOf("\"", inheritIndex + 9));
                            inherit = Boolean.parseBoolean(inheritString);
                        }

                        boolean disableAccessControl = false;
                        int disableAccessControlIndex = slotString.indexOf("disableAccessControl");
                        if (disableAccessControlIndex > -1) {
                            String disableAccessControlString = slotString.substring(
                                    disableAccessControlIndex + "disableAccessControl".length() + 2,
                                    slotString.indexOf("\"",
                                            disableAccessControlIndex + "disableAccessControl".length() + 2));
                            disableAccessControl = Boolean.parseBoolean(disableAccessControlString);
                        }

                        String[] allowedComponentNamesArray = null;
                        int allowedComponentNamesIndex = slotString.indexOf(" allowedComponentNames");
                        if (allowedComponentNamesIndex > -1) {
                            String allowedComponentNames = slotString.substring(allowedComponentNamesIndex + 24,
                                    slotString.indexOf("\"", allowedComponentNamesIndex + 24));
                            allowedComponentNamesArray = allowedComponentNames.split(",");
                        }

                        String[] disallowedComponentNamesArray = null;
                        int disallowedComponentNamesIndex = slotString.indexOf(" disallowedComponentNames");
                        if (disallowedComponentNamesIndex > -1) {
                            String disallowedComponentNames = slotString.substring(
                                    disallowedComponentNamesIndex + 27,
                                    slotString.indexOf("\"", disallowedComponentNamesIndex + 27));
                            disallowedComponentNamesArray = disallowedComponentNames.split(",");
                        }

                        String[] allowedComponentGroupNamesArray = null;
                        int allowedComponentGroupNamesIndex = slotString.indexOf(" allowedComponentGroupNames");
                        if (allowedComponentGroupNamesIndex > -1) {
                            String allowedComponentGroupNames = slotString.substring(
                                    allowedComponentGroupNamesIndex + 29,
                                    slotString.indexOf("\"", allowedComponentGroupNamesIndex + 29));
                            allowedComponentGroupNamesArray = allowedComponentGroupNames.split(",");
                        }

                        String addComponentText = null;
                        int addComponentTextIndex = slotString.indexOf("addComponentText");
                        if (addComponentTextIndex > -1) {
                            addComponentText = slotString.substring(
                                    addComponentTextIndex + "addComponentText".length() + 2, slotString.indexOf(
                                            "\"", addComponentTextIndex + "addComponentText".length() + 2));
                        }

                        String addComponentLinkHTML = null;
                        int addComponentLinkHTMLIndex = slotString.indexOf("addComponentLinkHTML");
                        if (addComponentLinkHTMLIndex > -1) {
                            addComponentLinkHTML = slotString.substring(
                                    addComponentLinkHTMLIndex + "addComponentLinkHTML".length() + 2,
                                    slotString.indexOf("\"",
                                            addComponentLinkHTMLIndex + "addComponentLinkHTML".length() + 2));
                        }

                        int allowedNumberOfComponentsInt = -1;
                        int allowedNumberOfComponentsIndex = slotString.indexOf("allowedNumberOfComponents");
                        if (allowedNumberOfComponentsIndex > -1) {
                            String allowedNumberOfComponents = slotString.substring(
                                    allowedNumberOfComponentsIndex + "allowedNumberOfComponents".length() + 2,
                                    slotString.indexOf("\"", allowedNumberOfComponentsIndex
                                            + "allowedNumberOfComponents".length() + 2));
                            try {
                                allowedNumberOfComponentsInt = new Integer(allowedNumberOfComponents);
                            } catch (Exception e) {
                                allowedNumberOfComponentsInt = -1;
                            }
                        }

                        Slot slot = new Slot();
                        slot.setId(slotId);
                        slot.setInherit(inherit);
                        slot.setDisableAccessControl(disableAccessControl);
                        slot.setAllowedComponentsArray(allowedComponentNamesArray);
                        slot.setDisallowedComponentsArray(disallowedComponentNamesArray);
                        slot.setAllowedComponentGroupsArray(allowedComponentGroupNamesArray);
                        slot.setAddComponentLinkHTML(addComponentLinkHTML);
                        slot.setAddComponentText(addComponentText);
                        slot.setAllowedNumberOfComponents(new Integer(allowedNumberOfComponentsInt));

                        Element componentsElement = (Element) componentElement.selectSingleNode("components");

                        //groups = new String[]{CacheController.getPooledString(1, contentVO.getId())};

                        List subComponents = getPageComponents(db, componentXML, componentsElement, slotId,
                                slot, component, siteNodeId, languageId, principal);
                        //logger.info("subComponents:" + subComponents);
                        slot.setComponents(subComponents);

                        component.getSlotList().add(slot);

                        offset = slotStopIndex;
                        slotStartIndex = componentString.indexOf("<ig:slot", offset);
                    }
                } catch (Exception e) {
                    logger.warn(
                            "An component with either an empty template or with no template in the sitelanguages was found:"
                                    + e.getMessage());
                }

                components.add(component);
            } catch (Exception e) {
                logger.warn(
                        "There was deleted referenced component or some other problem when rendering siteNode: "
                                + siteNodeId + ") in language " + languageId + ":" + e.getMessage());
            }
            slotPosition++;
        }
    }

    if (groups == null)
        groups = new String[] { "selectiveCacheUpdateNonApplicable" };

    if (components != null)
        CacheController.cacheObjectInAdvancedCache("pageComponentsCache", key, components, groups, false);
    else
        CacheController.cacheObjectInAdvancedCache("pageComponentsCache", key, new NullObject(), groups, false);

    //logger.info("Returning " + components.size() + " components for:" + slotName);
    return components;
}

From source file:org.infoglue.igide.cms.InfoglueCMS.java

License:Open Source License

public static Map<String, ContentTypeAttribute> getContentTypeAttributes(String schemaValue) {
    Map<String, ContentTypeAttribute> attributes = new HashMap<String, ContentTypeAttribute>();

    try {//from  w  w w.j  a  va  2s .co m
        SAXReader reader = new SAXReader();
        Document document = reader.read(new StringReader(schemaValue));
        // Document document = reader.read(new java.io.ByteArrayInputStream(schemaValue.getBytes()));
        String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element";

        @SuppressWarnings("unchecked")
        List<Element> anl = document.selectNodes(attributesXPath);
        // XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath);

        int cnt = 0;
        for (Iterator<Element> i = anl.iterator(); i.hasNext();) {
            cnt++;
            Element child = i.next();
            String attributeName = child.valueOf("@name");
            String attributeType = child.valueOf("@type");

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

            //attributes.put(contentTypeAttribute.getName(), contentTypeAttribute);
            attributes.put(contentTypeAttribute.getName(), contentTypeAttribute);

            // Get extra parameters
            org.dom4j.Node paramsNode = child.selectSingleNode("xs:annotation/xs:appinfo/params");
            if (paramsNode != null) {
                @SuppressWarnings("unchecked")
                List<Element> childnl = paramsNode.selectNodes("param");

                for (Iterator<Element> i2 = childnl.iterator(); i2.hasNext();) {
                    Element param = i2.next();
                    String paramId = param.valueOf("@id");
                    String paramInputTypeId = param.valueOf("@inputTypeId");

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

                    contentTypeAttribute.putContentTypeAttributeParameter(paramId,
                            contentTypeAttributeParameter);

                    @SuppressWarnings("unchecked")
                    List<Element> valuesNodeList = param.selectNodes("values");
                    for (Iterator<Element> i3 = valuesNodeList.iterator(); i3.hasNext();) {
                        Element values = i3.next();
                        @SuppressWarnings("unchecked")
                        List<Element> valueNodeList = values.selectNodes("value");
                        String valueId;
                        ContentTypeAttributeParameterValue contentTypeAttributeParameterValue;
                        for (Iterator<Element> i4 = valueNodeList.iterator(); i4
                                .hasNext(); contentTypeAttributeParameter.addContentTypeAttributeParameterValue(
                                        valueId, contentTypeAttributeParameterValue)) {
                            Element value = i4.next();
                            valueId = value.valueOf("@id");
                            contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue();
                            contentTypeAttributeParameterValue.setId(valueId);
                            @SuppressWarnings("unchecked")
                            List<Attribute> nodeMap = value.attributes();
                            String valueAttributeName;
                            String valueAttributeValue;
                            for (Iterator<Attribute> i5 = nodeMap.iterator(); i5
                                    .hasNext(); contentTypeAttributeParameterValue
                                            .addAttribute(valueAttributeName, valueAttributeValue)) {
                                Attribute attribute = i5.next();
                                valueAttributeName = attribute.getName();
                                valueAttributeValue = attribute.getValue();
                            }

                        }

                    }
                }
            }
            // End extra parameters
            //comparator.appendToStaticCompareString(contentTypeAttribute.getName());

        }

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

    return attributes;
}

From source file:org.jboss.mx.metadata.JBossXMBean10.java

License:Open Source License

protected Descriptor[] buildInterceptors(Element descriptor) {
    List interceptors = descriptor.elements("interceptor");
    ArrayList tmp = new ArrayList();
    for (int i = 0; i < interceptors.size(); i++) {
        Element interceptor = (Element) interceptors.get(i);
        String code = interceptor.attributeValue("code");
        DescriptorSupport interceptorDescr = new DescriptorSupport();
        interceptorDescr.setField("code", code);
        List attributes = interceptor.attributes();
        for (int a = 0; a < attributes.size(); a++) {
            Attribute attr = (Attribute) attributes.get(a);
            String name = attr.getName();
            String value = attr.getValue();
            value = StringPropertyReplacer.replaceProperties(value);
            interceptorDescr.setField(name, value);
        }/*from  ww  w.  j  av a  2s. c  o m*/
        tmp.add(interceptorDescr);
    }
    Descriptor[] descriptors = new Descriptor[tmp.size()];
    tmp.toArray(descriptors);
    return descriptors;
}

From source file:org.jboss.seam.init.Initialization.java

License:LGPL

@SuppressWarnings("unchecked")
private void installComponentFromXmlElement(Element component, String name, String className,
        Properties replacements) throws ClassNotFoundException {
    String installText = component.attributeValue("installed");
    boolean installed = false;
    if (installText == null || "true".equals(replace(installText, replacements))) {
        installed = true;// w w  w .  j  av  a 2  s .co m
    }

    String scopeName = component.attributeValue("scope");
    String jndiName = component.attributeValue("jndi-name");
    String precedenceString = component.attributeValue("precedence");
    int precedence = precedenceString == null ? Install.APPLICATION : Integer.valueOf(precedenceString);
    ScopeType scope = scopeName == null ? null : ScopeType.valueOf(scopeName.toUpperCase());
    String autocreateAttribute = component.attributeValue("auto-create");
    Boolean autoCreate = autocreateAttribute == null ? null : "true".equals(autocreateAttribute);
    String startupAttribute = component.attributeValue("startup");
    Boolean startup = startupAttribute == null ? null : "true".equals(startupAttribute);
    String startupDependsAttribute = component.attributeValue("startupDepends");
    String[] startupDepends = startupDependsAttribute == null ? new String[0]
            : startupDependsAttribute.split(" ");

    if (className != null) {
        Class<?> clazz = getClassUsingImports(className);

        if (name == null) {
            if (!clazz.isAnnotationPresent(Name.class)) {
                throw new IllegalArgumentException(
                        "Component class must have @Name annotation or name must be specified in components.xml: "
                                + clazz.getName());
            }

            name = clazz.getAnnotation(Name.class).value();
        }

        ComponentDescriptor descriptor = new ComponentDescriptor(name, clazz, scope, autoCreate, startup,
                startupDepends, jndiName, installed, precedence);
        addComponentDescriptor(descriptor);
        installedComponentClasses.add(clazz);
    } else if (name == null) {
        throw new IllegalArgumentException("must specify either class or name in <component/> declaration");
    }

    for (Element prop : (List<Element>) component.elements()) {
        String propName = prop.attributeValue("name");
        if (propName == null) {
            propName = prop.getQName().getName();
        }
        String qualifiedPropName = name + '.' + toCamelCase(propName, false);
        properties.put(qualifiedPropName, getPropertyValue(prop, qualifiedPropName, replacements));
    }

    for (Attribute prop : (List<Attribute>) component.attributes()) {
        String attributeName = prop.getName();
        if (isProperty(prop.getNamespaceURI(), attributeName)) {
            String qualifiedPropName = name + '.' + toCamelCase(prop.getQName().getName(), false);
            Conversions.PropertyValue propValue = null;
            try {
                propValue = getPropertyValue(prop, replacements);
                properties.put(qualifiedPropName, propValue);
            } catch (Exception ex) {
                throw new IllegalArgumentException(String.format(
                        "Exception setting property %s on component %s.  Expression %s evaluated to %s.",
                        qualifiedPropName, name, prop.getValue(), propValue), ex);

            }
        }
    }
}