Package de.innovationgate.wgpublisher.webtml.utils

Examples of de.innovationgate.wgpublisher.webtml.utils.ResultIterator


             return queryParameters;
         }

         public ResultIterator getResultIterator() throws WGBackendException {
             List resultSetsCopy = new ArrayList(resultSets);
             return new ResultIterator(new ResultSetIterator(resultSetsCopy.iterator()), results());
         }
View Full Code Here


       
        public void addResultSet(WGResultSet resultSet, String language) {}
       
        public ResultIterator getResultIterator() {
            if (result instanceof List) {
                return new ResultIterator((List) result);
            }
            else {
                return null;
            }
        }
View Full Code Here

      calcCurrentPage(status.intPageSize);
    }

    // get iteration items
    ResultIterator objectIterator = retrieveResultIterator();
   
    // If no objects retrieved, exit tag
    if (objectIterator == null) {
      this.setEvalBody(false);
      return;
    }
   
    // sorting of entries - We must prefetch all contents here to be able to sort them in WebTML
    String sortOrder = this.getSortorder();
    if (sortOrder != null && !sortOrder.equals("none")) {
        List<Object> objects = objectIterator.extractCompleteList();
      if (!status.forEachType.equals("content")) {
        java.util.Collections.sort(objects, new ObjectComparator(retrieveCollator()));
      }
      else {
        contentSort(objects);
      }
     
      if (sortOrder.startsWith("desc")) {
        Collections.reverse(objects);
      }
     
      objectIterator = new ResultIterator(objects);
    }
   
    // In case of type content wrap the iterator inside a FilterVisibleIterator() to filter out hidden docs
    if (status.forEachType.equals("content")) {
        OnlyVisibleIterator onlyVisibleIterator = new OnlyVisibleIterator(objectIterator, status.onlyPublished);
            objectIterator = new ResultIterator(onlyVisibleIterator, objectIterator.getResultSize());
    }
   
    // In case of a filter condition wrap it into a filter iterator
        String filterExpression = getFilter();
        if (filterExpression != null) {
            FilterIterator filterIterator = new FilterIterator(filterExpression, objectIterator);
            objectIterator = new ResultIterator(filterIterator, objectIterator.getResultSize());
        }
   
        // Fill last page behaviour - Fetch the double pagesize and only use the last pageSize of docs of it. This should in most situations ensure that enough docs are retrieved
        int realResultSize = objectIterator.getResultSize();
        if (status.intPageSize > 0 && stringToBoolean(getFilllastpage())) {
            int pageOffset = status.offset - status.baseOffset;
            int goBack = (pageOffset >= status.intPageSize ? status.intPageSize : pageOffset);
            int newOffset = status.offset - goBack;
            objectIterator.proceedToOffset(newOffset, stringToBoolean(getLinear()));
           
            List results = new ArrayList<Object>();
            for (int docsToFetch = 1; docsToFetch <= goBack + status.intPageSize; docsToFetch++) {
                if (!objectIterator.hasNext()) {
                    realResultSize = newOffset + (docsToFetch - 1);
                    break;
                }
                results.add(objectIterator.next());
            }
           
            List subList;
            if (results.size() > status.intPageSize) {
                int startIndex = results.size() - status.intPageSize;
                subList = results.subList(startIndex, results.size());
                status.offset = newOffset + startIndex;
            }
            else {
                subList = results;
                status.offset = newOffset;
            }
            objectIterator = new ResultIterator(subList.iterator(), realResultSize);
        }
       
        // Else proceed directly to offset
        else {
            objectIterator.proceedToOffset(status.offset, stringToBoolean(getLinear()));
        }
       
        status.resultIterator = objectIterator;
        status.resultSize = realResultSize;
    if (status.intPageSize > 0) {
View Full Code Here

    this.setEvalBody(this.proceedValues());

  }

    private ResultIterator retrieveResultIterator() throws TMLException, WGAPIException {
        ResultIterator objectIterator = null;
       
        Status status = (Status) getStatus();
    if (status.forEachType.equals("content")) {
      ResultSetTagStatus tag;

      if (this.getSourcetag() != null) {
        tag = (ResultSetTagStatus) this.getTagStatusById(this.getSourcetag(), ResultSetTagStatus.class);
        if (tag == null) {
          throw new TMLException("Could not find content list tag with id " + this.getSourcetag(), true);
        }
      }
      else if (this.getRelationgroup() != null) {
          String group = getRelationgroup();
          status.contentLanguage = getTMLContext().content().getLanguage().getName();
              return new ResultIterator(getTMLContext().content().getRelationsOfGroup(group));
      }
      else if (getStatus() instanceof ResultSetTagStatus) {
        tag = (ResultSetTagStatus) getStatus();
      }
      else {
        tag = (ResultSetTagStatus) getStatus().getAncestorTag(ResultSetTagStatus.class);
        if (tag == null) {
          throw new TMLException("No content list tag specified", true);
        }
      }

      objectIterator = tag.getResultIterator();
            status.contentLanguage = tag.getResultLanguage();
     
    }
    else if (status.forEachType.equals("loop") || status.forEachType.equals("level")) {

      int count = 0;
      if (status.forEachType.equals("loop")) {
        String strCount = this.getCount();
        if (strCount == null) {
          throw new TMLException("Foreach with type loop but without attribute count", true);
        }
        count = stringToInteger(strCount, 0);
      }
      else if (status.forEachType.equals("level")) {
          WGContentNavigator nav = new WGContentNavigator(null, new WebTMLLanguageChooser(getTMLContext().db(), getTMLContext()));
        count = nav.getContentLevel(this.getTMLContext().content()).intValue();
      }
      List objects = new java.util.ArrayList();
      for (int idx = 0; idx < count; idx++) {
        objects.add(new Integer(idx + 1));
      }
      objectIterator = new ResultIterator(objects.iterator(), objects.size());
    }
    else if (status.forEachType.equals("itemvalue")) {
      Object obj = this.getTMLContext().itemlist(this.getItem());
      if (obj == null) {
        throw new TMLException("Could not retrieve item " + this.getItem(), true);
      }
      if (obj instanceof List) {
        objectIterator = new ResultIterator((java.util.List) obj);
      }
      else {
        objectIterator = new ResultIterator(java.util.Collections.singletonList(obj));
      }
     
    }
    else if (status.forEachType.equals("fieldvalue")) {
      Object obj=null;
      // Register with form parent (if present) and retrieve item values from it;
      FormInputRegistrator form = (FormInputRegistrator) getStatus().getAncestorTag(FormBase.class)
      if (form != null)
        obj=form.getFieldValue(this.getItem(), false, "", false);
      else obj = this.getTMLContext().itemlist(this.getItem());
     
      if (obj == null) {
        throw new TMLException("Could not retrieve item " + this.getItem(), true);
      }
      if (obj instanceof List) {
        objectIterator = new ResultIterator((java.util.List) obj);
      }
      else {
        objectIterator = new ResultIterator(java.util.Collections.singletonList(obj));
      }
     
    }
    else if (status.forEachType.equals("tagresult")) {
      if (this.getSourcetag() == null) {
        throw new TMLException("No tag specified to take tagresult from", true);
      }
      BaseTagStatus tag = this.getTagStatusById(this.getSourcetag());
      if (tag == null) {
        throw new TMLException("Could not find tag with id " + this.getSourcetag(), true);
      }
      Object result = tag.result;
      if (de.innovationgate.utils.WGUtils.isCollection(result)) {
        objectIterator = new ResultIterator((java.util.Collection) result);
      }
      else {
        objectIterator = new ResultIterator(java.util.Collections.singletonList(result));
      }
    }
    else {
      throw new TMLException("Unknown type for foreach tag: " + status.forEachType, true);
    }
View Full Code Here

          return MULTILANGUAGE_RESULT;
      }
     
      public ResultIterator getResultIterator() throws TMLException {
          if (contentList != null) {
              return new ResultIterator((List) contentList);
          }
          else {
              throw new TMLException("Tag has no result list", true);
          }
      }
View Full Code Here

TOP

Related Classes of de.innovationgate.wgpublisher.webtml.utils.ResultIterator

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.