Example usage for java.util TreeSet remove

List of usage examples for java.util TreeSet remove

Introduction

In this page you can find the example usage for java.util TreeSet remove.

Prototype

public boolean remove(Object o) 

Source Link

Document

Removes the specified element from this set if it is present.

Usage

From source file:com.michelin.cio.hudson.plugins.rolestrategy.RoleMap.java

/**
 * Get all the sids referenced in this {@link RoleMap}.
 * @param includeAnonymous True if you want the {@code Anonymous} sid to be included in the set
 * @return A sorted set containing all the sids
 *//*from  w  w w .j  a  va2 s  . c o  m*/
public SortedSet<String> getSids(Boolean includeAnonymous) {
    TreeSet<String> sids = new TreeSet<String>();
    for (Map.Entry entry : this.grantedRoles.entrySet()) {
        sids.addAll((Set) entry.getValue());
    }
    // Remove the anonymous sid if asked to
    if (!includeAnonymous) {
        sids.remove("anonymous");
    }
    return Collections.unmodifiableSortedSet(sids);
}

From source file:org.paxle.crawler.impl.SubCrawlerManager.java

/**
 * Removes a uninstalled {@link ISubCrawler} from the {@link Activator#subCrawlerList subcrawler-list}
 * @param ref the reference to the {@link ISubCrawler subcrawler-service} to be removed
 *//*www. ja  va2s. co m*/
protected void removeSubCrawler(final ServiceReference ref) {
    final String crawlerPid = (String) ref.getProperty(Constants.SERVICE_PID);

    // getting all protocols supported by the crawler
    final String[] protocols = getProtocols(ref);
    if (protocols == null)
        return;

    for (String protocol : protocols) {
        protocol = protocol.trim().toLowerCase();

        // getting all crawlers supporting the given protocol
        TreeSet<ServiceReference> refs = this.subCrawlerList.get(protocol);
        if (refs == null)
            continue;

        // removing crawler fro the list
        refs.remove(ref);
    }

    if (this.logger.isInfoEnabled()) {
        final StringBuilder msg = new StringBuilder();
        msg.append(String.format("Crawler '%s' uninstalled. %d supported protocols: ", crawlerPid,
                Integer.valueOf(protocols.length)));
        for (String protocol : protocols) {
            msg.append("\r\n\t").append(protocol).append(": ")
                    .append(this.isEnabled(protocol, ref) ? "enabled" : "disabled");
        }
        this.logger.info(msg.toString());
    }
}

From source file:org.opendatakit.security.server.SecurityServiceUtil.java

/**
 * Method to enforce an access configuration constraining only registered users, authenticated
 * users and anonymous access./*from w  ww  .  j av  a  2  s.  c om*/
 * 
 * Add additional checks of the incoming parameters and patch things up if the incoming list of
 * users omits the super-user.
 * 
 * @param users
 * @param anonGrants
 * @param allGroups
 * @param cc
 * @throws DatastoreFailureException
 * @throws AccessDeniedException
 */
