List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:jodtemplate.pptx.ImageService.java
License:Apache License
private void setPicSize(final Element pic, final Image image) throws DataConversionException { final Element ext = pic.getChild(PPTXDocument.SPPR_ELEMENT, getPresentationmlNamespace()) .getChild(PPTXDocument.XFRM_ELEMENT, getDrawingmlNamespace()) .getChild(PPTXDocument.EXT_ELEMENT, getDrawingmlNamespace()); final Attribute cxAttr = ext.getAttribute("cx"); final Attribute cyAttr = ext.getAttribute("cy"); final int cx = cxAttr.getIntValue(); final int cy = cyAttr.getIntValue(); final ImageSize newSize = calculateNewImageSize(cx, cy, image.getWidth(), image.getHeight()); cxAttr.setValue(String.valueOf(newSize.width)); cyAttr.setValue(String.valueOf(newSize.height)); }
From source file:jworkspace.ui.plaf.XPlafConnector.java
License:Open Source License
/** * Create connector from binary jdom branch * <p>/* w w w . j a v a 2 s . c om*/ * Example element: * <plaf> * <class>com.incors.plaf.kunststoff.KunststoffLookAndFeel</class> * <theme>com.incors.plaf.kunststoff.themes.KunststoffDesktopTheme</theme> * <theme>com.incors.plaf.kunststoff.themes.KunststoffNotebookTheme</theme> * <theme>com.incors.plaf.kunststoff.themes.KunststoffPresentationTheme</theme> * <method access="public" static="true" type="void" name="setCurrentTheme"/> * </plaf> * * @param element binary jdom branch * @return new connector or null */ public static XPlafConnector create(Element element) { XPlafConnector connector = new XPlafConnector(); //** create and install laf, if it is not installed on creation Element clazzNameEl = element.getChild(CLASS_NODE); String lafClazzName = clazzNameEl.getText(); try { Class clazz = Class.forName(lafClazzName); LookAndFeel laf = (LookAndFeel) clazz.newInstance(); connector.info = new UIManager.LookAndFeelInfo(laf.getName(), lafClazzName); //** check if this laf is installed in system if (PlafFactory.getInstance().getLookAndFeel(lafClazzName) == null) { UIManager.installLookAndFeel(connector.info); } } catch (Exception | Error e) { LOG.error("Cannot create laf: ", e); return null; } //** look for themes List<Element> themes = element.getChildren(THEME_NODE); List<MetalTheme> ths = new ArrayList<>(); /* * Set current theme, do not install it in look and feel */ for (Element theme : themes) { String themeName = theme.getText(); if (themeName != null && !themeName.trim().equals("")) { try { Class clazz = Class.forName(themeName); MetalTheme th = (MetalTheme) clazz.newInstance(); ths.add(th); /* * Set current theme, do not install it in look and feel */ if (theme.getAttribute(CURRENT) != null && theme.getAttributeValue(CURRENT).equalsIgnoreCase(Boolean.TRUE.toString())) { connector.currentTheme = th; } } catch (Exception e) { LOG.error("Cannot load laf: ", e); } } } //** copy themes to array connector.themes = ths.toArray(new MetalTheme[0]); //** set method connector.method = element.getChild("method"); //** finally return connector return connector; }
From source file:MCHelper.ToTree.java
private static void buildLeaves(Tree t) { recipes = root.getChildren("Recipe"); //Rcuprer les recettes Iterator i = recipes.iterator(); //Itrer sur la liste while (i.hasNext()) { Element cur = (Element) i.next(); //On rcupre une des recettes, Element prod = (Element) cur.getChild("Outcome");//le noeud du produit String name = prod.getText(); //son nom Attribute curQtAttr = prod.getAttribute("qt"); //la quantit cre int curQt = 1; try {//from w w w. jav a2 s . c om curQt = curQtAttr.getIntValue(); //en tant que int } catch (Exception ex) { System.out.println("Erreur :" + ex); } t.addLeave(name, curQt); //On cr un noeud son nom et on le stocke } resources = root.getChildren("Resource"); //On rcupre maintenant les ressources i = resources.iterator(); //Et on itre dessus while (i.hasNext()) { Element cur = (Element) i.next(); //Pour chacune des ressources, String name = cur.getText(); //On rcupre son nom t.addLeave(name, true); //Et on lui fait un noeud (en indiquant que c'est une ressource) qu'on stocke } //A la fin de ces boucles, tous les objets du jeu ont d tre recenss : //Tous peuvent soit tre trouvs naturellement, ou bien fabriqus. }
From source file:MCHelper.ToTree.java
private static void buildTree(Tree t) { Iterator i = recipes.iterator(); while (i.hasNext()) { try {/* w w w . java2 s.c om*/ Element curRec = (Element) i.next(); //On rcupre le noeud XML de la recette pioche en bois, Element out = curRec.getChild("Outcome"); //le noeud XML du produit pioche en bois, String recName = out.getText(); //le nom du produit pioche en bois, List<Element> ingredients = curRec.getChildren("Ingredient"); //On fait une liste des ingrdients Iterator j = ingredients.iterator(); //et on itre dessus //Pour chacun des ingrdients, on veut ajouter le noeud correspondant son nom //dans les enfants de curRec (un ingrdient est un enfant du produit d'une recette). while (j.hasNext()) { Element curIng = (Element) j.next(); //On rcupre le noeud XML de l'ingrdient bton, String ingName = curIng.getText(); //le nom de l'ingrdient bton, Attribute qtAttr = curIng.getAttribute("qt"); //et la quantit (attribut) de bton ncessaires pour fabriquer la pioche en bois int qt = qtAttr.getIntValue(); //on convertit en int t.addChildToLeave(recName, ingName, qt); //On lie les feuilles } } catch (Exception e) { System.out.println("Erreur: " + e); } } //System.out.println(leaves); }
From source file:modelo.RegistroPlanesXML.java
public void modificar(Planes planes) { Element planEncontrado = this.buscarNombre(planes.getNombre()); planEncontrado.getAttribute("nombre").setValue(planes.getNombre()); planEncontrado.getAttribute("precio").setValue(Integer.toString(planes.getPrecio())); planEncontrado.getAttribute("NumMensajes").setValue(planes.getMensajes()); planEncontrado.getAttribute("NumMinutos").setValue(planes.getMinutos()); try {/*ww w . j a v a 2 s . c o m*/ save(); } catch (IOException ex) { Logger.getLogger(RegistroPlanesXML.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:mom.trd.opentheso.core.alignment.GpsQuery.java
public ArrayList<NodeAlignment> queryGps2(String idC, String idTheso, String lexicalValue, String lang, String requete) {//from ww w . j av a2 s. c om ArrayList<NodeLang> nodeLangs; try { lexicalValue = URLEncoder.encode(lexicalValue, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(GpsQuery.class.getName()).log(Level.SEVERE, null, ex); } lexicalValue = lexicalValue.replaceAll(" ", "%20"); requete = requete.replace("##lang##", lang); requete = requete.replace("##value##", lexicalValue); try { //URL url = new URL("https://" + lang + ".wikipedia.org/w/api.php?action=query&list=search&srwhat=text&format=xml&srsearch=" + lexicalValue + "&srnamespace=0"); // requete = URLEncoder.encode(requete, "UTF-8"); URL url = new URL(requete); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/xml"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; String xmlRecord = ""; while ((output = br.readLine()) != null) { xmlRecord += output; } byte[] bytes = xmlRecord.getBytes(); xmlRecord = new String(bytes, Charset.forName("UTF-8")); conn.disconnect(); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xmlRecord)); org.w3c.dom.Document doc = db.parse(is); NodeList nodes = doc.getElementsByTagName("geoname"); listeAlign = new ArrayList<>(); // iterate the employees for (int i = 0; i < nodes.getLength(); i++) { nodeLangs = new ArrayList<>(); org.w3c.dom.Element element = (org.w3c.dom.Element) nodes.item(i); NodeAlignment nodeAlignment = new NodeAlignment(); NodeList nodeList = element.getElementsByTagName("name"); for (int j = 0; j < nodeList.getLength(); j++) { nodeAlignment.setName(nodeList.item(j).getTextContent()); } nodeList = element.getElementsByTagName("lat"); if (nodeList != null && nodeList.getLength() > 0) { for (int j = 0; j < nodeList.getLength(); j++) { nodeAlignment.setLat(Double.parseDouble(nodeList.item(j).getTextContent())); } } nodeList = element.getElementsByTagName("lng"); if (nodeList != null && nodeList.getLength() > 0) { for (int j = 0; j < nodeList.getLength(); j++) { nodeAlignment.setLng(Double.parseDouble(nodeList.item(j).getTextContent())); } } nodeList = element.getElementsByTagName("geonameId"); if (nodeList != null && nodeList.getLength() > 0) { for (int j = 0; j < nodeList.getLength(); j++) { nodeAlignment .setIdUrl("http://www.geonames.org/" + (nodeList.item(j).getTextContent())); } } nodeList = element.getElementsByTagName("countryName"); if (nodeList != null && nodeList.getLength() > 0) { for (int j = 0; j < nodeList.getLength(); j++) { nodeAlignment.setCountryName(nodeList.item(j).getTextContent()); } } nodeList = element.getElementsByTagName("toponymName"); if (nodeList != null && nodeList.getLength() > 0) { for (int j = 0; j < nodeList.getLength(); j++) { nodeAlignment.setToponymName(nodeList.item(j).getTextContent()); } } nodeList = element.getElementsByTagName("alternateName"); if (nodeList != null && nodeList.getLength() > 0) { for (int j = 0; j < nodeList.getLength(); j++) { NodeLang nodeLang = new NodeLang(); //nodeAlignment.setToponymName(p.item(j).getTextContent()); ArrayList<String> langueFound = new ArrayList<>(); org.w3c.dom.Element el = (org.w3c.dom.Element) nodeList.item(j); if (el.hasAttribute("lang")) { nodeLang.setCode(el.getAttribute("lang")); nodeLang.setValue(nodeList.item(j).getTextContent()); } nodeLangs.add(nodeLang); } nodeAlignment.setAlltraductions(nodeLangs); } listeAlign.add(nodeAlignment); } } catch (ParserConfigurationException | SAXException | IOException e) { } } catch (MalformedURLException e) { } catch (IOException e) { } return listeAlign; }
From source file:msi.gama.doc.util.UnifyDoc.java
License:Open Source License
private static Document mergeFiles(final HashMap<String, File> hmFilesPackages) { try {//from w ww . j a v a2 s.c om SAXBuilder builder = new SAXBuilder(); Document doc = null; doc = new Document(new Element(XMLElements.DOC)); for (String elt : tabEltXML) { doc.getRootElement().addContent(new Element(elt)); } for (Entry<String, File> fileDoc : hmFilesPackages.entrySet()) { Document docTemp = builder.build(fileDoc.getValue()); for (String catXML : tabEltXML) { if (docTemp.getRootElement().getChild(catXML) != null) { List<Element> existingElt = doc.getRootElement().getChild(catXML).getChildren(); for (Element e : docTemp.getRootElement().getChild(catXML).getChildren()) { // Do not add the projectName for every kinds of // categories // if (!Arrays.asList(tabCategoriesEltXML).contains(catXML)) { e.setAttribute("projectName", fileDoc.getKey()); // } // Test whether the element is already in the merged // doc boolean found = false; for (Element exElt : existingElt) { boolean equals = exElt.getName().equals(e.getName()); for (Attribute att : exElt.getAttributes()) { String valueExElt = exElt.getAttribute(att.getName()) != null ? exElt.getAttributeValue(att.getName()) : ""; String valueE = e.getAttribute(att.getName()) != null ? e.getAttributeValue(att.getName()) : ""; equals = equals && valueExElt.equals(valueE); } found = found || equals; } // Add if it is not already in the merged doc if (!found) { doc.getRootElement().getChild(catXML).addContent(e.clone()); } } } } } // Add an element for the generated types doc.getRootElement().getChild(XMLElements.OPERATORS_CATEGORIES) .addContent(new Element(XMLElements.CATEGORY).setAttribute(XMLElements.ATT_CAT_ID, new TypeConverter().getProperCategory("Types"))); return doc; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:multiprocDM.wow.java
public static void main(String[] args) { SAXBuilder sxb = new SAXBuilder(); try {/* www. j a v a2 s . c o m*/ Document document = sxb.build(new File("mpts30.xml")); Element racine = document.getRootElement(); for (Element taskset : racine.getChildren("taskset")) { for (Element task : taskset.getChildren("Task")) { if (task.getAttribute("Compute").getLongValue() > task.getAttribute("Deadline").getLongValue()) System.exit(0); } } System.out.println("Ok"); //System.out.println(racine.getChildren("taskset").get(250).getChildren("Task").get(9).getAttribute("Compute").getLongValue()); } catch (Exception e) { } }
From source file:mx.com.pixup.portal.dao.ArtistaParserDaoJdbc.java
public void parserXML() { try {/* w ww .ja v a 2 s . c o m*/ //variables BD String sql = "INSERT INTO artista VALUES (?,?,?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz Element artistas = this.xmlDocumento.getRootElement(); //elementos 2do nivel List<Element> listaArtistas = artistas.getChildren(); Iterator<Element> i = listaArtistas.iterator(); while (i.hasNext()) { Element artista = i.next(); //Elementos de tercer nivel Attribute id = artista.getAttribute("id"); Element nombre = artista.getChild("nombre"); Element descripcion = artista.getChild("descripcion"); //construye parametros de la query preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id.getIntValue()); preparedStatement.setString(2, nombre.getText()); preparedStatement.setString(3, descripcion.getText()); preparedStatement.execute(); } //preparedStatement = connection.prepareStatement(sql); // preparedStatement.setInt(1, valor); // preparedStatement.execute(); connection.commit(); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }
From source file:mx.com.pixup.portal.dao.CancionParserDaoJdbc.java
public void parserXML() { try {// w w w. ja v a2s . c o m //variables BD String sql = "INSERT INTO cancion VALUES (?,?,?)"; //String sql = "INSERT INTO cancion(nombre, duracion) VALUES (?,?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz Element cancion = this.xmlDocumento.getRootElement(); //elementos 2do nivel Element nombre = cancion.getChild("nombre"); Element duracion = cancion.getChild("duracion"); Attribute id = cancion.getAttribute("id"); //construye parametros de la query preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id.getIntValue()); preparedStatement.setString(2, nombre.getText()); preparedStatement.setString(3, duracion.getText()); preparedStatement.execute(); connection.commit(); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }