| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractTextPrimitive |
|
| 1.3333333333333333;1.333 |
| 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 primitive datatypes 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 | 564688 | super(theMessage); |
| 45 | 564688 | } |
| 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 <center>MIDDLE<center><br> | |
| 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 <br>) | |
| 72 | * <li><b>\.ce\</b> (converted to <center>) | |
| 73 | * <li><b>\.sk\</b> (converted to &nbsp;) | |
| 74 | * <li><b>\.sp\</b> (converted to <br> and then multiple &nbsp;) | |
| 75 | * <li><b>\.sp ###\</b> (converted to multiple <br> and then multiple | |
| 76 | * &nbsp;) | |
| 77 | * <li><b>\.fi\</b> (cancels \.nf\) | |
| 78 | * <li><b>\.nf\</b> (converted to <nobr> ... </nobr> around each line) | |
| 79 | * <li><b>\.in ###\</b> (converted to <div style="margin-left: ###em;"> ... | |
| 80 | * </div> 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 <b>) | |
| 85 | * <li><b>\N\</b> (converted to </b>) | |
| 86 | * <li><b>Ampersands (&)</b> are converted to their HTML equivalent (&amp;) | |
| 87 | * <li><b>Chars over ASCII 160</b> are HTML encoded (e.g. &#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 | * @see FormattedTextEncoder | |
| 96 | */ | |
| 97 | public String getValueAsHtml() { | |
| 98 | 155 | return FormattedTextEncoder.getInstanceHtml().encode(getValue()); |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Returns the value of the datatype as returned by {@link #getValue()} but | |
| 103 | * returns an empty string ("") if the value is <code>null</code>. This | |
| 104 | * method is mostly provided as a convenience in code which maps from one | |
| 105 | * format to another, since it avoids the need for some null checks. | |
| 106 | */ | |
| 107 | public String getValueOrEmpty() { | |
| 108 | 0 | String retVal = getValue(); |
| 109 | 0 | if (retVal == null) { |
| 110 | 0 | retVal = ""; |
| 111 | } | |
| 112 | 0 | return retVal; |
| 113 | } | |
| 114 | ||
| 115 | } |