DUMultiDuplicateHandler.java :  » Content-Management-System » webman » de » webman » duplication » eventhandler » Java Open Source

Java Open Source » Content Management System » webman 
webman » de » webman » duplication » eventhandler » DUMultiDuplicateHandler.java
package de.webman.duplication.eventhandler;

import com.teamkonzept.web.*;
import com.teamkonzept.webman.*;
import com.teamkonzept.webman.db.TKWebmanDBManager;
import com.teamkonzept.webman.mainint.*;
import com.teamkonzept.webman.mainint.db.*;


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

import java.sql.*;
import java.io.*;
import org.apache.log4j.Category;

/**
*
*
*
 * @author  $Author: ralf $
 * @version $Revision: 1.4 $
*/
public class DUMultiDuplicateHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants, DatabaseDefaults
{
  /**
   * the log category
   */
  private static Category CAT = Category.getInstance(DUMultiDuplicateHandler.class);
  
   private DUMultiDuplicateHandler()
  {}
  
  private static DUMultiDuplicateHandler instance = new DUMultiDuplicateHandler();
  
  public static DUMultiDuplicateHandler getInstance()
  {
    return instance;
  }
  
    public void handleEvent(TKEvent evt) throws TKException
  {
      try
      {
      
    TKParams params = evt.getParams();
        
    String numberOfCopiesString = params.get( "PAR", "NUMBER_OF_COPIES" );
    //String numberingDirection = params.get( "PAR", "NUM_DIRECTION" );
    
    if(numberOfCopiesString != null  && !numberOfCopiesString.equals("")){
      // Falls dieser Parameter nicht bereitgestellt wird, so wird nur einmal dupliziert
      NameAssembler nameAssembler = new NameAssembler(params);
      
      Integer numberOfCopies = new Integer(numberOfCopiesString);
      for(int i=0; i < numberOfCopies.intValue() ; i++){
        
        Integer[] newRootIDs = new Integer[2];
        //doDuDuplicate((i == numberOfCopies.intValue() -1), newRootIDs);
        //doDURenameDuplicates(i+1 , numberOfCopies, newRootIDs);
        
        DUDuplicateHandler.getInstance().doDuDuplicate(i == numberOfCopies.intValue()-1, newRootIDs, evt);
        String nameExtension = nameAssembler.assemble(i, null);
        doDURenameDuplicates(nameExtension, newRootIDs, evt);
        // note: this is a hack!!! oracle 9i throws an exception otherwise!
        TKDBConnectionManager.getInstance().closeConnection();
      }
      
    }
    else
    {// Nur eine Kopie
      DUDuplicateHandler.getInstance().doDuDuplicate(evt);  
    }  
    }
    catch (Throwable e)
    {
      // TO DO : Analyze Exception !
      throw WebmanExceptionHandler.getException(e);
    }
  }
  
  public boolean isHandler(TKEvent evt)
  {
    return evt.getName().equalsIgnoreCase("DU_MULTI_DUPLICATE");
  }

    /** 
   * Umbenennt Knoten oder ganze Bume
   *    
   * @param
   */
   //doDURenameDuplicates(int copyNr, Integer numOfCopies, Integer[] newRootIDs)
  public boolean doDURenameDuplicates(String nameExtension, Integer[] newRootIDs, TKEvent evt) throws Throwable
  {  
    TKParams params = evt.getParams();
    
    //if(printwriter != null) printwriter.println("doDURenameDuplicates called with copyNr " + copyNr + " numOfCopies " + numOfCopies +
    //          " newRootIDs[0] " + newRootIDs[0] + " newRootIDs[1] "+newRootIDs[1] );
    Integer contentRoot = newRootIDs[0];
    Integer siteRoot = newRootIDs[1];
    
    
    String extModeStr = params.get( "PAR", "NAME_EXTENSION" );      // NAME_EXTENSION: Nein (0) Ja (1) oder Recursiv (2) 
              
    int extMode;
    
    if(extModeStr == null || extModeStr.equals("")){
      extMode = 0;
    }
    else{
      try{
        extMode = (new Integer(extModeStr)).intValue();
      }
      catch(NumberFormatException e){
        CAT.warn(" Exception caught by DuplicateServlet.doDuMultiDuplicate() ", e);
        extMode = 0;
      }
    }
    
    
    
    
//    if(printwriter != null) printwriter.println(" nameExtension " + nameExtension);
    if(extMode == 2)
    {
          if(contentRoot != null )
          {
            //printwriter.println("doDURenameDuplicates contentRoot " + contentRoot);
            TKQuery qContentRename = TKDBManager.newQuery( TKDBContentTreeRenameRecursive.class );
            qContentRename.setQueryParams("NAME_EXT", nameExtension );
            qContentRename.setQueryParams("ROOT_ID", contentRoot);
            if(true){
              qContentRename.setQueryParams("POS", new Integer(1));
              // Wenn dieser Queryparameter nicht geestzt ist, wird die Extension hinten angehangt
            }    
            qContentRename.execute();
            qContentRename.close();
            //printwriter.println("TKDBContentTreeRenameRecursive executed witth  contentRoot " + contentRoot);
          }  
          if(siteRoot!= null){// Auch im Sitetree  Recursives Umbenennen der neu erzeugten Knoten
            TKQuery qSiteRename = TKDBManager.newQuery( TKDBSiteTreeRenameRecursive.class );
            qSiteRename.setQueryParams("NAME_EXT", nameExtension  );
            qSiteRename.setQueryParams("ROOT_ID", siteRoot);
            if(true){
              qSiteRename.setQueryParams("POS", new Integer(1));
              // Wenn dieser Queryparameter nicht geestzt ist, wird die Extension hinten angehangt
            }    
            qSiteRename.execute();
            qSiteRename.close();
          }
      }
      if(extMode >= 1){// Umbenennen der Roots der neuen Subtrees
        
        TKQuery TKDBContentNodeNameExtend = TKDBManager.newQuery( TKDBContentNodeNameExtend.class );
        TKDBContentNodeNameExtend.setQueryParams("NAME_EXT",nameExtension);
        TKDBContentNodeNameExtend.setQueryParams("CONTENT_NODE_ID", contentRoot);
        if(true)
        {
          TKDBContentNodeNameExtend.setQueryParams("POS", new Integer(1));
          // Wenn dieser Queryparameter nicht geestzt ist, wird die Extension hinten angehangt
        }
        //TKLog.println("executing with nameExtension "+ nameExtension + " contentRoot " +  contentRoot +""+ TKDBContentNodeNameExtend);
            
        TKDBContentNodeNameExtend.execute();
        //if(printwriter != null) printwriter.println("TKDBContentNodeNameExtend contentRoot " + contentRoot);
        TKDBContentNodeNameExtend.close();
          if(siteRoot!= null){
            TKQuery TKDBSiteNodeNameExtend = TKDBManager.newQuery( TKDBSiteNodeNameExtend.class );
          TKDBSiteNodeNameExtend.setQueryParams("NAME_EXT",nameExtension);
          TKDBSiteNodeNameExtend.setQueryParams("SITE_NODE_ID", siteRoot);
          if(true){
            TKDBSiteNodeNameExtend.setQueryParams("POS", new Integer(1));
            // Wenn dieser Queryparameter nicht geestzt ist, wird die Extension hinten angehangt
          }    
          TKDBSiteNodeNameExtend.execute();
          TKDBSiteNodeNameExtend.close();
      }
    }
    return true;  
  }   
    
    
}
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.