public static final void setStandardSiteAccessConfiguration(ArrayList<UserSecurityInfo> users,
        ArrayList<GrantedAuthorityName> allGroups, CallingContext cc)
        throws DatastoreFailureException, AccessDeniedException {

    // remove anonymousUser from the set of users and collect its
    // permissions (anonGrantStrings) which will be placed in
    // the granted authority hierarchy table.
    List<String> anonGrantStrings = new ArrayList<String>();
    {
        UserSecurityInfo anonUser = null;
        for (UserSecurityInfo i : users) {
            if (i.getType() == UserType.ANONYMOUS) {
                anonUser = i;
                // clean up grants for anonymousUser --
                // ignore anonAuth (the grant under which we will place things)
                // and forbid Site Admin
                for (GrantedAuthorityName a : i.getAssignedUserGroups()) {
                    if (anonAuth.getAuthority().equals(a.name()))
                        continue; // avoid circularity...
                    // only allow ROLE_ATTACHMENT_VIEWER and GROUP_ assignments.
                    if (!a.name().startsWith(GrantedAuthorityName.GROUP_PREFIX)) {
                        continue;
                    }
                    // do not allow Site Admin assignments for Anonymous --
                    // or Tables super-user or Tables Administrator.
                    // those all give access to the full set of users on the system
                    // and giving that information to Anonymous is a security
                    // risk.
                    if (GrantedAuthorityName.GROUP_SITE_ADMINS.equals(a)
                            || GrantedAuthorityName.GROUP_ADMINISTER_TABLES.equals(a)
                            || GrantedAuthorityName.GROUP_SUPER_USER_TABLES.equals(a)) {
                        continue;
                    }
                    anonGrantStrings.add(a.name());
                }
                break;
            }
        }
        if (anonUser != null) {
            users.remove(anonUser);
        }
    }

    // scan through the users and remove any entries under assigned user groups
    // that do not begin with GROUP_.
    //
    // Additionally, if the user is an e-mail, remove the GROUP_DATA_COLLECTORS
    // permission since ODK Collect does not support oauth2 authentication.
    {
        TreeSet<GrantedAuthorityName> toRemove = new TreeSet<GrantedAuthorityName>();
        for (UserSecurityInfo i : users) {
            // only working with registered users
            if (i.getType() != UserType.REGISTERED) {
                continue;
            }
            // get the list of assigned groups
            // -- this is not a copy -- we can directly manipulate this.
            TreeSet<GrantedAuthorityName> assignedGroups = i.getAssignedUserGroups();

            // scan the set of assigned groups and remove any that don't begin with GROUP_
            toRemove.clear();
            for (GrantedAuthorityName name : assignedGroups) {
                if (!name.name().startsWith(GrantedAuthorityName.GROUP_PREFIX)) {
                    toRemove.add(name);
                }
            }
            if (!toRemove.isEmpty()) {
                assignedGroups.removeAll(toRemove);
            }
            // for e-mail accounts, remove the Data Collector permission since ODK Collect
            // does not support an oauth2 authentication mechanism.
            if (i.getEmail() != null) {
                assignedGroups.remove(GrantedAuthorityName.GROUP_DATA_COLLECTORS);
            }
        }
    }

    // find the entry(entries) for the designated super-user(s)
    String superUserUsername = cc.getUserService().getSuperUserUsername();
    int expectedSize = ((superUserUsername != null) ? 1 : 0);
    ArrayList<UserSecurityInfo> superUsers = new ArrayList<UserSecurityInfo>();
    for (UserSecurityInfo i : users) {
        if (i.getType() == UserType.REGISTERED) {
            if (i.getUsername() != null && superUserUsername != null
                    && i.getUsername().equals(superUserUsername)) {
                superUsers.add(i);
            }
        }
    }

    if (superUsers.size() != expectedSize) {
        // we are missing one or both super-users.
        // remove any we have and recreate them from scratch.
        users.removeAll(superUsers);
        superUsers.clear();

        // Synthesize a UserSecurityInfo object for the super-user(s)
        // and add it(them) to the list.

        try {
            List<RegisteredUsersTable> tList = RegisteredUsersTable.assertSuperUsers(cc);

            for (RegisteredUsersTable t : tList) {
                UserSecurityInfo i = new UserSecurityInfo(t.getUsername(), t.getFullName(), t.getEmail(),
                        UserSecurityInfo.UserType.REGISTERED);
                superUsers.add(i);
                users.add(i);
            }

        } catch (ODKDatastoreException e) {
            e.printStackTrace();
            throw new DatastoreFailureException("Incomplete update");
        }
    }

    // reset super-user privileges to have (just) site admin privileges
    // even if caller attempts to change, add, or remove them.
    for (UserSecurityInfo i : superUsers) {
        TreeSet<GrantedAuthorityName> grants = new TreeSet<GrantedAuthorityName>();
        grants.add(GrantedAuthorityName.GROUP_SITE_ADMINS);
        grants.add(GrantedAuthorityName.ROLE_SITE_ACCESS_ADMIN);
        // override whatever the user gave us.
        i.setAssignedUserGroups(grants);
    }

    try {
        // enforce our fixed set of groups and their inclusion hierarchy.
        // this is generally a no-op during normal operations.
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(siteAuth,
                SecurityServiceUtil.siteAdministratorGrants, cc);
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(administerTablesAuth,
                SecurityServiceUtil.administerTablesGrants, cc);
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(superUserTablesAuth,
                SecurityServiceUtil.superUserTablesGrants, cc);
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(synchronizeTablesAuth,
                SecurityServiceUtil.synchronizeTablesGrants, cc);
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(dataOwnerAuth,
                SecurityServiceUtil.dataOwnerGrants, cc);
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(dataViewerAuth,
                SecurityServiceUtil.dataViewerGrants, cc);
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(dataCollectorAuth,
                SecurityServiceUtil.dataCollectorGrants, cc);

        // place the anonymous user's permissions in the granted authority table.
        GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(anonAuth, anonGrantStrings, cc);

        // get all granted authority names
        TreeSet<String> authorities = GrantedAuthorityHierarchyTable
                .getAllPermissionsAssignableGrantedAuthorities(cc.getDatastore(), cc.getCurrentUser());
        // remove the groups that have structure (i.e., those defined above).
        authorities.remove(siteAuth.getAuthority());
        authorities.remove(administerTablesAuth.getAuthority());
        authorities.remove(superUserTablesAuth.getAuthority());
        authorities.remove(synchronizeTablesAuth.getAuthority());
        authorities.remove(dataOwnerAuth.getAuthority());
        authorities.remove(dataViewerAuth.getAuthority());
        authorities.remove(dataCollectorAuth.getAuthority());
        authorities.remove(anonAuth.getAuthority());

        // delete all hierarchy structures under anything else.
        // i.e., if somehow USER_IS_REGISTERED had been granted GROUP_FORM_MANAGER
        // then this loop would leave USER_IS_REGISTERED without any grants.
        // (it repairs the database to conform to our privilege hierarchy expectations).
        List<String> empty = Collections.emptyList();
        for (String s : authorities) {
            GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy(new SimpleGrantedAuthority(s), empty,
                    cc);
        }

        // declare all the users (and remove users that are not in this set)
        Map<UserSecurityInfo, String> pkMap = setUsers(users, cc);

        // now, for each GROUP_..., update the user granted authority
        // table with the users that have that GROUP_... assignment.
        setUsersOfGrantedAuthority(pkMap, siteAuth, cc);
        setUsersOfGrantedAuthority(pkMap, administerTablesAuth, cc);
        setUsersOfGrantedAuthority(pkMap, superUserTablesAuth, cc);
        setUsersOfGrantedAuthority(pkMap, synchronizeTablesAuth, cc);
        setUsersOfGrantedAuthority(pkMap, dataOwnerAuth, cc);
        setUsersOfGrantedAuthority(pkMap, dataViewerAuth, cc);
        setUsersOfGrantedAuthority(pkMap, dataCollectorAuth, cc);
        // all super-users would already have their site admin role and
        // we leave that unchanged. The key is to ensure that the
        // super users are in the users list so they don't get
        // accidentally removed and that they have siteAuth group
        // membership. I.e., we don't need to manage ROLE_SITE_ACCESS_ADMIN
        // here. it is done elsewhere.

    } catch (ODKDatastoreException e) {
        e.printStackTrace();
        throw new DatastoreFailureException("Incomplete update");
    } finally {
        Datastore ds = cc.getDatastore();
        User user = cc.getCurrentUser();
        try {
            SecurityRevisionsTable.setLastRegisteredUsersRevisionDate(ds, user);
        } catch (ODKDatastoreException e) {
            // if it fails, use RELOAD_INTERVAL to force reload.
            e.printStackTrace();
        }
        try {
            SecurityRevisionsTable.setLastRoleHierarchyRevisionDate(ds, user);
        } catch (ODKDatastoreException e) {
            // if it fails, use RELOAD_INTERVAL to force reload.
            e.printStackTrace();
        }
    }
}

