Package org.apache.slide.projector

Examples of org.apache.slide.projector.Result


    };

    public Result process(Map parameter, Context context) throws Exception {
        String query = ((StringValue)parameter.get(DASL_QUERY)).toString();
        Value []values = Projector.getRepository().search(query, context.getCredentials());
        if ( values.length == 0 ) return new Result(EMPTY);
        return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new ArrayValue(values));
    }
View Full Code Here


        new ParameterDescriptor(URI, new DefaultMessage("propertyQuery/uri"), new URIValueDescriptor())
    };

    public Result process(Map parameter, Context context) throws Exception {
      ArrayValue properties = Projector.getRepository().getProperties((URIValue)parameter.get(URI), context.getCredentials());
        if ( properties.getArray().length == 0 ) return new Result(EMPTY);
        Result result= new Result(StateDescriptor.OK, ARRAY, properties);
        Map properyMap = new HashMap();
        for ( int i = 0; i < properties.getArray().length; i++ ) {
            properyMap.put(((MapValue)properties.getArray()[i]).getMap().get("name").toString(), ((MapValue)properties.getArray()[i]).getMap().get("value"));
        }
        result.addResultEntry(MAP, new MapValue(properyMap));
        return result;
    }
View Full Code Here

          resultMap.put(CONTENT_ENTRY, content);
        }
      }
      arrayEntries.add(new MapValue(resultMap));
    }
    return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new ArrayValue((Value [])arrayEntries.toArray(new Value[arrayEntries.size()])));
  }
View Full Code Here

    };

    public Result process(Map parameter, Context context) throws Exception {
        Value []resources = ((ArrayValue)parameter.get(SimpleProcessor.INPUT)).getArray();
        Locale locale = ((LocaleValue)context.getStore(Store.SESSION).get(LOCALE)).getLocale();
        return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, localize(resources, locale, context));
    }
View Full Code Here

    private static ParameterDescriptor []parameterDescriptors;
    private Map routes = new HashMap();

    public Result process(Map parameter, Context context) throws Exception {
        String value = ((StringValue)parameter.get(SimpleProcessor.INPUT)).toString();
        return new Result((String)routes.get(value));
    }
View Full Code Here

        logger.log(Level.FINE, "Request uri=" + request.getRequestURI());
        logger.log(Level.FINE, "Context path=" + request.getContextPath());
        logger.log(Level.FINE, "Servlet path=" + request.getServletPath());
        URI uri = new URIValue(request.getRequestURI().substring(request.getContextPath().length()+request.getServletPath().length()+1));
        try {
            Result result;
            Processor processor;
            try {
                logger.log(Level.FINE, "Processing started with URI=" + uri);
                Map requestParameters = request.getParameterMap();
                if ( requestParameters.containsKey(Constants.PROCESS_ID_PARAMETER) ) {
                  context.setProcessId(requestParameters.get(Constants.PROCESS_ID_PARAMETER).toString());
                } else {
                    StringBuffer processIdBuffer = new StringBuffer(Constants.PROCESS_ID_LENGTH);
                  for ( int i = 0; i < Constants.PROCESS_ID_LENGTH; i++) {
                      processIdBuffer.append(allowedChars.charAt(random.nextInt(allowedChars.length())));
                  }
                  context.setProcessId(processIdBuffer.toString());
                }
                processor = ProcessorManager.getInstance().getProcessor(uri);
                Scheduler.getInstance();
                Scheduler.setContext(context);
              if ( sessionCreated ) {
                // new session
                    Scheduler.getInstance().launchSessionJobs(context);
              }
                Scheduler.getInstance().launchRequestJobs(context);
                if ( ProcessorManager.getInstance().getProcessorDescriptor(uri).isBookmark() ) {
                    context.setBookmark(uri);
                }
                ParameterDescriptor[] parameterDescriptors = processor.getParameterDescriptors();
                result = ProcessorManager.process(processor, new HashMap(requestParameters), context);
            } catch ( Exception exception ) {
                logger.log(Level.SEVERE, "Exception while processing processor with URI="+uri+"", exception);
                processor = ProcessorManager.getInstance().getProcessor(DEFAULT_EXCEPTION_PROCESSOR);
                Map exceptionParameters = new HashMap();
                exceptionParameters.put(ExceptionRenderer.EXCEPTION, new ObjectValue(exception));
                result = ProcessorManager.process(processor, exceptionParameters, context);
            }
            Value presentableResource = ((HttpContext)context).getPresentableResource();
            if (presentableResource == null) {
                // check for 'output' resource in processor result
                presentableResource = (Value)result.getResultEntries().get(SimpleProcessor.OUTPUT);
            }
            if ( presentableResource != null ) {
                if ( presentableResource instanceof StreamableValue ) {
                    response.setContentType(((StreamableValue)presentableResource).getContentType()+"; charset=UTF-8");
                    response.setContentLength(((StreamableValue)presentableResource).getContentLength());
View Full Code Here

            linkBuffer.append(entry.getValue());
            }
    } else {
            throw new ProcessException(new ErrorMessage("httpContextRequired"));
        }
        return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new StringValue(linkBuffer.toString()));
  }
