Package org.apache.abdera.writer

Examples of org.apache.abdera.writer.StreamWriter


   
    if (response.isCommitted()) {
        log.error("Could not write an error message as the headers & HTTP status were already committed!");
    } else {
      response.setStatus(500);
      StreamWriter sw =
        getAbdera().newStreamWriter()
                   .setOutputStream(
                     response.getOutputStream(),
                     "UTF-8");
      Error.create(sw, 500, message,t);
      sw.close();
    }
  }
View Full Code Here


   
    if (response.isCommitted()) {
        log.error("Could not write an error message as the headers & HTTP status were already committed!");
    } else {
      response.setStatus(500);
      StreamWriter sw =
        getAbdera().newStreamWriter()
                   .setOutputStream(
                     response.getOutputStream(),
                     "UTF-8");
      Error.create(sw, 500, message,t);
      sw.close();
    }
  }
View Full Code Here

            type = _text != null ? _text.type() : type;
            contentValue = source;
            valueContext = objectContext;
        }
        QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor());
        StreamWriter sw = context.getStreamWriter();
        sw.startText(qname, type);
        writeAttributes(source, objectContext, context, conventions);

        switch (type) {
            case TEXT:
            case HTML:
                sw.writeElementText(toString(contentValue));
                break;
            case XHTML:
                Div div = null;
                if (contentValue instanceof Div)
                    div = (Div)contentValue;
View Full Code Here

    protected void process(Object source,
                           ObjectContext objectContext,
                           SerializationContext context,
                           Conventions conventions) {

        StreamWriter sw = context.getStreamWriter();
        Category _category = objectContext.getAnnotation(Category.class);

        String scheme = null;
        AccessibleObject accessor = objectContext.getAccessor(Scheme.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                scheme = toString(value);
        }
        if (scheme == null) {
            Scheme _scheme = objectContext.getAnnotation(Scheme.class);
            if (_scheme != null && !_scheme.value().equals(DEFAULT)) {
                scheme = _scheme.value();
            }
        }
        if (scheme == null && _category != null && !_category.scheme().equals(DEFAULT)) {
            scheme = _category.scheme();
        }
        if (scheme != null)
            sw.writeAttribute("scheme", scheme);

        String label = null;
        accessor = objectContext.getAccessor(Label.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                label = toString(value);
        }
        if (label == null) {
            Label _label = objectContext.getAnnotation(Label.class);
            if (_label != null && !_label.value().equals(DEFAULT)) {
                label = _label.value();
            }
        }
        if (label == null && _category != null && !_category.label().equals(DEFAULT)) {
            label = _category.label();
        }
        if (label != null)
            sw.writeAttribute("label", label);

        String term = null;
        accessor = objectContext.getAccessor(Value.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                term = toString(value);
        }
        if (term == null)
            term = toString(source);
        if (term != null)
            sw.writeAttribute("term", term);

        writeAttributes(source, objectContext, context, conventions);
        writeExtensions(source, objectContext, context, conventions);
    }
View Full Code Here

    protected void init(Object source,
                        ObjectContext objectContext,
                        SerializationContext context,
                        Conventions conventions) {
        QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor());
        StreamWriter sw = context.getStreamWriter();
        sw.startElement(qname);
    }
