Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName, String defaultValue);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or the default value if there is no such attribute value.

Usage

From source file:batch.performance.ScriptScenario.java

License:Open Source License

/**
 * Parses ECMAScript-based scenario from XML description
 * of the form://from   w ww  .j  av  a2 s.c o m
 * 
 * <pre><xmp>
 * <scenario>
 *   <prepare> ... </prepare>
 *   <run> ... </run>
 *   <teardown> ... </teardown>
 * </scenario>
 */
public ScriptScenario(Element performanceElement) {
    prepareScript = performanceElement.elementText("prepare");
    runScript = performanceElement.elementText("run");
    teardownScript = performanceElement.elementText("teardown");

    name = performanceElement.attributeValue("name", "script-based scenario");
}

From source file:com.arc.intro.CompilerSamplesProvider.java

License:Open Source License

private Toolset[] computeRecognizedToolsets() {
    if (mRecognizedToolsets == null) {
        List<Element> targets = Cast.toType(samplesDoc.getRootElement().elements(TARGET_TAG));
        Toolset[] result = new Toolset[targets.size()];
        int i = 0;
        for (Element target : targets) {
            String name = target.attributeValue(NAME_ATTR, "???");
            String desc = target.attributeValue(DESC_ATTR, "???");
            result[i++] = new Toolset(name, desc);
        }/*ww  w . j a  va2s  .  c  o m*/
        assert (i == result.length);
        mRecognizedToolsets = result;
    }
    return mRecognizedToolsets;
}

From source file:com.arc.intro.CompilerSamplesProvider.java

License:Open Source License

private String getProjectDescription(Element cat, File projectFile) {
    List<Element> projects = Cast.toType(cat.elements(PROJECT_TAG));
    String projectName = projectFile.getName();
    for (Element projectElement : projects) {
        if (projectName.equals(projectElement.attributeValue(NAME_ATTR, null))) {
            return projectElement.getTextTrim();
        }/* w w w .j ava2  s.  co  m*/
    }
    File readmeFile = new File(projectFile, "README.txt");
    if (readmeFile.exists()) {
        try {
            FileReader reader = new FileReader(readmeFile);
            BufferedReader input = new BufferedReader(reader);
            StringBuilder buf = new StringBuilder();
            String line = input.readLine();
            while (line != null) {
                buf.append(line);
                buf.append("\n");
                line = input.readLine();
            }
            return buf.toString();
        } catch (IOException e) {
            //couldn't read the "README.txt" file.
        }
    }
    return "";
}

From source file:com.arc.intro.CompilerSamplesProvider.java

License:Open Source License

private Category[] computeSampleCategories(Toolset ts) {
    List<Element> categories = Cast.toType(samplesDoc.getRootElement().elements(CATEGORY_TAG));
    List<Category> list = new ArrayList<Category>();
    File demosDir = computeDemosDirForToolset(ts.name);
    if (demosDir.isDirectory()) {
        for (Element c : categories) {
            String title = c.attributeValue(TITLE_ATTR, "?title?");
            String id = c.attributeValue(ID_ATTR, "compiler");
            String wsPattern = c.attributeValue(WORKSPACE_ATTR, ".*");
            File wsDirs[] = findWorkspacesIn(demosDir, wsPattern);
            List<Sample> samples = new ArrayList<Sample>();
            for (File wsDir : wsDirs) {
                File projects[] = computeProjectsWithin(wsDir);
                for (File project : projects) {
                    Sample s = new Sample();
                    s.projectName = project.getName();
                    s.toolsetName = ts.desc;
                    s.project = project;
                    s.description = getProjectDescription(c, project);
                    samples.add(s);/*from www  .  j ava  2 s . co  m*/
                }
            }
            if (samples.size() > 0) {
                Category cat = new Category();
                cat.samples = samples.toArray(new Sample[samples.size()]);
                cat.title = title;
                cat.id = id;
                list.add(cat);
            }
        }
    }
    return list.toArray(new Category[list.size()]);
}

From source file:com.arc.seecode.internal.display.UserGuiWalker.java

License:Open Source License

/**
 * Walk a menu description and fill in an existing
 * menu description./*  w w  w.ja v  a  2 s  .co  m*/
 * @param root the XML representation of the menu.
 * @param md the menu description to fill in.
 */
