Search in sources :

Example 1 with WSProjectInfo

use of org.openhab.binding.ihc.ws.datatypes.WSProjectInfo 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 WSProjectInfo

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

the class IhcControllerService method getProjectInfo.

/**
     * Query project information from the controller.
     * 
     * @return project information.
     * @throws IhcExecption
     */
public synchronized WSProjectInfo getProjectInfo() throws IhcExecption {
    openConnection(url);
    setRequestProperty("SOAPAction", "getProjectInfo");
    String response = sendQuery(emptyQuery, timeout);
    closeConnection();
    WSProjectInfo projectInfo = new WSProjectInfo();
    projectInfo.encodeData(response);
    return projectInfo;
}
Also used : WSProjectInfo(org.openhab.binding.ihc.ws.datatypes.WSProjectInfo)

Aggregations

WSProjectInfo (org.openhab.binding.ihc.ws.datatypes.WSProjectInfo)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 WSFile (org.openhab.binding.ihc.ws.datatypes.WSFile)1 InputSource (org.xml.sax.InputSource)1