View Full Code Here

            type = _content != null ? _content.type() : type;
            contentValue = source;
            valueContext = objectContext;
        }

        StreamWriter sw = context.getStreamWriter();
        sw.startContent(type);
        writeAttributes(source, objectContext, context, conventions);

        if (type == Type.MEDIA || type == Type.XML) {
            String mediatype = null;
            AccessibleObject mtaccessor = valueContext.getAccessor(MediaType.class, conventions);
            if (mtaccessor != null) {
                Object mtvalue = eval(mtaccessor, contentValue);
                mediatype = mtvalue != null ? toString(mtvalue) : null;
            }
            if (mediatype == null) {
                MediaType mt = valueContext.getAnnotation(MediaType.class);
                mediatype = mt != null && !mt.value().equals(DEFAULT) ? mt.value() : null;
            }
            if (mediatype != null)
                sw.writeAttribute("type", mediatype);
        }

        switch (type) {
            case TEXT:
            case HTML:
                sw.writeElementText(toString(contentValue));
                break;
            case XHTML:
                Div div = null;
                if (contentValue instanceof Div)
                    div = (Div)contentValue;
                else {
                    div = context.getAbdera().getFactory().newDiv();
                    div.setValue(toString(contentValue));
                }
                context.serialize(div, new ObjectContext(div));
                break;
            case XML:
                Element el = null;
                if (contentValue instanceof Element)
                    el = (Element)contentValue;
                else {
                    StringReader sr = new StringReader(toString(contentValue));
                    Document<Element> doc = context.getAbdera().getParser().parse(sr);
                    el = doc.getRoot();
                }
                context.serialize(el, new ObjectContext(el));
                break;
            case MEDIA:
                try {
                    if (contentValue instanceof DataHandler)
                        sw.writeElementText((DataHandler)contentValue);
                    else if (contentValue instanceof InputStream)
                        sw.writeElementText((InputStream)contentValue);
                    else
                        sw.writeElementText(toString(contentValue));
                } catch (IOException e) {
                    throw new SerializationException(e);
                }
        }
    }
View Full Code Here

    protected void writeAttributes(Object source,
                                   ObjectContext objectContext,
                                   SerializationContext context,
                                   Conventions conventions) {
        writeCommon(source, objectContext, context, conventions);
        StreamWriter sw = context.getStreamWriter();
        AccessibleObject[] accessors = objectContext.getAccessors(Attribute.class, conventions);
        for (AccessibleObject accessor : accessors) {
            QName qname = getQName(accessor);
            Object value = eval(accessor, source);
            if (value != null)
                sw.writeAttribute(qname, toString(value));
        }
    }
View Full Code Here

    @SuppressWarnings("deprecation")
    protected void writeCommon(Object source,
                               ObjectContext objectContext,
                               SerializationContext context,
                               Conventions conventions) {
        StreamWriter sw = context.getStreamWriter();
        String lang = null;
        AccessibleObject accessor = objectContext.getAccessor(Language.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null) {
                if (value instanceof Lang || value instanceof org.apache.abdera.i18n.lang.Lang) {
                    lang = value.toString();
                } else {
                    lang = toString(value);
                }
            }
        }
        if (lang == null) {
            Language _lang = objectContext.getAnnotation(Language.class);
            if (_lang != null && !_lang.value().equals(DEFAULT)) {
                lang = _lang.value();
            }
        }
        if (lang != null)
            sw.writeLanguage(lang);

        String base = null;
        accessor = objectContext.getAccessor(BaseURI.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                base = toString(value);
        }
        if (base != null)
            sw.writeBase(base);
    }
View Full Code Here

    protected void init(Object source,
                        ObjectContext objectContext,
                        SerializationContext context,
                        Conventions conventions) {
        QName qname = this.qname != null ? this.qname : getQName(objectContext.getAccessor());
        StreamWriter sw = context.getStreamWriter();
        sw.startElement(qname);
    }
View Full Code Here

        }
        writeValue(value != null ? value : source, context);
    }

    private void writeValue(Object value, SerializationContext context) {
        StreamWriter sw = context.getStreamWriter();
        Date date = null;
        if (value == null)
            return;
        if (value instanceof Date) {
            date = (Date)value;
        } else if (value instanceof Calendar) {
            date = ((Calendar)value).getTime();
        } else if (value instanceof Long) {
            date = new Date(((Long)value).longValue());
        } else if (value instanceof String) {
            date = AtomDate.parse((String)value);
        } else {
            date = AtomDate.parse(value.toString());
        }
        sw.writeElementText(date);
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.writer.StreamWriter

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.