Examples of StreamWriter


Examples of org.apache.abdera.writer.StreamWriter

    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

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

Examples of org.apache.abdera.writer.StreamWriter

        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

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

Examples of org.apache.abdera.writer.StreamWriter

  }
 
  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

    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

    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

    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

   
    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

Examples of org.apache.abdera.writer.StreamWriter

  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
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.