List of usage examples for javax.xml.xpath XPathExpressionException getLocalizedMessage
public String getLocalizedMessage()
From source file:android.databinding.tool.MakeCopy.java
public static void main(String[] args) { if (args.length < 5) { System.out.println("required parameters: [-l] manifest adk-dir src-out-dir xml-out-dir " + "res-out-dir res-in-dir..."); System.out.println("Creates an android data binding class and copies resources from"); System.out.println("res-source to res-target and modifies binding layout files"); System.out.println("in res-target. Binding data is extracted into XML files"); System.out.println("and placed in xml-out-dir."); System.out.println(" -l indicates that this is a library"); System.out.println(" manifest path to AndroidManifest.xml file"); System.out.println(" src-out-dir path to where generated source goes"); System.out.println(" xml-out-dir path to where generated binding XML goes"); System.out.println(" res-out-dir path to the where modified resources should go"); System.out.println(// w w w . ja v a 2 s .c o m " res-in-dir path to source resources \"res\" directory. One" + " or more are allowed."); System.exit(1); } final boolean isLibrary = args[0].equals("-l"); final int indexOffset = isLibrary ? 1 : 0; final String applicationPackage; final int minSdk; final Document androidManifest = readAndroidManifest(new File(args[MANIFEST_INDEX + indexOffset])); try { final XPathFactory xPathFactory = XPathFactory.newInstance(); final XPath xPath = xPathFactory.newXPath(); applicationPackage = xPath.evaluate("string(/manifest/@package)", androidManifest); final Double minSdkNumber = (Double) xPath.evaluate("number(/manifest/uses-sdk/@android:minSdkVersion)", androidManifest, XPathConstants.NUMBER); minSdk = minSdkNumber == null ? 1 : minSdkNumber.intValue(); } catch (XPathExpressionException e) { e.printStackTrace(); System.exit(6); return; } final File srcDir = new File(args[SRC_INDEX + indexOffset], APP_SUBPATH); if (!makeTargetDir(srcDir)) { System.err.println("Could not create source directory " + srcDir); System.exit(2); } final File resTarget = new File(args[RES_OUT_INDEX + indexOffset]); if (!makeTargetDir(resTarget)) { System.err.println("Could not create resource directory: " + resTarget); System.exit(4); } final File xmlDir = new File(args[XML_INDEX + indexOffset]); if (!makeTargetDir(xmlDir)) { System.err.println("Could not create xml output directory: " + xmlDir); System.exit(5); } System.out.println("Application Package: " + applicationPackage); System.out.println("Minimum SDK: " + minSdk); System.out.println("Target Resources: " + resTarget.getAbsolutePath()); System.out.println("Target Source Dir: " + srcDir.getAbsolutePath()); System.out.println("Target XML Dir: " + xmlDir.getAbsolutePath()); System.out.println("Library? " + isLibrary); boolean foundSomeResources = false; for (int i = RES_IN_INDEX + indexOffset; i < args.length; i++) { final File resDir = new File(args[i]); if (!resDir.exists()) { System.out.println("Could not find resource directory: " + resDir); } else { System.out.println("Source Resources: " + resDir.getAbsolutePath()); try { FileUtils.copyDirectory(resDir, resTarget); addFromFile(resDir, resTarget); foundSomeResources = true; } catch (IOException e) { System.err.println("Could not copy resources from " + resDir + " to " + resTarget + ": " + e.getLocalizedMessage()); System.exit(3); } } } if (!foundSomeResources) { System.err.println("No resource directories were found."); System.exit(7); } processLayoutFiles(applicationPackage, resTarget, srcDir, xmlDir, minSdk, isLibrary); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.xml.XmlReaderXPath.java
private void ensureIdValidity(Node node) { NodeList idNodes = null;//from w ww. ja va 2 s .co m try { idNodes = (NodeList) compiledIdXPath.evaluate(node, XPathConstants.NODESET); } catch (XPathExpressionException e) { // Already checked in initialize(), should not happen. getUimaContext().getLogger().log(Level.WARNING, e.getLocalizedMessage()); return; } if (idNodes.getLength() == 0) { // DocID not found throw new IllegalStateException( "DocID tag \"" + docIdTag + "\" not found: " + currentFileResource.getFile().getAbsolutePath()); } else if (idNodes.getLength() != 1) { // DocID not unique (two id elements in one doc) throw new IllegalStateException("DocID tag \"" + docIdTag + "\" has multiple occurences: " + currentFileResource.getFile().getAbsolutePath()); } Node idNode = idNodes.item(0); String id = idNode.getTextContent(); if (StringUtils.isEmpty(id)) { // Empty DocID (e.g. <num></num>) throw new IllegalStateException("Emtpy DocID tag \"" + docIdTag + "\" in file: " + currentFileResource.getFile().getAbsolutePath()); } getUimaContext().getLogger().log(Level.INFO, "ID '" + id + "' found"); }