//# 0 errors, 116 messages
//#
/*
    //#EntriesPager.java:1:1: class: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.ui.struts2.pagers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.pojos.WeblogEntry;
import org.apache.roller.weblogger.util.URLUtilities;


/**
 * Paging through a collection of entries.
 */
public class EntriesPager {
    
    private static final Log log = LogFactory.getLog(EntriesPager.class);
    //#EntriesPager.java:35: method: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init
    //#EntriesPager.java:35: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager
    //#    method: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/pagers/EntriesPager]
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.createURL(Ljava/lang/String;Ljava/util/Map;)Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.getItems()Ljava/util/List;
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.getNextLink()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.getPrevLink()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.isMoreItems()Z
    //#output(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): log
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/pagers/EntriesPager] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.createURL(Ljava/lang/String;Ljava/util/Map;)Ljava/lang/String; == &createURL
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.getItems()Ljava/util/List; == &getItems
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.getNextLink()Ljava/lang/String; == &getNextLink
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.getPrevLink()Ljava/lang/String; == &getPrevLink
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): __Dispatch_Table.isMoreItems()Z == &isMoreItems
    //#post(org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init): init'ed(log)
    //#EntriesPager.java:35: end of method: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager__static_init
    
    // the collection for the pager
    private final List<WeblogEntry> items;
    
    // base url for the pager
    private final String baseUrl;
    
    // what page we are on
    private final int pageNum;
    
    // are there more items?
    private final boolean moreItems;
    
    
    public EntriesPager(String url, int page, List<WeblogEntry> entries, boolean hasMore) {
    //#EntriesPager.java:50: method: void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)
    //#input(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): entries
    //#input(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): hasMore
    //#input(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): page
    //#input(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this
    //#input(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): url
    //#output(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.baseUrl
    //#output(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.items
    //#output(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.moreItems
    //#output(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.pageNum
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.baseUrl == url
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): init'ed(this.baseUrl)
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.items == entries
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): init'ed(this.items)
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.moreItems == hasMore
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): init'ed(this.moreItems)
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): this.pageNum == page
    //#post(void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)): init'ed(this.pageNum)
        this.baseUrl = url;
        this.pageNum = page;
        this.items = entries;
        this.moreItems = hasMore;
    }
    //#EntriesPager.java:55: end of method: void org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager(String, int, List, bool)
    
    
    public String getNextLink() {
        if(isMoreItems()) {
    //#EntriesPager.java:59: method: String org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.getNextLink()
    //#input(String getNextLink()): ""._tainted
    //#input(String getNextLink()): "&amp;"._tainted
    //#input(String getNextLink()): __Descendant_Table[org/apache/roller/weblogger/ui/struts2/pagers/EntriesPager]
    //#input(String getNextLink()): __Descendant_Table[others]
    //#input(String getNextLink()): __Dispatch_Table.isMoreItems()Z
    //#input(String getNextLink()): this
    //#input(String getNextLink()): this.__Tag
    //#input(String getNextLink()): this.baseUrl
    //#input(String getNextLink()): this.baseUrl._tainted
    //#input(String getNextLink()): this.moreItems
    //#input(String getNextLink()): this.pageNum
    //#output(String getNextLink()): java.lang.StringBuilder:toString(...)._tainted
    //#output(String getNextLink()): return_value
    //#new obj(String getNextLink()): java.lang.StringBuilder:toString(...)
    //#pre[2] (String getNextLink()): this.__Tag == org/apache/roller/weblogger/ui/struts2/pagers/EntriesPager
    //#pre[3] (String getNextLink()): (soft) this.baseUrl != null
    //#pre[6] (String getNextLink()): (soft) this.pageNum <= 4_294_967_294
    //#post(String getNextLink()): init'ed(java.lang.StringBuilder:toString(...)._tainted)
    //#post(String getNextLink()): return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
    //#unanalyzed(String getNextLink()): Effects-of-calling:org.apache.roller.weblogger.util.URLUtilities:getQueryString
    //#unanalyzed(String getNextLink()): Effects-of-calling:java.lang.String:indexOf
    //#unanalyzed(String getNextLink()): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(String getNextLink()): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(String getNextLink()): Effects-of-calling:java.lang.String:substring
    //#unanalyzed(String getNextLink()): Effects-of-calling:java.lang.StringBuilder:toString
    //#test_vector(String getNextLink()): this.moreItems: {0}, {1}
            int nextPage = pageNum + 1;
            Map<String, String> params = new HashMap();
            params.put("bean.page", ""+nextPage);
            return createURL(baseUrl, params);
        }
        return null;
    //#EntriesPager.java:65: end of method: String org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.getNextLink()
    }
    
    
    public String getPrevLink() {
        if (pageNum > 0) {
    //#EntriesPager.java:70: method: String org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.getPrevLink()
    //#input(String getPrevLink()): ""._tainted
    //#input(String getPrevLink()): "&amp;"._tainted
    //#input(String getPrevLink()): this
    //#input(String getPrevLink()): this.baseUrl
    //#input(String getPrevLink()): this.baseUrl._tainted
    //#input(String getPrevLink()): this.pageNum
    //#output(String getPrevLink()): java.lang.StringBuilder:toString(...)._tainted
    //#output(String getPrevLink()): return_value
    //#new obj(String getPrevLink()): java.lang.StringBuilder:toString(...)
    //#pre[2] (String getPrevLink()): (soft) this.baseUrl != null
    //#post(String getPrevLink()): init'ed(java.lang.StringBuilder:toString(...)._tainted)
    //#post(String getPrevLink()): return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
    //#unanalyzed(String getPrevLink()): Effects-of-calling:org.apache.roller.weblogger.util.URLUtilities:getQueryString
    //#unanalyzed(String getPrevLink()): Effects-of-calling:java.lang.String:indexOf
    //#unanalyzed(String getPrevLink()): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(String getPrevLink()): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(String getPrevLink()): Effects-of-calling:java.lang.String:substring
    //#unanalyzed(String getPrevLink()): Effects-of-calling:java.lang.StringBuilder:toString
    //#test_vector(String getPrevLink()): this.pageNum: {-2_147_483_648..0}, {1..4_294_967_295}
            int prevPage = pageNum - 1;
            Map<String, String> params = new HashMap();
            params.put("bean.page", ""+prevPage);
            return createURL(baseUrl, params);
        }
        return null;
    //#EntriesPager.java:76: end of method: String org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.getPrevLink()
    }
    
    
    private String createURL(String base, Map<String, String> params) {
        String qString = URLUtilities.getQueryString(params);
    //#EntriesPager.java:81: method: String org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.createURL(String, Map)
    //#EntriesPager.java:81: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.util.URLUtilities:getQueryString(Map)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager
    //#    method: String createURL(String, Map)
    //#    unanalyzed callee: String org.apache.roller.weblogger.util.URLUtilities:getQueryString(Map)
    //#input(String createURL(String, Map)): "&amp;"._tainted
    //#input(String createURL(String, Map)): base
    //#input(String createURL(String, Map)): base._tainted
    //#input(String createURL(String, Map)): params
    //#output(String createURL(String, Map)): java.lang.StringBuilder:toString(...)._tainted
    //#output(String createURL(String, Map)): return_value
    //#new obj(String createURL(String, Map)): java.lang.StringBuilder:toString(...)
    //#pre[1] (String createURL(String, Map)): base != null
    //#presumption(String createURL(String, Map)): org.apache.roller.weblogger.util.URLUtilities:getQueryString(...)@81 != null
    //#post(String createURL(String, Map)): init'ed(java.lang.StringBuilder:toString(...)._tainted)
    //#post(String createURL(String, Map)): return_value in Addr_Set{&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
    //#test_vector(String createURL(String, Map)): java.lang.String:indexOf(...)@83: {-1}, {-2_147_483_648..-2, 0..4_294_967_295}
        
        if(base.indexOf("?") != -1) {
            // if base url already has params them just append our query string
            return base + "&" + qString.substring(1);
        } else {
            return base + qString;
    //#EntriesPager.java:87: end of method: String org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.createURL(String, Map)
        }
    }
    
    
    public List<WeblogEntry> getItems() {
        return items;
    //#EntriesPager.java:93: method: List org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.getItems()
    //#input(List getItems()): this
    //#input(List getItems()): this.items
    //#output(List getItems()): return_value
    //#post(List getItems()): return_value == this.items
    //#post(List getItems()): init'ed(return_value)
    //#EntriesPager.java:93: end of method: List org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.getItems()
    }

    public boolean isMoreItems() {
        return moreItems;
    //#EntriesPager.java:97: method: bool org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.isMoreItems()
    //#input(bool isMoreItems()): this
    //#input(bool isMoreItems()): this.moreItems
    //#output(bool isMoreItems()): return_value
    //#post(bool isMoreItems()): return_value == this.moreItems
    //#post(bool isMoreItems()): init'ed(return_value)
    //#EntriesPager.java:97: end of method: bool org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager.isMoreItems()
    }
    
}
    //#EntriesPager.java:: end of class: org.apache.roller.weblogger.ui.struts2.pagers.EntriesPager
