Example usage for org.jdom2 Namespace getNamespace

List of usage examples for org.jdom2 Namespace getNamespace

Introduction

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

Prototype

public static Namespace getNamespace(final String uri) 

Source Link

Document

This will retrieve (if in existence) or create (if not) a Namespace for the supplied URI, and make it usable as a default namespace, as no prefix is supplied.

Usage

From source file:org.rometools.feed.module.sle.io.ModuleParser.java

License:Apache License

/**
 * Parses the XML node (JDOM element) extracting module information.
 * <p>/*from w w w . j a  va  2s  .  c  om*/
 *
 * @param element the XML node (JDOM element) to extract module information from.
 * @return a module instance, <b>null</b> if the element did not have module information.
 */
public Module parse(Element element) {
    if (element.getChild("treatAs", NS) == null) {
        return null;
    }

    SimpleListExtension sle = new SimpleListExtensionImpl();
    sle.setTreatAs(element.getChildText("treatAs", NS));

    Element listInfo = element.getChild("listinfo", NS);
    List groups = listInfo.getChildren("group", NS);
    ArrayList values = new ArrayList();

    for (int i = 0; (groups != null) && (i < groups.size()); i++) {
        Element ge = (Element) groups.get(i);
        Namespace ns = (ge.getAttribute("ns") == null) ? element.getNamespace()
                : Namespace.getNamespace(ge.getAttributeValue("ns"));
        String elementName = ge.getAttributeValue("element");
        String label = ge.getAttributeValue("label");
        values.add(new Group(ns, elementName, label));
    }

    sle.setGroupFields((Group[]) values.toArray(new Group[values.size()]));
    values = (values.size() == 0) ? values : new ArrayList();

    List sorts = listInfo.getChildren("sort", NS);

    for (int i = 0; (sorts != null) && (i < sorts.size()); i++) {
        Element se = (Element) sorts.get(i);
        System.out.println(
                "Parse cf:sort " + se.getAttributeValue("element") + se.getAttributeValue("data-type"));
        Namespace ns = (se.getAttributeValue("ns") == null) ? element.getNamespace()
                : Namespace.getNamespace(se.getAttributeValue("ns"));
        String elementName = se.getAttributeValue("element");
        String label = se.getAttributeValue("label");
        String dataType = se.getAttributeValue("data-type");
        boolean defaultOrder = (se.getAttributeValue("default") == null) ? false
                : new Boolean(se.getAttributeValue("default")).booleanValue();
        values.add(new Sort(ns, elementName, dataType, label, defaultOrder));
    }

    sle.setSortFields((Sort[]) values.toArray(new Sort[values.size()]));
    insertValues(sle, element.getChildren());

    return sle;
}

From source file:org.shaman.rpg.battle.attack.MonsterAttackLoader.java

private void initSaxBuilder() {
    if (saxBuilder == null) {
        //read schema
        InputStream in = null;/* www .  j a  v a  2 s. c o  m*/
        try {
            in = new BufferedInputStream(
                    MonsterAttackLoader.class.getClassLoader().getResourceAsStream(SCHEMA));
            StreamSource source = new StreamSource(in, SCHEMA);
            xsdFactory = new XMLReaderXSDFactory(source);
        } catch (JDOMException ex) {
            throw new ExceptionInInitializerError(ex);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ex) {
                } //ignore
            }
        }
        //create sax builder
        saxBuilder = new SAXBuilder(xsdFactory);
        //Create the namespace
        namespace = Namespace.getNamespace("Engine/Battle/Attacks");
    }
}

From source file:org.shaman.rpg.battle.monster.MonsterRaceLoader.java

private void initSaxBuilder() {
    if (saxBuilder == null) {
        //read schema
        InputStream in = null;/*from ww w.  j av a  2 s  .  c o m*/
        try {
            in = new BufferedInputStream(MonsterRaceLoader.class.getClassLoader().getResourceAsStream(SCHEMA));
            StreamSource source = new StreamSource(in, SCHEMA);
            xsdFactory = new XMLReaderXSDFactory(source);
        } catch (JDOMException ex) {
            throw new ExceptionInInitializerError(ex);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ex) {
                } //ignore
            }
        }
        //create sax builder
        saxBuilder = new SAXBuilder(xsdFactory);
        //Create the namespace
        namespace = Namespace.getNamespace("Engine/Battle/MonsterRaces");
    }
}

From source file:org.yawlfoundation.yawl.engine.interfce.SpecificationData.java

License:Open Source License

/**
 * If the specification contains a schema library this method returns the
 * schema library as a string (in XML Schema format).
 * @return  schema library as a string./*w  w w. j  a  va2s .  c om*/
 */
