List of usage examples for org.dom4j.io SAXReader read
public Document read(InputSource in) throws DocumentException
Reads a Document from the given InputSource
using SAX
From source file:com.olympum.tools.CsJniNetWrapperGenerator.java
License:Open Source License
public void generate(String filename, String dir) { try {/*from w w w .ja va2 s. c o m*/ SAXReader reader = new SAXReader(); Document apiDocument = reader.read(new File(filename)); Element root = apiDocument.getRootElement(); if (root != null && root.getName().equals("api")) { populateMangleMap(root); generate(root, dir); } else { throw new RuntimeException(filename + " does not contain root " + "element `api'."); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.openkm.openmeetings.service.RestService.java
License:Open Source License
/** * call// w w w.j a va 2 s . c o m * * @param request * @param param * @return * @throws Exception */ public static Map<String, Element> callMap(String request, Object param) throws Exception { HttpClient client = new HttpClient(); GetMethod method = null; try { method = new GetMethod(getEncodetURI(request).toString()); } catch (MalformedURLException e) { e.printStackTrace(); } int statusCode = 0; try { statusCode = client.executeMethod(method); } catch (HttpException e) { throw new Exception( "Connection to OpenMeetings refused. Please check your OpenMeetings configuration."); } catch (IOException e) { throw new Exception( "Connection to OpenMeetings refused. Please check your OpenMeetings configuration."); } switch (statusCode) { case 200: // OK break; case 400: throw new Exception( "Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect."); case 403: throw new Exception( "Forbidden. You do not have permission to access this resource, or are over your rate limit."); case 503: throw new Exception( "Service unavailable. An internal problem prevented us from returning data to you."); default: throw new Exception("Your call to OpenMeetings! Web Services returned an unexpected HTTP status of: " + statusCode); } InputStream rstream = null; try { rstream = method.getResponseBodyAsStream(); } catch (IOException e) { e.printStackTrace(); throw new Exception("No Response Body"); } BufferedReader br = new BufferedReader(new InputStreamReader(rstream)); SAXReader reader = new SAXReader(); Document document = null; String line; try { while ((line = br.readLine()) != null) { document = reader.read(new ByteArrayInputStream(line.getBytes("UTF-8"))); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new Exception("UnsupportedEncodingException by SAXReader"); } catch (IOException e) { e.printStackTrace(); throw new Exception("IOException by SAXReader in REST Service"); } catch (DocumentException e) { e.printStackTrace(); throw new Exception("DocumentException by SAXReader in REST Service"); } finally { br.close(); } Element root = document.getRootElement(); Map<String, Element> elementMap = new LinkedHashMap<String, Element>(); for (@SuppressWarnings("unchecked") Iterator<Element> it = root.elementIterator(); it.hasNext();) { Element item = it.next(); if (item.getNamespacePrefix() == "soapenv") { throw new Exception(item.getData().toString()); } String nodeVal = item.getName(); elementMap.put(nodeVal, item); } return elementMap; }
From source file:com.openkm.openmeetings.service.RestService.java
License:Open Source License
/** * call/*from ww w . j a va 2 s . co m*/ * * @param request * @param param * @return * @throws Exception */ public static List<Element> callList(String request, Object param) throws Exception { HttpClient client = new HttpClient(); GetMethod method = null; try { method = new GetMethod(getEncodetURI(request).toString()); } catch (MalformedURLException e) { e.printStackTrace(); } int statusCode = 0; try { statusCode = client.executeMethod(method); } catch (HttpException e) { throw new Exception( "Connection to OpenMeetings refused. Please check your OpenMeetings configuration."); } catch (IOException e) { throw new Exception( "Connection to OpenMeetings refused. Please check your OpenMeetings configuration."); } switch (statusCode) { case 200: // OK break; case 400: throw new Exception( "Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect."); case 403: throw new Exception( "Forbidden. You do not have permission to access this resource, or are over your rate limit."); case 503: throw new Exception( "Service unavailable. An internal problem prevented us from returning data to you."); default: throw new Exception("Your call to OpenMeetings! Web Services returned an unexpected HTTP status of: " + statusCode); } InputStream rstream = null; try { rstream = method.getResponseBodyAsStream(); } catch (IOException e) { e.printStackTrace(); throw new Exception("No Response Body"); } BufferedReader br = new BufferedReader(new InputStreamReader(rstream)); SAXReader reader = new SAXReader(); Document document = null; String line; try { while ((line = br.readLine()) != null) { document = reader.read(new ByteArrayInputStream(line.getBytes("UTF-8"))); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new Exception("UnsupportedEncodingException by SAXReader"); } catch (IOException e) { e.printStackTrace(); throw new Exception("IOException by SAXReader in REST Service"); } catch (DocumentException e) { e.printStackTrace(); throw new Exception("DocumentException by SAXReader in REST Service"); } finally { br.close(); } Element root = document.getRootElement(); List<Element> elementList = new ArrayList<Element>(); for (@SuppressWarnings("unchecked") Iterator<Element> it = root.elementIterator(); it.hasNext();) { Element item = it.next(); if (item.getNamespacePrefix() == "soapenv") { throw new Exception(item.getData().toString()); } elementList.add(item); } return elementList; }
From source file:com.orange.atk.atkUI.anaMixScript.reportGenerator.resultLink.MixScriptResultLink.java
License:Apache License
/** * @param resultsFile// www . j a v a 2s .co m */ public MixScriptResultLink(File resultsFile) { resultsTable = new Hashtable<String, Vector<MixScriptResult>>(); SAXReader reader = new SAXReader(); try { doc = reader.read(resultsFile); root = doc.getRootElement(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:com.orange.atk.atkUI.anaScript.reportGenerator.resultLink.JatkResultLink.java
License:Apache License
/** * @param resultsFile/*w ww. j a v a 2 s . co m*/ */ public JatkResultLink(File resultsFile) { resultsTable = new Hashtable<String, Vector<JatkResult>>(); SAXReader reader = new SAXReader(); try { doc = reader.read(resultsFile); root = doc.getRootElement(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:com.orange.atk.atkUI.corecli.utils.FileUtilities.java
License:Apache License
/** * Copy a source html file into a destination file, patching the style sheet * on the fly for the given one.//from www .j a v a 2 s . c o m * * @param in * source html file * @param out * destination file * @param newStyleSheetPath * the new css style sheet absolute path * @throws Exception */ public static void copyHTMLFilePrettyPrint(File in, File out, String newStyleSheetPath) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(in.getAbsolutePath()); Element linkElem = (Element) document.selectSingleNode("/html/head/link"); if (linkElem != null) { linkElem.addAttribute("href", newStyleSheetPath); } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileOutputStream(out), format); writer.write(document); writer.close(); }
From source file:com.orange.atk.atkUI.corecli.utils.XMLParser.java
License:Apache License
public XMLParser(File f, String dtdURL, String dtdDirectory) { this.file = f; SAXReader reader = new SAXReader(); if (dtdURL != null && dtdDirectory != null) { reader.setEntityResolver(new MatosResolver(dtdURL, dtdDirectory)); }/*w w w .j a v a 2 s .c o m*/ try { doc = reader.read(f); root = doc.getRootElement(); } catch (DocumentException e) { Alert.raise(e, "Error with file '" + f.getAbsolutePath() + "': \n" + e.getMessage()); } }
From source file:com.ostrichemulators.semtool.poi.main.LowMemXlsReader.java
/** * Gets sheet name-to-id mapping// w w w . j a va2s . com * * @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 {// w ww . ja v 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.pactera.edg.am.metamanager.extractor.util.Dom4jReader.java
License:Open Source License
/** * /*from ww w . ja v a2s. c o m*/ * @param file * @return */ public boolean initDocument(InputStream input) { SAXReader xmlReader = new SAXReader(); try { document = xmlReader.read(new BufferedReader(createReader(input, "UTF-8"))); return true; } catch (DocumentException e) { e.printStackTrace(); } finally { } return false; }