Package org.apache.abdera.writer

Examples of org.apache.abdera.writer.StreamWriter


  public static void main(String... args) {
   
    Abdera abdera = Abdera.getInstance();
   
    StreamWriter out =
      abdera.newStreamWriter()
        .setOutputStream(System.out,"UTF-8")
        .setAutoflush(false)
        .setAutoIndent(true)
        .startDocument()
          .startFeed()
            .writeBase("http://example.org")
            .writeLanguage("en-US")
            .writeId("http://example.org")
            .writeTitle("<Testing 123>")
            .writeSubtitle("Foo")
            .writeAuthor("James", null, null)
            .writeUpdated(new Date())
            .writeLink("http://example.org/foo")
            .writeLink("http://example.org/bar","self")
            .writeCategory("foo")
            .writeCategory("bar")
            .writeLogo("logo")
            .writeIcon("icon")
            .writeGenerator("1.0", "http://example.org", "foo")
            .flush();
     
    for (int n = 0; n < 100; n++) {
      out.startEntry()     
        .writeId("http://example.org/" + n)
        .writeTitle("Entry #" + n)
        .writeUpdated(new Date())
        .writePublished(new Date())
        .writeEdited(new Date())
        .writeSummary("This is text summary")
        .writeAuthor("James", null, null)
        .writeContributor("Joe", null, null)
        .startContent("application/xml")
          .startElement("a","b","c")
            .startElement("x","y","z")
              .writeElementText("This is a test")
              .startElement("a")
                .writeElementText("foo")
              .endElement()
              .startElement("b","bar")
                .writeAttribute("foo", new Date())
                .writeAttribute("bar", 123L)
                .writeElementText(123.123)
              .endElement()
            .endElement()
          .endElement()
        .endContent()
        .endEntry()
        .flush();
    }
     
    out.endFeed()
      .endDocument()
      .flush();
   
  }
View Full Code Here


  public static void main(
    String... args)
      throws Exception {   
    Abdera abdera = Abdera.getInstance();
    StreamWriter sw =
      abdera.newStreamWriter()
            .setOutputStream(System.out)
            .setAutoIndent(true);
    Foo foo = new Foo();
    foo.writeTo(sw);
    sw.close();
  }
View Full Code Here

    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

  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

    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

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.