Search in sources :

Example 1 with NullCommandException

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));
}
Also used : NodeList(org.w3c.dom.NodeList) NullCommandException(qz.exception.NullCommandException) Document(org.w3c.dom.Document)

Example 2 with NullCommandException

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);
}
Also used : JobName(javax.print.attribute.standard.JobName) NullCommandException(qz.exception.NullCommandException) NullPrintServiceException(qz.exception.NullPrintServiceException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Aggregations

NullCommandException (qz.exception.NullCommandException)2 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)1 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)1 JobName (javax.print.attribute.standard.JobName)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1 NullPrintServiceException (qz.exception.NullPrintServiceException)1