Package org.apache.abdera.ext.serializer

Examples of org.apache.abdera.ext.serializer.ObjectContext


                           SerializationContext context,
                           Conventions conventions) {

        Type type = Type.TEXT;
        Object contentValue = null;
        ObjectContext valueContext = null;
        AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions);
        if (accessor != null && !(source instanceof Element)) {
            contentValue = eval(accessor, source);
            valueContext = new ObjectContext(contentValue, source, accessor);
            Text _text = valueContext.getAnnotation(Text.class);
            type = _text != null ? _text.type() : type;
        } else {
            Text _text = objectContext.getAnnotation(Text.class);
            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;
                else {
                    div = context.getAbdera().getFactory().newDiv();
                    div.setValue(toString(contentValue));
                }
                context.serialize(div, new ObjectContext(div));
                break;
        }
    }
View Full Code Here


                           SerializationContext context,
                           Conventions conventions) {

        Type type = Type.TEXT;
        Object contentValue = null;
        ObjectContext valueContext = null;
        AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions);
        if (accessor != null && !(source instanceof Element)) {
            contentValue = eval(accessor, source);
            valueContext = new ObjectContext(contentValue, source, accessor);
            Content _content = valueContext.getAnnotation(Content.class);
            type = _content != null ? _content.type() : type;
        } else {
            Content _content = objectContext.getAnnotation(Content.class);
            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);
View Full Code Here

        AccessibleObject accessor = objectContext.getAccessor(Draft.class, conventions);
        if (accessor != null) {
            Object value = eval(accessor, source);
            if (value instanceof Boolean) {
                String val = ((Boolean)value).booleanValue() ? "yes" : "no";
                ObjectContext valueContext = new ObjectContext(val);
                Serializer ser = new SimpleElementSerializer(Constants.DRAFT);
                ser.serialize(val, valueContext, context);
            } else {
                ObjectContext valueContext = new ObjectContext(value);
                context.serialize(value, valueContext);
            }
        }
        writeExtensions(source, objectContext, context, conventions);
    }
View Full Code Here

            sw.writeAttribute(attr, element.getAttributeValue(attr));
        XPath xpath = context.getAbdera().getXPath();
        List<?> children = xpath.selectNodes("node()", element);
        for (Object child : children) {
            if (child instanceof Element) {
                process(child, new ObjectContext(child), context, conventions);
            } else if (child instanceof Comment) {
                Comment comment = (Comment)child;
                sw.writeComment(comment.getText());
            } else if (child instanceof ProcessingInstruction) {
                ProcessingInstruction pi = (ProcessingInstruction)child;
View Full Code Here

    SerializationContext context,
    Conventions conventions) {
   
    Type type = Type.TEXT;
    Object contentValue = null;
    ObjectContext valueContext = null;
    AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions);
    if (accessor != null && !(source instanceof Element)) {
      contentValue = eval(accessor, source);
      valueContext = new ObjectContext(contentValue,source,accessor);
      Text _text = valueContext.getAnnotation(Text.class);
      type = _text != null ? _text.type() : type;
    } else {
      Text _text = objectContext.getAnnotation(Text.class);
      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;
        else {
          div = context.getAbdera().getFactory().newDiv();
          div.setValue(toString(contentValue));
        }
        context.serialize(div, new ObjectContext(div));
        break;
    }
  }
View Full Code Here

    SerializationContext context,
    Conventions conventions) {
     
      Type type = Type.TEXT;
      Object contentValue = null;
      ObjectContext valueContext = null;
      AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions);
      if (accessor != null && !(source instanceof Element)) {
        contentValue = eval(accessor, source);
        valueContext = new ObjectContext(contentValue,source,accessor);
        Content _content = valueContext.getAnnotation(Content.class);
        type = _content != null ? _content.type() : type;
      } else {
        Content _content = objectContext.getAnnotation(Content.class);
        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);
View Full Code Here

      AccessibleObject accessor = objectContext.getAccessor(Draft.class, conventions);
      if (accessor != null) {
        Object value = eval(accessor,source);
        if (value instanceof Boolean) {
          String val = ((Boolean)value).booleanValue() ? "yes" : "no";
          ObjectContext valueContext = new ObjectContext(val);
          Serializer ser = new SimpleElementSerializer(Constants.DRAFT);
          ser.serialize(val, valueContext, context);
        } else {
          ObjectContext valueContext = new ObjectContext(value);
          context.serialize(value, valueContext);
        }
      }
      writeExtensions(source, objectContext, context, conventions);
  }
View Full Code Here

          element.getAttributeValue(attr));
      XPath xpath = context.getAbdera().getXPath();
      List<?> children = xpath.selectNodes("node()", element);
      for (Object child : children) {
        if (child instanceof Element) {
          process(child, new ObjectContext(child), context, conventions);
        } else if (child instanceof Comment) {
          Comment comment = (Comment) child;
          sw.writeComment(comment.getText());
        } else if (child instanceof ProcessingInstruction) {
          ProcessingInstruction pi = (ProcessingInstruction) child;
View Full Code Here

TOP

Related Classes of org.apache.abdera.ext.serializer.ObjectContext

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.