001package org.hl7.fhir.r5.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.r5 006 * %% 007 * Copyright (C) 2014 - 2019 Health Level 7 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023 024import java.io.IOException; 025import java.util.List; 026 027import ca.uhn.fhir.model.api.annotation.DatatypeDef; 028import org.hl7.fhir.exceptions.FHIRException; 029import org.hl7.fhir.r5.model.StringType; 030import org.hl7.fhir.utilities.xhtml.NodeType; 031import org.hl7.fhir.utilities.xhtml.XhtmlComposer; 032import org.hl7.fhir.utilities.xhtml.XhtmlNode; 033 034 035public class XhtmlType extends Element { 036 037 private Narrative place; 038 039 public XhtmlType(Narrative place) { 040 super(); 041 this.place = place; 042 } 043 044 public XhtmlType() { 045 // "<div xmlns=\""+FormatUtilities.XHTML_NS+"\"></div>" 046 } 047 048 @Override 049 public String fhirType() { 050 return "xhtml"; 051 } 052 053 @Override 054 protected void listChildren(List<Property> result) { 055 } 056 057 @Override 058 public String getIdBase() { 059 return null; 060 } 061 062 @Override 063 public void setIdBase(String value) { 064 } 065 066 @Override 067 public Element copy() { 068 return null; 069 } 070 071 public XhtmlNode getValue() { 072 return place == null ? new XhtmlNode(NodeType.Element, "div") : place.getDiv(); 073 } 074 075 @Override 076 public Base setProperty(int hash, String name, Base value) throws FHIRException { 077 if ("value".equals(name)) { 078 if (value instanceof StringType) { 079 // div is already generated with getValue, we cannot just overwrite it 080 place.getDiv().setValueAsString(((StringType) value).asStringValue()); 081 } else { 082 place.setDiv(TypeConvertor.castToXhtml(value)); 083 } 084 return value; 085 } else 086 return super.setProperty(hash, name, value); 087 } 088 089 @Override 090 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 091 if ("value".equals(name)) 092 return new Base[] {this}; 093 return super.getProperty(hash, name, checkValid); 094 } 095 096 @Override 097 public String primitiveValue() { 098 try { 099 return new XhtmlComposer(false).compose(getValue()); 100 } catch (IOException e) { 101 } 102 return null; 103 } 104 105 @Override 106 public boolean isPrimitive() { 107 return true; 108 } 109 110 @Override 111 public boolean hasPrimitiveValue() { 112 return true; 113 } 114 115 116}