List of usage examples for org.jdom2 Element getNamespace
public Namespace getNamespace()
From source file:org.yawlfoundation.yawl.resourcing.jsf.dynform.DynFormFieldAssembler.java
License:Open Source License
private List<DynFormField> createFieldList(Element schema, Element data, Namespace ns, int level) throws DynFormException { List<DynFormField> fieldList = null; Element next;/*from w w w .j av a2 s . co m*/ // increment nested depth level & get next contents ++level; if (schema.getName().equals("choice")) { fieldList = createChoice(schema, data, ns, level); } else { ns = schema.getNamespace(); Element complex = schema.getChild("complexType", ns); if (complex == null) { throw new DynFormException( "Malformed data schema, at element: " + JDOMUtil.elementToString(schema)); } next = complex.getChild("sequence", ns); if (next == null) next = complex.getChild("all", ns); if (next != null) { fieldList = createSequence(next, data, ns, level); } else { next = complex.getChild("choice", ns); if (next != null) { fieldList = createChoice(next, data, ns, level); } } } return fieldList; }
From source file:org.yawlfoundation.yawl.resourcing.ResourceMap.java
License:Open Source License
/** * Parse the Element passed for task resourcing info and build the appropriate * objects./*from w w w .j a v a2s .c o m*/ * @param eleSpec the [resourcing] section from a particular task definition * within a specification file. */ public void parse(Element eleSpec) { if (eleSpec != null) { Namespace nsYawl = eleSpec.getNamespace(); try { _offer.parse(eleSpec.getChild("offer", nsYawl), nsYawl); _allocate.parse(eleSpec.getChild("allocate", nsYawl), nsYawl); _start.parse(eleSpec.getChild("start", nsYawl), nsYawl); _secondary.parse(eleSpec.getChild("secondary", nsYawl), nsYawl); _privileges.parse(eleSpec.getChild("privileges", nsYawl), nsYawl); _log.info("Resourcing specification parse completed for task: {}", _taskID); } catch (ResourceParseException rpe) { _log.error("Error parsing resourcing specification for task: " + _taskID, rpe); } } }
From source file:org.yawlfoundation.yawl.scheduling.PlanningGraphCreator.java
License:Open Source License
@SuppressWarnings("unchecked") /**//from w ww . j av a 2 s. c o m * 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.unmarshal.YDecompositionParser.java
License:Open Source License
/** * Parses the decomposition from the appropriate XML doclet. * @param decompElem the XML doclet containing the decomp configuration. * @param specificationParser a reference to parent spec parser. * @param version the version of XML structure *//* ww w . j av a 2s . c om*/ YDecompositionParser(Element decompElem, YSpecificationParser specificationParser, YSchemaVersion version) { _decompElem = decompElem; _yawlNS = decompElem.getNamespace(); _specificationParser = specificationParser; _version = version; _postsetIDs = new Postset(); _removeSetIDs = new HashMap<YTask, List<String>>(); _decomposesToIDs = new HashMap<YTask, String>(); _decomposition = createDecomposition(decompElem); _postsetIDs.addImplicitConditions(); linkElements(); }
From source file:org.yawlfoundation.yawl.unmarshal.YMarshal.java
License:Open Source License
/** * Builds a list of specification objects from a XML string. * @param specStr the XML string describing the specification set * @param schemaValidate when true, will cause the specifications to be * validated against schema while being parsed * @return a list of YSpecification objects taken from the XML string. * @throws YSyntaxException if a parsed specification doesn't validate against * schema//ww w.ja va 2 s . c o m */ public static List<YSpecification> unmarshalSpecifications(String specStr, boolean schemaValidate) throws YSyntaxException { List<YSpecification> result = null; // first check if the xml string is well formed and build a document Document document = JDOMUtil.stringToDocument(specStr); if (document != null) { Element specificationSetEl = document.getRootElement(); YSchemaVersion version = getVersion(specificationSetEl); Namespace ns = specificationSetEl.getNamespace(); // strip layout element, if any (the engine doesn't use it) specificationSetEl.removeChild("layout", ns); // now check the specification file against its respective schema if (schemaValidate) { SchemaHandler validator = new SchemaHandler(version.getSchemaURL()); if (!validator.compileAndValidate(specStr)) { throw new YSyntaxException(" The specification file failed to verify against YAWL's Schema:\n" + validator.getConcatenatedMessage()); } } // now build a set of specifications - verification has not yet occurred. result = buildSpecifications(specificationSetEl, ns, version); } else { throw new YSyntaxException("Invalid XML specification."); } return result; }
From source file:org.yawlfoundation.yawl.unmarshal.YSpecificationParser.java
License:Open Source License
/** * build a specification object from part of an XML document * @param specificationElem the specification part of an XMl document * @param version the version of the XML representation (i.e. beta2 or beta3). * @throws YSyntaxException/* w ww . java 2 s . com*/ */ public YSpecificationParser(Element specificationElem, YSchemaVersion version) throws YSyntaxException { _yawlNS = specificationElem.getNamespace(); parseSpecification(specificationElem, version); linkDecompositions(); }
From source file:proyect.prueba.java
public static void main(String[] args) throws JDOMException, IOException { /*GeneraSoapBanco n=new GeneraSoapBanco(); String id="2222";//ww w.j a va 2 s . c o m String noC="1111"; String Tip="Gold"; String name="Mario"; String ap="reyes"; String am="Dominguez"; n.cabezera(); n.soap(); n.body(); n.Usuario(); n.IdUsuario(id); n.Cuenta(noC); n.tipoCta(Tip); n.FinUsuario(); n.persona(); n.nombre(name); n.ApellidoP(ap); n.ApellidoM(am); n.Finpersona(); n.finBody(); n.finSoap(); n.finCabezera(); */ File XmlFile = new File("Banco.xml"); SAXBuilder db = new SAXBuilder(); Document dc = db.build(XmlFile); XMLOutputter output = new XMLOutputter(); //imprime en pantalla el documento //output.output(dc,System.out); //obtiene al padre wsdl Element root = dc.getRootElement(); Namespace ns = root.getNamespace(); Namespace sobre = root.getNamespace("http:www.nada.com"); System.out.println(root); Element body = root.getChild("Body", ns); Element us = body.getChild("usuario"); Element id = us.getChild("NoCuenta"); String tipo = id.getText(); System.out.println(tipo); }
From source file:proyect.ServidorWS.java
public static void main(String args[]) throws JDOMException, ClassNotFoundException { ServerSocket mi_servicio2 = null; Socket socket_conectado = null; try {/* w w w .j a v a 2s . c o m*/ mi_servicio2 = new ServerSocket(2017); } catch (IOException excepcion) { System.out.println(excepcion); } try { socket_conectado = mi_servicio2.accept(); OutputStream ostream = socket_conectado.getOutputStream(); ObjectOutput s = new ObjectOutputStream(ostream); OutputStream ostream2 = socket_conectado.getOutputStream(); ObjectOutput s2 = new ObjectOutputStream(ostream2); InputStream istream2 = socket_conectado.getInputStream(); ObjectInput in2 = new ObjectInputStream(istream2); int op = (int) in2.readObject(); /*********************************************************************/ /*Parseo para el menu dinamico*/ if (op == 1) { File XmlFile = new File("banco.wsdl"); SAXBuilder db = new SAXBuilder(); Document dc = db.build(XmlFile); XMLOutputter output = new XMLOutputter(); //imprime en pantalla el documento // output.output(dc,System.out); //obtiene al padre wsdl Element root = dc.getRootElement(); Namespace ns = root.getNamespace(); Namespace soap = root.getNamespace("http://schemas.xmlsoap.org/wsdl/soap/"); System.out.println(root); //ubicamos alhijo en portType Element hijo = root.getChild("portType", ns); //System.out.println(hijo); List row = hijo.getChildren("operation", ns); //envia el tamao de la lista al cliente s.writeObject(row.size()); //crea arrgelo del tamao de la opciones String[] arr = new String[row.size()]; for (int i = 0; i < row.size(); i++) { Element infoElenemt = (Element) row.get(i); String h = infoElenemt.getAttributeValue("name"); arr[i] = h; } //envia el arreglo con todos los tipos de opciones s.writeObject(arr); s.flush(); /*******************************************************************/ /*Operaciones con el menu*/ int opcionMenu = (int) in2.readObject(); /*********************************************************************/ /*Servicio Banco*/ if (opcionMenu == 0) { File XmlFile3 = new File("Banco.xml"); SAXBuilder db3 = new SAXBuilder(); Document dc3 = db3.build(XmlFile3); Element root3 = dc3.getRootElement(); Namespace ns2 = root.getNamespace(); Element hijo3 = root3.getChild("usuario", ns2); Element hijoID = hijo3.getChild("IdUsuario", ns2); String valor = hijoID.getText(); String num2 = (String) in2.readObject(); if (valor.equals(num2)) { Element hijoP = root3.getChild("Persona"); Element name = hijoP.getChild("Nombre"); String nombre = name.getText(); s.writeObject(nombre); Element apellido = hijoP.getChild("ApellidoP"); String ap = apellido.getText(); s.writeObject(ap); Element apellidoM = hijoP.getChild("ApellidoM"); String apM = apellidoM.getText(); s.writeObject(apM); s.flush(); } } else if (opcionMenu == 1) { File XmlFile4 = new File("Banco.xml"); SAXBuilder db4 = new SAXBuilder(); Document dc4 = db4.build(XmlFile4); Element root4 = dc4.getRootElement(); Element hijo4 = root4.getChild("usuario"); Element typeC = hijo4.getChild("TipoCuenta"); String tipo = typeC.getText(); String cuenta = (String) in2.readObject(); if (cuenta.equals(tipo)) { Element IDus = hijo4.getChild("IdUsuario"); String Id = IDus.getText(); s.writeObject(Id); s.flush(); } } else if (opcionMenu == 2) { File XmlFile5 = new File("Banco.xml"); SAXBuilder db5 = new SAXBuilder(); Document dc5 = db5.build(XmlFile5); Element root5 = dc5.getRootElement(); Element P = root5.getChild("Persona"); Element name = P.getChild("Nombre"); String nombreP = name.getText(); Element ap = P.getChild("ApellidoP"); String aP = ap.getText(); String nombre = (String) in2.readObject(); String apellido = (String) in2.readObject(); if (nombreP.equals(nombre) && aP.equals(apellido)) { Element hijo5 = root5.getChild("usuario"); Element Id = hijo5.getChild("IdUsuario"); String idP = Id.getText(); s.writeObject(idP); s.flush(); } } else if (opcionMenu == 3) { File XmlFile6 = new File("Banco.xml"); SAXBuilder db6 = new SAXBuilder(); Document dc6 = db6.build(XmlFile6); Element root6 = dc6.getRootElement(); Element h = root6.getChild("usuario"); Element num = h.getChild("NoCuenta"); String n = num.getText(); String NumC = (String) in2.readObject(); if (NumC.equals(n)) { Element Person = root6.getChild("Persona"); Element name = Person.getChild("Nombre"); String nombre = name.getText(); s.writeObject(nombre); Element ap = Person.getChild("ApellidoP"); String aP = ap.getText(); s.writeObject(aP); Element apM = Person.getChild("ApellidoM"); String aM = apM.getText(); s.writeObject(aM); s.flush(); } } /*********************************************************************/ /*Servicio Farmacia*/ } else if (op == 2) { /*********************************************************************/ /*Menu dimanico del wsdl*/ File XmlFile2 = new File("farmacia.wsdl"); SAXBuilder db2 = new SAXBuilder(); Document dc2 = db2.build(XmlFile2); XMLOutputter output2 = new XMLOutputter(); //imprime en pantalla el documento // output.output(dc,System.out); //obtiene al padre wsdl Element root2 = dc2.getRootElement(); System.out.println(root2); //ubicamos alhijo en portType Element hijo2 = root2.getChild("portType"); //crea una lista con las operaciones List row2 = hijo2.getChildren("operation"); //envia el tamao de la lista al cliente s2.writeObject(row2.size()); //crea arrgelo del tamao de la opciones String[] arr2 = new String[row2.size()]; for (int i = 0; i < row2.size(); i++) { Element infoElenemt2 = (Element) row2.get(i); String h2 = infoElenemt2.getAttributeValue("name"); arr2[i] = h2; // System.out.println(arr[i]); } //envia el arreglo con todos los tipos de opciones s2.writeObject(arr2); s2.flush(); /**************************************************************/ /*Opciones del menu*/ int opcionMenuF = (int) in2.readObject(); if (opcionMenuF == 0) { File XmlFile7 = new File("Farmacia.xml"); SAXBuilder db7 = new SAXBuilder(); Document dc7 = db7.build(XmlFile7); Element root7 = dc7.getRootElement(); Element hijo7 = root7.getChild("Producto"); Element precio = hijo7.getChild("Precio"); String precioC = precio.getText(); String Precio = (String) in2.readObject(); if (Precio.equals(precioC)) { Element nombre = hijo7.getChild("Nombre"); String n = nombre.getText(); s.writeObject(n); Element com = hijo7.getChild("Compuesto"); String compuesto = com.getText(); s.writeObject(compuesto); s.flush(); } } else if (opcionMenuF == 1) { File XmlFile8 = new File("Farmacia.xml"); SAXBuilder db8 = new SAXBuilder(); Document dc8 = db8.build(XmlFile8); Element root8 = dc8.getRootElement(); Element hijo8 = root8.getChild("Producto"); Element prec = hijo8.getChild("Nombre"); String p = prec.getText(); String Pr = (String) in2.readObject(); if (Pr.equals(p)) { Element nombre = hijo8.getChild("Compuesto"); String n = nombre.getText(); s.writeObject(n); s.flush(); } } } socket_conectado.close(); } catch (IOException excepcion) { System.out.println(excepcion); } }
From source file:reclassification.util.XMIVersionExtractor.java
public XMIVersionExtractor(File xmlFile) { try {//from w ww .ja v a 2 s .c om SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(xmlFile); Element root = doc.getRootElement(); if (root.getName().equals("XMI")) { String version = null; version = root.getAttributeValue("xmi.version"); if (version != null) { this.version = version; } else { version = root.getAttributeValue("version", root.getNamespace()); if (version != null) this.version = version; } } else { Element xmiRoot = root.getChild("XMI"); if (xmiRoot != null) { String version = null; version = xmiRoot.getAttributeValue("xmi.version"); if (version != null) { this.version = version; } else { version = xmiRoot.getAttributeValue("version", xmiRoot.getNamespace()); if (version != null) this.version = version; } } } } catch (IOException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } }
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. ja va 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; }