public void walk(Element root, MenuDescriptor md) {
    String rootName = root.getName();
    if (rootName.equals("menu")) {
        String name = root.attributeValue("name", "missing-menu-name");
        MenuDescriptor subMD = new MenuDescriptor();
        doKids(root, subMD);
        md.addSubMenu(name, name, subMD);
    } else if (rootName.equals("menuitem") || rootName.equals("menu_item")) {
        final String menu_name = root.attributeValue("name", "missing-menuitem-name");
        final String id = root.attributeValue("id", menu_name);
        //           String sc = root.attributeValue("shortcut");
        String checkbox = root.attributeValue("checkbox");
        String radio_group = root.attributeValue("checkbox_group");
        String selectValue = root.attributeValue("on_select");
        if (selectValue == null)
            selectValue = root.attributeValue("onselect", menu_name);
        final String displayKind = root.attributeValue("display");
        final String valueWhenSelected = selectValue;
        // Now record the group with the created menu item.
        if (checkbox != null && checkbox.charAt(0) == '1') {
            final String initial = root.attributeValue("initial");

            md.addCheckBoxMenuItem(id, menu_name, new MenuDescriptor.ICheckBoxObserver() {

                @Override
                public void selectionChanged(String checkBoxID, boolean value) {
                    String s = (value ? "1" : "0") + valueWhenSelected;
                    //                          First digit is state; rest is identification.
                    doSelection(s);
                    mCheckBoxRecorder.saveCheckBoxValue(checkBoxID, value);
                }
            }, initial != null && initial.equals("1"), radio_group);

        } else {
            md.addMenuItem(id, menu_name, new MenuDescriptor.IActionObserver() {

                @Override
                public void actionPerformed(String name) {
                    //NOTE: "display" was added late, and we have
                    // specifications that include "select_on" in case "display"
                    // isn't supported. So, "display" overrides "select_on"
                    if (displayKind != null) {
                        mDisplayActivator.activateDisplay(displayKind);
                    } else if (valueWhenSelected != null)
                        doSelection(valueWhenSelected);

                }
            });
        }
        //            String enabled = lookupAttribute("enabled");
        //            if (enabled != null)
        //                M.setEnabled(enabled.charAt(0) != '0');
        //            if (sc != null && sc.length() > 0) {
        //                M.setMnemonic(sc.charAt(0)/*
        //                                           * , lookupAttribute("shortcut_shift") !=
        //                                           * null
        //                                           */);
        //            }
    } else if (rootName.equals("menuseparator") || rootName.equals("menu_separator")) {
        md.addSeparator();
    } else if (rootName.equals("sequence") || rootName.equals("gui")) {
        // A vector of objects.
        // Absorb any vectors below into this one so we just have
        // one top-level vector.
        doKids(root, md);
    } else {
        throw new IllegalArgumentException("Missing component property in form: " + root.getName());
    }

}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMJpdlXmlReader.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w w .  jav a2 s . com*/
  */
@Override
protected void readNodeTimer(Element timerElement, Node node) {
    // NOTE: This method implementation is a copy from the JpdlXmlReader class
    //       with the difference of constructing an AlfrescoCreateTimerAction.
    //       It may need to be updated whenever a jbpm library upgrade is performed.

    String name = timerElement.attributeValue("name", node.getName());
    if (logger.isDebugEnabled())
        logger.debug("Create Timer using BX CustomCreateTimerAction");

    CreateTimerAction createTimerAction = new CustomCreateTimerAction();
    createTimerAction.read(timerElement, this);
    createTimerAction.setTimerName(name);
    createTimerAction.setTimerAction(readSingleAction(timerElement));
    addAction(node, Event.EVENTTYPE_NODE_ENTER, createTimerAction);

    CancelTimerAction cancelTimerAction = new CancelTimerAction();
    cancelTimerAction.setTimerName(name);
    addAction(node, Event.EVENTTYPE_NODE_LEAVE, cancelTimerAction);
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMJpdlXmlReader.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w w  . jav a2 s.c o m*/
  */
@Override
protected void readTaskTimer(Element timerElement, Task task) {
    // NOTE: This method implementation is a copy from the JpdlXmlReader class
    //       with the difference of constructing an AlfrescoCreateTimerAction.
    //       It may need to be updated whenever a jbpm library upgrade is performed.

    String name = timerElement.attributeValue("name", task.getName());
    if (name == null)
        name = "timer-for-task-" + task.getId();
    if (logger.isDebugEnabled())
        logger.debug("Create Task Timer using BX CustomCreateTimerAction");

    CreateTimerAction createTimerAction = new CustomCreateTimerAction();
    createTimerAction.read(timerElement, this);
    createTimerAction.setTimerName(name);
    Action action = null;
    if ("timer".equals(timerElement.getName())) {
        action = readSingleAction(timerElement);
    } else {
        Delegation delegation = createMailDelegation("task-reminder", null, null, null, null);
        action = new Action(delegation);
    }
    createTimerAction.setTimerAction(action);
    addAction(task, Event.EVENTTYPE_TASK_CREATE, createTimerAction);

    // read the cancel-event types
    Collection<String> cancelEventTypes = new ArrayList<String>();

    String cancelEventTypeText = timerElement.attributeValue("cancel-event");
    if (cancelEventTypeText != null) {
        // cancel-event is a comma separated list of events
        StringTokenizer tokenizer = new StringTokenizer(cancelEventTypeText, ",");
        while (tokenizer.hasMoreTokens()) {
            cancelEventTypes.add(tokenizer.nextToken().trim());
        }
    } else {
        // set the default
        cancelEventTypes.add(Event.EVENTTYPE_TASK_END);
    }
    for (String cancelEventType : cancelEventTypes) {
        CancelTimerAction cancelTimerAction = new CancelTimerAction();
        cancelTimerAction.setTimerName(name);
        addAction(task, cancelEventType, cancelTimerAction);
    }
}