From source file:com.cyanogenmod.eleven.ui.fragments.QueueFragment.java

/**
 * {@inheritDoc}/*from w  ww.  j a v a2s  .com*/
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPopupMenuHelper = new PopupMenuHelper(getActivity(), getFragmentManager()) {
        private Song mSong;
        private int mSelectedPosition;
        private MusicPlaybackTrack mSelectedTrack;

        @Override
        public PopupMenuType onPreparePopupMenu(int position) {
            mSelectedPosition = position;
            mSong = mAdapter.getItem(mSelectedPosition);
            mSelectedTrack = MusicUtils.getTrack(mSelectedPosition);

            return PopupMenuType.Queue;
        }

        @Override
        protected long[] getIdList() {
            return new long[] { mSong.mSongId };
        }

        @Override
        protected long getSourceId() {
            if (mSelectedTrack == null) {
                return -1;
            }

            return mSelectedTrack.mSourceId;
        }

        @Override
        protected Config.IdType getSourceType() {
            if (mSelectedTrack == null) {
                return Config.IdType.NA;
            }

            return mSelectedTrack.mSourceType;
        }

        @Override
        protected String getArtistName() {
            return mSong.mArtistName;
        }

        @Override
        protected void onDeleteClicked() {
            DeleteDialog.newInstance(mSong.mSongName, new long[] { getId() }, null).show(getFragmentManager(),
                    "DeleteDialog");
        }

        @Override
        protected void playNext() {
            NowPlayingCursor queue = (NowPlayingCursor) QueueLoader.makeQueueCursor(getActivity());
            queue.removeItem(mSelectedPosition);
            queue.close();
            queue = null;
            MusicUtils.playNext(getIdList(), getSourceId(), getSourceType());
            refreshQueue();
        }

        @Override
        protected void removeFromQueue() {
            MusicUtils.removeTrackAtPosition(getId(), mSelectedPosition);
            refreshQueue();
        }

        @Override
        protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
            super.updateMenuIds(type, set);

            // Don't show more by artist if it is an unknown artist
            if (MediaStore.UNKNOWN_STRING.equals(mSong.mArtistName)) {
                set.remove(FragmentMenuItems.MORE_BY_ARTIST);
            }
        }
    };

    // Create the adapter
    mAdapter = new SongAdapter(getActivity(), R.layout.edit_queue_list_item, -1, Config.IdType.NA);
    mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() {
        @Override
        public void onPopupMenuClicked(View v, int position) {
            mPopupMenuHelper.showPopupMenu(v, position);
        }
    });
}

