Package org.nextime.ion.frontoffice.servlet

Source Code of org.nextime.ion.frontoffice.servlet.SectionServlet

/*
* �ON content management system.
* Copyright (C) 2002  Guillaume Bort(gbort@msn.com). All rights reserved.
*
* Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
* Copyright 2000-2002 (C) Intalio Inc. All Rights Reserved.
*
* �ON is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* �ON core framework, �ON content server, �ON backoffice, �ON frontoffice
* and �ON admin application are parts of �ON and are distributed under
* same terms of licence.
*
*
* �ON includes software developed by the Apache Software Foundation (http://www.apache.org/)
* and software developed by the Exolab Project (http://www.exolab.org).
*
* �ON 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 General Public License for more details.
*/

package org.nextime.ion.frontoffice.servlet;

import java.io.IOException;
import java.util.Vector;

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

import org.nextime.ion.frontoffice.bean.IonStatus;
import org.nextime.ion.frontoffice.bean.SectionTypes;
import org.nextime.ion.frontoffice.smartCache.SmartCacheManager;

import org.nextime.ion.framework.business.Section;
import org.nextime.ion.framework.mapping.Mapping;
import org.nextime.ion.framework.mapping.MappingException;

public class SectionServlet extends HttpServlet {
 
  public static String relativePath;

  public void service(
    HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {

    try {         

      // cherche l'identifiant de la section demand�e dans
      // la query string
      String requestedId =
        (request.getPathInfo() != null)
          ? request.getPathInfo().substring(1)
          : null;
      if (requestedId != null) {
        if (requestedId.indexOf(".") != -1) {
          requestedId =
            requestedId.substring(0, requestedId.indexOf("."));
        }
      } 
     
      boolean shouldBeCached = false;
      // smart cache used
      if ( SmartCacheManager.isCacheValid() && request.getParameter("nocache")==null && request.getParameter("templateType")==null ) {
        if( SmartCacheManager.isSectionCached(requestedId) ) {
          response.setContentType("text/html");
          response.getOutputStream().write(SmartCacheManager.getCachedSection(requestedId));
          response.getOutputStream().flush();
          response.getOutputStream().close();
          return;
        } else {
          shouldBeCached = true;
        }
      } 
     
      // rollback dirty transaction ??
      if( Mapping.getInstance().isTransactionActive() ) {
        try {
          Mapping.rollback();
        } catch(Exception e) {}
      }
      
      // demarre une transaction pour acc�der aux
      // donn�es du framework wcm
      Mapping.begin();   
     
      // choisis une section par default si aucune n'est
      // sp�cifi�e
      if (requestedId == null) {
        requestedId = getDefaultSectionId();
      }

      // recup�re une instance sur la Section
      Section section = Section.getInstance(requestedId)
     
      // cache
      if( shouldBeCached && !"disabled".equalsIgnoreCase(SectionTypes.getSectionBean(this,section.getMetaData("template")+"").getCache()) ) {
        SmartCacheManager.cacheSection(requestedId);
      }   

      // cr�� le bean de status
      IonStatus status = new IonStatus();
      status.setCurrentSection(section);
      if( request.getParameter("static")!=null ) status.setIsStatic(true);
      request.setAttribute("ionStatus", status);

      // utilise la metaData "template" de la section
      // pour decider vers quelle vue rediriger le flux
      String template = (String) section.getMetaData("template");
      if (template == null)
        template = "default";
       
      String jsp = SectionTypes.getSectionBean(this,template).getJsp();
       
      if( request.getParameter("templateType")!=null ) {
        jsp = jsp.substring(0,jsp.lastIndexOf(".jsp"))+"-"+request.getParameter("templateType")+".jsp";
      }

      getServletContext()
        .getRequestDispatcher(
          "/WEB-INF/jsp/section-templates/" + jsp)
        .forward(request, response)
       
      Mapping.rollback();   

    } catch (Exception e) {   
      Mapping.rollback()
      //transmet l'exception a tomcat
      throw new ServletException(e);
    }
  }

  protected String getDefaultSectionId() throws MappingException {
    // selectionne la premi�re des sections racines   
    Vector rootSections = Section.listRootSections();
    return ((Section) rootSections.get(0)).getId();
  }
 

  public void init() throws ServletException {
    relativePath = getInitParameter("relativePath");
  }

}
TOP

Related Classes of org.nextime.ion.frontoffice.servlet.SectionServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.