001package org.hl7.fhir.r4.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.r4 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 org.hl7.fhir.exceptions.FHIRException; 028import org.hl7.fhir.utilities.xhtml.NodeType; 029import org.hl7.fhir.utilities.xhtml.XhtmlComposer; 030import org.hl7.fhir.utilities.xhtml.XhtmlNode; 031 032public class XhtmlType extends Element { 033 034 private Narrative place; 035 036 public XhtmlType(Narrative place) { 037 super(); 038 this.place = place; 039 } 040 041 public XhtmlType() { 042 this(new Narrative()); 043 // "<div xmlns=\""+FormatUtilities.XHTML_NS+"\"></div>" 044 } 045 046 @Override 047 public String fhirType() { 048 return "xhtml"; 049 } 050 051 @Override 052 protected void listChildren(List<Property> result) { 053 } 054 055 @Override 056 public String getIdBase() { 057 return null; 058 } 059 060 @Override 061 public void setIdBase(String value) { 062 } 063 064 @Override 065 public Element copy() { 066 return null; 067 } 068 069 public XhtmlNode getValue() { 070 return place == null ? new XhtmlNode(NodeType.Element, "div") : place.getDiv(); 071 } 072 073 @Override 074 public Base setProperty(int hash, String name, Base value) throws FHIRException { 075 if ("value".equals(name)) { 076 if (value instanceof StringType) { 077 // div is already generated with getValue, we cannot just overwrite it 078 place.getDiv().setValueAsString(((StringType) value).asStringValue()); 079 } else { 080 place.setDiv(castToXhtml(value)); 081 } 082 return value; 083 } else 084 return super.setProperty(hash, name, value); 085 } 086 087 @Override 088 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 089 if ("value".equals(name)) 090 return new Base[] {this}; 091 return super.getProperty(hash, name, checkValid); 092 } 093 094 @Override 095 public String primitiveValue() { 096 try { 097 return new XhtmlComposer(false).compose(getValue()); 098 } catch (IOException e) { 099 } 100 return null; 101 } 102 103 @Override 104 public boolean isPrimitive() { 105 return true; 106 } 107 108 @Override 109 public boolean hasPrimitiveValue() { 110 return true; 111 } 112 113 114}