001/**
002 * The contents of this file are subject to the Mozilla Public License Version 1.1
003 * (the "License"); you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
005 * Software distributed under the License is distributed on an "AS IS" basis,
006 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
007 * specific language governing rights and limitations under the License.
008 *
009 * The Original Code is "".  Description:
010 * ""
011 *
012 * The Initial Developer of the Original Code is University Health Network. Copyright (C)
013 * 2005.  All Rights Reserved.
014 *
015 * Contributor(s): ______________________________________.
016 *
017 * Alternatively, the contents of this file may be used under the terms of the
018 * GNU General Public License (the "GPL"), in which case the provisions of the GPL are
019 * applicable instead of those above.  If you wish to allow use of your version of this
020 * file only under the terms of the GPL and not to allow others to use your version
021 * of this file under the MPL, indicate your decision by deleting  the provisions above
022 * and replace  them with the notice and other provisions required by the GPL License.
023 * If you do not delete the provisions above, a recipient may use your version of
024 * this file under either the MPL or the GPL.
025 */
026
027package ca.uhn.hl7v2.model.primitive;
028
029import ca.uhn.hl7v2.model.AbstractPrimitive;
030import ca.uhn.hl7v2.model.Message;
031
032/**
033 * Base class for a textual datatype such as FT, TX, ST.
034 * 
035 * @author James Agnew
036 */
037@SuppressWarnings("serial")
038public abstract class AbstractTextPrimitive extends AbstractPrimitive {
039
040        /**
041         * Constructor
042         */
043        public AbstractTextPrimitive(Message theMessage) {
044                super(theMessage);
045        }
046
047        /**
048         * <p>
049         * Returns the value of this type with HL7 defined formatting codes replaced
050         * by their HTML equivalent.
051         * </p>
052         * <p>
053         * For example, if this type contained the string:<br>
054         * 
055         * <pre>
056         * ABC \.ce\MIDDLE\.br\
057         * </pre>
058         * 
059         * <br>
060         * This would be returned as:<br>
061         * 
062         * <pre>
063         * ABC &lt;center&gt;MIDDLE&lt;center&gt;&lt;br&gt;
064         * </pre>
065         * 
066         * </p>
067         * <p>
068         * The following codes are handled (note that contrary to the HL7
069         * specification, codes are interpreted in a case-insensitive manner):
070         * <ul>
071         * <li><b>\.br\</b> (converted to &lt;br&gt;)
072         * <li><b>\.ce\</b> (converted to &lt;center&gt;)
073         * <li><b>\.sk\</b> (converted to &amp;nbsp;)
074         * <li><b>\.sp\</b> (converted to &lt;br&gt; and then multiple &amp;nbsp;)
075         * <li><b>\.sp ###\</b> (converted to multiple &lt;br&gt; and then multiple
076         * &amp;nbsp;)
077         * <li><b>\.fi\</b> (cancels \.nf\)
078         * <li><b>\.nf\</b> (converted to &lt;nobr&gt; ... &lt;/nobr&gt; around each line)
079         * <li><b>\.in ###\</b> (converted to &lt;div style="margin-left: ###em;"&gt; ...
080         * &lt;/div&gt; around each line)
081         * <li><b>\.ti ###\</b> (treated the same as \.in ###\ but only affects the current
082         * line, and the numeric value is added to the value provided by \.in ###\.
083         * See section 2.7 of the HL7 specification for more details.)
084         * <li><b>\H\</b> (converted to &lt;b&gt;)
085         * <li><b>\N\</b> (converted to &lt;/b&gt;)
086         * <li><b>Ampersands (&amp;)</b> are converted to their HTML equivalent (&amp;amp;)
087         * <li><b>Chars over ASCII 160</b> are HTML encoded (e.g. &amp;#199;)
088         * </ul>
089         * </p>
090         * <p>
091         * Note that the returned value from this method is an HTML snippet, not a
092         * complete HTML document.
093         * </p>
094         */
095        public String getValueAsHtml() {
096                return FormattedTextEncoder.getInstanceHtml().encode(getValue());
097        }
098
099}