Skip to content

Commit

Permalink
#4302 - Files imported as HTML do not show properly in HTML-based editor
Browse files Browse the repository at this point in the history
- The HtmlFormatSupport now returns the default HTML content policy
- When logging masked element, also log the name of the respective policy
- Do not pass the body element through the sanitizer - it should always pass
  • Loading branch information
reckart committed Nov 15, 2023
1 parent 157c5a8 commit 040cb6d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public ResponseEntity<String> getDocument(@PathVariable("projectId") long aProje

renderHead(doc, rawHandler);

sanitizingHandler.startElement(null, null, BODY, null);
rawHandler.startElement(null, null, BODY, null);
if (maybeXmlDocument.isEmpty()) {
// Gracefully handle the case that the CAS does not contain any XML structure at all
// and show only the document text in this case.
Expand All @@ -172,7 +172,7 @@ public ResponseEntity<String> getDocument(@PathVariable("projectId") long aProje
else {
renderXmlContent(doc, sanitizingHandler, aEditor, maybeXmlDocument.get());
}
sanitizingHandler.endElement(null, null, BODY);
rawHandler.endElement(null, null, BODY);

rawHandler.endElement(null, null, HTML);

Expand Down
8 changes: 8 additions & 0 deletions inception/inception-io-html/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-model</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-external-editor</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-support</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@

import static org.apache.uima.fit.factory.CollectionReaderFactory.createReaderDescription;

import java.io.IOException;
import java.util.Optional;

import org.apache.uima.collection.CollectionReaderDescription;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.metadata.TypeSystemDescription;

import de.tudarmstadt.ukp.clarin.webanno.api.format.FormatSupport;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.inception.externaleditor.policy.DefaultHtmlDocumentPolicy;
import de.tudarmstadt.ukp.inception.io.html.config.HtmlSupportAutoConfiguration;
import de.tudarmstadt.ukp.inception.io.html.dkprocore.HtmlDocumentReader;
import de.tudarmstadt.ukp.inception.support.xml.sanitizer.PolicyCollection;

/**
* Support for HTML format.
Expand All @@ -41,6 +46,13 @@ public class HtmlFormatSupport
public static final String ID = "htmldoc";
public static final String NAME = "HTML";

private final DefaultHtmlDocumentPolicy defaultPolicy;

public HtmlFormatSupport(DefaultHtmlDocumentPolicy aDefaultPolicy)
{
defaultPolicy = aDefaultPolicy;
}

@Override
public String getId()
{
Expand All @@ -66,4 +78,10 @@ public CollectionReaderDescription getReaderDescription(Project aProject,
{
return createReaderDescription(HtmlDocumentReader.class, aTSD);
}

@Override
public Optional<PolicyCollection> getPolicy() throws IOException
{
return Optional.of(defaultPolicy.getPolicy());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import de.tudarmstadt.ukp.inception.externaleditor.policy.DefaultHtmlDocumentPolicy;
import de.tudarmstadt.ukp.inception.io.html.HtmlFormatSupport;
import de.tudarmstadt.ukp.inception.io.html.LegacyHtmlFormatSupport;

Expand All @@ -30,9 +31,9 @@ public class HtmlSupportAutoConfiguration
@Bean
@ConditionalOnProperty(prefix = "format.html", name = "enabled", //
havingValue = "true", matchIfMissing = false)
public HtmlFormatSupport htmlFormatSupport()
public HtmlFormatSupport htmlFormatSupport(DefaultHtmlDocumentPolicy aDefaultPolicy)
{
return new HtmlFormatSupport();
return new HtmlFormatSupport(aDefaultPolicy);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ public void endElement(String aUri, String aLocalName, String aQName) throws SAX

if (stack.isEmpty()) {
if (policies.isDebug() && log.isDebugEnabled()) {
log.debug("Masked elements: {}", maskedElements.stream() //
log.debug("[{}] Masked elements: {}", policies.getName(), maskedElements.stream() //
.map(QName::toString) //
.sorted() //
.collect(toList()));
for (var element : maskedAttributes.keySet().stream()
.sorted(comparing(QName::getLocalPart)).collect(toList())) {
log.debug("Masked attributes on {}: {}", element,
log.debug("[{}] Masked attributes on {}: {}", policies.getName(), element,
maskedAttributes.get(element).stream().map(QName::toString) //
.sorted() //
.collect(toList()));
Expand Down

0 comments on commit 040cb6d

Please sign in to comment.