cancel
Showing results for 
Search instead for 
Did you mean: 

overriding site-index.jsp

chrisokelly
Champ on-the-rise
Champ on-the-rise
Hi guys,

I have very little experience in a development environment. We use ant on Ubuntu with the folder structure and build.xml file from fme's redtheme (http://code.google.com/p/fme-alfresco-extensions/wiki/FmeTheme), mainly because it was the only one I could get working. We use community 4.0.d

So now that we have the themes figured out I am trying to override the default landing page for share. Originally I was trying to follow http://blogs.alfresco.com/wp/ddraper/2011/11/01/advanced-share-customization-part-1 but then realized this is more for a custom html page, where we just want one that looks like any other share dashboard. I created a site in the share browser that we can access from our.server:8080/share/page/site/example/dashboard without issue and tried just the slingshot.site.configuration.xml change with root-page field set to 'example'. This did not work, I think mainly because of something that David touches on in his comments to another user (with custom themes active, a slingshot.site.configuration.xml file is already in the remote store overriding the one I make).

Deleting the file in the local store doesn't work, and deactivates our custom themes. As soon as I reactivate them the slingshot config is back in the repository and I am back to square 1.

So I have looked in to other ways to achieve this. Other google results suggest modifying site-index.jsp. I can do this and, as a matter of fact, by modifying site-index.jsp in tomcat/webapps/share I get exactly what I want. I have changed it to look like -

<%@ page import="org.alfresco.web.site.*" %>
<%@ page import="org.springframework.extensions.surf.*" %>
<%@ page import="org.springframework.extensions.surf.site.*" %>
<%@ page import="org.springframework.extensions.surf.util.*" %>
<%@ page import="java.util.*" %>
<%
   // retrieve user name from the session
   String userid = (String)session.getAttribute(SlingshotUserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);

   // test user dashboard page exists?
   RequestContext context = (RequestContext)request.getAttribute(RequestContext.ATTR_REQUEST_CONTEXT);
   if (context.getObjectService().getPage("user/" + userid + "/dashboard") == null)
   {
      // no user dashboard page found! create initial dashboard for this user…
      Map<String, String> tokens = new HashMap<String, String>();
      tokens.put("userid", userid);
      FrameworkUtil.getServiceRegistry().getPresetsManager().constructPreset("user-dashboard", tokens);
   }

   // redirect to site or user dashboard as appropriate
   String siteName = request.getParameter("site");
   // forward to Example site
   siteName = "Example";
   response.sendRedirect(request.getContextPath() + "/page/site/" + URLEncoder.encode(siteName) + "/dashboard");
%>

But I know that this is a poor practice and will get deleted/overwritten once we update. I knew that I should be overriding the default site-index.jsp with one in a jar file in tomcat/shared/lib but wasn't sure how to change the development environment so I could affect files in tomcat/webapps/share. It was at this point I realized the favicon.ico file was in the same directory as site-index.jsp and I remembered I had modified this with the themes. Now I have created a JAR in which there is a single file - site-index.jsp inside the META-INF directory (the same directory which the favicon.ico was put into to override) however nothing changes. When I log in I am taken to the user dashboard as per normal. I know that the site-index.jsp itself is fine, as I said above overriding it directly in the webapps/share directory works. It seems I must be putting it in the wrong place but I can't figure out for the life of me where else it would be.

TL;DR version - Where can I put a custom site-index.jsp in order to override the default one?
1 REPLY 1

boumbh
Champ in-the-making
Champ in-the-making
If somebody knows the solution of this one I would be very grateful, I’ve already spent one day on this issue…

I need to set the landing page to be the document library of a given site (fix url: "/page/site/ourcompany/documentlibrary").

I followed this tutorial <a>http://docs.alfresco.com/4.1/tasks/tutorial-share-add-page.html</a>, but I realized that I could not make a HTTP redirection in FTL (no control over the header?)

So I created a template-type:

<?xml version="1.0" encoding="UTF-8"?>
<template-type>
   <title>Site index landing page template type</title>
   <description>Site index landing page JSP Template Type</description>
   <!– Define the rendering processors for this template type –>   
   <processor mode="view">
      <id>jsp</id>
      <jsp-path>/custom-site-index.jsp</jsp-path>
   </processor>
</template-type>

And a JSP…

<% response.sendRedirect(request.getContextPath() + "/page/site/ourcompany/documentlibrary"); %>

It works very well when the JSP is in the webapps/share/ folder.

…but now I don’t know where to put the JSP in my JAR…

Do I need to define a custom processor that would take JSP from the resources?

How come it so difficult to define the landing page? I must be missing something obvious!

Thanks for any advice.

Edit: Finally I made an AMP and put the file inside the /web/jsp. Here is the new template type:

<?xml version="1.0" encoding="UTF-8"?>
<template-type>
   <title>Site index landing page template type</title>
   <description>Site index landing page JSP Template Type</description>
   <!– Define the rendering processors for this template type –>   
   <processor mode="view">
      <id>jsp</id>
      <jsp-path>/jsp/custom-site-index.jsp</jsp-path>
   </processor>
</template-type>

Just to make sure I’m being comprehensive, here is the tree of my project:

|– pom.xml
`– src/main
    |– amp
    |   |– module.properties
    |   `– web/jsp
    |       `– custom-site-index.jsp
    `– resources/alfresco
        |– site-data
        |   |– configurations
        |   |   `– custom.slingshot.site.configuration.xml
        |   |– pages
        |   |   `– custom-site-index.xml
        |   |– template-instances
        |   |   `– custom-site-index.xml
        |   `– template-types
        |       `– custom-site-index.xml
        `– web-extension
            `– share-config-custom.xml

/src/main/resources/alfresco/site-data/pages/custom-site-index.xml

<page>
   <template-instance>custom-site-index</template-instance>
   <authentication>user</authentication>
</page>

/src/main/resources/alfresco/site-data/template-instances/custom-site-index.xml

<template-instance>
   <template-type>custom-site-index</template-type>
</template-instance>

/src/main/amp/web/jsp/custom-site-index.jsp

<% response.sendRedirect(request.getContextPath() + "/page/site/foo/documentlibrary"); %>


I’m a little bit disappointed I could not keep it to a JAR, but I’m glad I found a way that suits my requirements.