Example usage for org.jdom2 Attribute getValue

List of usage examples for org.jdom2 Attribute getValue

Introduction

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

Prototype

public String getValue() 

Source Link

Document

This will return the actual textual value of this Attribute.

Usage

From source file:org.universaal.tools.configurationEditor.editors.ConfigurationEditor.java

License:Apache License

private void showMapConfigItem(Element el) {
    for (Control wi : selectedItemGroup.getChildren()) {
        wi.dispose();/* www .  j a  v  a2s. c  o  m*/
    }

    List<Attribute> tiAtts = el.getAttributes();
    Label l1;
    Text t1;

    for (Attribute att : tiAtts) {
        l1 = new Label(selectedItemGroup, SWT.NONE);
        l1.setText(att.getName() + ":");

        t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER);
        t1.setEditable(true);
        t1.setText(att.getValue());

        // ------------- <Listener> --------------

        WidgetMapping.put(t1, att);
        t1.addModifyListener(widgetListener);

        // ------------- </Listener> --------------

        GridData gd = new GridData();
        gd.horizontalAlignment = GridData.FILL;
        gd.grabExcessHorizontalSpace = true;
        t1.setLayoutData(gd);
    }

    // TI's children
    List<Element> tiEls = el.getChildren();

    for (Element tiEl : tiEls) {

        // mapConfigItem
        if (tiEl.getName().equals("options")) {
            //            l1 = new Label(selectedItemGroup, SWT.NONE);
            //            l1.setText(tiEl.getName() + ":");

            //            Combo combo = new Combo(selectedItemGroup, SWT.NONE | SWT.READ_ONLY);

            List<Element> opt = tiEl.getChildren();
            for (Element e : opt) {
                l1 = new Label(selectedItemGroup, SWT.NONE);
                l1.setText(e.getName() + ":");
                t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER);
                t1.setEditable(true);
                t1.setText(e.getValue());

                // ------------- <Listener> --------------
                WidgetMapping.put(t1, e);
                t1.addModifyListener(widgetListener);
                // ------------- </Listener> --------------

                GridData gd = new GridData();
                gd.horizontalAlignment = GridData.FILL;
                gd.grabExcessHorizontalSpace = true;
                t1.setLayoutData(gd);
            }

            //            GridData gd = new GridData();
            //            gd.horizontalAlignment = GridData.FILL;
            //            gd.grabExcessHorizontalSpace = true;
            //            combo.setLayoutData(gd);

            // Validators
        } else if (tiEl.getName().equals("validators")) {
            //DO NOTHING!
        } else {

            l1 = new Label(selectedItemGroup, SWT.NONE);
            l1.setText(tiEl.getName() + ":");

            t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER);
            t1.setEditable(true);
            t1.setText(tiEl.getValue());

            // ------------- <Listener> --------------

            WidgetMapping.put(t1, tiEl);
            t1.addModifyListener(widgetListener);

            // ------------- </Listener> --------------

            GridData gd = new GridData();
            gd.horizontalAlignment = GridData.FILL;
            gd.grabExcessHorizontalSpace = true;
            t1.setLayoutData(gd);
        }
    }

}

From source file:org.xflatdb.xflat.db.ElementTable.java

License:Apache License

private String getId(Element element) {
    Attribute a = element.getAttribute("id", XFlatConstants.xFlatNs);
    if (a != null) {
        return a.getValue();
    }/* www.j  av  a  2s  .co  m*/

    return null;
}

From source file:org.yawlfoundation.yawl.elements.YAttributeMap.java

License:Open Source License

/**
 * Replace the stored attributes (if any) with the JDOM attributes specified.
 * @param jdomAttributes a List of JDOM Attribute objects to convert to key=value
 * pairs and place in this map, replacing any previous contents.
 *///ww w  . j a  v a  2s  .  co m
public void fromJDOM(List<Attribute> jdomAttributes) {
    if (jdomAttributes != null) {
        clear();
        for (Attribute attribute : jdomAttributes) {
            put(attribute.getName(), attribute.getValue());
        }
    }
}

