Alfresco - View in Browser Html file ignoring style

cancel
Showing results for 
Search instead for 
Did you mean: 
sanjaybandhniya
Intermediate

Alfresco - View in Browser Html file ignoring style

Hi,

I have uploaded html file in documentlibrary.

When I use View in Browser , it is ignoring html style and display plain text only.

it is loading in browser so It should display like normal html file we are opening in browser with style.

Thanks & Regards,
Sanjay
9 Replies
afaust
Master

Re: Alfresco - View in Browser Html file ignoring style

Unfortunately, Alfresco Share has a very aggressive "HTML stripping" functionality to prevent malicious content / hijacking in HTML files, which applies to the "view in browser" feature for HTML files. Essentially, the style markup is transparently removed from the HTML when it is being loaded from the backend, resulting in the plain-text-like display. In one of my modules I circumvent that URL-based handling by mapping a default functionality to a custom URL, and then reconfigure the "view in browser" action in a customer system to use that non-processed URL instead of the default.

sanjaybandhniya
Intermediate

Re: Alfresco - View in Browser Html file ignoring style

Please help to achieve that scenario.

How Can I change code?

Is it proper way to override bean?

Thanks & Regards,
Sanjay
davidzuluaga5
Member II

Re: Alfresco - View in Browser Html file ignoring style

Hi Axel! thanks for the input.

I am having the same issue. Could you please point me on the right direction on how to avoid this filters in order for the html files to load correctly?

 

Thanks!

David

jackandru
Member II

Re: Alfresco - View in Browser Html file ignoring style

i hope can fix the issue please refer to the WebLogic training tutorial.

afaust
Master

Re: Alfresco - View in Browser Html file ignoring style

I do not advocate changing Alfresco code for this. I primarily advocate mapping the download web script to a different URL (similar to how I do it via a custom web script mapped to a bean extended from the same parent ), and then reconfiguring the view-content action to use a different href that maps to the custom web script (the default viewUrl is calculated here using https://github.com/Alfresco/share/blob/master/share-services/src/main/resources/alfresco/templates/w... ). E.g. for my web script I would have to configure the following href pattern:

/share/proxy/alfresco/acosix/api/utility/node/slingshot/{node.nodeRef.storeType}/{node.nodeRef.storeId}/{node.nodeRef.id}

If you wanted to eliminate the /share/proxy/alfresco/ prefix and use constants with deployment specific values (technically both "share" and "alfresco" in the prefix could be different in some deployments, but 99.99% stick to the default, and most people probably don't know how it could be changed to begin with), you would have to write a JavaScript based action, register and use it as documented on docs.alfresco.com.

sanjaybandhniya
Intermediate

Re: Alfresco - View in Browser Html file ignoring style

I did the same thing but  I am getting error like 

org.springframework.extensions.webscripts.WebScriptException - 04130115 Web Script format '' is not registered

 

Step 1 : this path I have created given .xml file with same content for test.

Step 2: Created bean in webscript-context.xml 

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
 	<bean id="webscript.de.acosix.acosix-utility.slingshot-content.get" parent="webscript.default" /> 
</beans>

Step 3 : Create javascript base custom action and opening url.

(function() {

	YAHOO.Bubbling
	.fire("registerAction",
					{
						actionName : "viewInBrowser",
						fn : function viewInBrowser(file) {
							console.log(file);
							var contentUrl = Alfresco.constants.PROXY_URI+"acosix/api/utility/node/slingshot/"+file.nodeRef.replace(":/","")+"/"+file.fileName;
							window.open(contentUrl);
						}
					});


})();

 Do I need to override all the bean of this  file?

Thanks & Regards,
Sanjay
afaust
Master

Re: Alfresco - View in Browser Html file ignoring style

You need to set the parent of the bean to "webscript.org.alfresco.slingshot.download.get". This is done by a dynamic component in my module, but you may simply set it on the existing bean without the dynamic handling (that handling is only in place to be compatible with Alfresco installations where Share Services is not installed)

sanjaybandhniya
Intermediate

Re: Alfresco - View in Browser Html file ignoring style

I did the same thing but getting NullPointerException.

2021-05-15 12:46:57,840  ERROR [extensions.webscripts.AbstractRuntime] [http-bio-9090-exec-2] Exception from executeScript - redirecting to status template error: null
 java.lang.NullPointerException
	at org.alfresco.repo.web.scripts.content.ContentGet.execute(ContentGet.java:108)
	at org.alfresco.slingshot.web.scripts.SlingshotContentGet.execute(SlingshotContentGet.java:114)
	at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:505)
	at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:457)
	at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:580)
	at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:649)
	at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:421)
	at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:301)
	at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
	at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
	at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

 

 

Here I am attching Demo .

Here is bean . 

Action Name is View In Browser HTML 

Am i doing anything wrong?

 

@afaust  Any Suggestion?

Thanks & Regards,
Sanjay
afaust
Master

Re: Alfresco - View in Browser Html file ignoring style

This error is due to the fact that you are calling the web script without any URL parameters. The implementation expects that there is at least one parameter (e.g. the `?a=true` to trigger sending the response with attachment disposition), and does not check for null - so you could say you are simply running into a bug / implementation mistake by an Alfresco developer here.