From source file:org.apache.pig.impl.logicalLayer.LOLoad.java

public RequiredFieldResponse pushProjection(RequiredFieldList requiredFieldList) throws FrontendException {
    RequiredFieldResponse response = new RequiredFieldResponse(false);
    if (mSchema == null)
        return response;

    if (requiredFieldList.getFields() == null)
        return response;

    if (requiredFieldList.getFields() == null) {
        return response;
    }// w  w w .ja  va2s .  c o m

    this.requiredFieldList = requiredFieldList;
    if (mLoadFunc instanceof LoadPushDown) {
        response = ((LoadPushDown) mLoadFunc).pushProjection(requiredFieldList);
    } else {
        // loadfunc does not support pushing projections
        response = new RequiredFieldResponse(false);
    }
    if (!response.getRequiredFieldResponse())
        return response;

    // Change LOLoad schema to reflect this pruning
    TreeSet<Integer> prunedIndexSet = new TreeSet<Integer>();
    for (int i = 0; i < mSchema.size(); i++)
        prunedIndexSet.add(i);

    for (int i = 0; i < requiredFieldList.getFields().size(); i++) {
        RequiredField requiredField = requiredFieldList.getFields().get(i);
        if (requiredField.getIndex() >= 0)
            prunedIndexSet.remove(requiredField.getIndex());
        else {

            try {
                int index = mSchema.getPosition(requiredField.getAlias());
                if (index > 0)
                    prunedIndexSet.remove(index);
            } catch (FrontendException e) {
                return new RequiredFieldResponse(false);
            }

        }
    }

    Integer index;
    while ((index = prunedIndexSet.pollLast()) != null)
        mSchema.getFields().remove(index.intValue());

    mIsProjectionMapComputed = false;
    getProjectionMap();
    return response;

}