From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java

License:Open Source License

/**
 * Gets an attribute value, fixing its namespace prefix (if any)
 * @param attribute the attribute to get the value for
 * @param prefix the correct namespace prefix
 * @param defNS the default namespace//from w  w w . j a  v  a2  s .  com
 * @return the attribute's value with the prefix corrected if required
 */
private String getAttributeValue(Attribute attribute, String prefix, Namespace defNS) {
    String value = attribute.getValue();
    if (prefix.length() > 0) {
        value = value.replaceFirst(prefix, defNS.getPrefix());
    }
    return value;
}

From source file:org.yawlfoundation.yawl.scheduling.PlanningGraphCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
/**//from  w  w  w.j a  v  a2  s.  c om
 * TODO@tbe: determine order of activities, store them as utilisation relations and sort
 * activities according to utilisation relations
 */
public Collection<Element> getActivityElements(String caseId)
        throws IOException, JDOMException, JaxenException {
    Element element = SchedulingService.getInstance().getSpecificationForCase(caseId);
    Document doc = new Document(element);

    Map<String, String> map = new HashMap<String, String>();
    map.put("bla", element.getNamespace().getURI());
    for (Object o : element.getAdditionalNamespaces()) {
        Namespace ns = (Namespace) o;
        map.put(ns.getPrefix(), ns.getURI());
    }

    org.jaxen.XPath xp = new JDOMXPath("//bla:expression/@query");
    xp.setNamespaceContext(new SimpleNamespaceContext(map));
    List<Attribute> list = xp.selectNodes(doc);
    List<String> activityNames = new ArrayList<String>();
    for (Attribute e : list) {
        String value = e.getValue();
        int startIndex = value.indexOf("<" + XML_ACTIVITYNAME + ">");
        int endIndex = value.indexOf("</" + XML_ACTIVITYNAME + ">");
        while (startIndex >= 0 && endIndex > startIndex) {
            if (!value.startsWith("<" + XML_EVENT_RECEIVE + ">")) {
                String activityName = value.substring(startIndex + lenActName, endIndex).trim();

                // ignore XPath expressions
                if (!activityName.contains("/") && !activityNames.contains(activityName)) {
                    activityNames.add(activityName);
                }
            }
            value = value.substring(endIndex + lenActName);
            startIndex = value.indexOf("<" + XML_ACTIVITYNAME + ">");
            endIndex = value.indexOf("</" + XML_ACTIVITYNAME + ">");
        }
    }

    //TODO@tbe: sort activities, only until order of activities can be determined from process model
    final List<String> possibleActivities = Utils
            .parseCSV(PropertyReader.getInstance().getSchedulingProperty("possibleActivitiesSorted"));
    Collections.sort(activityNames, new Comparator<String>() {
        public int compare(String a1, String a2) {
            if (possibleActivities.indexOf(a1) < 0) {
                return -1; // set missing activities at beginning
            } else if (possibleActivities.indexOf(a2) < 0) {
                return 1; // set missing activities at beginning
            } else {
                return possibleActivities.indexOf(a1) - possibleActivities.indexOf(a2);
            }
        }
    });
    logger.debug("activityNames: " + Utils.toString(activityNames));

    Collection<Element> activities = new ArrayList<Element>();
    Element preRelation = null; // relation of previous activity
    for (int i = 0; i < activityNames.size(); i++) {
        String activityName = activityNames.get(i);
        if (i > 0) {
            preRelation.getChild(XML_OTHERACTIVITYNAME).setText(activityName);
        }

        Element activity = FormGenerator.getTemplate(XML_ACTIVITY);
        activities.add(activity);
        activity.getChild(XML_ACTIVITYNAME).setText(activityName);

        if (i < activityNames.size() - 1) {
            preRelation = FormGenerator.getTemplate(XML_UTILISATIONREL);
            activity.addContent(preRelation);
        }
    }
    return activities;
}

From source file:org.yawlfoundation.yawl.scheduling.util.Utils.java

