Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

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// ww  w .  j a v  a2  s. com
 */

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  ww .j av a  2  s  .  c  o  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.jage.platform.config.xml.loaders.ArgumentShortcutExtractor.java

License:Open Source License

private void extractConstrPropShortcuts(final Document document) throws ConfigurationException {
    for (final Element element : selectNodes(CONST_PROP, document)) {
        final Attribute valueAttr = element.attribute(ConfigAttributes.VALUE.toString());
        final Attribute typeAttr = element.attribute(ConfigAttributes.TYPE.toString());
        final Attribute refAttr = element.attribute(ConfigAttributes.REF.toString());

        if (bothNotNull(valueAttr, refAttr)) {
            throw new ConfigurationException(
                    element.getUniquePath() + ": Value and ref shortcut attributes can't be both set");
        }/*  w ww  . j  av  a  2 s  . c  om*/

        if (anyNotNull(valueAttr, refAttr)) {
            if (!element.elements().isEmpty()) {
                throw new ConfigurationException(element.getUniquePath()
                        + ": there can't be both a shortcut attribute and a child definition of some argument");
            }

            if (valueAttr != null) {
                final String value = valueAttr.getValue();
                final String type = typeAttr.getValue();
                element.remove(typeAttr);
                element.remove(valueAttr);
                element.add(newValueElement(type, value));
            } else if (refAttr != null) {
                final String ref = refAttr.getValue();
                element.remove(refAttr);
                element.add(newReferenceElement(ref));
            }
        } else if (element.elements().isEmpty()) {
            throw new ConfigurationException(element.getUniquePath()
                    + ": there must be either a shortcut attribute or a child definition of some argument");
        }
    }
}

From source file:org.jage.platform.config.xml.loaders.ArgumentShortcutExtractor.java

License:Open Source License

@SuppressWarnings("unchecked")
private void extractEntryShortcuts(final Document document) throws ConfigurationException {
    for (final Element element : selectNodes(ENTRIES, document)) {
        final Attribute keyAttr = element.attribute(ConfigAttributes.KEY.toString());
        final Attribute keyRefAttr = element.attribute(ConfigAttributes.KEY_REF.toString());

        if (bothNotNull(keyAttr, keyRefAttr)) {
            throw new ConfigurationException(
                    element.getUniquePath() + ": key and key-ref shortcut attributes can't be both set");
        }// w  ww . j  a v a  2  s.  c  o m

        if (anyNotNull(keyAttr, keyRefAttr)) {
            if (!getChildrenIncluding(element, KEY).isEmpty()) {
                throw new ConfigurationException(element.getUniquePath()
                        + ": there can't be both a key shortcut attribute and a child definition of some argument");
            }

            if (keyAttr != null) {
                final String key = keyAttr.getValue();
                element.remove(keyAttr);
                element.elements().add(0, newKeyElement(newValueElement(key)));
            } else if (keyRefAttr != null) {
                final String keyRef = keyRefAttr.getValue();
                element.remove(keyRefAttr);
                element.elements().add(0, newKeyElement(newReferenceElement(keyRef)));
            }
        } else if (getChildrenIncluding(element, KEY).isEmpty()) {
            throw new ConfigurationException(element.getUniquePath()
                    + ": there must be either a key shortcut attribute or a child definition of some argument");
        }

        final Attribute valueAttr = element.attribute(ConfigAttributes.VALUE.toString());
        final Attribute valueRefAttr = element.attribute(ConfigAttributes.VALUE_REF.toString());

        if (bothNotNull(valueAttr, valueRefAttr)) {
            throw new ConfigurationException(
                    element.getUniquePath() + ": value and value-ref shortcut attributes can't be both set");
        }

        if (anyNotNull(valueAttr, valueRefAttr)) {
            if (!getChildrenExcluding(element, KEY).isEmpty()) {
                throw new ConfigurationException(element.getUniquePath()
                        + ": there can't be both a value shortcut attribute and a child definition of some argument");
            }

            if (valueAttr != null) {
                final String value = valueAttr.getValue();
                element.remove(valueAttr);
                element.add(newValueElement(value));
            } else if (valueRefAttr != null) {
                final String valueRef = valueRefAttr.getValue();
                element.remove(valueRefAttr);
                element.add(newReferenceElement(valueRef));
            }
        } else if (getChildrenExcluding(element, KEY).isEmpty()) {
            throw new ConfigurationException(element.getUniquePath()
                    + ": there must be either a value shortcut attribute or a child definition of some argument");
        }
    }
}

