How to commit <style> tag into Alfresco node?

Viewed 72

I am trying to write a HTML content into Alfresco node using this service https://docs.alfresco.com/5.2/references/dev-services-content.html but this service cut out "style", "script" and some other tags!!! how to prevent it and write "style" tag in output stream?

protected void exportReportVHTML(NodeRef reportNodeRef,
                            String outputFormat, String report) throws JRException, IOException {
    ContentWriter contentWriter = alfrescoServices.getContentServiceDefault().getWriter(reportNodeRef,
            ContentModel.PROP_CONTENT, true);
    OutputStream reportOS = contentWriter.getContentOutputStream();

    contentWriter.setMimetype(alfrescoServices.getMimetypeService().getMimetype("html"));
    try {
        reportOS.write(report.getBytes("UTF-8"));
    } catch (Exception jrex) {
        jrex.printStackTrace();
        jrex.printStackTrace(new PrintWriter(reportOS));
        propertyHelper.setNodeProp(reportNodeRef, ContentModel.PROP_DESCRIPTION, jrex.getMessage());
        throw jrex;
    } finally {
        reportOS.close();
    }
}
1 Answers

The contentwriter shouldn't be stripping out tags.

If you download the html from the node, the tags should be retained. Perhaps they are being removed in a "view in browser" or editor view (as tags deemed unsafe are typically removed).

See how to whitelist tags here

Related