License:Open Source License

public static String attribute2String(Attribute a) {
    if (a == null)
        return null;
    else/*w w  w.  j ava2 s . c o  m*/
        return a.getName() + "=" + a.getValue();
}

From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java

License:Open Source License

private static String getAttributeFromSchema(String elementName, String attributeXPath) {
    String value = null;//from w w  w .j a  va2  s . c om
    try {
        String xpath = "//xs:element[@name='" + elementName + "']/" + attributeXPath;

        for (Document doc : getSchemaDocs()) {
            Attribute attr = getAttribute(doc, xpath);
            if (attr != null) {
                value = attr.getValue();
                break;
            }
        }
    } catch (Exception e) {
        logger.error("cannot load '" + attributeXPath + "' from element '" + elementName + "' from XSD", e);
    }
    return value;
}

From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java

License:Open Source License

/**
 * merges content of two elements recursively into element minor following
 * content will be copied: Text, Element, Attribute if conflicts, minor will
 * be overwrite with content of major/*from   w  w w. j  a  va 2  s.c o  m*/
 * 
 * @param minor
 * @param major
 */
public static boolean mergeElements(Element minor, Element major) throws Exception {
    // logger.debug("minor: " + Utils.element2String(minor, false));
    // logger.debug("major: " + Utils.element2String(major, false));
    boolean changed = false;
    if (minor == null) {
        minor = major;
        // logger.debug("set minor = " + Utils.element2String(major, false));
        changed = true;
    } else if (major != null) {
        if (!minor.getText().equals(major.getText())) {
            minor.setText(major.getText());
            // logger.debug("minor.setText("+major.getText()+")");
            changed = true;
        }

        for (Attribute a : (List<Attribute>) major.getAttributes()) {
            Attribute aCopy = (Attribute) Utils.deepCopy(a);
            if (minor.getAttribute(a.getName()) == null
                    || !minor.getAttributeValue(a.getName()).equals(a.getValue())) {
                minor.setAttribute(aCopy.detach());
                // logger.debug("minor.setAttribute("+Utils.toString(a)+")");
                changed = true;
            }
        }

        for (Element e : (List<Element>) major.getChildren()) {
            Element eCopy = (Element) Utils.deepCopy(e);
            List<Element> minorChildren = minor.getChildren(e.getName());
            // logger.debug("minorChildren: " + Utils.toString(minorChildren));
            // logger.debug("e: " + Utils.toString(e));
            Element firstInList = existInList(minorChildren, e);
            if (firstInList == null) {
                // logger.debug("minor.addContent: " +
                // Utils.toString(eCopy.detach()));
                minor = minor.addContent(eCopy.detach());
                // logger.debug("minor.addContent("+Utils.element2String(e,
                // false)+")");
                changed = true;
            } else {
                changed = mergeElements(firstInList, eCopy) || changed;
            }
        }
    }

    return changed;
}

From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java

License:Open Source License

private YDecomposition createDecomposition(Element decompElem) {
    Namespace schemaInstanceNS = decompElem.getNamespace("xsi");
    String xsiType = _decompElem.getAttributeValue("type", schemaInstanceNS);
    String id = _decompElem.getAttributeValue("id");

    String elementName = _decompElem.getName();
    if ("NetFactsType".equals(xsiType) || "rootNet".equals(elementName)) {
        _decomposition = new YNet(id, _specificationParser.getSpecification());
        parseNet((YNet) _decomposition, decompElem);
    } else if ("WebServiceGatewayFactsType".equals(xsiType)) {
        _decomposition = new YAWLServiceGateway(id, _specificationParser.getSpecification());
        parseWebServiceGateway((YAWLServiceGateway) _decomposition, decompElem);
    }/*from w w w.  j ava 2  s.com*/
    /**
     * AJH: Added to support XML attribute pass-thru from specification into task output data doclet.
     * Load element attributes
     */
    for (Attribute attr : decompElem.getAttributes()) {
        String attname = attr.getName();
        boolean isXsiNS = attr.getNamespace() == schemaInstanceNS;

        //don't add the standard YAWL schema attributes to the pass through list.
        if (!("id".equals(attname) || ("type".equals(attname) && isXsiNS))) {
            String value = attr.getValue();
            if (value.startsWith("dynamic{")) {
                _decomposition.setAttribute(attr.getName(), new DynamicValue(value, _decomposition));
            } else
                _decomposition.setAttribute(attr.getName(), value);
        }
    }

    parseDecompositionRoles(_decomposition, decompElem);
    _decomposition.setLogPredicate(parseLogPredicate(decompElem, _yawlNS));

    // added for resourcing
    parseExternalInteraction(_decomposition, decompElem);
    parseCodelet(_decomposition, decompElem);

    return _decomposition;
}

