use of qz.exception.NullCommandException in project tray by qzind.
the class FileUtilities method readXMLFile.
/**
* Reads an XML file from URL, searches for the tag specified by
* {@code dataTag} tag name and returns the {@code String} value
* of that tag.
*
* @param url location of the xml file to be read
* @param dataTag tag in the file to be searched
* @return value of the tag if found
*/
public static String readXMLFile(String url, String dataTag) throws DOMException, IOException, NullCommandException, ParserConfigurationException, SAXException {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url);
doc.getDocumentElement().normalize();
log.info("Root element " + doc.getDocumentElement().getNodeName());
NodeList nodeList = doc.getElementsByTagName(dataTag);
if (nodeList.getLength() > 0) {
return nodeList.item(0).getTextContent();
}
throw new NullCommandException(String.format("Node \"%s\" could not be found in XML file specified", dataTag));
}
use of qz.exception.NullCommandException in project tray by qzind.
the class PrintRaw method printToPrinter.
/**
* Constructs a {@code SimpleDoc} with the {@code commands} byte array.
*/
private void printToPrinter(PrintService service, byte[] cmds, PrintOptions.Raw rawOpts) throws PrintException {
if (service == null) {
throw new NullPrintServiceException("Service cannot be null");
}
if (cmds == null || cmds.length == 0) {
throw new NullCommandException("No commands found to send to the printer");
}
SimpleDoc doc = new SimpleDoc(cmds, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(new JobName(rawOpts.getJobName(Constants.RAW_PRINT), Locale.getDefault()));
DocPrintJob printJob = service.createPrintJob();
waitForPrint(printJob, doc, attributes);
}
Aggregations