Package org.exist.xquery.value

Examples of org.exist.xquery.value.BinaryValue


        }

        //get the image
        Image image = null;
        try {
            BinaryValue imageData = (BinaryValue) args[0].itemAt(0);
            image = ImageIO.read(imageData.getInputStream());
        } catch (IOException ioe) {
            logger.error("Unable to read image data!", ioe);
            return Sequence.EMPTY_SEQUENCE;
        }
View Full Code Here


        }

        //get the image
        Image image = null;
        try {
            BinaryValue imageData = (BinaryValue) args[0].itemAt(0);
            image = ImageIO.read(imageData.getInputStream());
        } catch (IOException ioe) {
            logger.error("Unable to read image data!", ioe);
            return Sequence.EMPTY_SEQUENCE;
        }
View Full Code Here

    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        if(args[0].isEmpty() || args[1].isEmpty()) {
            return (Sequence.EMPTY_SEQUENCE);
        }

        final BinaryValue binary = (BinaryValue) args[0].itemAt(0);
        final String contentType = args[1].getStringValue();
        String filename = null;

        if((args.length > 2) && !args[2].isEmpty()) {
            filename = args[2].getStringValue();
        }

        final ResponseModule myModule = (ResponseModule) context.getModule(ResponseModule.NAMESPACE_URI);

        // response object is read from global variable $response
        final Variable respVar = myModule.resolveVariable(ResponseModule.RESPONSE_VAR);

        if((respVar == null) || (respVar.getValue() == null)) {
            throw (new XPathException(this, "No response object found in the current XQuery context."));
        }

        if(respVar.getValue().getItemType() != Type.JAVA_OBJECT) {
            throw (new XPathException(this, "Variable $response is not bound to an Java object."));
        }

        final JavaObjectValue respValue = (JavaObjectValue) respVar.getValue().itemAt(0);

        if(!"org.exist.http.servlets.HttpResponseWrapper".equals(respValue.getObject().getClass().getName())) {
            throw (new XPathException(this, signature.toString() + " can only be used within the EXistServlet or XQueryServlet"));
        }

        final ResponseWrapper response = (ResponseWrapper) respValue.getObject();
        response.setHeader("Content-Type", contentType);

        if(filename != null) {
            response.setHeader("Content-Disposition", "inline; filename=\"" + filename + "\"");
        }

        try {
            final OutputStream os = response.getOutputStream();
            binary.streamBinaryTo(response.getOutputStream());
            os.close();

            //commit the response
            response.flushBuffer();
        } catch (final IOException e) {
View Full Code Here

            streamSource.setInputStream(is);

        } else if (item.getType() == Type.BASE64_BINARY || item.getType() == Type.HEX_BINARY) {
            LOG.debug("Streaming base64 binary");

            final BinaryValue binary = (BinaryValue) item;
           
            final byte[] data = (byte[]) binary.toJavaObject(byte[].class);
            final InputStream is = new ByteArrayInputStream(data);
            streamSource.setInputStream(is);

            //TODO consider using BinaryValue.getInputStream()
View Full Code Here

        final String value = "hello world";
        final String encoding = "UTF-8";

        TestableBinaryToString testable = new TestableBinaryToString(new MockXQueryContext(), null);

        final BinaryValue binary = testable.stringToBinary(value, encoding);
        StringValue result = testable.binaryToString(binary, encoding);

        assertEquals(value, result.getStringValue());
    }
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.BinaryValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.