Examples of StreamWriter


Examples of org.apache.abdera.writer.StreamWriter

    @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

Examples of org.apache.abdera.writer.StreamWriter

    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

Examples of org.apache.abdera.writer.StreamWriter

        }
        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

Examples of org.apache.abdera.writer.StreamWriter

    static Calendar cal_now = Calendar.getInstance();

    @Test
    public void testSimple() throws Exception {
        Abdera abdera = Abdera.getInstance();
        StreamWriter sw = abdera.newStreamWriter();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        sw.setOutputStream(out).setAutoIndent(true);
        ConventionSerializationContext c = new ConventionSerializationContext(sw);
        c.setSerializer(MyEntry.class, new EntrySerializer());
        sw.startDocument();
        c.serialize(new MyEntry());
        sw.endDocument();

        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        Document<Entry> doc = abdera.getParser().parse(in);
        Entry entry = doc.getRoot();
        assertEquals("tag:example.org,2008:foo", entry.getId().toString());
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

    }

    @Test
    public void testAnnotated() throws Exception {
        Abdera abdera = Abdera.getInstance();
        StreamWriter sw = abdera.newStreamWriter();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        sw.setOutputStream(out).setAutoIndent(true);
        ConventionSerializationContext c = new ConventionSerializationContext(sw);
        sw.startDocument();
        c.serialize(new MyAnnotatedEntry());
        sw.endDocument();

        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        Document<Entry> doc = abdera.getParser().parse(in);
        Entry entry = doc.getRoot();
        assertEquals("tag:example.org,2008:foo", entry.getId().toString());
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

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

        StreamWriter sw = context.getStreamWriter();
        Link _link = objectContext.getAnnotation(Link.class);

        String rel = null;
        AccessibleObject accessor = objectContext.getAccessor(Rel.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                rel = toString(value);
        }
        if (rel == null) {
            Rel _rel = objectContext.getAnnotation(Rel.class);
            if (_rel != null && !_rel.value().equals(DEFAULT)) {
                rel = _rel.value();
            }
        }
        if (rel == null && _link != null && !_link.rel().equals(DEFAULT)) {
            rel = _link.rel();
        }
        if (rel != null)
            sw.writeAttribute("rel", rel);

        String type = null;
        accessor = objectContext.getAccessor(MediaType.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                type = toString(value);
        }
        if (type == null) {
            MediaType _type = objectContext.getAnnotation(MediaType.class);
            if (_type != null && !_type.value().equals(DEFAULT)) {
                type = _type.value();
            }
        }
        if (type == null && _link != null && !_link.type().equals(DEFAULT)) {
            type = _link.type();
        }
        if (type != null)
            sw.writeAttribute("type", type);

        String title = null;
        accessor = objectContext.getAccessor(Title.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                title = toString(value);
        }
        if (title == null && _link != null && !_link.title().equals(DEFAULT)) {
            title = _link.title();
        }
        if (title != null)
            sw.writeAttribute("title", title);

        String hreflang = null;
        accessor = objectContext.getAccessor(HrefLanguage.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                hreflang = toString(value);
        }
        if (hreflang == null) {
            HrefLanguage _hreflang = objectContext.getAnnotation(HrefLanguage.class);
            if (_hreflang != null && !_hreflang.value().equals(DEFAULT)) {
                hreflang = _hreflang.value();
            }
        }
        if (hreflang == null && _link != null && !_link.hreflang().equals(DEFAULT)) {
            hreflang = _link.hreflang();
        }
        if (hreflang != null)
            sw.writeAttribute("hreflang", hreflang);

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

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

Examples of org.apache.abdera.writer.StreamWriter

    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

Examples of org.apache.abdera.writer.StreamWriter

    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);
        writeCommon(source, objectContext, context, conventions);

    }
View Full Code Here

Examples of org.apache.abdera.writer.StreamWriter

    protected void process(Object source,
                           ObjectContext objectContext,
                           SerializationContext context,
                           Conventions conventions) {
        writeAttributes(source, objectContext, context, conventions);
        StreamWriter sw = context.getStreamWriter();
        Generator _generator = objectContext.getAnnotation(Generator.class);

        String uri = null;
        AccessibleObject accessor = objectContext.getAccessor(URI.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                uri = toString(value);
        }
        if (uri == null) {
            URI _uri = objectContext.getAnnotation(URI.class);
            if (_uri != null && !_uri.value().equals(DEFAULT)) {
                uri = _uri.value();
            }
        }
        if (uri == null && _generator != null && !_generator.uri().equals(DEFAULT)) {
            uri = _generator.uri();
        }
        if (uri != null)
            sw.writeAttribute("uri", uri);

        String version = null;
        accessor = objectContext.getAccessor(URI.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value != null)
                version = toString(value);
        }
        if (version == null) {
            URI _version = objectContext.getAnnotation(URI.class);
            if (_version != null && !_version.value().equals(DEFAULT)) {
                version = _version.value();
            }
        }
        if (version == null && _generator != null && !_generator.version().equals(DEFAULT)) {
            version = _generator.version();
        }
        if (version != null)
            sw.writeAttribute("version", version);

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

Examples of org.apache.abdera.writer.StreamWriter

  }

  public Object transformTuple(Object[] tuple, String[] aliases) {
    try {
      if (tuple.length == 1) {       
        StreamWriter sw = abdera.newStreamWriter();
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          sw.setOutputStream(out).setAutoIndent(true);
          ConventionSerializationContext c =
            new ConventionSerializationContext(sw);
          c.setSerializer(tuple[0].getClass(), new EntrySerializer());
          sw.startDocument();
          c.serialize(tuple[0]);
          sw.endDocument();
         
          ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
          Document<Entry> doc = abdera.getParser().parse(in);
          Entry entry = doc.getRoot();
          if (ProviderHelper.getEditUriFromEntry(entry) == null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.