View Full Code Here

        String handlerUrl = ProcessorManager.getInstance().process(ProcessorManager.URL, TableHandler.URL, context).toString();
        String id = parameters.get(TableHandler.ID).toString();
        String storeName = parameters.get(TableHandler.STORE).toString();
        Store store = context.getStore(StoreHelper.getStoreByName(storeName));
        MapValue idResource = (MapValue)store.get(id);
        if ( idResource == null ) return new Result(FAILED);
        Map state = idResource.getMap();
        int itemsPerPage = ((NumberValue)state.get(TableMapRenderer.ITEMS_PER_PAGE)).getNumber().intValue();
        if (itemsPerPage <= 0) {
            return new Result(FAILED);
        }
        Result result = new Result(StateDescriptor.OK);
        NumberValue firstItem = ((NumberValue)state.get(TableHandler.CURRENT_POSITION));
        int currentPosition = firstItem.getNumber().intValue();
        int currentPage = currentPosition / itemsPerPage;
        int length = ((NumberValue)state.get(TableMapRenderer.LENGTH)).getNumber().intValue();
        int totalPages = (int)Math.floor((double)length / ((double)itemsPerPage) + 1);
        int lastItem = Math.min(currentPosition + itemsPerPage, length);
        result.addResultEntry(FIRST_ITEM, firstItem);
        result.addResultEntry(LAST_ITEM, new NumberValue(new Integer(lastItem)));
        result.addResultEntry(CURRENT_PAGE, new NumberValue(new Integer(currentPage)));
        result.addResultEntry(TOTAL_PAGES, new NumberValue(new Integer(totalPages)));
        boolean hasNext = false, hasPrevious = false;
        if (itemsPerPage > 0) {
            hasNext = (currentPosition + itemsPerPage < length);
            hasPrevious = (currentPosition > 0);
        }
        StringBuffer buffer = new StringBuffer();
        if (pre != null) pre.evaluate(buffer, parameters);
        createHandler(0, itemsPerPage, handlerUrl, storeName, id, parameters, parameter);
        if ( firstSelected != null && !hasPrevious ) {
            firstSelected.evaluate(buffer, parameters);
        } else if ( first  != null) {
            first.evaluate(buffer, parameters);
        }
        createHandler(Math.max(0, currentPosition - itemsPerPage), itemsPerPage, handlerUrl, storeName, id, parameters, parameter);
        if (hasPrevious) {
            if ( previous != null) previous.evaluate(buffer, parameters);
        } else {
            if ( previousDisabled != null) previousDisabled.evaluate(buffer, parameters);
        }
        int step = itemsPerPage > 0 ? itemsPerPage : 1;
        boolean first = true;
        lastItem = 0;
        int itemsInRange = range * step;
        int lowerBorder = currentPosition - itemsInRange;
        int upperBorder = currentPosition + itemsInRange;
        int i = 0;
        for (; i < length; i += step) {
            lastItem = i;
            parameters.put(CURRENT_PAGE, new NumberValue(new Integer(i / itemsPerPage + 1)));
            createHandler(i, Math.min(i+itemsPerPage, length), handlerUrl, storeName, id, parameters, parameter);
            int rangeState = IN;
            if (showRange && (i < lowerBorder || i > upperBorder)) rangeState = OUT;
            if (showRange && (i == lowerBorder || i == upperBorder)) rangeState = BORDER;
            boolean pagingTemplate = false;
            Template templateToUse = null;
            if (i == currentPosition && selectedPage != null) {
                pagingTemplate = true;
                templateToUse = selectedPage;
            } else if (rangeState == IN && page != null) {
                pagingTemplate = true;
                templateToUse = page;
            } else if (rangeState == IN) {
                pagingTemplate = true;
                templateToUse = page;
            } else if (rangeState == BORDER) {
                templateToUse = etc;
            }
            if (templateToUse != null ) {
                if (pagingTemplate) {
                    if (!first) {
                        if (pageSeparator != null) pageSeparator.evaluate(buffer, parameters);
                    }
                    first = false;
                }
                templateToUse.evaluate(buffer, parameters);
            }
        }
        createHandler(currentPosition + itemsPerPage, itemsPerPage, handlerUrl, storeName, id, parameters, parameter);
        if (hasNext) {
            if ( next != null) next.evaluate(buffer, parameters);
        } else {
            if ( nextDisabled != null) nextDisabled.evaluate(buffer, parameters);
        }
        createHandler(i-itemsPerPage, length, handlerUrl, storeName, id, parameters, parameter);
        if ( lastSelected != null && !hasNext ) {
            lastSelected.evaluate(buffer, parameters);
        } else if ( last != null) {
            last.evaluate(buffer, parameters);
        }
        if ( post != null) post.evaluate(buffer, parameters);
        result.addResultEntry(OUTPUT, new StringValue(buffer.toString()));
        return result;
    }
View Full Code Here

      Scheduler.getInstance().saveJobs();
        }
        resultEntries.put(SimpleProcessor.OUTPUT, output);
        // build url to activate this processor on top level
        resultEntries.put(URL, new StringValue(url));
        return new Result(StateDescriptor.OK, resultEntries);
    }
View Full Code Here

    DateValue date = (DateValue)parameters.get(DATE);
    String dateFormat = parameters.get(DATE_FORMAT).toString();
    String timeFormat = parameters.get(TIME_FORMAT).toString();
    Locale locale = ((LocaleValue)context.getStore(Store.SESSION).get(LOCALE)).getLocale();
    String formattedDate = getDateFormatter(dateFormat, timeFormat, locale).format(date.getDate());
    return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new StringValue(formattedDate));
  }
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.