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:password.pwm.config.PwmSetting.java

License:Open Source License

public boolean isRequired() {
    final Element settingElement = PwmSettingXml.readSettingXml(this);
    final Attribute requiredAttribute = settingElement.getAttribute("required");
    return requiredAttribute != null && "true".equalsIgnoreCase(requiredAttribute.getValue());
}

From source file:password.pwm.config.PwmSetting.java

License:Open Source License

public boolean isHidden() {
    final Element settingElement = PwmSettingXml.readSettingXml(this);
    final Attribute requiredAttribute = settingElement.getAttribute("hidden");
    return requiredAttribute != null && "true".equalsIgnoreCase(requiredAttribute.getValue());
}

From source file:password.pwm.config.PwmSetting.java

License:Open Source License

public int getLevel() {
    final Element settingElement = PwmSettingXml.readSettingXml(this);
    final Attribute levelAttribute = settingElement.getAttribute("level");
    return levelAttribute != null ? Integer.parseInt(levelAttribute.getValue()) : 0;
}

From source file:password.pwm.config.PwmSettingCategory.java

License:Open Source License

public int getLevel() {
    final Element settingElement = PwmSettingXml.readCategoryXml(this);
    final Attribute levelAttribute = settingElement.getAttribute("level");
    return levelAttribute != null ? Integer.parseInt(levelAttribute.getValue()) : 0;
}

From source file:password.pwm.config.PwmSettingCategory.java

License:Open Source License

public boolean isHidden() {
    final Element settingElement = PwmSettingXml.readCategoryXml(this);
    final Attribute requiredAttribute = settingElement.getAttribute("hidden");
    return requiredAttribute != null && "true".equalsIgnoreCase(requiredAttribute.getValue());
}

From source file:projetxml.model.DownloadOmdb.java

/**
 * return map about Omdb information//from w  w w  .ja va2  s. c o m
 * @return map about Omdb information
 * @throws JDOMException
 * @throws IOException
 */
public Map<String, String> getInfos() throws JDOMException, IOException {
    //Rcupration de la liste des attributs
    Map<String, String> informations = new HashMap<>();
    //On creer un fichier qui sert de relai pour stocker
    //temporairement les informations
    //C'est plus simple comme a
    File f = new File("intermediaire.xml");
    //Ajout du string
    //Conversion sous la forme d'un xml
    try {
        FileWriter fw = new FileWriter(f);
        BufferedWriter output = new BufferedWriter(fw);
        output.write(this.infos);
        output.flush();
        output.close();
    } catch (IOException e) {
    }
    //Rcupration de la balise movie
    Document document = new SAXBuilder().build(f);
    //Il se peut que l'url ne contienne pas de "movie"
    //Il va donc lever une exception
    //On l'attrape donc pour eviter que l'appli plante
    try {
        Element movie = document.getRootElement().getChild("movie");
        for (Attribute a : movie.getAttributes()) {
            informations.put(a.getName(), a.getValue());
        }
    } catch (Exception e) {
    }
    //Suppresion du file
    f.delete();
    //Rcupration de tous les attributs sous la forme d'une map        
    return informations;
}

From source file:qtiscoringengine.CustomOperatorRegistry.java

License:Open Source License

private static String getOperatorType(Element customOperatorNode) {
    for (Attribute attribute : customOperatorNode.getAttributes()) {
        if ("CLASS".equalsIgnoreCase(attribute.getName())) {
            return attribute.getValue();
        }// ww  w .j a va 2 s .  c  om
    }
    return "";
}

From source file:qtiscoringengine.ISECustomExpression.java

License:Open Source License

private static String getOperatorType(Element customOperatorNode) {
    for (Attribute attribute : customOperatorNode.getAttributes()) {
        if (StringUtils.equalsIgnoreCase(attribute.getName(), "CLASS")) {
            return attribute.getValue();
        }//from  www.j  a  va2s. co m
    }
    return "";
}

From source file:qtiscoringengine.ISECustomOperator.java

License:Open Source License

public boolean supportsOperator(Element customOperatorNode) {
    Element coElement = customOperatorNode;
    Attribute classAttribute = coElement.getAttribute("class");
    if (classAttribute == null)
        return false;
    return _externalScorer.GetScorerInfo(classAttribute.getValue()) != null;
}

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 {/*  w w  w  . ja v  a2 s .c  o m*/
            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;

}