Monday, April 19, 2010

Creating a new Alfresco module to change the Alfresco Footer.

Hi., Here I am going to explain about to change the default footer of alfresco.

follow the below steps .

Step1: Create java project with  the structure as shown below in eclipse



Step2: Import the Alfresco related files to change the UI of it.suppose here i want to change  login page and the footer of the alfresco so., lets start to import the files to alfresco as shown below with below structure.

Step3: copy the below code for build.xml file.

<?xml version="1.0"?>

<project name="Sample Module" default="package-amp" basedir=".">

<property name="project.dir" value="." />
<property file="${project.dir}/build.properties" />
<property file="${project.dir}/module.properties" />

<property name="build.dir" value="${project.dir}/build" />
<property name="config.dir" value="${project.dir}/config" />
<property name="jar.file" value="${build.dir}/lib/${module.id}.jar" />
<property name="amp.file" value="${build.dir}/dist/${module.id}.amp" />

<target name="mkdirs">
<mkdir dir="${build.dir}/dist" />
<mkdir dir="${build.dir}/lib" />
<mkdir dir="${build.dir}/classes" />
</target>

<path id="class.path">
<dirset dir="${build.dir}" />
<fileset dir="${project.dir}/lib" includes="**/*.jar" />
<!-- fileset dir="${alfresco.sdk.dir}/lib/server" includes="**/*.jar" / -->
</path>

<target name="clean">
<delete dir="${build.dir}" />
</target>

<target name="compile" depends="mkdirs">
<javac classpathref="class.path" debug="${debug}" srcdir="${project.dir}/source/java" destdir="${build.dir}/classes" target="1.5" encoding="UTF-8" />
<copy todir="${build.dir}/classes">
<fileset dir="${project.dir}/source/java" defaultexcludes="false">
<exclude name="**/*.java" />
<exclude name="**/.svn/**" />
<exclude name="**/CVS/**" />
</fileset>
</copy>
</target>

<target name="package-jar" depends="compile">
<jar destfile="${jar.file}" encoding="UTF-8">
<fileset dir="${build.dir}/classes" excludes="**/custom*,**/*Test*" defaultexcludes="false" />
</jar>
</target>

<target name="package-amp" depends="package-jar" description="Package the Module">
<zip destfile="${amp.file}" encoding="UTF-8">
<fileset dir="${project.dir}/build" includes="lib/*.jar" />
<fileset dir="${project.dir}" includes="config/**/*.*" excludes="**/module.properties" />
<fileset dir="${project.dir}">
<include name="module.properties" />
<include name="file-mapping.properties" />
<include name="WEB-INF/**/*" />
<exclude name="WEB-INF/alfresco.tld" />
<exclude name="WEB-INF/repo.tld" />
</fileset>
<zipfileset dir="source/web" prefix="web" />
</zip>
</target>
</project>

Step4: for pagetag.java., copy the below code ., and change the code as follows., which is high lated in red color.
-------------------------------------------------------------------------------------------------------------

 /*
* Copyright (C) 2005-2010 Alfresco Software Limited.
 *
 * This file is part of Alfresco
 *
 * Alfresco is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Alfresco is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Alfresco. If not, see .
 */
package org.alfresco.web.ui.repo.tag;

import java.io.IOException;
import java.io.Writer;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.bean.coci.CCProperties;
import org.alfresco.web.config.ClientConfigElement;
import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * A non-JSF tag library that adds the HTML begin and end tags if running in servlet mode
 * 
 * @author gavinc
 */
public class PageTag extends TagSupport
{
   private static final long serialVersionUID = 8142765393181557228L;
   
   private final static String SCRIPTS_START = "\n";
   private final static String STYLES_START  = "\n";

   private final static String[] SCRIPTS = 
   {
      // menu javascript
      "/scripts/menu.js",
      // webdav javascript
      "/scripts/webdav.js",
      // base yahoo file
      "/scripts/ajax/yahoo/yahoo/yahoo-min.js",
      // io handling (AJAX)
      "/scripts/ajax/yahoo/connection/connection-min.js",
      // event handling
      "/scripts/ajax/yahoo/event/event-min.js",
      // mootools
      "/scripts/ajax/mootools.v1.11.js",
      // common Alfresco util methods
      "/scripts/ajax/common.js",
      // pop-up panel helper objects
      "/scripts/ajax/summary-info.js",
      // ajax pickers
      "/scripts/ajax/picker.js",
      "/scripts/ajax/tagger.js"
   };
   
