Package org.apache.abdera.model

Examples of org.apache.abdera.model.Document


    }

    public void writeTo(Base base, WritableByteChannel out, WriterOptions options) throws IOException {
        String charset = options.getCharset();
        if (charset == null) {
            Document doc = null;
            if (base instanceof Document)
                doc = (Document)base;
            else if (base instanceof Element) {
                doc = ((Element)base).getDocument();
            }
            charset = doc != null ? doc.getCharset() : null;
        }
        writeTo(base, Channels.newWriter(out, charset != null ? charset : "utf-8"), options);
    }
View Full Code Here


        ClientResponse resp = client.get(url);
        switch (resp.getType()) {
            case SUCCESS:
                try {
                    Document doc = resp.getDocument();
                    response.setContentType("application/json");
                    response.setCharacterEncoding("UTF-8");
                    if (doc.getEntityTag() != null)
                        response.setHeader("ETag", doc.getEntityTag().toString());
                    if (doc.getLanguage() != null)
                        response.setHeader("Content-Language", doc.getLanguage());
                    if (doc.getLastModified() != null)
                        response.setDateHeader("Last-Modified", doc.getLastModified().getTime());
                    OutputStream out = response.getOutputStream();
                    doc.writeTo("json", out);
                } catch (Exception e) {
                    response.sendError(500);
                    return;
                }
            case CLIENT_ERROR:
View Full Code Here

        Encryption enc = absec.getEncryption();
        EncryptionOptions options = enc.getDefaultEncryptionOptions();
        options.setDataEncryptionKey(key);

        // Encrypt the document using the generated key
        Document enc_doc = enc.encrypt(entry.getDocument(), options);

        assertEquals(new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), enc_doc.getRoot().getQName());

        // Decrypt the document using the generated key
        Document<Entry> entry_doc = enc.decrypt(enc_doc, options);

        assertTrue(entry_doc.getRoot() instanceof Entry);
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static <T extends Element> Direction guessDirectionFromEncoding(T element, boolean ignoredir) {
        if (!ignoredir && hasDirection(element))
            return getDirection(element);
        Document doc = element.getDocument();
        if (doc == null)
            return Direction.UNSPECIFIED;
        return Bidi.guessDirectionFromEncoding(doc.getCharset());
    }
View Full Code Here

        assertNotNull(resp);
        assertEquals(ResponseType.SUCCESS, resp.getType());
        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(),
                                          OpenSearchConstants.OPENSEARCH_DESCRIPTION_CONTENT_TYPE));

        Document doc = resp.getDocument();
        StringWriter writer = new StringWriter();
        doc.writeTo(writer);

        String result = writer.toString();
        System.out.println(result);

        assertXpathEvaluatesTo(SHORT_NAME, "/os:OpenSearchDescription/os:ShortName", result);
View Full Code Here

        Encryption enc = absec.getEncryption();
        EncryptionOptions options = enc.getDefaultEncryptionOptions();
        options.setDataEncryptionKey(key);

        // Encrypt the document using the generated key
        Document enc_doc = enc.encrypt(entry.getDocument(), options);

        enc_doc.writeTo(System.out);

        System.out.println("\n\n");

        // Decrypt the document using the generated key
        Document<Entry> entry_doc = enc.decrypt(enc_doc, options);
View Full Code Here

        // Prepare the encryption options
        Encryption enc = absec.getEncryption();

        // Encrypt the document using A's DHContext
        EncryptionOptions options = context_a.getEncryptionOptions(enc);
        Document enc_doc = enc.encrypt(entry.getDocument(), options);

        enc_doc.writeTo(System.out);

        System.out.println("\n\n");

        // Decrypt the document using B's DHContext
        options = context_b.getEncryptionOptions(enc);
View Full Code Here

        String charset = options.getCharset();
        if (charset == null) {
            if (base instanceof Document)
                charset = ((Document)base).getCharset();
            else if (base instanceof Element) {
                Document doc = ((Element)base).getDocument();
                if (doc != null)
                    charset = doc.getCharset();
            }
            if (charset == null)
                charset = "UTF-8";
        } else {
            Document doc = null;
            if (base instanceof Document)
                doc = (Document)base;
            else if (base instanceof Element)
                doc = ((Element)base).getDocument();
            if (doc != null)
                doc.setCharset(charset);
        }
        base.writeTo(new OutputStreamWriter(out, charset));
        finishCompressedOutputStream(out, options);
        if (options.getAutoClose())
            out.close();
View Full Code Here

    public Content setContent(InputStream in, String mediatype) {
        if (MimeTypeHelper.isText(mediatype)) {
            try {
                StringBuilder buf = new StringBuilder();
                String charset = MimeTypeHelper.getCharset(mediatype);
                Document doc = this.getDocument();
                charset = charset != null ? charset : doc != null ? doc.getCharset() : null;
                charset = charset != null ? charset : "UTF-8";
                InputStreamReader isr = new InputStreamReader(in, charset);
                char[] data = new char[500];
                int r = -1;
                while ((r = isr.read(data)) != -1) {
View Full Code Here

    public void writeTo(Writer writer, java.io.Writer out, WriterOptions options) throws IOException {
        writer.writeTo(this, out, options);
    }

    public void writeTo(OutputStream out) throws IOException {
        Document doc = getDocument();
        String charset = doc != null ? doc.getCharset() : "UTF-8";
        Writer writer = this.getFactory().getAbdera().getWriter();
        writeTo(writer, new OutputStreamWriter(out, charset));
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.model.Document

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.