View Javadoc

1   /**
2    * The contents of this file are subject to the Mozilla Public License Version 1.1
3    * (the "License"); you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5    * Software distributed under the License is distributed on an "AS IS" basis,
6    * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
7    * specific language governing rights and limitations under the License.
8    *
9    * The Original Code is "".  Description:
10   * ""
11   *
12   * The Initial Developer of the Original Code is University Health Network. Copyright (C)
13   * 2005.  All Rights Reserved.
14   *
15   * Contributor(s): ______________________________________.
16   *
17   * Alternatively, the contents of this file may be used under the terms of the
18   * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
19   * applicable instead of those above.  If you wish to allow use of your version of this
20   * file only under the terms of the GPL and not to allow others to use your version
21   * of this file under the MPL, indicate your decision by deleting  the provisions above
22   * and replace  them with the notice and other provisions required by the GPL License.
23   * If you do not delete the provisions above, a recipient may use your version of
24   * this file under either the MPL or the GPL.
25   */
26  
27  package ca.uhn.hl7v2.model.primitive;
28  
29  import ca.uhn.hl7v2.model.AbstractPrimitive;
30  import ca.uhn.hl7v2.model.Message;
31  
32  /**
33   * Base class for a textual datatype such as FT, TX, ST.
34   * 
35   * @author James Agnew
36   */
37  @SuppressWarnings("serial")
38  public abstract class AbstractTextPrimitive extends AbstractPrimitive {
39  
40  	/**
41  	 * Constructor
42  	 */
43  	public AbstractTextPrimitive(Message theMessage) {
44  		super(theMessage);
45  	}
46  
47  	/**
48  	 * <p>
49  	 * Returns the value of this type with HL7 defined formatting codes replaced
50  	 * by their HTML equivalent.
51  	 * </p>
52  	 * <p>
53  	 * For example, if this type contained the string:<br>
54  	 * 
55  	 * <pre>
56  	 * ABC \.ce\MIDDLE\.br\
57  	 * </pre>
58  	 * 
59  	 * <br>
60  	 * This would be returned as:<br>
61  	 * 
62  	 * <pre>
63  	 * ABC &lt;center&gt;MIDDLE&lt;center&gt;&lt;br&gt;
64  	 * </pre>
65  	 * 
66  	 * </p>
67  	 * <p>
68  	 * The following codes are handled (note that contrary to the HL7
69  	 * specification, codes are interpreted in a case-insensitive manner):
70  	 * <ul>
71  	 * <li><b>\.br\</b> (converted to &lt;br&gt;)
72  	 * <li><b>\.ce\</b> (converted to &lt;center&gt;)
73  	 * <li><b>\.sk\</b> (converted to &amp;nbsp;)
74  	 * <li><b>\.sp\</b> (converted to &lt;br&gt; and then multiple &amp;nbsp;)
75  	 * <li><b>\.sp ###\</b> (converted to multiple &lt;br&gt; and then multiple
76  	 * &amp;nbsp;)
77  	 * <li><b>\.fi\</b> (cancels \.nf\)
78  	 * <li><b>\.nf\</b> (converted to &lt;nobr&gt; ... &lt;/nobr&gt; around each line)
79  	 * <li><b>\.in ###\</b> (converted to &lt;div style="margin-left: ###em;"&gt; ...
80  	 * &lt;/div&gt; around each line)
81  	 * <li><b>\.ti ###\</b> (treated the same as \.in ###\ but only affects the current
82  	 * line, and the numeric value is added to the value provided by \.in ###\.
83  	 * See section 2.7 of the HL7 specification for more details.)
84  	 * <li><b>\H\</b> (converted to &lt;b&gt;)
85  	 * <li><b>\N\</b> (converted to &lt;/b&gt;)
86  	 * <li><b>Ampersands (&amp;)</b> are converted to their HTML equivalent (&amp;amp;)
87  	 * <li><b>Chars over ASCII 160</b> are HTML encoded (e.g. &amp;#199;)
88  	 * </ul>
89  	 * </p>
90  	 * <p>
91  	 * Note that the returned value from this method is an HTML snippet, not a
92  	 * complete HTML document.
93  	 * </p>
94  	 */
95  	public String getValueAsHtml() {
96  		return FormattedTextEncoder.getInstanceHtml().encode(getValue());
97  	}
98  
99  }