001//
002// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-2 
003// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
004// Any modifications to this file will be lost upon recompilation of the source schema. 
005// Generated on: 2015.05.31 at 11:45:27 PM CEST 
006//
007
008
009package org.jomc.model;
010
011import javax.annotation.Generated;
012import javax.xml.bind.annotation.XmlAccessType;
013import javax.xml.bind.annotation.XmlAccessorType;
014import javax.xml.bind.annotation.XmlAttribute;
015import javax.xml.bind.annotation.XmlType;
016import javax.xml.bind.annotation.XmlValue;
017import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
018import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
019
020
021/**
022 * 
023 * Model of text.
024 * 
025 * The 'Text' type defines attributes 'language', 'type' and 'value'. Attribute 'language' holds the language key
026 * identifying the text in a set of texts. Attribute 'type' specifies a Multipurpose Internet Mail Extension (MIME) type,
027 * as defined in RFC 2045 and 2046. Attribute 'value' holds the text of the type corresponding to the language.
028 *       
029 * 
030 * <p>Java class for Text complex type.
031 * 
032 * <p>The following schema fragment specifies the expected content contained within this class.
033 * 
034 * <pre>
035 * &lt;complexType name="Text">
036 *   &lt;simpleContent>
037 *     &lt;extension base="&lt;http://jomc.org/model>String">
038 *       &lt;attribute name="language" use="required" type="{http://jomc.org/model}Language" />
039 *       &lt;attribute name="type" type="{http://jomc.org/model}MimeType" default="text/plain" />
040 *     &lt;/extension>
041 *   &lt;/simpleContent>
042 * &lt;/complexType>
043 * </pre>
044 * 
045 * 
046 */
047@XmlAccessorType(XmlAccessType.FIELD)
048@XmlType(name = "Text", namespace = "http://jomc.org/model", propOrder = {
049    "value"
050})
051@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
052public class Text implements Cloneable
053{
054
055    @XmlValue
056    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
057    protected String value;
058    @XmlAttribute(name = "language", required = true)
059    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
060    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
061    protected String language;
062    @XmlAttribute(name = "type")
063    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
064    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
065    protected String type;
066
067    /**
068     * Creates a new {@code Text} instance.
069     * 
070     */
071    public Text() {
072        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
073        super();
074    }
075
076    /**
077     * Creates a new {@code Text} instance by deeply copying a given {@code Text} instance.
078     * 
079     * 
080     * @param o
081     *     The instance to copy.
082     * @throws NullPointerException
083     *     if {@code o} is {@code null}.
084     */
085    public Text(final Text o) {
086        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
087        super();
088        if (o == null) {
089            throw new NullPointerException("Cannot create a copy of 'Text' from 'null'.");
090        }
091        // CBuiltinLeafInfo: java.lang.String
092        this.value = ((o.value == null)?null:o.getValue());
093        // CBuiltinLeafInfo: java.lang.String
094        this.language = ((o.language == null)?null:o.getLanguage());
095        // CBuiltinLeafInfo: java.lang.String
096        this.type = ((o.type == null)?null:o.getType());
097    }
098
099    /**
100     * Gets the value of the value property.
101     * 
102     * @return
103     *     possible object is
104     *     {@link String }
105     *     
106     */
107    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
108    public String getValue() {
109        return value;
110    }
111
112    /**
113     * Sets the value of the value property.
114     * 
115     * @param value
116     *     allowed object is
117     *     {@link String }
118     *     
119     */
120    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
121    public void setValue(String value) {
122        this.value = value;
123    }
124
125    /**
126     * The language key of this text.
127     * 
128     * @return
129     *     possible object is
130     *     {@link String }
131     *     
132     */
133    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
134    public String getLanguage() {
135        return language;
136    }
137
138    /**
139     * Sets the value of the language property.
140     * 
141     * @param value
142     *     allowed object is
143     *     {@link String }
144     *     
145     */
146    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
147    public void setLanguage(String value) {
148        this.language = value;
149    }
150
151    /**
152     * The Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045 and 2046.
153     * 
154     * @return
155     *     possible object is
156     *     {@link String }
157     *     
158     */
159    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
160    public String getType() {
161        if (type == null) {
162            return "text/plain";
163        } else {
164            return type;
165        }
166    }
167
168    /**
169     * Sets the value of the type property.
170     * 
171     * @param value
172     *     allowed object is
173     *     {@link String }
174     *     
175     */
176    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
177    public void setType(String value) {
178        this.type = value;
179    }
180
181    /**
182     * Creates and returns a deep copy of this object.
183     * 
184     * 
185     * @return
186     *     A deep copy of this object.
187     */
188    @Override
189    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T11:45:26+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
190    public Text clone() {
191        try {
192            {
193                // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
194                final Text clone = ((Text) super.clone());
195                // CBuiltinLeafInfo: java.lang.String
196                clone.value = ((this.value == null)?null:this.getValue());
197                // CBuiltinLeafInfo: java.lang.String
198                clone.language = ((this.language == null)?null:this.getLanguage());
199                // CBuiltinLeafInfo: java.lang.String
200                clone.type = ((this.type == null)?null:this.getType());
201                return clone;
202            }
203        } catch (CloneNotSupportedException e) {
204            // Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
205            throw new AssertionError(e);
206        }
207    }
208    
209    /**
210     * Gets the mime-type of the text.
211     *
212     * @return The mime-type of the text.
213     *
214     * @throws ModelObjectException if compiling the type to a {@code MimeType} fails.
215     *
216     * @see #getType()
217     *
218     * @since 1.4
219     */
220    public javax.activation.MimeType getMimeType() throws ModelObjectException
221    {
222        try
223        {
224            return new javax.activation.MimeType( this.getType() );
225        }
226        catch ( final javax.activation.MimeTypeParseException e )
227        {
228            throw new ModelObjectException( getMessage( "mimeTypeParseException", this.getType(),
229                                                        getMessage( e ) ), e );
230
231        }
232    }
233
234    /**
235     * Formats the text to a Javadoc comment.
236     *
237     * @param lineSeparator String to use for separating lines.
238     * @param indentation String to prepend any lines with.
239     *
240     * @return The Javadoc comment of the text or {@code null}.
241     *
242     * @throws NullPointerException if {@code lineSeparator} or {@code indentation} is {@code null}.
243     * @throws ModelObjectException if compiling the referenced type to a {@code MimeType} fails.
244     *
245     * @since 1.4
246     */
247    public String getJavadocComment( final String lineSeparator, final String indentation ) throws ModelObjectException
248    {
249        if ( lineSeparator == null )
250        {
251            throw new NullPointerException( "lineSeparator" );
252        }
253        if ( indentation == null )
254        {
255            throw new NullPointerException( "indentation" );
256        }
257
258        java.io.BufferedReader reader = null;
259
260        try
261        {
262            String javadocComment = null;
263
264            if ( this.getValue() != null )
265            {
266                reader = new java.io.BufferedReader( new java.io.StringReader( this.getValue() ) );
267                final StringBuilder builder = new StringBuilder( this.getValue().length() );
268                final boolean escapeHtml = !this.getMimeType().match( "text/html" );
269
270                String line;
271                while ( ( line = reader.readLine() ) != null )
272                {
273                    if ( escapeHtml )
274                    {
275                        builder.append( lineSeparator ).append( indentation ).append( " * " ).
276                            append( line.replace( "&", "&amp;" ).replace( "<", "&lt;" ).replace( ">", "&gt;" ).
277                            replace( "\"", "&quot;" ).replace( "*", "&lowast;" ) );
278
279                    }
280                    else
281                    {
282                        builder.append( lineSeparator ).append( indentation ).append( " * " ).append( line );
283                    }
284                }
285
286                if ( builder.length() > 0 )
287                {
288                    javadocComment =
289                        builder.substring( lineSeparator.length() + indentation.length() + " * ".length() );
290
291                }
292
293                reader.close();
294                reader = null;
295            }
296
297            return javadocComment;
298        }
299        catch ( final javax.activation.MimeTypeParseException e )
300        {
301            throw new AssertionError( e );
302        }
303        catch ( final java.io.IOException e )
304        {
305            throw new AssertionError( e );
306        }
307        finally
308        {
309            try
310            {
311                if ( reader != null )
312                {
313                    reader.close();
314                }
315            }
316            catch ( final java.io.IOException e )
317            {
318                throw new AssertionError( e );
319            }
320        }
321    }
322
323    private static String getMessage( final Throwable t )
324    {
325        return t != null
326               ? t.getMessage() != null && t.getMessage().trim().length() > 0
327                 ? t.getMessage()
328                 : getMessage( t.getCause() )
329               : null;
330
331    }
332
333    private static String getMessage( final String key, final Object... arguments )
334    {
335        return java.text.MessageFormat.format( java.util.ResourceBundle.getBundle(
336            Text.class.getName().replace( '.', '/' ), java.util.Locale.getDefault() ).
337            getString( key ), arguments );
338
339    }
340      
341}