public String getSchemaLibrary() throws IOException, JDOMException {
    Document document = JDOMUtil.stringToDocument(_specAsXML);
    Element yawlSpecSetElement = document.getRootElement();

    String ns = isSecondGenSchemaVersion() ? "http://www.yawlfoundation.org/yawlschema"
            : "http://www.citi.qut.edu.au/yawl";

    Namespace yawlNameSpace = Namespace.getNamespace(ns);
    Element yawlSpecElement = yawlSpecSetElement.getChild("specification", yawlNameSpace);

    if (yawlSpecElement != null) {
        Namespace schema2SchNS = Namespace.getNamespace("http://www.w3.org/2001/XMLSchema");
        Element schemaLibraryElement = yawlSpecElement.getChild("schema", schema2SchNS);

        if (schemaLibraryElement != null) {
            return JDOMUtil.elementToString(schemaLibraryElement);
        }
    }
    return null;
}

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  a va2  s  . c  o  m
    }
    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);
}

From source file:pt.ist.socialsoftware.edition.export.ExpertEditionTEIExport.java

License:Creative Commons License

public ExpertEditionTEIExport() {
    this.xmlns = Namespace.getNamespace("http://www.tei-c.org/ns/1.0");
}

From source file:pt.ist.socialsoftware.edition.visitors.TEIGenerator.java

License:Creative Commons License

public TEIGenerator() {
    xmlns = Namespace.getNamespace("http://www.tei-c.org/ns/1.0");
}

From source file:recparser.idmef.IdmefParser.java

License:Open Source License

