All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.wink.common.model.atom.AtomText Maven / Gradle / Ivy

There is a newer version: 1.4
Show newest version
/*******************************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *  
 *******************************************************************************/
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1.1-b02-fcs 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2008.09.15 at 04:04:57 PM IDT 
//

package org.apache.wink.common.model.atom;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Providers;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlMixed;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.apache.wink.common.internal.model.AnyContentHandler;
import org.apache.wink.common.internal.model.ModelUtils;
import org.apache.wink.common.model.synd.SyndText;
import org.apache.wink.common.model.synd.SyndTextType;

/**
 * Text Construct Per RFC4287
 * 
 * 
 * A Text construct contains human-readable text, usually in small quantities. The content of Text
 * constructs is Language-Sensitive.
 * 
 * atomPlainTextConstruct =
 *       atomCommonAttributes,
 *       attribute type { "text" | "html" }?,
 *       text
 * 
 *    atomXHTMLTextConstruct =
 *       atomCommonAttributes,
 *       attribute type { "xhtml" },
 *       xhtmlDiv
 * 
 *    atomTextConstruct = atomPlainTextConstruct | atomXHTMLTextConstruct
 * 
 * o The "type" Attribute
 * 
 * Text constructs MAY have a "type" attribute. When present, the value MUST be one of "text",
 * "html", or "xhtml". If the "type" attribute is not provided, Atom Processors MUST behave as
 * though it were present with a value of "text". Unlike the atom:content element defined in Section
 * 4.1.3, MIME media types [MIMEREG] MUST NOT be used as values for the "type" attribute on Text
 * constructs.
 * 
 *   o Text
 * 
 *     Example atom:title with text content:
 * 
 *     ... <title type="text"> Less: < </title> ...
 * 
 *     If the value is "text", the content of the Text construct MUST NOT contain child elements. Such
 *     text is intended to be presented to humans in a readable fashion. Thus, Atom Processors MAY
 *     collapse white space (including line breaks) and display the text using typographic techniques
 *     such as justification and proportional fonts.
 * 
 *   o HTML
 * 
 *     Example atom:title with HTML content:
 * 
 *     ... <title type="html"> Less: <em> &lt; </em> </title> ...
 * 
 *     If the value of "type" is "html", the content of the Text construct MUST NOT contain child
 *     elements and SHOULD be suitable for handling as HTML [HTML]. Any markup within MUST be escaped;
 *     for example, "<br>
 *     " as "<br>". HTML markup within SHOULD be such that it could validly appear directly within an
 *     HTML <DIV> element, after unescaping. Atom Processors that display such content MAY use that
 *     markup to aid in its display.
 * 
 * 
 *   o XHTML
 * 
 *     Example atom:title with XHTML content:
 * 
 *     ... <title type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <xhtml:div> Less: <xhtml:em>
 *     < </xhtml:em> </xhtml:div> </title> ...
 * 
 *     If the value of "type" is "xhtml", the content of the Text construct MUST be a single XHTML div
 *     element [XHTML] and SHOULD be suitable for handling as XHTML. The XHTML div element itself MUST
 *     NOT be considered part of the content. Atom Processors that display the content MAY use the
 *     markup to aid in displaying it. The escaped versions of characters such as "&" and ">" represent
 *     those characters, not markup.
 * 
 * 
 *     Examples of valid XHTML content:
 * 
 *     ... <summary type="xhtml"> <div xmlns="http://www.w3.org/1999/xhtml"> This is <b>XHTML</b>
 *     content. </div> </summary> ... <summary type="xhtml"> <xhtml:div
 *     xmlns:xhtml="http://www.w3.org/1999/xhtml"> This is <xhtml:b>XHTML</xhtml:b> content.
 *     </xhtml:div> </summary> ...
 * 
 *     The following example assumes that the XHTML namespace has been bound to the "xh" prefix earlier
 *     in the document:
 * 
 *     ... <summary type="xhtml"> <xh:div> This is <xh:b>XHTML</xh:b> content. </xh:div> </summary> ...
 * 
*/ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "atomText", propOrder = {"any"}) public class AtomText extends AtomCommonAttributes { @XmlTransient private List any; @XmlAttribute protected AtomTextType type; @XmlTransient private String savedValue = null; @XmlMixed @XmlAnyElement(lax = true, value = AnyContentHandler.class) List getAny() { ModelUtils.fixAnyContent(any, type == null ? null : type.name()); return any; } void setAny(List any) { this.any = any; } /** * Create an empty AtomText with no type and no value */ public AtomText() { } /** * Create an AtomText with a type of AtomTextType.TEXT * * @param value the TEXT value */ public AtomText(String value) { this(value, AtomTextType.text); } /** * Create an AtomText with the specified value and type * * @param value * @param type */ public AtomText(String value, AtomTextType type) { setType(type); setValue(value); } public AtomText(SyndText value) { super(value); if (value == null) { return; } if (value.getType() != null) { setType(AtomTextType.valueOf(value.getType().toString())); } setValue(value.getValue(Object.class)); } public SyndText toSynd(SyndText value) { if (value == null) { return value; } super.toSynd(value); if (getType() != null) { value.setType(SyndTextType.valueOf(getType().toString())); } value.setValue(getValue(Object.class)); return value; } public void setValue(Object value) { if (value != null) { any = Arrays.asList(value); } else { any = null; } } /** *

* Gets the content of the "atom:text" element as a String. The "type" * attribute should be used to determine how to treat the content. *

* Pay attention that de-serialization occurs each time the method is * called, so multiple calls to this method may effect the application * performance. */ public String getValue() { return getValue(String.class); } /** *

* Gets the content of the "atom:text" element serialized to provided class. * The "type" attribute should be used to determine how to treat the * content. *

* Pay attention that de-serialization occurs each time the method is * called, so multiple calls to this method may effect the application * performance. */ public T getValue(Class cls) { try { return getValue(cls, cls, null, ModelUtils.EMPTY_ARRAY, ModelUtils.EMPTY_STRING_MAP, ModelUtils.determineMediaType(type == null ? null : type.name())); } catch (IOException e) { // should never happen throw new WebApplicationException(e); } } /** *

* Gets the content of the "atom:text" element serialized to provided class * according to provided parameters. *

* Pay attention that de-serialization occurs each time the method is * called, so multiple calls to this method may effect the application * performance. */ public T getValue(Class cls, Type genericType, Providers providers, Annotation[] annotations, MultivaluedMap httpHeaders, MediaType mediaType) throws IOException { return ModelUtils.readValue(getAny(), cls, providers, genericType, annotations, httpHeaders, mediaType); } /** * Gets the value of type. * * @return possible object is {@link AtomTextType } */ public AtomTextType getType() { return type; } /** * Sets the value of type. * * @param value allowed object is {@link AtomTextType } */ public void setType(AtomTextType type) { this.type = type; } /* package */void revertValue() { setValue(savedValue); savedValue = null; } /* package */String saveValue() { this.savedValue = getValue(); setValue(null); return this.savedValue; } }