Package org.apache.slide.projector

Examples of org.apache.slide.projector.Result


  public Result process(Map parameter, Context context) throws Exception {
    Store formStore = context.getStore(Store.FORM);
    if ( formStore != null ) {
      ((FormStore)formStore).clear();
    }
    return new Result(StateDescriptor.OK);
  }
View Full Code Here


            }
        }
        parameter.put(ControlComposer.CONTROL_DESCRIPTIONS, new ArrayValue((Value[])controlDescriptions.toArray(new Value[controlDescriptions.size()])));
        parameter.put(ControlComposer.TRIGGER_DESCRIPTIONS, new ArrayValue((Value[])triggerDescriptions.toArray(new Value[triggerDescriptions.size()])));
        ProcessorManager.prepareValues(super.getParameterDescriptors(), parameter, context);
        Result controlComposerResult = super.process(parameter, context);
        Value[] generatedControls = ((ArrayValue)controlComposerResult.getResultEntries().get(GENERATED_CONTROLS)).getArray();
        for ( int i = 0; i < generatedControls.length; i++ ) {
          Iterator j = ((MapValue)generatedControls[i]).getMap().entrySet().iterator();
          Map.Entry entry = (Map.Entry)j.next();
          parameter.put(entry.getKey(), entry.getValue());
        }
        Value[] generatedTriggers = ((ArrayValue)controlComposerResult.getResultEntries().get(GENERATED_TRIGGERS)).getArray();
        for ( int i = 0; i < generatedTriggers.length; i++ ) {
          Iterator j = ((MapValue)generatedTriggers[i]).getMap().entrySet().iterator();
          Map.Entry entry = (Map.Entry)j.next();
          parameter.put(entry.getKey(), entry.getValue());
        }
      parameter.put(RENDERED_ERRORS, controlComposerResult.getResultEntries().get(RENDERED_ERRORS));
        Template template = defaultTemplate;
        String state = controlComposerResult.getState();
        if ( state == VALID_STATE && validTemplate != null ) {
            template = validTemplate;
        } else if ( state == INVALID_STATE && invalidTemplate != null ) {
            template = invalidTemplate;
        }
        return new Result(state, OUTPUT, renderFragment(template, parameter));
    }