   private final static String[] CSS = 
   {
      "/css/main.css",
      "/css/picker.css"
   };

/**
 * Please ensure you understand the terms of the license before changing the contents of this file.
 */
   
   private final static String ALF_LOGO_HTTP  = "http://www.alfresco.com/assets/images/logos/community-edition-3.3.png";
   private final static String ALF_LOGO_HTTPS = "https://www.alfresco.com/assets/images/logos/community-edition-3.3.png";
   private final static String ALF_URL   = "http://www.alfresco.com";
   private final static String ALF_TEXT  = "Alfresco Community";
   private final static String ALF_COPY  = "Supplied free of charge with " +
        "no support, " +
        "no certification, " +
        "no maintenance, " +
        "no warranty and " +
        "no indemnity by " +
        "Alfresco or its " +
        "Certified Partners. " +
        "Click here for support. " +
        "Alfresco Software Inc. © 2005-2010 All rights reserved.";
   
   private final static Log logger = LogFactory.getLog(PageTag.class);
   private static String alfresco = null;
   private static String loginPage = null;
   
   private long startTime = 0;
   private String title;
   private String titleId;
   private String doctypeRootElement;
   private String doctypePublic;
   private String doctypeSystem;
   
   /**
    * @return The title for the page
    */
   public String getTitle()
   {
      return title;
   }

   /**
    * @param title Sets the page title
    */
   public void setTitle(String title)
   {
      this.title = title;
   }
   
   /**
    * @return The title message Id for the page
    */
   public String getTitleId()
   {
      return titleId;
   }

   /**
    * @param titleId Sets the page title message Id
    */
   public void setTitleId(String titleId)
   {
      this.titleId = titleId;
   }

   public String getDoctypeRootElement()
   {
      return this.doctypeRootElement;
   }

   public void setDoctypeRootElement(final String doctypeRootElement)
   {
      this.doctypeRootElement = doctypeRootElement;
   }
   
   public String getDoctypePublic()
   {
      return this.doctypePublic;
   }

   public void setDoctypePublic(final String doctypePublic)
   {
      this.doctypePublic = doctypePublic;
   }

   public String getDoctypeSystem()
   {
      return this.doctypeSystem;
   }
   
   public void setDoctypeSystem(final String doctypeSystem)
   {
      this.doctypeSystem = doctypeSystem;
   }
   
   public void release()
   {
      super.release();
      this.title = null;
      this.titleId = null;
      this.doctypeRootElement = null;
      this.doctypeSystem = null;
      this.doctypePublic = null;
   }

   /**
    * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
    */
   public int doStartTag() throws JspException
   {
      if (logger.isDebugEnabled())
         startTime = System.currentTimeMillis();
      
      try
      {
         String reqPath = ((HttpServletRequest)pageContext.getRequest()).getContextPath();
         Writer out = pageContext.getOut();
         
         if (!Application.inPortalServer())
         {
            if (this.getDoctypeRootElement() != null &&
                this.getDoctypePublic() != null)
            {
               out.write("\n");
            }
            else
            {
               out.write("\n");
            }
            out.write("\n");
            out.write("\n");
            out.write("\n");
            out.write("\n");
         }
         
         // CSS style includes
         for (final String css : PageTag.CSS)
         {
            out.write(STYLES_START);
            out.write(reqPath);
            out.write(css);
            out.write(STYLES_MAIN);
         }
         
         // JavaScript includes
         for (final String s : PageTag.SCRIPTS)
         {
            out.write(SCRIPTS_START);
            out.write(reqPath);
            out.write(s);
            out.write(SCRIPTS_END);
         }
         
         out.write("\n"); // end - generate naked javascript code

         if (!Application.inPortalServer())
         {
            out.write("");
            out.write("\n");
         }
      }
      catch (IOException ioe)
      {
         throw new JspException(ioe.toString());
      }
      
      return EVAL_BODY_INCLUDE;
   }

