roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r209362 - /incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java
Date Wed, 06 Jul 2005 00:08:19 GMT
Author: agilliland
Date: Tue Jul  5 17:08:17 2005
New Revision: 209362

URL: http://svn.apache.org/viewcvs?rev=209362&view=rev
Log:
Small change to use website.getPageByName()

Modified:
    incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java?rev=209362&r1=209361&r2=209362&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java Tue Jul 
5 17:08:17 2005
@@ -1,2 +1 @@
-package org.roller.presentation.velocity;

import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import
org.apache.velocity.servlet.VelocityServlet;
import org.roller.RollerException;
import org.roller.model.UserManager;
import
org.roller.pojos.WeblogTemplate;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import
org.roller.presentation.RollerContext;
import org.roller.presentation.RollerRequest;
import
org.roller.util.Utilities;

import java.io.IOException;

import javax.servlet.ServletException;
import
javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


//////////////////////////////////////////////////////////////////////////////

/**
 * <p>Responsible for rendering FOAF feed.  This servlet requires
  * that the RequestFilter
is in place for it, and should also
  * have the IfModifiedFilter configured.</p>
 
* 
  * <p>Resources:<br />
  * <a href="http://xmlns.com/foaf/0.1/"
  *   
 >FOAF Vocabulary Specification</a><br />
  * <a href="http://www.xml.com/lpt/a/2004/02/04/foaf.html"
 *     >An Introduction to FOAF</a></p>
  * 
  * <p>FOAF Autodiscovery:
<br />
  * <link rel="meta" type="application/rdf+xml" title="FOAF" 
  *     href="$absBaseURL/foaf/$userName"
/> </p>
  *
  * @author Lance Lavandowska
  *
  * @web.servlet name="FoafServlet"
 * @web.servlet-mapping url-pattern="/foaf/*"
  */
public class FoafServlet extends VelocityServlet
{
   static final long serialVersionUID = -1893244416537298619L;
    
    private static Log
mLogger = LogFactory.getFactory()
                                           .getInstance(RollerRequest.class);

   /**
     * This Velocity servlet does not make use of ContextLoader and associated
   
 * classes (as do FlavorServlet and PageServlet) because that is more
     * work than is
really necessary.  It implements its own setupContext()
     * to load necessary values into
the Velocity Context.
     * 
     * @param ctx
     * @param rreq
     * @throws RollerException
    */
    public Template handleRequest(HttpServletRequest request,
                    
             HttpServletResponse response, Context ctx)
    {
        RollerRequest rreq =
null;
        try
        {
            rreq = RollerRequest.getRollerRequest(request, getServletContext());
       }
        catch (RollerException e)
        {
            // An error initializing
the request is considered to be a 404
            if (mLogger.isDebugEnabled())
         
  {
                mLogger.debug("RollerRequest threw Exception", e);
            }

   
        try
            {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
           }
            catch (IOException e1)
            {
                if (mLogger.isDebugEnabled())
               {
                    mLogger.debug("IOException sending error", e);
     
          }
            }
            return null;
        }
        
        try
       
{
            setupContext(ctx, rreq);

            response.setContentType("application/rdf+xml");
           return getTemplate("/flavors/foaf.vm");
        }
        catch (Exception e)
       {
            mLogger.error("ERROR in FoafServlet", e);
        }
        return null;
   }

    /**
	 * @param ctx
	 */
	private void setupContext(Context ctx, RollerRequest rreq)
throws RollerException
	{
        HttpServletRequest request = rreq.getRequest();
       
RollerContext rollerCtx = RollerContext.getRollerContext( request );
        
        UserData
user = rreq.getUser();
-        ctx.put("fullName", user.getFullName()); // name for FlavorServlet compatibility
       
        // foaf:homepage to equal base URL for user
        String homepage = Utilities.escapeHTML(

                rollerCtx.getAbsoluteContextUrl(request) + 
                    "/page/"
+ rreq.getUser().getUserName() );
        ctx.put("websiteURL", homepage); // name for FlavorServlet
compatibility

        // see if foaf:weblog is different Page
        WebsiteData website
= rreq.getWebsite();
        UserManager usrMgr = RollerContext.getRoller(request).getUserManager();
       WeblogTemplate weblog = usrMgr.getPageByName(website, "Weblog");
        // if weblog
!= homepage, add to context
        if (weblog != null && !website.getDefaultPageId().equals(weblog.getId()))
       {
            String weblogUrl = Utilities.escapeHTML( 
                    rollerCtx.getAbsoluteContextUrl(request)
+ 
                        "/page/" + rreq.getUser().getUserName() + 
                   
        "/" + weblog.getLink() );
        	ctx.put("weblog", weblogUrl);
        }
      
 
        // use SHA1 encrypted email address, including mailto: prefix
        String shaEmail
= Utilities.encodePassword(
                "mailto:" + user.getEmailAddress(), "SHA");
 
      ctx.put("shaEmail", shaEmail);
	}