From source file:uk.ac.horizon.ubihelper.service.LogManager.java

private synchronized void checkSubscriptions() {
    float period = getLogPeriod();
    String cns[] = getChannels();
    TreeSet<String> ecns = new TreeSet<String>();
    ecns.addAll(subscriptions.keySet());
    for (int i = 0; i < cns.length; i++) {
        String cn = cns[i];/*from   w  ww  . ja va  2 s . c om*/
        if (cn.length() == 0)
            continue;
        ecns.remove(cn);
        LogSubscription sub = subscriptions.get(cn);
        if (sub == null) {
            // add
            Log.d(TAG, "Start logging " + cn + " (update)");
            sub = new LogSubscription(this, cn);
            sub.updateConfiguration(period, period / 2, 0);
            channelManager.addSubscription(sub);
            subscriptions.put(cn, sub);
            channelManager.refreshChannel(cn);
        } else {
            // update
            if (Math.abs(sub.getPeriod() - period) > MIN_PERIOD_CHANGE) {
                Log.d(TAG, "Update period for " + cn + " (update)");
                sub.updateConfiguration(period, period / 2, 0);
                channelManager.refreshChannel(cn);
            }
        }
    }
    // remove?
    for (String cn : ecns) {
        Log.d(TAG, "Stop logging " + cn + " (update)");
        LogSubscription sub = subscriptions.remove(cn);
        if (sub != null)
            channelManager.removeSubscription(sub);
        channelManager.refreshChannel(cn);
    }
}

From source file:org.opendatakit.persistence.table.GrantedAuthorityHierarchyTable.java

public static final void assertGrantedAuthorityHierarchy(GrantedAuthority dominantGrant,
        Collection<String> desiredGrants, CallingContext cc) throws ODKDatastoreException {

    if (!GrantedAuthorityName.permissionsCanBeAssigned(dominantGrant.getAuthority())) {
        throw new IllegalArgumentException("Dominant grant must be permissions-assignable!");
    }/*  w  ww  .  j  a  v a  2 s.  c om*/

    Datastore ds = cc.getDatastore();
    User user = cc.getCurrentUser();

    boolean hasNotChanged = true;

    try {
        GrantedAuthorityHierarchyTable relation = GrantedAuthorityHierarchyTable.assertRelation(ds, user);

        TreeSet<String> groups = new TreeSet<String>();
        TreeSet<String> roles = new TreeSet<String>();
        for (String grant : desiredGrants) {
            if (!GrantedAuthorityName.permissionsCanBeAssigned(grant)) {
                roles.add(grant);
            } else {
                groups.add(grant);
            }
        }

        // get the hierarchy as currently defined for this group
        List<? extends CommonFieldsBase> groupsList;
        relation = GrantedAuthorityHierarchyTable.assertRelation(ds, user);
        Query query = ds.createQuery(relation, "GrantedAuthorityHierarchyTable.assertGrantedAuthorityHierarchy",
                user);
        query.addFilter(GrantedAuthorityHierarchyTable.DOMINATING_GRANTED_AUTHORITY, FilterOperation.EQUAL,
                dominantGrant.getAuthority());
        groupsList = query.executeQuery();

        // OK we have the groups and roles to establish for this dominantGrant.
        // AND we have the groupsList of groups and roles already established for dominantGrant.
        List<EntityKey> deleted = new ArrayList<EntityKey>();
        for (CommonFieldsBase b : groupsList) {
            GrantedAuthorityHierarchyTable t = (GrantedAuthorityHierarchyTable) b;
            String authority = t.getSubordinateGrantedAuthority().getAuthority();
            if (groups.contains(authority)) {
                groups.remove(authority);
            } else if (roles.contains(authority)) {
                roles.remove(authority);
            } else {
                deleted.add(t.getEntityKey());
            }
        }
        // we now have the list of groups and roles to insert, and the list of
        // existing records to delete...
        List<GrantedAuthorityHierarchyTable> added = new ArrayList<GrantedAuthorityHierarchyTable>();
        for (String group : groups) {
            GrantedAuthorityHierarchyTable t = ds.createEntityUsingRelation(relation, user);
            t.setDominatingGrantedAuthority(dominantGrant.getAuthority());
            t.setSubordinateGrantedAuthority(group);
            added.add(t);
        }

        for (String role : roles) {
            GrantedAuthorityHierarchyTable t = ds.createEntityUsingRelation(relation, user);
            t.setDominatingGrantedAuthority(dominantGrant.getAuthority());
            t.setSubordinateGrantedAuthority(role);
            added.add(t);
        }

        hasNotChanged = added.isEmpty() && deleted.isEmpty();

        // we now have the list of EntityKeys to delete, and the list of records to add -- do it.
        ds.putEntities(added, user);
        ds.deleteEntities(deleted, user);
    } finally {
        if (!hasNotChanged) {
            // finally, since we mucked with the group hierarchies, flag that
            // the cache of those hierarchies has changed.
            SecurityRevisionsTable.setLastRoleHierarchyRevisionDate(ds, user);
        }
    }
}

