Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4302 - Files imported as HTML do not show properly in HTML-based editor #4303

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,20 +19,25 @@

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.
* <p>
* This class is exposed as a Spring Component via
* {@link HtmlSupportAutoConfiguration#htmlFormatSupport()}.
* {@link HtmlSupportAutoConfiguration#htmlFormatSupport}.
* </p>
*/
public class HtmlFormatSupport
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