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 java.util.regex.Matcher; 030import java.util.regex.Pattern; 031 032import ca.uhn.hl7v2.model.AbstractPrimitive; 033import ca.uhn.hl7v2.model.Message; 034 035/** 036 * Base class for a textual datatype such as FT, TX, ST. 037 * 038 * @author James Agnew 039 */ 040public abstract class AbstractTextPrimitive extends AbstractPrimitive { 041 042 /** 043 * Constructor 044 */ 045 public AbstractTextPrimitive(Message theMessage) { 046 super(theMessage); 047 } 048 049 /** 050 * <p> 051 * Returns the value of this type with HL7 defined formatting codes replaced 052 * by their HTML equivalent. 053 * </p> 054 * <p> 055 * For example, if this type contained the string:<br> 056 * 057 * <pre> 058 * ABC \.ce\MIDDLE\.br\ 059 * </pre> 060 * 061 * <br> 062 * This would be returned as:<br> 063 * 064 * <pre> 065 * ABC <center>MIDDLE<center><br> 066 * </pre> 067 * 068 * </p> 069 * <p> 070 * The following codes are handled (note that contrary to the HL7 071 * specification, codes are interpreted in a case-insensitive manner): 072 * <ul> 073 * <li><b>\.br\</b> (converted to <br>) 074 * <li><b>\.ce\</b> (converted to <center>) 075 * <li><b>\.sk\</b> (converted to &nbsp;) 076 * <li><b>\.sp\</b> (converted to <br> and then multiple &nbsp;) 077 * <li><b>\.sp ###\</b> (converted to multiple <br> and then multiple 078 * &nbsp;) 079 * <li><b>\.fi\</b> (cancels \.nf\) 080 * <li><b>\.nf\</b> (converted to <nobr> ... </nobr> around each line) 081 * <li><b>\.in ###\</b> (converted to <div style="margin-left: ###em;"> ... 082 * </div> around each line) 083 * <li><b>\.ti ###\</b> (treated the same as \.in ###\ but only affects the current 084 * line, and the numeric value is added to the value provided by \.in ###\. 085 * See section 2.7 of the HL7 specification for more details.) 086 * <li><b>\H\</b> (converted to <b>) 087 * <li><b>\N\</b> (converted to </b>) 088 * <li><b>Ampersands (&)</b> are converted to their HTML equivalent (&amp;) 089 * <li><b>Chars over ASCII 160</b> are HTML encoded (e.g. &#199;) 090 * </ul> 091 * </p> 092 * <p> 093 * Note that the returned value from this method is an HTML snippet, not a 094 * complete HTML document. 095 * </p> 096 */ 097 public String getValueAsHtml() { 098 return FormattedTextEncoder.getInstanceHtml().encode(getValue()); 099 } 100 101}