From source file:org.paxle.parser.impl.SubParserManager.java

@SuppressWarnings("unchecked")
public void removeSubParser(final ServiceReference ref) {
    final String[] mimeTypes = getMimeTypes(ref);
    if (mimeTypes == null)
        return;/* www .j a  v  a2  s  .c o  m*/
    for (String mimeType : mimeTypes) {
        mimeType = mimeType.trim();
        TreeSet<ServiceReference> refs = this.subParserList.get(mimeType);
        if (refs == null)
            continue;
        this.services.remove(keyFor(mimeType, ref));
        refs.remove(ref);
        this.logger.info(String.format("Parser for mimetypes '%s' was uninstalled.", mimeType));
    }
    try {
        final Dictionary props = config.getProperties();
        props.put(ENABLED_MIMETYPES, this.enabledServices.toArray(new String[this.enabledServices.size()]));
        config.update(props);
    } catch (IOException e) {
        logger.error("error updating configuration", e);
    }
}

From source file:pl.edu.icm.coansys.kwdextraction.langident.Profile.java

/**
 * Generates profile from a text.//from   www.j a v a2s.  com
 *
 * @param text Text to profile
 */
public Profile(final String txt) {
    final String text = txt.toLowerCase().replaceAll("[^\\p{L}']+", SPACE_STRING);
    final String[] words = text.split(SPACE_STRING);

    int processedWords = 0;
    int processedLetters = 0;
    final Map<String, Integer> grams = new HashMap<String, Integer>();
    for (final String word : words) {
        final int len = word.length();

        for (int n = 1; n <= MAX_GRAM - 1; n++) {
            if (len >= n) {
                addGram(grams, UNTERLINE_STRING + word.substring(0, n));
                addGram(grams, word.substring(len - n, len) + UNTERLINE_STRING);
            }
        }

        for (int n = 1; n <= MAX_GRAM; n++) {
            for (int i = 0; i < len - n + 1; i++) {
                addGram(grams, word.substring(i, i + n));
            }
        }
        processedWords += 1;
        processedLetters += len;
    }

    LOG.debug(PROCESSED_WORDS + processedWords + LETTERS + processedLetters);

    //        All the N-grams are in the grams map -- now we need
    //        to sort them and put first PROFILE_CUTOFF most valuable
    //        ones in the profile
    final TreeSet<TreeElement> ts = new TreeSet<TreeElement>();
    for (final Map.Entry<String, Integer> me : grams.entrySet()) {
        ts.add(new TreeElement(me.getKey(), me.getValue().intValue()));
    }

    int newSize = grams.entrySet().size();
    if (newSize > PROFILE_CUTOFF) {
        newSize = PROFILE_CUTOFF;
    }

    data = new ArrayList<String>(newSize);
    hash = new HashMap<String, Integer>(newSize);
    for (int i = 0; i < newSize; i++) {
        final TreeElement te = ts.first();
        data.add(te.s);
        hash.put(data.get(i), Integer.valueOf(i));
        ts.remove(te);
    }
}

