CEContentVersionsHandler.java :  » Content-Management-System » webman » de » webman » content » eventhandler » Java Open Source

Java Open Source » Content Management System » webman 
webman » de » webman » content » eventhandler » CEContentVersionsHandler.java
package de.webman.content.eventhandler;

import com.teamkonzept.web.*;
import com.teamkonzept.webman.*;
import com.teamkonzept.webman.mainint.*;
import com.teamkonzept.webman.mainint.db.queries.*;
import com.teamkonzept.webman.mainint.events.*;
import com.teamkonzept.lib.*;
import com.teamkonzept.field.*;
import com.teamkonzept.field.db.*;
import com.teamkonzept.db.*;

import de.webman.content.workflow.*;
import java.sql.*;


/**
* Auflisten aller Versionen eines Contents:
*
*
* @param String event
* @author  $Author: sebastian $
* @version $Revision: 1.10 $
*/
public class CEContentVersionsHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants
{
  private CEContentVersionsHandler()
  {}

  private static CEContentVersionsHandler instance = new CEContentVersionsHandler();

  public static CEContentVersionsHandler getInstance()
  {
    return instance;
  }

  /**
    Dieser Handler braucht deutlich weniger Infos als die anderen Handler, die sich
    mit Versionen befassen, trotzdem in den Cache ???
    -> Ist andere Datenbankabfrage !!!
  */
    public void handleEvent(TKEvent evt) throws TKException
  {
    try
    {
      CEUtils.checkEvent(evt);

        TKHTMLTemplate t = evt.getPrepHTMLTemplate( "ce_conVersList.tmpl" );
      
        ContentContext ceContext = CEUtils.keepCEContext( evt, t );

        // statische Daten der Versionsverwaltung abrufen
        VersionStatics statics = VersionStatics.setup();

        String action = evt.getParameter(ACTION,evt.getName());

        if (action == null || action.length() == 0 || action.equalsIgnoreCase ("GET"))
        {
              if (ceContext.instanceId.intValue() != -1)
              {
              TKQuery q = TKDBManager.newQuery(TKDBListContentVersions.class);
              q.setQueryParams( "INSTANCE_ID", ceContext.instanceId );
              q.execute();
              ResultSet rs = q.fetchResultSet();
              TKVector vec = new TKVector();
              int currentContentId = -1;

              while (rs.next())
              {
                TKHashtable tb = new TKHashtable();
                vec.addElement (tb);

                int statusId = rs.getInt("STATUS_ID");

                String version = rs.getString ("VERSION_ID");
                String status = rs.getString ("STATUS");
                String info = rs.getString ("INFO");
                String author = rs.getString ("AUTHOR");
                String date = TKContentAttributeTableData.dateFormat.format(rs.getTimestamp("VERSION_DATE"));

              // hier kann NULL kommen - > Ergebnis ist 0 (kompaktiert)
                int contentId = rs.getInt ("CONTENT_ID");

                VersionStatus desc = (VersionStatus)
                  statics.getStatusPool().get (new Integer(statusId));
                if (desc.comment) tb.put ("IS_COMMENT",Boolean.TRUE);

                tb.put ("VERSION_ID",version);
                tb.put ("STATUS",status);
                tb.put ("INFO",info);
                if (author != null) tb.put ("AUTHOR",author);
                tb.put ("DATE",date);

                tb.put ("CURR_CONTENT_ID",new Integer (currentContentId));
                tb.put ("CONTENT_ID",new Integer (contentId));

                if (currentContentId != -1 && currentContentId != contentId)
                  tb.put ("NEW_CONTENT", Boolean.TRUE);

                currentContentId = contentId;
              }

              t.setListIterator (new TKStandardPluginIterator ("CONTENT_VERSIONS","VERSION",
                vec,false,t.getListIterator()));
            }
        WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ContextConstants.CONTENT_EDIT);
          evt.finishTemplate(t);
          return;
        }
    }
    catch (Throwable e)
    {
      // TO DO : Analyze Exception !
      throw WebmanExceptionHandler.getException(e);
    }
  }

  public boolean isHandler(TKEvent evt)
  {
    return evt.getName().equalsIgnoreCase("CE_CONTENT_VERSIONS");
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.