<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'org.apache.xml.workflow.ContextResourceManager',
    'org.apache.xml.workflow.StateFlowManager',
    'org.apache.xml.workflow.ContextFailedException',
    'org.apache.xml.workflow.State',
    'org.apache.xml.workflow.User',
    'lang.ElementNotFoundException',
    'util.log.Logger',
    'util.log.FileAppender'
  );

  /**
   * Context
   *
   * @see      xp://org.apache.xml.workflow.AbstractXMLScriptlet
   * @purpose  Part of the workflow model
   */
  class Context extends Object {
    var
      $crm          = NULL,
      $sfm          = NULL,
      $cat          = NULL,
      $user         = NULL;
    
    /**
     * Called to initialize this application context
     *
     * @access  public
     * @param   &lang.ClassLoader classloader
     * @param   &org.apache.HttpScriptletRequest request 
     */
    function initialize(&$classloader, &$request) {
      $this->crm= &new ContextResourceManager();
      $this->crm->initialize($classloader);
      $this->sfm= &new StateFlowManager();
      $this->sfm->initialize($classloader);
      
      $this->setUser(new User(
        $request->getEnvValue('REMOTE_ADDR'),
        $request->getEnvValue('HTTP_USER_AGENT'),
        $request->getLanguage()
      ));
    }

    /**
     * Set User
     *
     * @access  public
     * @param   &org.apache.xml.workflow.User user
     */
    function setUser(&$user) {
      $this->user= &$user;
    }

    /**
     * Get User
     *
     * @access  public
     * @return  &org.apache.xml.workflow.User
     */
    function &getUser() {
      return $this->user;
    }
    
    /**
     * Get ContextResourceManager
     *
     * @access  public
     * @return  &org.apache.xml.workflow.ContextResourceManager
     */
    function &getContextResourceManager() {
      return $this->crm;
    }

    /**
     * Convenience function to get ContextResource
     *
     * @access  public
     * @param   string name
     * @return  &org.apache.xml.workflow.ContextResource
     * @see     xp://org.apache.xml.workflow.ContextResourceManager#getContextResource
     */
    function &getContextResource($name, $class= 'ContextResource') {
      $cr= &$this->crm->getContextResource($name, $class);

      $l= &Logger::getInstance();
      $cat= &$l->getCategory($this->getClassName());
      $cat->debug('getContextResource', $name, $class, '>>>', $cr->getClassName());

      return $cr;
    }
    
    /**
     * Handle a single request
     *
     * @access  public
     * @param   &org.apache.xml.XMLScriptletRequest request
     * @param   &org.apache.xml.XMLScriptletResponse response
     * @return  bool
     */
    function handleRequest(&$request, &$response) {
      $this->crm->setStorage($request->getSession());
      
      $l= &Logger::getInstance();
      $cat= &$l->getCategory($this->getClassName());
      
      // Load corresponding state
      $cat->info('Requested state name is', $request->getState(), $request->getPage());
      $state= &$this->sfm->getStateByName($request->getState());
      while ($state && !$state->isAccessible($this)) {
        $cat->debug($state->getName(), 'is not accessible, getting next...');
        $state= &$this->sfm->getNextState();
      }
      
      // No state found
      if (!$state) {
        return throw(new ContextFailedException(
          'State/workflow error', 
          new ElementNotFoundException($request->getState()))
        );
      }
      
      // Initialize state and set is as current state
      $state->initialize($this);
      $this->sfm->setCurrentState($state);
      $request->setState($state->getName());
      $cat->info('Current state is', $state->getClassName());

      // Now that we have the correct state:
      // - call all of its handlers and if this succeeds,
      // - call its getDocument method
      $return= TRUE;
      try(); {
        if ($st= $state->isSubmitTrigger($request)) {
          $cat->info('Have submit trigger', $st);
        }
          
        $handled= $has_error= FALSE;
        for ($i= 0, $s= sizeof($state->handlers); $i < $s; $i++) {
          $cat->info('Calling handler #'.$i, $state->handlers[$i]->getClassName());

          // If the prerequisites for this handler are'nt met, proceed
          if (!$this->handlers[$i]->prerequisitesMet($context)) {
            $cat->warn('Handler\'s prerequisites are not met, proceeding...');
            continue;
          }

          // If this handler is satisfied, ask the next handler in the queue
          if (!$state->handlers[$i]->needsData($this, $request)) {
            $cat->warn('Handler does not need data, proceeding...');
            continue;
          }
          
          // No trigger
          if (!$st) continue;

          // If this handler is not active, ask the next handler in the queue
          if (!$state->handlers[$i]->isActive($this, $st)) {
            $cat->warn('Handler is not active for submit trigger', $st, ', proceeding...');
            continue;
          }

          // Handle submitted data
          if ($state->handlers[$i]->handleSubmittedData($this, $request)) {
            $handled= TRUE;
            $cat->info('handleSubmittedData returns TRUE, proceeding...');             
            continue;
          }<commit_msg>- Fix "call to method of non-objct" created by variable typo<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'org.apache.xml.workflow.ContextResourceManager',
    'org.apache.xml.workflow.StateFlowManager',
    'org.apache.xml.workflow.ContextFailedException',
    'org.apache.xml.workflow.State',
    'org.apache.xml.workflow.User',
    'lang.ElementNotFoundException',
    'util.log.Logger',
    'util.log.FileAppender'
  );

  /**
   * Context
   *
   * @see      xp://org.apache.xml.workflow.AbstractXMLScriptlet
   * @purpose  Part of the workflow model
   */
  class Context extends Object {
    var
      $crm          = NULL,
      $sfm          = NULL,
      $cat          = NULL,
      $user         = NULL;
    
    /**
     * Called to initialize this application context
     *
     * @access  public
     * @param   &lang.ClassLoader classloader
     * @param   &org.apache.HttpScriptletRequest request 
     */
    function initialize(&$classloader, &$request) {
      $this->crm= &new ContextResourceManager();
      $this->crm->initialize($classloader);
      $this->sfm= &new StateFlowManager();
      $this->sfm->initialize($classloader);
      
      $this->setUser(new User(
        $request->getEnvValue('REMOTE_ADDR'),
        $request->getEnvValue('HTTP_USER_AGENT'),
        $request->getLanguage()
      ));
    }

    /**
     * Set User
     *
     * @access  public
     * @param   &org.apache.xml.workflow.User user
     */
    function setUser(&$user) {
      $this->user= &$user;
    }

    /**
     * Get User
     *
     * @access  public
     * @return  &org.apache.xml.workflow.User
     */
    function &getUser() {
      return $this->user;
    }
    
    /**
     * Get ContextResourceManager
     *
     * @access  public
     * @return  &org.apache.xml.workflow.ContextResourceManager
     */
    function &getContextResourceManager() {
      return $this->crm;
    }

    /**
     * Convenience function to get ContextResource
     *
     * @access  public
     * @param   string name
     * @return  &org.apache.xml.workflow.ContextResource
     * @see     xp://org.apache.xml.workflow.ContextResourceManager#getContextResource
     */
    function &getContextResource($name, $class= 'ContextResource') {
      $cr= &$this->crm->getContextResource($name, $class);

      $l= &Logger::getInstance();
      $cat= &$l->getCategory($this->getClassName());
      $cat->debug('getContextResource', $name, $class, '>>>', $cr->getClassName());

      return $cr;
    }
    
    /**
     * Handle a single request
     *
     * @access  public
     * @param   &org.apache.xml.XMLScriptletRequest request
     * @param   &org.apache.xml.XMLScriptletResponse response
     * @return  bool
     */
    function handleRequest(&$request, &$response) {
      $this->crm->setStorage($request->getSession());
      
      $l= &Logger::getInstance();
      $cat= &$l->getCategory($this->getClassName());
      
      // Load corresponding state
      $cat->info('Requested state name is', $request->getState(), $request->getPage());
      $state= &$this->sfm->getStateByName($request->getState());
      while ($state && !$state->isAccessible($this)) {
        $cat->debug($state->getName(), 'is not accessible, getting next...');
        $state= &$this->sfm->getNextState();
      }
      
      // No state found
      if (!$state) {
        return throw(new ContextFailedException(
          'State/workflow error', 
          new ElementNotFoundException($request->getState()))
        );
      }
      
      // Initialize state and set is as current state
      $state->initialize($this);
      $this->sfm->setCurrentState($state);
      $request->setState($state->getName());
      $cat->info('Current state is', $state->getClassName());

      // Now that we have the correct state:
      // - call all of its handlers and if this succeeds,
      // - call its getDocument method
      $return= TRUE;
      try(); {
        if ($st= $state->isSubmitTrigger($request)) {
          $cat->info('Have submit trigger', $st);
        }
          
        $handled= $has_error= FALSE;
        for ($i= 0, $s= sizeof($state->handlers); $i < $s; $i++) {
          $cat->info('Calling handler #'.$i, $state->handlers[$i]->getClassName());

          // If the prerequisites for this handler are'nt met, proceed
          if (!$state->handlers[$i]->prerequisitesMet($context)) {
            $cat->warn('Handler\'s prerequisites are not met, proceeding...');
            continue;
          }

          // If this handler is satisfied, ask the next handler in the queue
          if (!$state->handlers[$i]->needsData($this, $request)) {
            $cat->warn('Handler does not need data, proceeding...');
            continue;
          }
          
          // No trigger
          if (!$st) continue;

          // If this handler is not active, ask the next handler in the queue
          if (!$state->handlers[$i]->isActive($this, $st)) {
            $cat->warn('Handler is not active for submit trigger', $st, ', proceeding...');
            continue;
          }

          // Handle submitted data
          if ($state->handlers[$i]->handleSubmittedData($this, $request)) {
            $handled= TRUE;
            $cat->info('handleSubmittedData returns TRUE, proceeding...');             
            continue;
          }
{'fraction_non_alphanumeric': 0.152271034996277, 'fraction_numerical': 0.00018615040953090097, 'mean_word_length': 2.1519507186858315, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '129576', 'n_tokens_mistral': 3151, 'n_tokens_neox': 3084, 'n_words': 676}