From source file:org.yawlfoundation.yawl.unmarshal.YSpecificationParser.java

License:Open Source License

private void parseSpecification(Element specificationElem, YSchemaVersion version) throws YSyntaxException {
    List<Element> decompositionElems = specificationElem.getChildren("decomposition", _yawlNS);
    for (Element decompositionElem : decompositionElems) {
        Namespace xsiNameSpc = decompositionElem.getNamespace("xsi");
        String decompID = decompositionElem.getAttributeValue("id");
        Attribute type = decompositionElem.getAttribute("type", xsiNameSpc);
        if (type != null) {
            String decompType = type.getValue();
            _decompAndTypeMap.put(decompID, decompType);
        }//from   w  ww .j  av  a 2s .c om
    }
    String uriString = specificationElem.getAttributeValue("uri");
    _specification = new YSpecification(uriString);
    _specification.setVersion(version);
    _specification.setMetaData(parseMetaData(specificationElem));
    String name = specificationElem.getChildText("name", _yawlNS);
    String documentation = specificationElem.getChildText("documentation", _yawlNS);

    // if name and doco fields missing from spec, see if they are in metadata
    if (name == null)
        name = _specification.getMetaData().getTitle();
    if (documentation == null)
        documentation = _specification.getMetaData().getDescription();
    _specification.setName(name);
    _specification.setDocumentation(documentation);

    Namespace schema4SchemaNS = Namespace.getNamespace(_schema4SchemaURI);
    Element schemaElem = specificationElem.getChild("schema", schema4SchemaNS);
    if (null != schemaElem) {
        extractEmptyComplexTypeFlagTypeNames(schemaElem);
        _specification.setSchema(JDOMUtil.elementToString(schemaElem));
    } else {

        // if the spec has no schema definition insert a default one so that a
        // DataValidator gets created
        _specification.setSchema(_defaultSchema);
    }

    //If is version beta2 we loop through in a slightly different way.
    if (isBeta2Version()) {
        _decompositionParser = new YDecompositionParser[decompositionElems.size() + 1];
        Element rootNetElem = specificationElem.getChild("rootNet", _yawlNS);
        _decompositionParser[0] = new YDecompositionParser(rootNetElem, this,
                _specification.getSchemaVersion());
        YNet rootNet = (YNet) _decompositionParser[0].getDecomposition();
        _specification.setRootNet(rootNet);

        for (int i = 1; i <= decompositionElems.size(); i++) {
            Element decompositionElem = decompositionElems.get(i - 1);
            _decompositionParser[i] = new YDecompositionParser(decompositionElem, this,
                    _specification.getSchemaVersion());
            YDecomposition decomposition = _decompositionParser[i].getDecomposition();
            _specification.addDecomposition(decomposition);
        }
    } else {//must be beta3 or greater
        _decompositionParser = new YDecompositionParser[decompositionElems.size()];
        for (int i = 0; i < decompositionElems.size(); i++) {
            Element decompositionElem = decompositionElems.get(i);
            _decompositionParser[i] = new YDecompositionParser(decompositionElem, this,
                    _specification.getSchemaVersion());
            YDecomposition decomposition = _decompositionParser[i].getDecomposition();
            _specification.addDecomposition(decomposition);
        }
    }
    addSchema(specificationElem);
}