List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
private void emitMethods(PrintStream out, Element clazz, boolean isClassFinal, boolean isClassInterface, boolean forceNonAbstract) { String type = normalize(clazz.attributeValue("name")); String className = getClassNameFromType(type); List methods = clazz.elements("method"); for (int i = 0; i < methods.size(); i++) { Element e = (Element) methods.get(i); boolean isAbstract = e.attributeValue("abstract") != null; if (!forceNonAbstract || (forceNonAbstract && isAbstract)) emitMethod(out, type, className, e, i, isClassFinal, isClassInterface, forceNonAbstract); }//from w w w . j a v a2 s .c om }
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
private void emitInnerClasses(PrintStream out, Element parentClass) { List declaredClasses = parentClass.elements("class"); for (int i = 0; i < declaredClasses.size(); i++) { Element clazz = (Element) declaredClasses.get(i); emitClassDeclaration(out, clazz, parentClass); }//w w w . j a v a 2 s .com }
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
private void mangleType(Element clazz, Element parentClass) { int parentModifers = 0; if (parentClass != null) parentModifers = Integer.parseInt(parentClass.attributeValue("modifiers")); if (Modifier.isInterface(parentModifers)) { String typeName = clazz.attributeValue("name"); String mangledType = normalize(typeName.replace('$', '_')); System.out.println("Mangled " + typeName + " as " + mangledType); mangledTypes.put(typeName, mangledType); }/*w w w. ja va 2 s.c o m*/ List declaredClasses = clazz.elements("class"); for (int i = 0; i < declaredClasses.size(); i++) { Element e = (Element) declaredClasses.get(i); mangleType(e, clazz); } }
From source file:com.orange.atk.atkUI.corecli.utils.XMLParser.java
License:Apache License
/** * Extracts the set of XML elements having a given name in a given XML * element./*from w w w. j a v a 2 s . co m*/ * @param e the element to explore * @param name the name of the elements searched * @return an array of elements */ public Element[] getElements(Element e, String name) { List<?> list = e.elements(name); int l = list.size(); Element r[] = new Element[l]; for (int i = 0; i < l; i++) { r[i] = (Element) list.get(i); } return r; }
From source file:com.orange.atk.atkUI.corecli.utils.XMLParser.java
License:Apache License
/** * Extracts a given XML element having a given name son of a given * XML element. There should be only one such element: * @param e the element to explore//ww w . java2 s . c o m * @param name the name of the elements searched * @return an array of elements */ public Element getElement(Element e, String name) { List<?> list = e.elements(name); if (list.size() == 1) return (Element) list.get(0); else return null; }
From source file:com.ostrichemulators.semtool.poi.main.LowMemXlsReader.java
/** * Gets sheet name-to-id mapping//from w w w .jav a 2 s.c o m * * @param r * @return */ private LinkedHashMap<String, String> readSheetInfo(XSSFReader r) { LinkedHashMap<String, String> map = new LinkedHashMap<>(); try (InputStream is = r.getWorkbookData()) { SAXReader sax = new SAXReader(); Document doc = sax.read(is); Namespace ns = new Namespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); Element sheets = doc.getRootElement().element("sheets"); for (Object sheet : sheets.elements("sheet")) { Element e = Element.class.cast(sheet); String name = e.attributeValue("name"); String id = e.attributeValue(new QName("id", ns)); map.put(name, id); } } catch (Exception e) { log.error(e, e); } return map; }
From source file:com.oubeichen.gefexp.ShapesEditor.java
License:Open Source License
@Override protected void setInput(IEditorInput input) { super.setInput(input); try {//from w w w .j av a 2 s. co m IFile file = ((IFileEditorInput) input).getFile(); if (!file.getName().contains(".raw.obsp")) {//XXX.raw.obsp ObjectInputStream in = new ObjectInputStream(file.getContents()); diagram = (ShapesDiagram) in.readObject(); in.close(); } else { diagram = new ShapesDiagram(); /*InputStreamReader isr = new InputStreamReader(file.getContents()); BufferedReader reader = new BufferedReader(isr); String tempString, name; ArrayList<String> shapename = new ArrayList<String>(); int shapenum, connnum; reader.readLine();//"Shape:" tempString = reader.readLine();//shape number try{ shapenum = Integer.parseInt(tempString); }catch(NumberFormatException ex){ shapenum = 0; } for(int i = 0;i < shapenum;i++){ int height, width, x, y; name = reader.readLine();//shape name shapename.add(name); reader.readLine();//"height:" tempString = reader.readLine();//shape height try{ height = Integer.parseInt(tempString); }catch(NumberFormatException ex){ height = 0; } reader.readLine();//"width:" tempString = reader.readLine();//shape width try{ width = Integer.parseInt(tempString); }catch(NumberFormatException ex){ width = 0; } reader.readLine();//"location:" tempString = reader.readLine();//shape location try{ x = Integer.parseInt(tempString.split(" ")[0]); }catch(NumberFormatException ex){ x = 0; } try{ y = Integer.parseInt(tempString.split(" ")[1]); }catch(NumberFormatException ex){ y = 0; } reader.readLine();//empty line //add to the diagram Shape sp; if(name.contains("Ellipse")){ sp = new EllipticalShape(); }else if(name.contains("Triangle")){ sp = new TriangularShape(); }else if(name.contains("Rectangle")){ sp = new RectangularShape(); }else{ System.err.println("Shape unsupported!"); sp = new EllipticalShape(); } sp.setSize(new Dimension(width, height)); sp.setLocation(new Point(x, y)); diagram.addChild(sp); } reader.readLine();//"Connections:" tempString = reader.readLine();//connection num try{ connnum = Integer.parseInt(tempString); }catch(NumberFormatException ex){ connnum = 0; } for(int i = 0;i < connnum;i++) { String source = reader.readLine(); String target = reader.readLine(); reader.readLine();//empty line int sourceindex = shapename.indexOf(source); int targetindex = shapename.indexOf(target); if(sourceindex == -1 || targetindex == -1) { System.err.println("Cannot find this shape!"); continue; } Shape sourceshape = (Shape) diagram.getChildren().get(sourceindex); Shape targetshape = (Shape) diagram.getChildren().get(targetindex); Connection conn = new Connection(sourceshape, targetshape); } reader.close();*/ SAXReader reader = new SAXReader(); Document document; try { reader.setEncoding("UTF-8"); document = reader.read(file.getContents());// } catch (DocumentException ex) { System.err.println("Cannot read input file!"); ex.printStackTrace(); throw new CoreException(null); } Element root = document.getRootElement(); Element shaperoot = root.element("shapes"); List list = shaperoot.elements("shape"); Iterator it = list.iterator(); ArrayList<String> shapename = new ArrayList<String>(); while (it.hasNext()) { Element shapeElm = (Element) it.next(); int height, width, x, y; String name = shapeElm.elementText("name"); try { height = Integer.parseInt(shapeElm.elementText("height")); width = Integer.parseInt(shapeElm.elementText("width")); x = Integer.parseInt(shapeElm.elementText("locx")); y = Integer.parseInt(shapeElm.elementText("locy")); Shape sp; if (name.contains("Ellipse")) { sp = new EllipticalShape(); } else if (name.contains("Triangle")) { sp = new TriangularShape(); } else if (name.contains("Rectangle")) { sp = new RectangularShape(); } else { System.err.println("Shape unsupported!"); sp = new EllipticalShape(); } diagram.addChild(sp); sp.setSize(new Dimension(width, height)); sp.setLocation(new Point(x, y)); shapename.add(name); } catch (Exception ex) { ex.printStackTrace(); } } Element connroot = root.element("connections"); list = connroot.elements("connection"); it = list.iterator(); while (it.hasNext()) { Element connElm = (Element) it.next(); String source = connElm.elementText("source"); String target = connElm.elementText("target"); int sourceindex = shapename.indexOf(source); int targetindex = shapename.indexOf(target); if (sourceindex == -1 || targetindex == -1) { System.err.println("Cannot find this shape!"); continue; } Shape sourceshape = (Shape) diagram.getChildren().get(sourceindex); Shape targetshape = (Shape) diagram.getChildren().get(targetindex); new Connection(sourceshape, targetshape); } } setPartName(file.getName()); } catch (CoreException e) { handleLoadException(e); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.poka.util.XmlSax.java
/** * SqlServer?//from w w w .ja v a 2 s . c o m * * @return */ public boolean changeSqlServerXmlAtt() { Document doc = load(sqlserverFile, true); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("session-factory"); List nodes = root1Elm.elements("property"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); String name = elm.attributeValue("name"); if (name.equals("connection.url")) { //String url = "jdbc:mysql://"+ip+":"+port+"/"+names; String url = "jdbc:sqlserver://" + ip + ":" + port + ";DatabaseName=" + names; elm.setText(url); } if (name.equals("connection.username")) { elm.setText(user); } if (name.equals("connection.password")) { elm.setText(pwd); } } return writeToXml(doc, sqlserverFile); }
From source file:com.poka.util.XmlSax.java
/** * ?sqlserver??// w w w.j a v a 2s . c om * * @return */ public void getSqlServerXmlVal() { Document doc = load(sqlserverFile, true); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("session-factory"); List nodes = root1Elm.elements("property"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); String name = elm.attributeValue("name"); if (name.equals("connection.url")) { String url = elm.getText(); int begingan = url.indexOf("//"); ip = url.substring(begingan + 2, url.lastIndexOf(":")); port = url.substring(url.lastIndexOf(":") + 1, url.lastIndexOf(";")); names = url.substring(url.lastIndexOf("=") + 1); } if (name.equals("connection.username")) { user = elm.getText(); } if (name.equals("connection.password")) { pwd = elm.getText(); } } }
From source file:com.poka.util.XmlSax.java
public boolean changeXmlAtt() { Document doc = load(f, true); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("session-factory"); List nodes = root1Elm.elements("property"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); String name = elm.attributeValue("name"); if (name.equals("connection.url")) { String url = ""; if (dbTyep.equals("mysql")) { url = " jdbc:mysql://" + ip + ":" + port + "/" + names + "?useUnicode=true&characterEncoding=utf8"; } else { url = "jdbc:sqlserver://" + ip + ":" + port + ";DatabaseName=" + names; }/* ww w . j a v a2 s. com*/ elm.setText(url); } if (name.equals("connection.username")) { elm.setText(user); } if (name.equals("connection.password")) { elm.setText(pwd); } } return writeToXml(doc, getF()); }