From source file:org.jasig.portal.io.xml.SpELDataTemplatingStrategy.java

License:Apache License

@Override
public Source processTemplates(Document data, String filename) {

    log.trace("Processing templates for document XML={}", data.asXML());
    for (String xpath : XPATH_EXPRESSIONS) {
        @SuppressWarnings("unchecked")
        List<Node> nodes = data.selectNodes(xpath);
        for (Node n : nodes) {
            String inpt, otpt;/*  w  w w.  j a v a 2s.  c  om*/
            switch (n.getNodeType()) {
            case org.w3c.dom.Node.ATTRIBUTE_NODE:
                Attribute a = (Attribute) n;
                inpt = a.getValue();
                otpt = processText(inpt);
                if (otpt == null) {
                    throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename);
                }
                if (!otpt.equals(inpt)) {
                    a.setValue(otpt);
                }
                break;
            case org.w3c.dom.Node.TEXT_NODE:
            case org.w3c.dom.Node.CDATA_SECTION_NODE:
                inpt = n.getText();
                otpt = processText(inpt);
                if (otpt == null) {
                    throw new RuntimeException("Invalid expression '" + inpt + "' in file " + filename);
                }
                if (!otpt.equals(inpt)) {
                    n.setText(otpt);
                }
                break;
            default:
                String msg = "Unsupported node type:  " + n.getNodeTypeName();
                throw new RuntimeException(msg);
            }
        }
    }

    final SAXSource rslt = new DocumentSource(data);
    rslt.setSystemId(filename); // must be set, else import chokes
    return rslt;

}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

License:Apache License

