Skip to content

Commit

Permalink
#151 HTML text imported by the viewpoint does not keep the div root t…
Browse files Browse the repository at this point in the history
…ag coming from reqif file (#152)


Fixes #151

Change-Id: I1bbb75217ad3b5478ed08184e1b0ac4e86992d7d
Signed-off-by: Tu Ton <minhtutonthat@gmail.com>
  • Loading branch information
minhtutonthat committed Jan 5, 2022
1 parent 9dc480e commit e718c24
Show file tree
Hide file tree
Showing 46 changed files with 15,577 additions and 15,538 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
import org.eclipse.rmf.reqif10.SpecElementWithAttributes;
import org.eclipse.rmf.reqif10.SpecHierarchy;
import org.eclipse.rmf.reqif10.SpecType;
import org.eclipse.rmf.reqif10.XhtmlContent;
import org.eclipse.rmf.reqif10.common.util.ReqIF10XhtmlUtil;
import org.eclipse.rmf.reqif10.xhtml.XhtmlDivType;
import org.polarsys.capella.vp.requirements.importer.extension.AttributesProvider;
import org.polarsys.capella.vp.requirements.importer.transposer.bridge.query.FolderQuery;
import org.polarsys.capella.vp.requirements.importer.transposer.bridge.query.ModuleQuery;
Expand Down Expand Up @@ -427,10 +429,14 @@ public Map<String, Object> parseStandardReqIFAttributes(AttributeValue value, At

protected String getContent(AttributeValueXHTML value, AttributeOwner owner) {
String content = "";
String rootTag = null;
try {
content = ReqIF10XhtmlUtil.getXhtmlString(((AttributeValueXHTML) value).getTheValue());
XhtmlContent theValue = ((AttributeValueXHTML) value).getTheValue();
// We've got to store root tag here since ReqIF10XhtmlUtil.getXhtmlString does not include the original root tag of the XHTML element
rootTag = getRootTag(theValue);
content = ReqIF10XhtmlUtil.getXhtmlString(theValue);
if (value.getDefinition().getLongName().equals("ReqIF.Text")) {
content = textParser.transformToHTML(content, owner);
content = textParser.transformToHTML(content, owner, rootTag);
} else {
content = transformToText(content);
}
Expand All @@ -440,6 +446,20 @@ protected String getContent(AttributeValueXHTML value, AttributeOwner owner) {
return content;
}

/**
*
* @param theValue
* @return the root tag of the xhtml element inside theValue
*/
protected String getRootTag(XhtmlContent theValue) {
// There's currently no better way to retrieve the root tag of a XhtmlContent.
// div is a commonly used tag in reqif coming from DOORS
if (theValue.getXhtml() instanceof XhtmlDivType) {
return "div";
}
return null;
}

protected String transformToText(String content) {
return LabelHelper.transformHTMLToText(content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,24 @@ public ReqIFTextParser(IContext context, ImageImporter imageImporter) {
* @return
*/
public String transformToHTML(String content, AttributeOwner owner) {
return transformToHTML(content, owner, null);
}

/**
* Transform XHTML text into HTML text
*
* @param content: the XHTML content
* rootTag: the original root tag of the content
* @return
*/
public String transformToHTML(String content, AttributeOwner owner, String rootTag) {
try {
DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
df.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
df.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
DocumentBuilder builder = df.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(content)));
transformToHTML(document, document.getDocumentElement());
transformToHTML(document, document.getDocumentElement(), rootTag);
removeOLEObjects(document, document.getDocumentElement());
replaceImgObjects(document, document.getDocumentElement());
convertAllImgElements(document, document.getDocumentElement(), owner);
Expand All @@ -106,16 +117,24 @@ public String transformToHTML(String content, AttributeOwner owner) {
// Return the raw content in case it cannot be parsed
return content;
}

/**
* Transform XHTML text into HTML text
*
* @param document
* @param element
*/
protected void transformToHTML(Document document, Element element) {
transformToHTML(document, element, null);
}

protected void transformToHTML(Document document, Element element, String rootTag) {
if (element.getTagName().equals("reqif:XHTML")) {
document.renameNode(element, null, "p");
if (rootTag == null) {
document.renameNode(element, null, "p");
} else {
document.renameNode(element, null, rootTag);
}
while (element.getAttributes().getLength() > 0) {
Node att = element.getAttributes().item(0);
element.getAttributes().removeNamedItem(att.getNodeName());
Expand All @@ -132,7 +151,7 @@ protected void transformToHTML(Document document, Element element) {

}
}

/**
* Remove OLE objects in ReqIF format
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata:Metadata xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:metadata="http://www.polarsys.org/kitalpha/ad/metadata/1.0.0" id="_2uVOAHjqEea__MYrXGSERA">
<viewpointReferences id="_dhQ1sIoOEeaQmcRqIfTB6w" vpId="org.polarsys.capella.core.viewpoint" version="5.1.0"/>
<viewpointReferences id="_dhQ1sIoOEeaQmcRqIfTB6w" vpId="org.polarsys.capella.core.viewpoint" version="5.2.0"/>
<viewpointReferences id="_Jxp_MHq0EeiC94JwciofZw" vpId="org.polarsys.kitalpha.vp.requirements" version="0.12.1"/>
<viewpointReferences id="_Jzcu8Hq0EeiC94JwciofZw" vpId="org.polarsys.capella.vp.requirements" version="0.12.1"/>
</metadata:Metadata>

0 comments on commit e718c24

Please sign in to comment.