Package org.apache.abdera.writer

Examples of org.apache.abdera.writer.StreamWriter


    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


  }
 
  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

    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

    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

    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

   
    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

  public static void main(String... args) throws Exception {
   
    Abdera abdera = Abdera.getInstance();
   
    // demonstrate serialization of a non-annotated java object
    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();
   
    // once the object has been serialized, we can see that it's a parseable Atom document
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    Document<Entry> doc = abdera.getParser().parse(in);
    Entry entry = doc.getRoot();
    entry.writeTo(System.out);
   
    System.out.println();
   
    // demonstrate serialization using an annotated java object
    // annotations allow the developer to customize the way the
    // object is serialized
    sw = abdera.newStreamWriter();
    out = new ByteArrayOutputStream();
    sw.setOutputStream(out)
      .setAutoIndent(true);
    c = new ConventionSerializationContext(sw);
    sw.startDocument();
    c.serialize(new MyAnnotatedEntry());
    sw.endDocument();
   
    in = new ByteArrayInputStream(out.toByteArray());
    doc = abdera.getParser().parse(in);
    entry = doc.getRoot();
    entry.writeTo(System.out);
View Full Code Here

    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

  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

  }
 
  @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

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.