   /**
    * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
    */
   public int doEndTag() throws JspException
   {
      try
      {
         HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
         if (req.getRequestURI().endsWith(getLoginPage()) == false)
         {
            pageContext.getOut().write(getAlfrescoButton());
         }
         
         if (!Application.inPortalServer())
         {
            pageContext.getOut().write("\n");
         }
      }
      catch (IOException ioe)
      {
         throw new JspException(ioe.toString());
      }
      
      if (logger.isDebugEnabled())
      {
         long endTime = System.currentTimeMillis();
         logger.debug("Time to generate page: " + (endTime - startTime) + "ms");
      }
      
      return super.doEndTag();
   }
   
   private String getLoginPage()
   {
      if (PageTag.loginPage == null)
      {
         PageTag.loginPage = Application.getLoginPage(pageContext.getServletContext());
      }
      
      return PageTag.loginPage;
   }

/**
 * Please ensure you understand the terms of the license before changing the contents of this file.
 */

   private String getAlfrescoButton()
   {
      if (PageTag.alfresco == null)
      {
         final HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
 
PageTag.alfresco = ("<center><table style='margin: 0px auto;'><tr><td>"  
                             "<a href='"   ALF_URL   "'>"  
                             "<img style='vertical-align:middle;border-width:0px;' alt='' title='"   ALF_TEXT   
                             "' src='"   reqPath   ALF_LOGO   "'/>"  
                             "</a></td><td align='center'>"  
                             "<span class='footer'>"   ALF_COPY  
                             "</span></td><td>"  
                             "</td></tr></table></center>");
      }
      return PageTag.alfresco;
   }

   /**
    * This method generate code for setting window.onload reference as
    * we need to open WebDav or CIFS URL in a new window.
    * 
    * Executes via javascript code(function onloadFunc()) in "onload.js" include file.
    * 
    * @return Returns window.onload javascript code
    */
   private static void generateWindowOnloadCode(Writer out)
      throws IOException
   {
      FacesContext fc = FacesContext.getCurrentInstance();
      if (fc != null)
      {
          CCProperties ccProps = (CCProperties)FacesHelper.getManagedBean(fc, "CCProperties");
          if (ccProps.getWebdavUrl() != null || ccProps.getCifsPath() != null)
          {
             out.write("window.onload=onloadFunc(\"");
             if (ccProps.getWebdavUrl() != null)
             {
                out.write(ccProps.getWebdavUrl());
             }
             out.write("\",\"");
             if (ccProps.getCifsPath() != null)
             {
                String val = ccProps.getCifsPath();
                val = Utils.replace(val, "\\", "\\\\");   // encode escape character
                out.write(val);
             }
             out.write("\");");
             
             // reset session bean state
             ccProps.setCifsPath(null);
             ccProps.setWebdavUrl(null);
          }
      }
   }
}
----------------------------------------------------------------------------------
here i want to change  the following code to change the footer of alfresco.
   
   private final static String ALF_URL   = "http://aboutalfresco.blogspot.com/";
   private final static String ALF_LOGO  = "/images/MySite/footer_logo.gif";
   private final static String ALF_TEXT  = "Chandu Enterprise";
   private final static String ALF_COPY  = "Certified and supported. Chandu Software Inc. © 2005-2009 All rights reserved.";

Step5: add these jar files in lib



Step6: change remaining files  as per our requirement., here i changed login.jsp, relogin.jsp, getting-started.jsp, titlebar.jsp, error.jsp, noaccess.jsp.

Step7: add the below code in module.properties.





module.id=MySite-AlfrescoNewUI
module.title=MySite UI Project
module.description=MySite Project to build an amp file
module.version=1.0

Step8: Then go to build.xml ., right click on it then click on run as ant build. you will get the amp file in dist.as shown below.



Step9:  paste this amp file in to alfresco amp folder and click on apply_amps., then restart the server you can find the changes what you made.










2 comments:

  1. hello chandu I'm new in Alfresco and i have task to deal with.. can you give a simple whole project that I can play with, the alfresco install in my system is alfresco community 4.0.a

    ReplyDelete
  2. Hello,

    i need your help please can you contact with me to do it on the alfresco 5.0.d ?? and how much for it ?

    ReplyDelete