public List<IntrusionAlert> parser(String input) {

    long initParser = System.currentTimeMillis();
    System.out.println("*** INIT PARSER IDMEF at " + initParser + " *** ");

    //Primero verificar si vienen una o mas alertas
    String[] mensajes = splitIDMEF(input);
    for (int i = 0; i < mensajes.length; i++) {
        IntrusionAlert intrusionAlert = new IntrusionAlert();
        try {//from   w  w  w  .  j  av a 2 s .c om
            DateToXsdDatetimeFormatter xdf = new DateToXsdDatetimeFormatter();
            String currentDate = xdf.format(new Date());
            String intrusionCount = currentDate.replace(":", "").replace("-", "");
            intrusionAlert.setIntCount(intrusionCount);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        String messageID = null;
        SAXBuilder builder = new SAXBuilder();
        StringReader inputReader = new StringReader(mensajes[i]);
        try {

            //XML parser SAX
            Document doc = builder.build(inputReader);
            Element root = doc.getRootElement();
            Namespace ns = root.getNamespace();
            root = root.getChild("Alert", ns);

            //Es una alerta
            if (root != null) {

                //Cogemos los valores relevantes
                Content content;
                // 0. ID de la alerta
                Attribute attribute = root.getAttribute("messageid");
                if (attribute != null) {
                    intrusionAlert.setIntID(attribute.getValue());
                    intrusionAlert.setMessageID(attribute.getValue());
                    messageID = attribute.getValue();
                }
                //1. Datos del analizador
                Element e = root.getChild("Analyzer", ns);
                if (e != null) {
                    attribute = e.getAttribute("analyzerid");
                    if (attribute != null) {
                        intrusionAlert.setAnalyzerID(attribute.getValue());
                        messageID = attribute.getValue() + messageID;
                        intrusionAlert.setIntID(messageID); //MOdificamos el valor de IntID = analyzerID+messageID
                    }
                }

                //2. Tiempo de creacin
                e = root.getChild("CreateTime", ns);
                if (e != null) {
                    for (int j = 0; j < e.getContentSize(); j++) {
                        content = e.getContent(j);
                        intrusionAlert.setIntAlertCreateTime(content.getValue());
                    }
                }

                //3. Severidad 
                e = root.getChild("Assessment", ns);
                if (e != null) {
                    attribute = e.getAttribute("completion");
                    if (attribute != null)
                        intrusionAlert.setIntCompletion(attribute.getValue());
                    e = e.getChild("Impact", ns);
                    if (e != null) {
                        attribute = e.getAttribute("severity");
                        if (attribute != null) {
                            String attributeValue = attribute.getValue();
                            for (int j = 0; j < 4; j++) {
                                if (attributeValue.equals(severidad[j])) {
                                    intrusionAlert.setIntSeverity(j + 1);
                                }
                            }
                        }
                    }
                }

                Namespace reclamo = Namespace.getNamespace("http://reclamo.inf.um.es/idmef");
                Element additional = null;
                additional = root.getChild("AdditionalData", ns);
                if (additional != null) {
                    //4. Porcentaje de ataque
                    additional = additional.getChild("xml", ns);
                    if (additional != null) {

                        additional = additional.getChild("IntrusionTrust", reclamo);

                        if (additional != null) {
                            e = additional.getChild("AttackPercentage", reclamo);
                            if (e != null) {
                                for (int j = 0; j < e.getContentSize(); j++)
                                    content = e.getContent(j);
                            }
                            //5. Certeza
                            additional = additional.getChild("AssessmentTrust", reclamo);
                            if (additional != null) {
                                additional = additional.getChild("Assessment", reclamo);
                                if (additional != null) {
                                    e = additional.getChild("Trust", reclamo);
                                    if (e != null) {
                                        for (int j = 0; j < e.getContentSize(); j++) {
                                            content = e.getContent(j);
                                            intrusionAlert.setAnalyzerConfidence(
                                                    Double.parseDouble(content.getValue()));
                                        }
                                    }
                                }
                            }
                        }
                    }

                }

                //6. Tiempo de deteccin
                e = root.getChild("DetectTime", ns);
                if (e != null) {
                    content = e.getContent(0);
                    intrusionAlert.setIntDetectionTime(content.getValue());

                } else if (additional != null) {//No aparece esta rama, hay que cogerlo del additionaldata
                    e = additional.getChild("Timestamp", reclamo);
                    if (e != null) {
                        for (int j = 0; j < e.getContentSize(); j++) {
                            content = e.getContent(j);
                            intrusionAlert.setIntDetectionTime(content.getValue());
                        }
                    }
                }

                //7. Recursividad en la rama Target
                List targets = root.getChildren("Target", ns);
                Iterator it = targets.iterator();
                while (it.hasNext()) {
                    IntrusionTarget intrusionTarget = new IntrusionTarget();
                    listChildren((Element) it.next(), intrusionTarget, null);
                    intrusionAlert.setIntrusionTarget(intrusionTarget);

                }

                //8. Recursividad en la rama Source
                List sources = root.getChildren("Source", ns);
                it = sources.iterator();
                while (it.hasNext()) {
                    IntrusionSource intrusionSource = new IntrusionSource();
                    listChildren((Element) it.next(), intrusionSource, null);
                    intrusionAlert.setIntrusionSource(intrusionSource);
                }

                //9. Classification

                e = root.getChild("Classification", ns);
                String tipo_alert = null;
                if (e != null) {
                    attribute = e.getAttribute("text");
                    if (attribute != null) {
                        tipo_alert = attribute.getValue();
                        intrusionAlert.setIntName(tipo_alert);
                        String path = "/"
                                + getClass().getProtectionDomain().getCodeSource().getLocation().toString();
                        String path2 = path.substring(6, path.length() - 13);
                        String classtype = this.obtainParameter(
                                path2 + props.getIdmefIntrusionClassificationFile(), tipo_alert);

                        intrusionAlert.setIntType(classtype);
                    }
                }

                //10. En caso de no tener el tipo de alerta antes:
                if (tipo_alert != null && tipo_alert.equals("unknown")) {
                    e = root.getChild("CorrelationAlert", ns);
                    if (e != null) {
                        e = e.getChild("name", ns);
                        if (e != null) {
                            for (int j = 0; j < e.getContentSize(); j++) {
                                content = e.getContent(j);
                                intrusionAlert.setIntType(content.getValue());
                            }
                        }

                    }
                }

                if (intrusionAlert.getIntSeverity() < 0) {
                    intrusionAlert.setIntSeverity(0); //Asignamos 0 al valor de la severidad en caso de que sea -1
                }
                //Insertamos la alerta leida
                intrusionAlerts.add(intrusionAlert);
            }
        }
        // indicates a well-formedness error
        catch (JDOMException e) {
            System.out.println(" is not well-formed.");
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println(e + "2");
        }

        long endParser = System.currentTimeMillis();
        System.out.println("*** END PARSER IDMEF *** Parsing time : " + (endParser - initParser) + " (ms)*** ");
    }

    return intrusionAlerts;

}

From source file:xmlproject.DOMParser.java

private VisualParameters parseVP(Element elem) {

    Namespace ns = Namespace.getNamespace("http://aaa.com/visual");

    VisualParameters parameters = new Gem.VisualParameters();

    parameters//w  ww.ja v a2  s .  c  om
            .setColor(Gem.VisualParameters.Color.valueOf(elem.getChild("color", ns).getValue().toUpperCase()));
    parameters.setOpacity(Integer.parseInt(elem.getChild("opacity", ns).getText()));
    parameters.setVerges(Integer.parseInt(elem.getChild("verges", ns).getText()));

    return parameters;
}