	//------------------------------------------------------------------------
   /**
     * Handle error in Velocity processing.
     */
    protected void error( HttpServletRequest
req, HttpServletResponse res,
        Exception e) throws ServletException, IOException
 
  {
        mLogger.warn("ERROR in FoafServlet",e);
    }
}
\ No newline at end of file
+package org.roller.presentation.velocity;

import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import
org.apache.velocity.servlet.VelocityServlet;
import org.roller.RollerException;
import org.roller.model.UserManager;
import
org.roller.pojos.WeblogTemplate;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import
org.roller.presentation.RollerContext;
import org.roller.presentation.RollerRequest;
import
org.roller.util.Utilities;

import java.io.IOException;

import javax.servlet.ServletException;
import
javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


//////////////////////////////////////////////////////////////////////////////

/**
 * <p>Responsible for rendering FOAF feed.  This servlet requires
  * that the RequestFilter
is in place for it, and should also
  * have the IfModifiedFilter configured.</p>
 
* 
  * <p>Resources:<br />
  * <a href="http://xmlns.com/foaf/0.1/"
  *   
 >FOAF Vocabulary Specification</a><br />
  * <a href="http://www.xml.com/lpt/a/2004/02/04/foaf.html"
 *     >An Introduction to FOAF</a></p>
  * 
  * <p>FOAF Autodiscovery:
<br />
  * <link rel="meta" type="application/rdf+xml" title="FOAF" 
  *     href="$absBaseURL/foaf/$userName"
/> </p>
  *
  * @author Lance Lavandowska
  *
  * @web.servlet name="FoafServlet"
 * @web.servlet-mapping url-pattern="/foaf/*"
  */
public class FoafServlet extends VelocityServlet
{
   static final long serialVersionUID = -1893244416537298619L;
    
    private static Log
mLogger = LogFactory.getFactory()
                                           .getInstance(RollerRequest.class);

   /**
     * This Velocity servlet does not make use of ContextLoader and associated
   
 * classes (as do FlavorServlet and PageServlet) because that is more
     * work than is
really necessary.  It implements its own setupContext()
     * to load necessary values into
the Velocity Context.
     * 
     * @param ctx
     * @param rreq
     * @throws RollerException
    */
    public Template handleRequest(HttpServletRequest request,
                    
             HttpServletResponse response, Context ctx)
    {
        RollerRequest rreq =
null;
        try
        {
            rreq = RollerRequest.getRollerRequest(request, getServletContext());
       }
        catch (RollerException e)
        {
            // An error initializing
the request is considered to be a 404
            if (mLogger.isDebugEnabled())
         
  {
                mLogger.debug("RollerRequest threw Exception", e);
            }

   
        try
            {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
           }
            catch (IOException e1)
            {
                if (mLogger.isDebugEnabled())
               {
                    mLogger.debug("IOException sending error", e);
     
          }
            }
            return null;
        }
        
        try
       
{
            setupContext(ctx, rreq);

            response.setContentType("application/rdf+xml");
           return getTemplate("/flavors/foaf.vm");
        }
        catch (Exception e)
       {
            mLogger.error("ERROR in FoafServlet", e);
        }
        return null;
   }

    /**
	 * @param ctx
	 */
	private void setupContext(Context ctx, RollerRequest rreq)
throws RollerException
	{
        HttpServletRequest request = rreq.getRequest();
       
RollerContext rollerCtx = RollerContext.getRollerContext( request );
        
        UserData
user = rreq.getUser();
        ctx.put("fullName", user.getFullName()); // name for FlavorServlet
compatibility
        
        // foaf:homepage to equal base URL for user
        String
homepage = Utilities.escapeHTML( 
                rollerCtx.getAbsoluteContextUrl(request)
+ 
                    "/page/" + rreq.getUser().getUserName() );
        ctx.put("websiteURL",
homepage); // name for FlavorServlet compatibility

        // see if foaf:weblog is different
Page
        WebsiteData website = rreq.getWebsite();
        UserManager usrMgr = RollerContext.getRoller(request).getUserManager();
       org.roller.model.Template weblog = website.getPageByName("Weblog");
        
     
  // if weblog != homepage, add to context
        if (weblog != null && !website.getDefaultPageId().equals(weblog.getId()))
       {
            String weblogUrl = Utilities.escapeHTML( 
                    rollerCtx.getAbsoluteContextUrl(request)
+ 
                        "/page/" + rreq.getUser().getUserName() + 
                   
        "/" + weblog.getLink() );
        	ctx.put("weblog", weblogUrl);
        }
      
 
        // use SHA1 encrypted email address, including mailto: prefix
        String shaEmail
= Utilities.encodePassword(
                "mailto:" + user.getEmailAddress(), "SHA");
 
      ctx.put("shaEmail", shaEmail);
	}

	//------------------------------------------------------------------------
   /**
     * Handle error in Velocity processing.
     */
    protected void error( HttpServletRequest
req, HttpServletResponse res,
        Exception e) throws ServletException, IOException
 
  {
        mLogger.warn("ERROR in FoafServlet",e);
    }
}
\ No newline at end of file



Mime
View raw message