View Full Code Here

                }
              }
            }
            controlParameters.put(Control.STATE, controlState);
            controlParameters.put(Control.VALUE, controlValue);
            Result controlResult = control.process(controlParameters, context);
            if ( controlContainerUri != NullValue.NULL ) {
              Processor controlContainer = ProcessorManager.getInstance().getProcessor((URI)controlContainerUri);
              Map controlContainerParameters = new HashMap();
              controlContainerParameters.putAll(parameter);
              if ( hasErrors(informations, parameterName) ) {
                explodeInformations(controlContainerParameters, informations, parameterName, locale);
              }
              controlContainerParameters.put(Control.STATE, controlState);
              controlContainerParameters.put(CONTROL, controlResult.getResultEntries().get(OUTPUT));
              controlContainerParameters.put(TITLE, description.getTitle(locale, parameterName ));
              try {
                controlContainerParameters.put(TEXT, description.getText(locale));
                controlContainerParameters.put(PROMPT, description.getPrompt(locale));
              } catch ( MessageNotFoundException exception ) {
                controlContainerParameters.put(TEXT, NO_PARAMETER_MESSAGE_AVAILABLE.getText(locale, "&nbsp;"));
                controlContainerParameters.put(PROMPT, NO_PARAMETER_MESSAGE_AVAILABLE.getPrompt(locale, "&nbsp;"));
              }
              try {
                ProcessorManager.prepareValues(controlContainer.getParameterDescriptors(), controlContainerParameters, context);
              } catch ( ValidationException exception ) {
                throw new ValidationException(new ErrorMessage("controlComposer/controlContainerParameterInvalid", new Object[] { controlContainerUri }), exception);
              }
              Result controlContainerResult = controlContainer.process(controlContainerParameters, context);
              generatedControls.add(new MapValue(controlName, (Value)controlContainerResult.getResultEntries().get(OUTPUT)));
            } else {
              generatedControls.add(new MapValue(controlName, (Value)controlResult.getResultEntries().get(OUTPUT)));
            }
            if ( controlState == Control.OPTIONAL_INVALID_CONTROL || controlState == Control.REQUIRED_INVALID_CONTROL  ) {
              state = INVALID_STATE;
            } else if ( state == DEFAULT_STATE && ( controlState == Control.OPTIONAL_VALID_CONTROL || controlState == Control.REQUIRED_VALID_CONTROL ) ) {
              state = VALID_STATE;
            }
        }
        Result composerResult = new Result(state, GENERATED_CONTROLS, new ArrayValue((Value [])generatedControls.toArray(new Value[generatedControls.size()])));
    List generatedTriggers = new ArrayList();
    for (int i = 0; i < triggerDescriptions.length; i++ ) {
          Map triggerParameters = ((MapValue)triggerDescriptions[i]).getMap();
          String triggerName = triggerParameters.get(TRIGGER_NAME).toString();
          Value involvedTriggerParameters = (Value)triggerParameters.get(Trigger.INVOLVED_PARAMETERS);
          if ( involvedTriggerParameters == NullValue.NULL ) {
            involvedTriggerParameters = new ArrayValue((StringValue[])involvedParameters.toArray(new StringValue[involvedParameters.size()]));
          }
          triggerParameters.put(Trigger.INVOLVED_PARAMETERS, involvedTriggerParameters);
          URI triggerUri = (URI)triggerParameters.get(TRIGGER);
          Trigger trigger = (Trigger)ProcessorManager.getInstance().getProcessor(triggerUri);
          Value triggerActionUri = (Value)triggerParameters.get(Trigger.ACTION);
          if ( triggerActionUri == NullValue.NULL ) triggerActionUri = actionUri;
           triggerParameters.put(Trigger.ACTION, triggerActionUri);
          try {
            ProcessorManager.prepareValues(trigger.getParameterDescriptors(), triggerParameters, context);
          } catch ( ValidationException exception ) {
            throw new ValidationException(new ErrorMessage("controlComposer/triggerParameterInvalid", new Object[] { triggerUri }), exception);
          }
            Value triggerContainerUri = (Value)triggerParameters.get(TRIGGER_CONTAINER);
            Result triggerResult = trigger.process(triggerParameters, context);
            if ( triggerContainerUri != NullValue.NULL ) {
              Processor triggerContainer = ProcessorManager.getInstance().getProcessor((URI)triggerContainerUri);
              Map triggerContainerParameters = new HashMap();
              triggerContainerParameters.putAll(parameter);
              triggerContainerParameters.put(TRIGGER, triggerResult.getResultEntries().get(OUTPUT));
              try {
                ProcessorManager.prepareValues(triggerContainer.getParameterDescriptors(), triggerContainerParameters, context);
              } catch ( ValidationException exception ) {
                throw new ValidationException(new ErrorMessage("controlComposer/triggerContainerParameterInvalid", new Object[] { triggerContainerUri }), exception);
              }
              Result triggerContainerResult = triggerContainer.process(triggerContainerParameters, context);
              generatedTriggers.add(new MapValue(triggerName, (Value)triggerContainerResult.getResultEntries().get(OUTPUT)));
            } else {
              generatedTriggers.add(new MapValue(triggerName, (Value)triggerResult.getResultEntries().get(OUTPUT)));
            }
        }
        composerResult.addResultEntry(GENERATED_TRIGGERS, new ArrayValue((Value [])generatedTriggers.toArray(new Value[generatedTriggers.size()])));
        if ( errorsProcessorUri instanceof URI ) {
          Processor errorsTable = ProcessorManager.getInstance().getProcessor((URI)errorsProcessorUri);
          List errorList = new ArrayList();
          for ( Iterator i = context.getInformations().iterator(); i.hasNext(); ) {
            Information info = (Information)i.next();
            Map errors = new HashMap();
            explodeInformation(errors, info, locale );
            errorList.add(new MapValue(errors));
          }
          Map errorsParameter = new HashMap();
          MapValue[] errorsArray = new MapValue[errorList.size()];
          errorsParameter.put(SimpleProcessor.INPUT, new ArrayValue((MapValue[])errorList.toArray(errorsArray)));
          Result renderedErrors = ProcessorManager.process(errorsTable, errorsParameter, context);
          composerResult.addResultEntry(RENDERED_ERRORS, (Value)renderedErrors.getResultEntries().get(OUTPUT));
        }
        return composerResult;
    }
View Full Code Here

        }
      }
      // 4. Launch target step if validation is successfull
    Processor formProcess = ProcessorManager.getInstance().getProcessor(new URIValue(domain));
        map.remove(RESULT);
        Result formResult = formProcess.process(parameter,  context);
        map.put(RESULT, formResult);
    Processor bookmark = ProcessorManager.getInstance().getProcessor(context.getBookmark());
        return bookmark.process(parameter,  context);
    }
