/** * Performs an XPATH lookup in an xml document whose filename is specified by the first parameter * (assumed to be in the auxiliary subdirectory) The XPATH expression is supplied as the second * string parameter The return value is of type string e.g. this is currently used primarily for * looking up the Company Prefix Index for encoding a GS1 Company Prefix into a 64-bit EPC tag */ private String xpathlookup(String xml, String expression) { try { // Parse the XML as a W3C document. DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(new File(xmldir + File.separator + "auxiliary" + File.separator + xml)); XPath xpath = XPathFactory.newInstance().newXPath(); String rv = (String) xpath.evaluate(expression, document, XPathConstants.STRING); return rv; } catch (ParserConfigurationException e) { System.err.println("ParserConfigurationException caught..."); e.printStackTrace(); return null; } catch (XPathExpressionException e) { System.err.println("XPathExpressionException caught..."); e.printStackTrace(); return null; } catch (SAXException e) { System.err.println("SAXException caught..."); e.printStackTrace(); return null; } catch (IOException e) { System.err.println("IOException caught..."); e.printStackTrace(); return null; } }
/** * Saves the query string to a text file. Unspectacular. * * @param completeQuery the query string * @throws IOException */ protected void saveCompleteQuery(String completeQuery) throws IOException { String queryFileName = outputDir + "query" + queryCount + "_" + currentQueryName + ".txt"; System.out.println("\n Saving query to: " + queryFileName); Writer out = new OutputStreamWriter(new FileOutputStream(queryFileName)); try { out.write(completeQuery); } catch (IOException e) { e.printStackTrace(); } finally { out.close(); } }