Search in sources :

Example 1 with WSFile

use of org.openhab.binding.ihc.ws.datatypes.WSFile in project openhab1-addons by openhab.

the class IhcClient method LoadProjectFileFromController.

private Document LoadProjectFileFromController() throws IhcExecption {
    try {
        WSProjectInfo projectInfo = getProjectInfo();
        int numberOfSegments = controllerService.getProjectNumberOfSegments();
        int segmentationSize = controllerService.getProjectSegmentationSize();
        logger.debug("Number of segments: {}", numberOfSegments);
        logger.debug("Segmentation size: {}", segmentationSize);
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        for (int i = 0; i < numberOfSegments; i++) {
            logger.debug("Downloading segment {}", i);
            WSFile data = controllerService.getProjectSegment(i, projectInfo.getProjectMajorRevision(), projectInfo.getProjectMinorRevision());
            byteStream.write(data.getData());
        }
        logger.debug("File size before base64 encoding: {} bytes", byteStream.size());
        byte[] decodedBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(byteStream.toString());
        logger.debug("File size after base64 encoding: {} bytes", decodedBytes.length);
        GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(decodedBytes));
        InputStreamReader in = new InputStreamReader(gzis, "ISO-8859-1");
        InputSource reader = new InputSource(in);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        return db.parse(reader);
    } catch (Exception e) {
        throw new IhcExecption(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStreamReader(java.io.InputStreamReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocketTimeoutException(java.net.SocketTimeoutException) WSFile(org.openhab.binding.ihc.ws.datatypes.WSFile) GZIPInputStream(java.util.zip.GZIPInputStream) WSProjectInfo(org.openhab.binding.ihc.ws.datatypes.WSProjectInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 2 with WSFile

use of org.openhab.binding.ihc.ws.datatypes.WSFile in project openhab1-addons by openhab.

the class IhcControllerService method getProjectSegment.

/**
     * Query project segment data.
     * 
     * @param index
     *            segments index.
     * @param major
     *            project major revision number.
     * @param minor
     *            project minor revision number.
     * @return segments data.
     */
public synchronized WSFile getProjectSegment(int index, int major, int minor) throws IhcExecption {
    final String soapQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body>" + " <ns1:getIHCProjectSegment1 xmlns:ns1=\"utcs\" xsi:type=\"xsd:int\">%s</ns1:getIHCProjectSegment1>" + " <ns2:getIHCProjectSegment2 xmlns:ns2=\"utcs\" xsi:type=\"xsd:int\">%s</ns2:getIHCProjectSegment2>" + " <ns3:getIHCProjectSegment3 xmlns:ns3=\"utcs\" xsi:type=\"xsd:int\">%s</ns3:getIHCProjectSegment3>" + "</soap:Body>" + "</soap:Envelope>";
    String query = String.format(soapQuery, index, major, minor);
    openConnection(url);
    setRequestProperty("SOAPAction", "getIHCProjectSegment");
    String response = sendQuery(query, timeout);
    closeConnection();
    WSFile file = new WSFile();
    file.encodeData(response);
    return file;
}
Also used : WSFile(org.openhab.binding.ihc.ws.datatypes.WSFile)

Aggregations

WSFile (org.openhab.binding.ihc.ws.datatypes.WSFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 SocketTimeoutException (java.net.SocketTimeoutException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 WSProjectInfo (org.openhab.binding.ihc.ws.datatypes.WSProjectInfo)1 InputSource (org.xml.sax.InputSource)1