Example usage for org.jdom2 Element getNamespace

List of usage examples for org.jdom2 Element getNamespace

Introduction

In this page you can find the example usage for org.jdom2 Element getNamespace.

Prototype

public Namespace getNamespace() 

Source Link

Document

Returns the element's Namespace .

Usage

From source file:de.hbrs.oryx.yawl.converter.handler.oryx.OryxTaskHandler.java

License:Open Source License

private void convertTimer(final YTask task) throws ConversionException {
    if (getShape().hasProperty("timer") && !getShape().getProperty("timer").isEmpty()) {
        Element root = YAWLUtils.parseToElement(getShape().getProperty("timer")).detachRootElement();
        Element artificalParent = new Element("task", YAWLUtils.YAWL_NS);
        artificalParent.addContent(root);
        // TODO replace this by some other code
        parseTimerParameters(task, artificalParent, root.getNamespace());
    }//from   w  w  w .  ja  v  a 2s . com
}

From source file:de.hbrs.oryx.yawl.converter.handler.yawl.element.AtomicTaskHandler.java

License:Open Source License

private HashMap<String, String> convertResourcing(final Element resourcingSpecs) {
    HashMap<String, String> properties = new HashMap<String, String>();

    if (resourcingSpecs == null) {
        getContext().addConversionWarnings("No resourcing specification " + getNetElement().getID(), null);
        return properties;
    }/*ww  w .  ja v  a 2s.  com*/

    Element offer = resourcingSpecs.getChild("offer", resourcingSpecs.getNamespace());
    if (offer != null) {
        properties.put("offerinitiator", offer.getAttributeValue("initiator"));
        properties.put("offerinteraction", YAWLUtils.elementToString(offer.getChildren()));
    }

    Element allocate = resourcingSpecs.getChild("allocate", resourcingSpecs.getNamespace());
    if (allocate != null) {
        properties.put("allocateinitiator", allocate.getAttributeValue("initiator"));
        properties.put("allocateinteraction", YAWLUtils.elementToString(allocate.getChildren()));
    }

    Element start = resourcingSpecs.getChild("start", resourcingSpecs.getNamespace());
    if (start != null) {
        properties.put("startinitiator", start.getAttributeValue("initiator"));
        properties.put("startinteraction", YAWLUtils.elementToString(start.getChildren()));
    }

    Element privileges = resourcingSpecs.getChild("privileges", resourcingSpecs.getNamespace());
    if (privileges != null) {
        properties.put("privileges", YAWLUtils.elementToString(privileges.getChildren()));
    }

    return properties;
}

From source file:de.hbrs.oryx.yawl.converter.handler.yawl.element.TaskHandler.java

License:Open Source License

/**
 * Converting the properties of a net.<br/>
 * CONTRACT: Sub-Classes have to call this method first, adding their properties afterwards.
 *
 * @param layout//from   w  ww  .ja v  a  2  s. co m
 *            of the YAWL task read from layout XML
 * @return Oryx Property HashMap
 */
protected HashMap<String, String> convertTaskProperties(final NetElementLayout layout) {
    HashMap<String, String> properties = new HashMap<String, String>();
    properties.put("yawlid", getTask().getID());
    if (layout.hasJoinDecorator()) {
        properties.put("join", convertConnectorType(getTask().getJoinType(), layout.getJoinDecorator()));
    }
    if (layout.hasSplitDecorator()) {
        properties.put("split", convertConnectorType(getTask().getSplitType(), layout.getSplitDecorator()));
    }

    properties.put("name", getTask().getName());

    if (getTask().getDocumentation() != null && !getTask().getDocumentation().isEmpty()) {
        properties.put("documentation", getTask().getDocumentation());
    }

    try {
        properties.put("cancelationset", convertCancelationSet(getTask()));
    } catch (JSONException e) {
        getContext().addConversionWarnings("Could not convert Cancelation Set " + getTask().getID(), e);
    }

    try {
        properties.put("flowsinto", convertFlowsInto(getTask()));
    } catch (JSONException e) {
        getContext().addConversionWarnings("Could not convert Flows Into " + getTask().getID(), e);
    }

    String iconPath = layout.getIconPath();
    if (iconPath != null && !iconPath.isEmpty()) {
        String[] splitPath = iconPath.split("/");
        String filename = splitPath[splitPath.length - 1];
        properties.put("icon", filename.substring(0, filename.length() - 4));
    }

    if (getTask().getCustomFormURL() != null) {
        properties.put("customform", getTask().getCustomFormURL().toString());
    }

    // The name ConfigurationElement is misleading, it contains the whole
    // Task XML
    Element configurationElement = getTask().getConfigurationElement();
    if (configurationElement != null) {
        Element realConfigurationElement = configurationElement.getChild("configuration",
                configurationElement.getNamespace());
        if (realConfigurationElement != null) {
            properties.put("configuration", YAWLUtils.elementToString(realConfigurationElement));
        }
    }

    if (getTask().getTimeParameters() != null) {
        properties.put("timer", getTask().timerParamsToXML());
    }

    if (hasDecomposition()) {
        // Only needs decomposition as lookup, does not really convert
        // information of the decomposition

        try {
            properties.put("inputparameters", convertInputParamMappings());
        } catch (JSONException e) {
            getContext().addConversionWarnings("Could not convert Input Parameters " + getTask().getID(), e);
        }
        try {
            properties.put("outputparameters", convertOutputParamMappings());
        } catch (JSONException e) {
            getContext().addConversionWarnings("Could not convert Output Parameters " + getTask().getID(), e);
        }
    }

    return properties;
}

From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutArranger.java

License:Open Source License