View Full Code Here

        Processor resultRenderer = ProcessorManager.getInstance().getProcessor(RESULT_RENDERER);
        Processor processor = ProcessorManager.getInstance().getProcessor((URI)uri);
      parameter.put(Control.ACTION, uri);
        parameter.put(ControlComposer.LOCALE, ProcessorManager.getInstance().process(ProcessorManager.LOCALE_RESOLVER, context.getStore(Store.REQUEST_HEADER).get("accept-language"), context));
        parameter.put(FormGenerator.TARGET_STEP, PROCESS_STEP);
        Result result = null;
        if ( step.equals(FORM_STEP) ) {
          result = formProcessor.process(parameter, context);
        } else if ( step.equals(PROCESS_STEP) ) {
          parameter.putAll(((MapValue)((FormStore)context.getStore(Store.FORM)).getDomain()).getMap());
          Result processorResult = ProcessorManager.process(processor, parameter, context);
          if ( hasErrors(context.getInformations()) ) {
              context.setStep(FORM_STEP);
            ((FormStore)context.getStore(Store.FORM)).put(ControlComposer.VALIDATE, BooleanValue.TRUE);
            result = formProcessor.process(parameter, context);
          } else {
            Map resultParameters = new HashMap();
            resultParameters.put("state", new StringValue(processorResult.getState()));
            result = ProcessorManager.process(resultRenderer, resultParameters, context);
            ((FormStore)context.getStore(Store.FORM)).clear();
          }
        } else {
        ((FormStore)context.getStore(Store.FORM)).clear();
View Full Code Here

  public Result process(Map parameter, Context context) throws Exception {
    URI processorUri = ProcessorManager.getInstance().getProcessorDescriptor(this).getUri();
    context.setProcess(processorUri);        // Remember current process in context
    String nextStep = getStep(firstStep, context);   // Lookup the first step of this process
    Store stepStore = new Cache();           // This store is used to allow stack-like result/parameter delivery between steps 
    Result result = new Result(OK);         // The result of this process processor
    Result stepResult = null;               // The result of the last executed step
    Step step;                    // The current step
    Store enclosingStepStore = context.getStore(Store.STEP)
    Map enclosingParameters = ((Cache)context.getStore(Store.INPUT)).getMap()
    context.setStepStore(stepStore);
    context.setInputParameters(parameter);
    do {
      logger.log(Level.FINE, "Processing "+processorUri+", step=" + nextStep);
      context.setStep(nextStep);          // Remember current step in context
      step = (Step)steps.get(nextStep);
      if (step == null) throw new ProcessException(new ErrorMessage("stepNotFound", new String[]{nextStep}));
      Processor processor = ProcessorManager.getInstance().getProcessor(step.getProcessorURI());
      try {
        Map processorParameters = loadParameters(step, processor, context);
        if ( processor instanceof EnvironmentConsumer ) {
          checkRequirements((EnvironmentConsumer)processor, context);
        }
        checkRoutings(step, processor);
        try {
          stepResult = ProcessorManager.process(processor, processorParameters, context);
          try {
            saveResults(step, stepResult, stepStore, result, getResultDescriptor().getResultEntryDescriptors(), context);
          } catch ( ProcessException e ) {
            throw new ProcessException(new ErrorMessage("saveFailed", new Object[] { step.getProcessorURI(), nextStep }), e );
          }
          nextStep = routeState(step, stepResult.getState());
        } catch (Exception e) {
          nextStep = routeException(step, e);
        }
      } catch ( ValidationException exception ) {
        throw new ValidationException(new ErrorMessage("validationFailed", new Object[] { step.getProcessorURI(), nextStep }), exception);
      }
    } while (nextStep != null);
    result.setState(getState(step, stepResult.getState()));
    context.setStepStore(enclosingStepStore);
    context.setInputParameters(enclosingParameters);
    return result;
  }
View Full Code Here

    }
    return OK;
  }
 
  private Result generateResult(String state, Result result) {
    Result processResult = new Result(state);
    // copy defined results from context store to result
    ResultEntryDescriptor[] resultEntryDescriptors = getResultDescriptor().getResultEntryDescriptors();
    for (int i = 0; i < resultEntryDescriptors.length; i++) {
      ResultEntryDescriptor descriptor = resultEntryDescriptors[i];
      Value resultValue = (Value)result.getResultEntries().get(descriptor.getName());
      if (resultValue != null) {
        processResult.addResultEntry(descriptor.getName(), resultValue);
      }
    }
    return processResult;
  }
View Full Code Here

                    active[counter] = Integer.parseInt(tokenizer.nextToken());
                    counter++;
                }
            }
        }
        return new Result(OK, OUTPUT, new StringValue(process(parameter, idArray, inputArray, active, 0, context), "text/html", false ));
    }
View Full Code Here

                                parameters.put(parameterDescriptors[i].getName(), parameterDescriptors[i].getDefaultValue());
                            }
                        }
                     
                    }
                    Result processorResult = processor.process(parameters, context);
                    input = processorResult.getResultEntries().get(resultKey);
                }
            } catch ( Exception exception ) {
                throw new ProcessException(new ErrorMessage("parameterProcessingException", new String[] { simpleProcessorUri.toString(), exception.getMessage() }), exception);
            }
        }
View Full Code Here

                    defaultTemplate.evaluate(buffer, parameter, i+offset);
                }
            }
            if ( footerTemplate != null ) footerTemplate.evaluate(buffer, parameter);
        }
        return new Result(OK, OUTPUT, new StringValue(buffer.toString(), defaultTemplate.getContentType(), false ));
    }
View Full Code Here

TOP

Related Classes of org.apache.slide.projector.Result

Copyright © 2018 www.massapicom. 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.