private org.dom4j.Element getExportLayoutDom(IPerson person, IUserProfile profile) {
    if (!this.layoutExistsForUser(person)) {
        return null;
    }/*from   w  ww .  ja  v  a 2  s.  c om*/

    org.dom4j.Document layoutDoc = null;
    try {
        final Document layoutDom = this._safeGetUserLayout(person, profile);
        person.setAttribute(Constants.PLF, layoutDom);
        layoutDoc = this.reader.get().read(layoutDom);
    } catch (final Throwable t) {
        final String msg = "Unable to obtain layout & profile for user '" + person.getUserName()
                + "', profileId " + profile.getProfileId();
        throw new RuntimeException(msg, t);
    }

    if (logger.isDebugEnabled()) {
        // Write out this version of the layout to the log for dev purposes...
        final StringWriter str = new StringWriter();
        final XMLWriter xml = new XMLWriter(str, new OutputFormat("  ", true));
        try {
            xml.write(layoutDoc);
            xml.close();
        } catch (final Throwable t) {
            throw new RuntimeException(
                    "Failed to write the layout for user '" + person.getUserName() + "' to the DEBUG log", t);
        }
        logger.debug("Layout for user: {}\n{}", person.getUserName(), str.getBuffer().toString());
    }

    /*
     * Attempt to detect a corrupted layout; return null in such cases
     */

    if (isLayoutCorrupt(layoutDoc)) {
        logger.warn("Layout for user: {} is corrupt; layout structures will not be exported.",
                person.getUserName());
        return null;
    }

    /*
     * Clean up the DOM for export.
     */

    // (1) Add structure & theme attributes...
    final int structureStylesheetId = profile.getStructureStylesheetId();
    this.addStylesheetUserPreferencesAttributes(person, profile, layoutDoc, structureStylesheetId, "structure");

    final int themeStylesheetId = profile.getThemeStylesheetId();
    this.addStylesheetUserPreferencesAttributes(person, profile, layoutDoc, themeStylesheetId, "theme");

    // (2) Remove locale info...
    final Iterator<org.dom4j.Attribute> locale = (Iterator<org.dom4j.Attribute>) layoutDoc
            .selectNodes("//@locale").iterator();
    while (locale.hasNext()) {
        final org.dom4j.Attribute loc = locale.next();
        loc.getParent().remove(loc);
    }

    // (3) Scrub unnecessary channel information...
    for (final Iterator<org.dom4j.Element> orphanedChannels = (Iterator<org.dom4j.Element>) layoutDoc
            .selectNodes("//channel[@fname = '']").iterator(); orphanedChannels.hasNext();) {
        // These elements represent UP_LAYOUT_STRUCT rows where the 
        // CHAN_ID field was not recognized by ChannelRegistryStore;  
        // best thing to do is remove the elements...
        final org.dom4j.Element ch = orphanedChannels.next();
        ch.getParent().remove(ch);
    }
    final List<String> channelAttributeWhitelist = Arrays.asList(new String[] { "fname", "unremovable",
            "hidden", "immutable", "ID", "dlm:plfID", "dlm:moveAllowed", "dlm:deleteAllowed" });
    final Iterator<org.dom4j.Element> channels = (Iterator<org.dom4j.Element>) layoutDoc
            .selectNodes("//channel").iterator();
    while (channels.hasNext()) {
        final org.dom4j.Element oldCh = channels.next();
        final org.dom4j.Element parent = oldCh.getParent();
        final org.dom4j.Element newCh = this.fac.createElement("channel");
        for (final String aName : channelAttributeWhitelist) {
            final org.dom4j.Attribute a = (org.dom4j.Attribute) oldCh.selectSingleNode("@" + aName);
            if (a != null) {
                newCh.addAttribute(a.getQName(), a.getValue());
            }
        }
        parent.elements().add(parent.elements().indexOf(oldCh), newCh);
        parent.remove(oldCh);
    }

    // (4) Convert internal DLM noderefs to external form (pathrefs)...
    for (final Iterator<org.dom4j.Attribute> origins = (Iterator<org.dom4j.Attribute>) layoutDoc
            .selectNodes("//@dlm:origin").iterator(); origins.hasNext();) {
        final org.dom4j.Attribute org = origins.next();
        final Pathref dlmPathref = this.nodeReferenceFactory.getPathrefFromNoderef(
                (String) person.getAttribute(IPerson.USERNAME), org.getValue(), layoutDoc.getRootElement());
        if (dlmPathref != null) {
            // Change the value only if we have a valid pathref...
            org.setValue(dlmPathref.toString());
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Layout element '{}' from user '{}' failed to match noderef '{}'",
                        org.getUniquePath(), person.getAttribute(IPerson.USERNAME), org.getValue());
            }
        }
    }
    for (final Iterator<org.dom4j.Attribute> it = (Iterator<org.dom4j.Attribute>) layoutDoc
            .selectNodes("//@dlm:target").iterator(); it.hasNext();) {
        final org.dom4j.Attribute target = it.next();
        final Pathref dlmPathref = this.nodeReferenceFactory.getPathrefFromNoderef(
                (String) person.getAttribute(IPerson.USERNAME), target.getValue(), layoutDoc.getRootElement());
        if (dlmPathref != null) {
            // Change the value only if we have a valid pathref...
            target.setValue(dlmPathref.toString());
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Layout element '{}' from user '{}' failed to match noderef '{}'",
                        target.getUniquePath(), person.getAttribute(IPerson.USERNAME), target.getValue());
            }
        }
    }
    for (final Iterator<org.dom4j.Attribute> names = (Iterator<org.dom4j.Attribute>) layoutDoc
            .selectNodes("//dlm:*/@name").iterator(); names.hasNext();) {
        final org.dom4j.Attribute n = names.next();
        if (n.getValue() == null || n.getValue().trim().length() == 0) {
            // Outer <dlm:positionSet> elements don't seem to use the name 
            // attribute, though their childern do.  Just skip these so we 
            // don't send a false WARNING.
            continue;
        }
        final Pathref dlmPathref = this.nodeReferenceFactory.getPathrefFromNoderef(
                (String) person.getAttribute(IPerson.USERNAME), n.getValue(), layoutDoc.getRootElement());
        if (dlmPathref != null) {
            // Change the value only if we have a valid pathref...
            n.setValue(dlmPathref.toString());
            // These *may* have fnames...
            if (dlmPathref.getPortletFname() != null) {
                n.getParent().addAttribute("fname", dlmPathref.getPortletFname());
            }
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Layout element '{}' from user '{}' failed to match noderef '{}'",
                        n.getUniquePath(), person.getAttribute(IPerson.USERNAME), n.getValue());
            }
        }
    }

    // Remove synthetic Ids, but from non-fragment owners only...
    if (!this.isFragmentOwner(person)) {

        /*
         * In the case of fragment owners, the original database Ids allow 
         * us keep (not break) the associations that subscribers have with 
         * nodes on the fragment layout.
         */

        // (5) Remove dlm:plfID...
        for (final Iterator<org.dom4j.Attribute> plfid = (Iterator<org.dom4j.Attribute>) layoutDoc
                .selectNodes("//@dlm:plfID").iterator(); plfid.hasNext();) {
            final org.dom4j.Attribute plf = plfid.next();
            plf.getParent().remove(plf);
        }

        // (6) Remove database Ids...
        for (final Iterator<org.dom4j.Attribute> ids = (Iterator<org.dom4j.Attribute>) layoutDoc
                .selectNodes("//@ID").iterator(); ids.hasNext();) {
            final org.dom4j.Attribute a = ids.next();
            a.getParent().remove(a);
        }
    }

    return layoutDoc.getRootElement();
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
@Transactional//  ww w.ja v  a  2s .c o  m
public void importLayout(org.dom4j.Element layout) {
    if (layout.getNamespaceForPrefix("dlm") == null) {
        layout.add(new Namespace("dlm", "http://www.uportal.org/layout/dlm"));
    }

    //Remove comments from the DOM they break import
    final List<org.dom4j.Node> comments = layout.selectNodes("//comment()");
    for (final org.dom4j.Node comment : comments) {
        comment.detach();
    }

    //Get a ref to the prefs element and then remove it from the layout
    final org.dom4j.Node preferencesElement = layout.selectSingleNode("preferences");
    if (preferencesElement != null) {
        preferencesElement.getParent().remove(preferencesElement);
    }

    final String ownerUsername = layout.valueOf("@username");

    //Get a ref to the profile element and then remove it from the layout
    final org.dom4j.Node profileElement = layout.selectSingleNode("profile");
    if (profileElement != null) {
        profileElement.getParent().remove(profileElement);

        final org.dom4j.Document profileDocument = new org.dom4j.DocumentFactory().createDocument();
        profileDocument.setRootElement((org.dom4j.Element) profileElement);
        profileDocument.setName(ownerUsername + ".profile");

        final DocumentSource profileSource = new DocumentSource(profileElement);
        this.portalDataHandlerService.importData(profileSource);
    }

    final IPerson person = new PersonImpl();
    person.setUserName(ownerUsername);

    int ownerId;
    try {
        //Can't just pass true for create here, if the user actually exists the create flag also updates the user data
        ownerId = this.userIdentityStore.getPortalUID(person);
    } catch (final AuthorizationException t) {
        if (this.errorOnMissingUser) {
            throw new RuntimeException("Unrecognized user " + person.getUserName()
                    + "; you must import users before their layouts or set org.jasig.portal.io.layout.errorOnMissingUser to false.",
                    t);
        }

        //Create the missing user
        ownerId = this.userIdentityStore.getPortalUID(person, true);
    }

    if (ownerId == -1) {
        throw new RuntimeException("Unrecognized user " + person.getUserName()
                + "; you must import users before their layouts or set org.jasig.portal.io.layout.errorOnMissingUser to false.");
    }
    person.setID(ownerId);

    IUserProfile profile = null;
    try {
        person.setSecurityContext(new BrokenSecurityContext());
        profile = this.getUserProfileByFname(person, "default");
    } catch (final Throwable t) {
        throw new RuntimeException("Failed to load profile for " + person.getUserName()
                + "; This user must have a profile for import to continue.", t);
    }

    // (6) Add database Ids & (5) Add dlm:plfID ...
    int nextId = 1;
    for (final Iterator<org.dom4j.Element> it = (Iterator<org.dom4j.Element>) layout
            .selectNodes("folder | dlm:* | channel").iterator(); it.hasNext();) {
        nextId = this.addIdAttributesIfNecessary(it.next(), nextId);
    }
    // Now update UP_USER...
    this.jdbcOperations.update("UPDATE up_user SET next_struct_id = ? WHERE user_id = ?", nextId,
            person.getID());

    // (4) Convert external DLM pathrefs to internal form (noderefs)...
    for (final Iterator<org.dom4j.Attribute> itr = (Iterator<org.dom4j.Attribute>) layout
            .selectNodes("//@dlm:origin").iterator(); itr.hasNext();) {
        final org.dom4j.Attribute a = itr.next();
        final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, a.getValue(), null,
                true, layout);
        if (dlmNoderef != null) {
            // Change the value only if we have a valid pathref...
            a.setValue(dlmNoderef.toString());
            // For dlm:origin only, also use the noderef as the ID attribute...
            a.getParent().addAttribute("ID", dlmNoderef.toString());
        } else {
            // At least insure the value is between 1 and 35 characters
            a.setValue(BAD_PATHREF_MESSAGE);
        }
    }
    for (final Iterator<org.dom4j.Attribute> itr = (Iterator<org.dom4j.Attribute>) layout
            .selectNodes("//@dlm:target").iterator(); itr.hasNext();) {
        final org.dom4j.Attribute a = itr.next();
        final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, a.getValue(), null,
                true, layout);
        // Put in the correct value, or at least insure the value is between 1 and 35 characters
        a.setValue(dlmNoderef != null ? dlmNoderef.toString() : BAD_PATHREF_MESSAGE);
    }
    for (final Iterator<org.dom4j.Attribute> names = (Iterator<org.dom4j.Attribute>) layout
            .selectNodes("//dlm:*/@name").iterator(); names.hasNext();) {
        final org.dom4j.Attribute a = names.next();
        final String value = a.getValue().trim();
        if (!VALID_PATHREF_PATTERN.matcher(value).matches()) {
            /* Don't send it to getDlmNoderef if we know in advance it's not 
             * going to work;  saves annoying/misleading log messages and 
             * possibly some processing.  NOTE this is _only_ a problem with 
             * the name attribute of some dlm:* elements, which seems to go 
             * unused intentionally in some circumstances
             */
            continue;
        }
        final org.dom4j.Attribute fname = a.getParent().attribute("fname");
        Noderef dlmNoderef = null;
        if (fname != null) {
            dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, value, fname.getValue(),
                    false, layout);
            // Remove the fname attribute now that we're done w/ it...
            fname.getParent().remove(fname);
        } else {
            dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, value, null, true, layout);
        }
        // Put in the correct value, or at least insure the value is between 1 and 35 characters
        a.setValue(dlmNoderef != null ? dlmNoderef.toString() : BAD_PATHREF_MESSAGE);
    }

    // (3) Restore chanID attributes on <channel> elements...
    for (final Iterator<org.dom4j.Element> it = (Iterator<org.dom4j.Element>) layout.selectNodes("//channel")
            .iterator(); it.hasNext();) {
        final org.dom4j.Element c = it.next();
        final String fname = c.valueOf("@fname");
        final IPortletDefinition cd = this.portletDefinitionRegistry.getPortletDefinitionByFname(fname);
        if (cd == null) {
            final String msg = "No portlet with fname=" + fname + " exists referenced by node "
                    + c.valueOf("@ID") + " from layout for " + ownerUsername;
            if (errorOnMissingPortlet) {
                throw new IllegalArgumentException(msg);
            } else {
                logger.warn(msg);
                //Remove the bad channel node
                c.getParent().remove(c);
            }
        } else {
            c.addAttribute("chanID", String.valueOf(cd.getPortletDefinitionId().getStringId()));
        }
    }

    // (2) Restore locale info...
    // (This step doesn't appear to be needed for imports)

    // (1) Process structure & theme attributes...
    Document layoutDom = null;
    try {

        final int structureStylesheetId = profile.getStructureStylesheetId();
        this.loadStylesheetUserPreferencesAttributes(person, profile, layout, structureStylesheetId,
                "structure");

        final int themeStylesheetId = profile.getThemeStylesheetId();
        this.loadStylesheetUserPreferencesAttributes(person, profile, layout, themeStylesheetId, "theme");

        // From this point forward we need the user's PLF set as DLM expects it...
        for (final Iterator<org.dom4j.Text> it = (Iterator<org.dom4j.Text>) layout
                .selectNodes("descendant::text()").iterator(); it.hasNext();) {
            // How many years have we used Java & XML, and this still isn't easy?
            final org.dom4j.Text txt = it.next();
            if (txt.getText().trim().length() == 0) {
                txt.getParent().remove(txt);
            }
        }

        final org.dom4j.Element copy = layout.createCopy();
        final org.dom4j.Document doc = this.fac.createDocument(copy);
        doc.normalize();
        layoutDom = this.writer.get().write(doc);
        person.setAttribute(Constants.PLF, layoutDom);

    } catch (final Throwable t) {
        throw new RuntimeException("Unable to set UserPreferences for user:  " + person.getUserName(), t);
    }

    // Finally store the layout...
    try {
        this.setUserLayout(person, profile, layoutDom, true, true);
    } catch (final Throwable t) {
        final String msg = "Unable to persist layout for user:  " + ownerUsername;
        throw new RuntimeException(msg, t);
    }

    if (preferencesElement != null) {
        final int ownerUserId = this.userIdentityStore.getPortalUserId(ownerUsername);
        //TODO this assumes a single layout, when multi-layout support exists portlet entities will need to be re-worked to allow for a layout id to be associated with the entity

        //track which entities from the user's pre-existing set are touched (all non-touched entities will be removed)
        final Set<IPortletEntity> oldPortletEntities = new LinkedHashSet<IPortletEntity>(
                this.portletEntityDao.getPortletEntitiesForUser(ownerUserId));

        final List<org.dom4j.Element> entries = preferencesElement.selectNodes("entry");
        for (final org.dom4j.Element entry : entries) {
            final String dlmPathRef = entry.attributeValue("entity");
            final String fname = entry.attributeValue("channel");
            final String prefName = entry.attributeValue("name");

            final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(person.getUserName(),
                    dlmPathRef, fname, false, layout);

            if (dlmNoderef != null && fname != null) {
                final IPortletEntity portletEntity = this.getPortletEntity(fname, dlmNoderef.toString(),
                        ownerUserId);
                oldPortletEntities.remove(portletEntity);

                final List<IPortletPreference> portletPreferences = portletEntity.getPortletPreferences();

                final List<org.dom4j.Element> valueElements = entry.selectNodes("value");
                final List<String> values = new ArrayList<String>(valueElements.size());
                for (final org.dom4j.Element valueElement : valueElements) {
                    values.add(valueElement.getText());
                }

                portletPreferences.add(
                        new PortletPreferenceImpl(prefName, false, values.toArray(new String[values.size()])));

                this.portletEntityDao.updatePortletEntity(portletEntity);
            }
        }

        //Delete all portlet preferences for entities that were not imported
        for (final IPortletEntity portletEntity : oldPortletEntities) {
            portletEntity.setPortletPreferences(null);

            if (portletEntityRegistry.shouldBePersisted(portletEntity)) {
                this.portletEntityDao.updatePortletEntity(portletEntity);
            } else {
                this.portletEntityDao.deletePortletEntity(portletEntity);
            }
        }
    }
}