public Element arrangeLayout(Element root) throws JDOMException, IOException {
    sb = new StringBuilder();
    sb.append("<layout>");
    sb.append("<specification id=\"Initial\">");
    sb.append("<size w=\"1000\" h=\"1000\"/>");

    List<Element> specifications = root.getChildren("specification", root.getNamespace());
    for (Element specification : specifications) {
        List<Element> decompositions = specification.getChildren("decomposition", root.getNamespace());
        for (Element yawlDecomposition : decompositions) {
            createNet(yawlDecomposition);
        }//  ww w  . j av a  2s . c o  m
    }
    sb.append("<labelFontSize>12</labelFontSize>");
    sb.append("</specification>");
    sb.append("</layout>");

    String XMLLayoutContent = sb.toString();

    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(XMLLayoutContent));
    return document.getRootElement();
}

From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutArranger.java

License:Open Source License

private void createNet(Element yawlDecomposition) {
    String isRootNet = yawlDecomposition.getAttributeValue("isRootNet");
    if (Boolean.parseBoolean(isRootNet)) {
        String id = yawlDecomposition.getAttributeValue("id");
        sb.append("<net id=\"" + id + "\">");
        createFakeXYWH();/*from ww  w .  ja va2  s.  c  om*/
        Element yawlProcessControlElements = yawlDecomposition.getChild("processControlElements",
                yawlDecomposition.getNamespace());
        if (yawlProcessControlElements != null) {
            createVertexesAndFlows(yawlProcessControlElements);
        }
        sb.append("</net>");
    }

}

From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutArranger.java

License:Open Source License

private List<String> searchFlows(Element element) {
    List<String> res = new LinkedList<String>();
    String sourceId = element.getAttributeValue("id"), targetId;
    List<Element> flowsIntos = element.getChildren("flowsInto", element.getNamespace());
    for (Element flowInto : flowsIntos) {
        List<Element> nextElementRefs = flowInto.getChildren("nextElementRef", element.getNamespace());
        for (Element nextElementRef : nextElementRefs) {
            targetId = nextElementRef.getAttributeValue("id");
            res.add("<flow source=\"" + sourceId + "\" target=\"" + targetId + "\">");
        }// ww  w  .java 2s.  c o  m
    }
    return res;
}

From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java

License:Open Source License

private void initXMLReader() throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(specificationString));
    Element root = document.getRootElement();
    layout = root.getChild("layout", root.getNamespace());
    if (layout == null)
        layout = yawlLayoutArranger.arrangeLayout(root);
    yawlNamespace = layout.getNamespace();
    setYAWLLocale(layout);//from  w ww .  j a va  2  s  .c o m
}

From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java

License:Open Source License

/**
 * Constructor// ww w  .j  av  a  2 s  .  c  om
 *
 * @param graphml_filename the GraphML Filenam
 */
public GraphmlParser(String graphml_filename) {
    try {
        Document doc = new SAXBuilder().build(graphml_filename);
        Element graphml = doc.getRootElement();
        this.ns = graphml.getNamespace();
        this.graph = graphml.getChild("graph", this.ns);
        List<Element> list = graphml.getChildren("key", ns);
        for (Element e : list) {
            String s = e.getAttributeValue("attr.name");
            switch (s) {
            case "Latitude":
                latitude_key = e.getAttributeValue("id");

                break;
            case "Country":
                country_key = e.getAttributeValue("id");

                break;
            case "Internal":
                internal_key = e.getAttributeValue("id");

                break;
            case "id":
                if (e.getAttributeValue("for").equals("node")) {
                    id_key = e.getAttributeValue("id");

                }
                break;
            case "Longitude":
                longitude_key = e.getAttributeValue("id");

                break;
            case "label":
                if (e.getAttributeValue("for").equals("node")) {
                    label_key = e.getAttributeValue("id");

                }
                break;
            case "LinkLabel":
                linklabel_key = e.getAttributeValue("id");
                break;
            default:
                break;
            }
        }
    } catch (JDOMException | IOException e) {
        logger.error("Error in GraphmlParser");
        System.exit(-1);
    }
}

From source file:edu.unc.lib.dl.xml.DepartmentOntologyUtil.java

License:Apache License

/**
 * Add the given department to the parent element as an affiliation if it is not already present
 *
 * @param dept/*from   ww  w.j a  va2 s. co m*/
 * @param parentEl
 * @param affilIndex
 * @param affiliationSet
 * @return True if an affiliation was added
 */
private boolean addAffiliation(String dept, Element parentEl, int affilIndex, Set<String> affiliationSet) {

    // Prevent duplicate departments from being added
    if (dept != null && !affiliationSet.contains(dept)) {
        Element newAffilEl = new Element("affiliation", parentEl.getNamespace());
        newAffilEl.setText(dept);
        // Insert the new element near where the original was
        try {
            parentEl.addContent(affilIndex, newAffilEl);
        } catch (IndexOutOfBoundsException e) {
            parentEl.addContent(newAffilEl);
        }
        affiliationSet.add(dept);

        return true;
    }

    return false;
}

From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.JSONTypesExtractorImpl.java

License:Apache License

/**
 * This method sets a given namespace to the given element and any of its descendants whose 
 * name is a provided one and have no namespace.
 * @param name the name of the searched elements
 * @param rootElement the root element to begin the search at
 * @param namespace the namespace to set
 *//* w ww  .  jav a2 s. com*/
private void setNamespaceToElementsByName(String name, Element rootElement, Namespace namespace) {
    IteratorIterable<Element> descendants = rootElement
            .getDescendants(Filters.element(name, Namespace.NO_NAMESPACE));
    for (Element descendant : descendants) {
        descendant.setNamespace(namespace);
    }
    if (rootElement.getName().equals(name) && rootElement.getNamespace().equals(Namespace.NO_NAMESPACE)) {
        rootElement.setNamespace(namespace);
    }
}