/** * Transforms A CDA StructDocText instance to a Java String containing the transformed text. * Since the method is a recursive one and handles with different types of object, parameter is taken as Object. However, parameters of type StructDocText should be given by the caller. * @param param A CDA StructDocText instance * @return A Java String containing the transformed text */ private String tStrucDocText2String(Object param) { if(param instanceof org.openhealthtools.mdht.uml.cda.StrucDocText) { org.openhealthtools.mdht.uml.cda.StrucDocText paramStrucDocText = (org.openhealthtools.mdht.uml.cda.StrucDocText)param; return "<div>" +tStrucDocText2String(paramStrucDocText.getMixed()) + "</div>"; } else if(param instanceof BasicFeatureMap) { String returnValue = ""; for(Object object : (BasicFeatureMap)param){ String pieceOfReturn = tStrucDocText2String(object); if(pieceOfReturn != null && !pieceOfReturn.isEmpty()) { returnValue = returnValue + pieceOfReturn; } } return returnValue; } else if(param instanceof EStructuralFeatureImpl.SimpleFeatureMapEntry) { String elementBody = ((EStructuralFeatureImpl.SimpleFeatureMapEntry)param).getValue().toString(); // deletion of unnecessary content (\n, \t) elementBody = elementBody.replaceAll("\n", "").replaceAll("\t", ""); // replacement of special characters elementBody = elementBody.replaceAll("<","<").replaceAll(">", ">").replaceAll("&", "&"); // if there was a well-formed char sequence "&", after replacement it will transform to &amp; // the following line of code will remove these type of typos elementBody = elementBody.replaceAll("&amp;", "&"); String typeName = ((EStructuralFeatureImpl.SimpleFeatureMapEntry) param).getEStructuralFeature().getName(); typeName = typeName.toLowerCase(); if(typeName.equals("comment")) { return "<!-- "+elementBody +" -->"; } else if(typeName.equals("text")){ return elementBody; } else { logger.warn("Unknown element type was found while transforming a StrucDocText instance to Narrative. Returning the value of the element"); return elementBody; } } else if(param instanceof EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry) { EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry entry = (EStructuralFeatureImpl.ContainmentUpdatingFeatureMapEntry)param; List<String> tagList = getTagsHelperForTStructDocText2String(entry); return tagList.get(0) + tStrucDocText2String(entry.getValue()) + tagList.get(1); } else if(param instanceof org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl) { // since the name and the attributes are taken already, we just send the mixed of anyTypeImpl return tStrucDocText2String(((org.eclipse.emf.ecore.xml.type.impl.AnyTypeImpl)param).getMixed()); } else { logger.warn("Parameter for the method tStrucDocText2String is unknown. Returning null", param.getClass()); return null; } }