From source file:org.jasig.portal.tenants.TemplateDataTenantOperationsListener.java

License:Apache License

@Override
public void onCreate(final ITenant tenant) {

    final StandardEvaluationContext ctx = new StandardEvaluationContext();
    ctx.setRootObject(new RootObjectImpl(tenant));

    /*/*from  ww w. j a v a  2  s  . c o  m*/
     * First load dom4j Documents and sort the entity files into the proper order 
     */
    final Map<PortalDataKey, Set<Document>> importQueue = new HashMap<PortalDataKey, Set<Document>>();
    Resource rsc = null;
    try {
        for (Resource r : templateResources) {
            rsc = r;
            if (log.isDebugEnabled()) {
                log.debug("Loading template resource file for tenant " + "'" + tenant.getFname() + "':  "
                        + rsc.getFilename());
            }
            final Document doc = reader.read(rsc.getInputStream());
            final QName qname = doc.getRootElement().getQName();
            PortalDataKey atLeastOneMatchingDataKey = null;
            for (PortalDataKey pdk : dataKeyImportOrder) {
                // Matching is tougher because it's dom4j <> w3c...
                boolean matches = qname.getName().equals(pdk.getName().getLocalPart())
                        && qname.getNamespaceURI().equals(pdk.getName().getNamespaceURI());
                if (matches) {
                    // Found the right bucket...
                    atLeastOneMatchingDataKey = pdk;
                    Set<Document> bucket = importQueue.get(atLeastOneMatchingDataKey);
                    if (bucket == null) {
                        // First of these we've seen;  create the bucket;
                        bucket = new HashSet<Document>();
                        importQueue.put(atLeastOneMatchingDataKey, bucket);
                    }
                    bucket.add(doc);
                    /*
                     * At this point, we would normally add a break;
                     * statement, but group_membership.xml files need to
                     * match more than one PortalDataKey.
                     */
                }
            }
            if (atLeastOneMatchingDataKey == null) {
                // We can't proceed
                throw new RuntimeException(
                        "No PortalDataKey found for QName:  " + doc.getRootElement().getQName());
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(
                "Failed to process the specified template:  " + (rsc != null ? rsc.getFilename() : ""), e);
    }

    log.trace("Ready to import data entity templates for new tenant '{}';  importQueue={}", tenant.getName(),
            importQueue);

    /*
     * Now import the identified entities each bucket in turn 
     */
    Document doc = null;
    org.w3c.dom.Document w3c = null;
    try {
        for (PortalDataKey pdk : dataKeyImportOrder) {
            Set<Document> bucket = importQueue.get(pdk);
            if (bucket != null) {
                log.debug("Importing the specified PortalDataKey tenant '{}':  {}", tenant.getName(),
                        pdk.getName());
                for (Document d : bucket) {
                    doc = d;
                    log.trace("Importing document XML={}", doc.asXML());
                    for (String xpath : XPATH_EXPRESSIONS) {
                        @SuppressWarnings("unchecked")
                        List<Node> nodes = doc.selectNodes(xpath);
                        for (Node n : nodes) {
                            String inpt, otpt;
                            switch (n.getNodeType()) {
                            case org.w3c.dom.Node.ATTRIBUTE_NODE:
                                Attribute a = (Attribute) n;
                                inpt = a.getValue();
                                otpt = processText(inpt, ctx);
                                if (!otpt.equals(inpt)) {
                                    a.setValue(otpt);
                                }
                                break;
                            case org.w3c.dom.Node.TEXT_NODE:
                                Text t = (Text) n;
                                inpt = t.getText();
                                otpt = processText(inpt, ctx);
                                if (!otpt.equals(inpt)) {
                                    t.setText(otpt);
                                }
                                break;
                            default:
                                String msg = "Unsupported node type:  " + n.getNodeTypeName();
                                throw new RuntimeException(msg);
                            }
                        }
                    }
                    w3c = writer.write(doc, domImpl);
                    Source source = new DOMSource(w3c);
                    source.setSystemId(rsc.getFilename()); // must be set, else import chokes
                    dataHandlerService.importData(source, pdk);
                }
            }
        }

    } catch (Exception e) {
        log.warn("w3c DOM=" + this.nodeToString(w3c));
        throw new RuntimeException(
                "Failed to process the specified template document:  " + (doc != null ? doc.asXML() : ""), e);
    }

}

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  w  w w  .j  a va 2  s.c o  m
        tmp.add(interceptorDescr);
    }
    Descriptor[] descriptors = new Descriptor[tmp.size()];
    tmp.toArray(descriptors);
    return descriptors;
}

From source file:org.jbpm.gd.jpdl.editor.JpdlContentProvider.java

License:Open Source License

private void processServerName(DeploymentInfo deploymentInfo, Attribute attribute, IPreferenceStore prefs) {
    if (attribute == null) {
        deploymentInfo.setServerName(prefs.getString(SERVER_NAME));
    } else {//from  w ww  . ja  va  2s.  co m
        deploymentInfo.setServerName(attribute.getValue());
    }
}