List of usage examples for org.jdom2 Element equals
@Override public final boolean equals(Object ob)
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void processServers(Element servers) { List<Server> serverList = new ArrayList<>(); if (servers == null) { List<Server> empty = Collections.emptyList(); Server.processServers(empty);/*www.j av a 2 s. c om*/ return; } for (Element server : servers.getChildren()) { if (!SERVER.equals(server.getName().toLowerCase())) continue; String name = null; for (Attribute attr : server.getAttributes()) { if (NAME.equals(attr.getName().toLowerCase())) name = attr.getValue(); } if (name == null) { LoggerFactory.getLogger(LouieProperties.class) .error("A server was missing it's 'name' attribute and will be skipped!"); continue; } Server prop = new Server(name); for (Element serverProp : server.getChildren()) { String propName = serverProp.getName().toLowerCase(); String propValue = serverProp.getTextTrim(); if (null != propName) switch (propName) { case HOST: prop.setHost(propValue); break; case DISPLAY: prop.setDisplay(propValue); break; case LOCATION: prop.setLocation(propValue); break; case GATEWAY: prop.setGateway(propValue); break; case IP: prop.setIp(propValue); break; case EXTERNAL_IP: prop.setExternalIp(propValue); break; case CENTRAL_AUTH: prop.setCentralAuth(Boolean.parseBoolean(propValue)); break; case PORT: prop.setPort(Integer.parseInt(propValue)); break; case SECURE: prop.setSecure(Boolean.parseBoolean(propValue)); break; case TIMEZONE: prop.setTimezone(propValue); break; case CUSTOM: for (Element child : serverProp.getChildren()) { prop.addCustomProperty(child.getName(), child.getTextTrim()); } break; default: LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property {}:{}", propName, propValue); break; } } serverList.add(prop); } Server.processServers(serverList); }
From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleParser.java
License:Apache License
/** Use feed links and/or xml:base attribute to determine baseURI of feed */ private static URL findBaseURI(final Element root) { URL baseURI = null;/*from ww w . j av a 2 s . c om*/ final List<Element> linksList = root.getChildren("link", OS_NS); if (linksList != null) { for (final Element element : linksList) { final Element link = element; if (!root.equals(link.getParent())) { break; } String href = link.getAttribute("href").getValue(); if (link.getAttribute("rel", OS_NS) == null || link.getAttribute("rel", OS_NS).getValue().equals("alternate")) { href = resolveURI(null, link, href); try { baseURI = new URL(href); break; } catch (final MalformedURLException e) { System.err.println("Base URI is malformed: " + href); } } } } return baseURI; }
From source file:org.mycore.restapi.v1.MCRRestAPIClassifications.java
License:Open Source License
/** * Output JSON/*from w w w . j a va2 s . co m*/ * @param eRoot - the category element * @param lang - the language to be filtered for or null if all languages should be displayed * @param style - the style * @return a string representation of a JSON object * @throws IOException */ private String writeJSON(Element eRoot, String lang, String style) throws IOException { StringWriter sw = new StringWriter(); JsonWriter writer = new JsonWriter(sw); writer.setIndent(" "); if (style.contains("checkboxtree")) { if (lang == null) { lang = "de"; } writer.beginObject(); writer.name("identifier").value(eRoot.getAttributeValue("ID")); for (Element eLabel : eRoot.getChildren("label")) { if (lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.name("label").value(eLabel.getAttributeValue("text")); } } writer.name("items"); writeChildrenAsJSONCBTree(eRoot = eRoot.getChild("categories"), writer, lang, style.contains("checked")); writer.endObject(); } else if (style.contains("jstree")) { if (lang == null) { lang = "de"; } writeChildrenAsJSONJSTree(eRoot = eRoot.getChild("categories"), writer, lang, style.contains("opened"), style.contains("disabled"), style.contains("selected")); } else { writer.beginObject(); // { writer.name("ID").value(eRoot.getAttributeValue("ID")); writer.name("label"); writer.beginArray(); for (Element eLabel : eRoot.getChildren("label")) { if (lang == null || lang.equals(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE))) { writer.beginObject(); writer.name("lang").value(eLabel.getAttributeValue("lang", Namespace.XML_NAMESPACE)); writer.name("text").value(eLabel.getAttributeValue("text")); if (eLabel.getAttributeValue("description") != null) { writer.name("description").value(eLabel.getAttributeValue("description")); } writer.endObject(); } } writer.endArray(); if (eRoot.equals(eRoot.getDocument().getRootElement())) { writeChildrenAsJSON(eRoot.getChild("categories"), writer, lang); } else { writeChildrenAsJSON(eRoot, writer, lang); } writer.endObject(); } writer.close(); return sw.toString(); }
From source file:org.rometools.feed.module.opensearch.impl.OpenSearchModuleParser.java
License:Apache License
/** Use feed links and/or xml:base attribute to determine baseURI of feed */ private static URL findBaseURI(Element root) { URL baseURI = null;//from w ww .j av a2s .c om List linksList = root.getChildren("link", OS_NS); if (linksList != null) { for (Iterator links = linksList.iterator(); links.hasNext();) { Element link = (Element) links.next(); if (!root.equals(link.getParent())) break; String href = link.getAttribute("href").getValue(); if (link.getAttribute("rel", OS_NS) == null || link.getAttribute("rel", OS_NS).getValue().equals("alternate")) { href = resolveURI(null, link, href); try { baseURI = new URL(href); break; } catch (MalformedURLException e) { System.err.println("Base URI is malformed: " + href); } } } } return baseURI; }
From source file:org.slc.sli.ingestion.parser.impl.XsdTypeProvider.java
License:Apache License
private boolean isContainedByUnboundedElement(Element e, Element parentElement) { // we may be able to remove this method/logic as the SLI-Edfi schema overrides all types // that contain unbounded choice to remove them. Element immediateParent = e.getParentElement(); while (!immediateParent.equals(parentElement)) { if (UNBOUNDED.equals(immediateParent.getAttributeValue(MAX_OCCURS))) { return true; }/*from w w w.j a va2 s . c o m*/ immediateParent = immediateParent.getParentElement(); } return false; }
From source file:proyect.ServidorWS.java
public static void main(String args[]) throws JDOMException, ClassNotFoundException { ServerSocket mi_servicio2 = null; Socket socket_conectado = null; try {//from w ww .j a v a2s . com 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:se.miun.itm.input.model.element.Value.java
License:Open Source License
private void renewLocalId(Content childContent) { if (childContent instanceof Value<?>) { Value<?> childValueElement = (Value<?>) childContent; String newFullChildId;/*from w w w . j a va 2s . co m*/ String childLocalId = childValueElement.getAttributeValue(Q.ID_ATTR); Element childParameterParent = childValueElement.getParam().getParentElement(); if (childParameterParent instanceof Param && !childParameterParent.equals(param) && getAttributeValue(Q.VALUE_ATTR) != null) { newFullChildId = getId() + "." + getAttributeValue(Q.VALUE_ATTR) + "." + childLocalId; } else newFullChildId = getId() + "." + childLocalId; childValueElement.setFullId(newFullChildId); } }
From source file:se.miun.itm.input.util.ParamInitializer.java
License:Open Source License
/** * A hull is a set of parameters that logically belong together. Structural * Parameters, and Structural Choices have to be initiated following a * certain logical order, in which parents SParam are always instantiated * before their choices, but any parameter and choice requires the * referenced parameters to be instantiated first. This function returns the * position of a searched hull.//from w ww . j ava 2 s . c o m * * @param dependees * @param lookup * @param params * @return */ private static int getHullPosition(List<IMapping> dependees, Map<IMapping, Element> lookup, LinkedList<Element> params) { // now, the local hull has to be placed BEHIND the last occuring // dependee in params. Element param, dependeeParam; int i = 0; while (!dependees.isEmpty()) { param = params.get(i); for (int j = 0; j < dependees.size(); j++) { dependeeParam = lookup.get(dependees.get(j)); if (param.equals(dependeeParam)) { dependees.remove(j); break; } } i++; } return i; }