List of usage examples for org.jdom2 Attribute getIntValue
public int getIntValue() throws DataConversionException
int
form, and if no conversion can occur, throws a DataConversionException
From source file:com.ardor3d.extension.model.collada.jdom.ColladaDOMUtil.java
License:Open Source License
/** * Parse an int value in an attribute.//www .ja v a 2 s.c o m * * @param input * Element containing the attribute * @param attributeName * Attribute name to parse a value for * @return parsed integer */ public int getAttributeIntValue(final Element input, final String attributeName, final int defaultVal) { final Attribute attribute = input.getAttribute(attributeName); if (attribute != null) { try { return attribute.getIntValue(); } catch (final DataConversionException e) { logger.log(Level.WARNING, "Could not parse int value", e); } } return defaultVal; }
From source file:com.sangupta.jerry.util.DomUtils.java
License:Apache License
/** * Returns the integer value of the attribute from the element. * /*from w w w . j a va 2 s .c o m*/ * @param element * @param attributeName */ public static int getAttributeValueAsInt(Element element, String attributeName) { Attribute attribute = element.getAttribute(attributeName); if (attribute != null) { try { return attribute.getIntValue(); } catch (DataConversionException e) { e.printStackTrace(); } } return 0; }
From source file:io.wcm.handler.commons.dom.AbstractElement.java
License:Apache License
/** * Gets attribute value as integer./*ww w . jav a2 s .c om*/ * @param attributeName Attribute name * @return Attribute value as integer or 0 if not set. */ public final int getAttributeValueAsInteger(String attributeName) { Attribute attribute = getAttribute(attributeName); if (attribute == null) { return 0; } else { try { return attribute.getIntValue(); } catch (DataConversionException ex) { return 0; } } }
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: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 {/*w w w.ja v a2 s .c o m*/ 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 {//from w ww .jav a 2 s . co m 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:mx.com.pixup.portal.dao.ArtistaParserDaoJdbc.java
public void parserXML() { try {/*from www. ja v a 2 s. c om*/ //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 {//from ww w .j av a 2 s. c om //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()); } }
From source file:mx.com.pixup.portal.dao.DiscoParserDaoJdbc.java
public void parserXML() { try {/*ww w . jav a2 s . c o m*/ //variables BD String sql = "INSERT INTO disco VALUES (?,?,?,?,?,?,?,?,?,?,?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz Element discos = this.xmlDocument.getRootElement(); //elementos 2do nivel List<Element> listaDiscos = discos.getChildren(); Iterator<Element> i = listaDiscos.iterator(); while (i.hasNext()) { Element disco = i.next(); Attribute id = disco.getAttribute("id"); Attribute idioma = disco.getAttribute("idioma"); Attribute pais = disco.getAttribute("pais"); Attribute disquera = disco.getAttribute("disquera"); Attribute genero = disco.getAttribute("genero"); //Elementos de 3er nivel Element titulo = disco.getChild("titulo"); Element fechalanzamiento = disco.getChild("fechalanzamiento"); Element precio = disco.getChild("precio"); Element cantidad = disco.getChild("cantidad"); Element promocion = disco.getChild("promocion"); Element iva = disco.getChild("iva"); //construye parametros de la query preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id.getIntValue()); preparedStatement.setString(2, titulo.getText()); preparedStatement.setString(3, fechalanzamiento.getText()); preparedStatement.setDouble(4, Double.parseDouble(precio.getText())); preparedStatement.setInt(5, Integer.parseInt(cantidad.getText())); preparedStatement.setInt(6, idioma.getIntValue()); preparedStatement.setInt(7, pais.getIntValue()); preparedStatement.setInt(8, disquera.getIntValue()); preparedStatement.setInt(9, genero.getIntValue()); preparedStatement.setInt(10, Integer.parseInt(promocion.getText())); preparedStatement.setInt(11, Integer.parseInt(iva.getText())); 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.EstadoMunicipioParserDaoJdbc.java
public void parserXML() { try {/*from w ww . j av a 2 s . co m*/ //variables BD String sql = "INSERT INTO estado VALUES (?,?)"; String sqlM = "INSERT INTO municipio VALUES (?,?,?)"; PreparedStatement preparedStatement; Connection connection = dataSource.getConnection(); connection.setAutoCommit(false); //se obtiene elemento raiz Element estado = this.xmlDocumento.getRootElement(); //elementos 2do nivel Element nombre = estado.getChild("nombre"); Element municipios = estado.getChild("municipios"); Attribute id = estado.getAttribute("id"); //construye parametros de la query preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, id.getIntValue()); preparedStatement.setString(2, nombre.getText()); preparedStatement.execute(); List<Element> listaMunicipios = municipios.getChildren("municipio"); Iterator<Element> i = listaMunicipios.iterator(); while (i.hasNext()) { Element municipio = i.next(); //Elementos de tercer nivel Attribute idMunicipio = municipio.getAttribute("id"); String nombreMunicipio = municipio.getText(); //construye parametros de la query preparedStatement = connection.prepareStatement(sqlM); preparedStatement.setInt(1, idMunicipio.getIntValue()); preparedStatement.setString(2, nombreMunicipio); preparedStatement.setInt(3, id.getIntValue()); preparedStatement.execute(); } connection.commit(); } catch (Exception e) { //*** se quit el return porque el mtodo es void System.out.println(e.getMessage()); } }