From source file:edu.fullerton.ldvw.ImageHistory.java

/**
 * Add a table of buttons/links and info to control display and deletion
 *
 * @param imgCnt total number of records in selection
 *//*www  .j av  a2s.  co m*/
private PageItemList getNavBar(int imgCnt, boolean isBottom, String frmName)
        throws WebUtilException, LdvTableException, SQLException {
    PageItemList ret = new PageItemList();
    PageTable navBar = new PageTable();
    PageTableRow cmds = new PageTableRow();

    // add next/prev buttons if applicable
    PageFormButton prevBtn = new PageFormButton("submitAct", "<", "Prev");
    prevBtn.setEnabled(strt > 0);
    cmds.add(prevBtn);

    String botSuffix = isBottom ? "2" : "";

    int curPage = strt / cnt + 1;
    int nPage = (imgCnt + cnt - 1) / cnt;
    PageItemList pageSel = new PageItemList();
    pageSel.add("Page: ");
    PageFormText pageNum = new PageFormText("pageNum" + botSuffix, String.format("%1$,d", curPage));
    pageNum.setSize(3);
    pageNum.setMaxLen(6);
    pageNum.addEvent("onchange", "historySubmit('Go" + botSuffix + "', this);");
    pageSel.add(pageNum);
    pageSel.add(String.format(" of %d ", nPage));
    cmds.add(pageSel);

    PageFormButton nextBtn = new PageFormButton("submitAct", ">", "Next");
    nextBtn.setEnabled(curPage < nPage);
    cmds.add(nextBtn);

    int stop = Math.min(strt + cnt, imgCnt);
    String showing = String.format("Showing %1$d-%2$d for:", strt + 1, stop);
    cmds.add(showing);

    // add selection by user
    String cn = vuser.getCn();

    TreeMap<String, Integer> ucounts = imgTbl.getCountByUser();
    String[] usrs = new String[ucounts.size() + 1];
    String sel = "All";
    usrs[0] = "All";
    int i = 1;
    for (Map.Entry<String, Integer> entry : ucounts.entrySet()) {
        String u = entry.getKey();
        Integer cnts = entry.getValue();
        String opt = String.format("%1$s (%2$d)", u, cnts);
        if (userWanted.equalsIgnoreCase(u)) {
            sel = opt;
        }
        usrs[i] = opt;
        i++;
    }
    if (!isBottom) {
        // allow them to select another user (or all)
        PageFormSelect usrSel = new PageFormSelect("usrSel", usrs);
        usrSel.setSelected(sel);
        usrSel.addEvent("onchange", "this.form.submit()");
        PageItemList owner = new PageItemList();
        owner.add(new PageItemString("Owner:&nbsp;", false));
        owner.add(usrSel);
        cmds.add(owner);

        // Group selector
        TreeSet<String> groups = imgGrpTbl.getGroups(userWanted);
        if (!groups.isEmpty()) {
            PageItemList grpPIL = new PageItemList();
            grpPIL.add(new PageItemString("Group:&nbsp;", false));
            groups.add("All");
            PageFormSelect grpSel = new PageFormSelect("group");
            grpSel.add(groups);
            String curGroup = request.getParameter("group");
            if (curGroup != null && !curGroup.isEmpty() && groups.contains(curGroup)) {
                grpSel.setSelected(curGroup);
            } else {
                grpSel.setSelected("All");
            }
            grpSel.addEvent("onchange", "document." + frmName + ".submit()");
            grpPIL.add(grpSel);
            cmds.add(grpPIL);
        }
    }
    cmds.setClassAll("noborder");
    navBar.addRow(cmds);
    ret.add(navBar);

    if (!isBottom) {
        // New table because this one has fewer columns and we want to hide it by default
        navBar = new PageTable();
        navBar.setClassName("hidable");
        navBar.addStyle("display", "none");

        // allow them to change image size
        PageTableRow cmd2 = new PageTableRow();
        String[] sizes = { "original", "small", "med" };
        PageFormSelect sizeSel = new PageFormSelect("size", sizes);
        String curSize = request.getParameter("size");
        if (curSize != null && !curSize.isEmpty() && ArrayUtils.contains(sizes, curSize)) {
            sizeSel.setSelected(curSize);
        }
        sizeSel.addEvent("onchange", "document." + frmName + ".submit()");
        PageItemString lbl;
        lbl = new PageItemString("Size:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        cmd2.add(lbl);
        PageTableColumn col;
        col = new PageTableColumn(sizeSel);
        cmd2.add(col);
        cmd2.add();
        cmd2.add();
        cmd2.setClassAll("noborder");
        navBar.addRow(cmd2);

        cmd2 = new PageTableRow();
        lbl = new PageItemString("Selections:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        cmd2.add(lbl);

        PageFormButton selAll = new PageFormButton("selAll", "Select all", "selall");
        selAll.setType("button");
        selAll.addEvent("onclick", "setChkBoxByClass('selBox',true)");
        cmd2.add(selAll);

        PageFormButton clrAll = new PageFormButton("selAll", "Clear all", "clrall");
        clrAll.setType("button");
        clrAll.addEvent("onclick", "setChkBoxByClass('selBox', false)");
        cmd2.add(clrAll);
        cmd2.add();
        cmd2.setClassAll("noborder");
        navBar.addRow(cmd2);

        if (userWanted.equalsIgnoreCase(vuser.getCn()) || vuser.isAdmin()) {
            cmd2 = new PageTableRow();
            lbl = new PageItemString("Delete images:&nbsp;", false);
            lbl.setAlign(PageItem.Alignment.RIGHT);
            cmd2.add(lbl);

            col = new PageTableColumn(new PageFormSubmit("submitAct", "Delete Selected"));
            cmd2.add(col);
            cmd2.add();
            cmd2.add();
            cmd2.setClassAll("noborder");
            navBar.addRow(cmd2);
        }

        PageTableRow grpRow = new PageTableRow();
        lbl = new PageItemString("My groups:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        grpRow.add(lbl);

        TreeSet<String> myGroup = imgGrpTbl.getGroups(curUser);
        if (!myGroup.contains("Favorites")) {
            myGroup.add("Favorites");
        }
        myGroup.remove("Last result");
        PageFormSelect grpSel = new PageFormSelect("op_group");
        grpSel.add(myGroup);
        String curGroup = request.getParameter("groupSel");
        if (curGroup != null && !curGroup.isEmpty() && myGroup.contains(curGroup)) {
            grpSel.setSelected(curGroup);
        } else {
            grpSel.setSelected("Favorites");
        }
        grpRow.add(grpSel);

        grpRow.add(new PageFormSubmit("submitAct", "Add to grp"));
        grpRow.add(new PageFormSubmit("submitAct", "Del from grp"));
        grpRow.setClassAll("noborder");
        navBar.addRow(grpRow);
        grpRow = new PageTableRow();
        lbl = new PageItemString("New Group:&nbsp;", false);
        lbl.setAlign(PageItem.Alignment.RIGHT);
        grpRow.add(lbl);
        PageFormText grpNameTxt = new PageFormText("newGrpName", "<new group name>");
        grpNameTxt.addEvent("onfocus", "if(this.value == '<new group name>'){ this.value = ''; }");
        grpNameTxt.addEvent("onblur", "if(this.value == ''){ this.value = '<new group name>'; }");
        grpRow.add(grpNameTxt);
        PageFormSubmit newGrpBtn = new PageFormSubmit("submitAct", "New grp");
        grpRow.add(newGrpBtn);
        grpRow.add();
        grpRow.setClassAll("noborder");
        navBar.addRow(grpRow);
        ret.add(navBar);

        PageItemString optBtn = new PageItemString("+More options");
        optBtn.addEvent("onclick", "showByClass('hidable',this)");
        optBtn.setClassName("showCmd");
        ret.addBlankLines(1);
        ret.add(optBtn);
    }
    vpage.includeJS("showByClass.js");
    return ret;
}