private HTMLNode getSetTrustCell(Identity trustee) { HTMLNode cell = new HTMLNode("td"); // There can be multiple checkboxes with the same name in HTML, however Fred does not support // it... cell.addChild( new HTMLNode( "input", new String[] {"type", "name", "value"}, new String[] {"checkbox", "SetTrustOf" + trustee.getID(), trustee.getID()})); return cell; }
private HTMLNode getReceivedTrustCell(OwnIdentity truster, Identity trustee) throws DuplicateTrustException { String trustValue = ""; String trustComment = ""; Trust trust; try { trust = mWebOfTrust.getTrust(truster, trustee); trustValue = String.valueOf(trust.getValue()); trustComment = trust.getComment(); } catch (NotTrustedException e) { } HTMLNode cell = new HTMLNode("td"); if (trustValue.length() > 0) { cell.addAttribute( "style", "background-color:" + KnownIdentitiesPage.getTrustColor(Integer.parseInt(trustValue)) + ";"); } // Trust value input field cell.addChild( "input", new String[] {"type", "name", "size", "maxlength", "value"}, new String[] {"text", "Value" + trustee.getID(), "4", "4", trustValue}); // Trust comment input field cell.addChild( "input", new String[] {"type", "name", "size", "maxlength", "value"}, new String[] { "text", "Comment" + trustee.getID(), "50", Integer.toString(Trust.MAX_TRUST_COMMENT_LENGTH), trustComment }); return cell; }
/** Makes the list of Identities known by the tree owner. */ private void makeKnownIdentitiesList() { String nickFilter = mRequest.getPartAsStringFailsafe("nickfilter", 100).trim(); String sortBy = mRequest.isPartSet("sortby") ? mRequest.getPartAsStringFailsafe("sortby", 100).trim() : "Nickname"; String sortType = mRequest.isPartSet("sorttype") ? mRequest.getPartAsStringFailsafe("sorttype", 100).trim() : "Ascending"; int page = mRequest.isPartSet("page") ? Integer.parseInt( mRequest.getPartAsStringFailsafe( "page", Integer.toString(Integer.MAX_VALUE).length())) : 0; page = page - 1; // What we get passed is the user-friendly page number counting from 1, not 0. page = Math.max(0, page); // In case no page part was set, it would be -1 HTMLNode knownIdentitiesBox = addContentBox(l10n().getString("KnownIdentitiesPage.KnownIdentities.Header")); knownIdentitiesBox = pr.addFormChild(knownIdentitiesBox, uri.toString(), "Filters").addChild("p"); knownIdentitiesBox.addChild( "input", new String[] {"type", "name", "value"}, new String[] {"hidden", "page", Integer.toString(page + 1)}); InfoboxNode filtersBoxNode = getContentBox(l10n().getString("KnownIdentitiesPage.FiltersAndSorting.Header")); { // Filters box knownIdentitiesBox.addChild(filtersBoxNode.outer); HTMLNode filtersBox = filtersBoxNode.content; filtersBox.addChild( "#", l10n().getString("KnownIdentitiesPage.FiltersAndSorting.ShowOnlyNicksContaining") + " : "); filtersBox.addChild( "input", new String[] {"type", "size", "name", "value"}, new String[] {"text", "15", "nickfilter", nickFilter}); filtersBox.addChild( "#", " " + l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy") + " : "); HTMLNode option = filtersBox.addChild( "select", new String[] {"name", "id"}, new String[] {"sortby", "sortby"}); TreeMap<String, String> options = new TreeMap<String, String>(); options.put( SortBy.Edition.toString(), l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.Edition")); options.put( SortBy.Nickname.toString(), l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.Nickname")); options.put( SortBy.Score.toString(), l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.Score")); options.put( SortBy.LocalTrust.toString(), l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.LocalTrust")); for (String e : options.keySet()) { HTMLNode newOption = option.addChild("option", "value", e, options.get(e)); if (e.equals(sortBy)) { newOption.addAttribute("selected", "selected"); } } option = filtersBox.addChild( "select", new String[] {"name", "id"}, new String[] {"sorttype", "sorttype"}); options = new TreeMap<String, String>(); options.put( "Ascending", l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.Ascending")); options.put( "Descending", l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.Descending")); for (String e : options.keySet()) { HTMLNode newOption = option.addChild("option", "value", e, options.get(e)); if (e.equals(sortType)) { newOption.addAttribute("selected", "selected"); } } filtersBox.addChild( "input", new String[] {"type", "value"}, new String[] { "submit", l10n().getString("KnownIdentitiesPage.FiltersAndSorting.SortIdentitiesBy.SubmitButton") }); } // Display the list of known identities HTMLNode identitiesTable = knownIdentitiesBox.addChild("table", "border", "0"); identitiesTable.addChild(getKnownIdentitiesListTableHeader()); WebOfTrust.SortOrder sortInstruction = WebOfTrust.SortOrder.valueOf("By" + sortBy + sortType); synchronized (mWebOfTrust) { long currentTime = CurrentTimeUTC.getInMillis(); int indexOfFirstIdentity = page * IDENTITIES_PER_PAGE; // Re-query it instead of using mLoggedInOwnIdentity because mLoggedInOwnIdentity is a // clone() and thus will not work with database queries on the WebOfTrust. // TODO: Performance: This can be removed once the TODO at // WebPageImpl.getLoggedInOwnIdentityFromHTTPSession() of not cloning the // OwnIdentity has been been resolved. final OwnIdentity ownId; try { ownId = mWebOfTrust.getOwnIdentityByID(mLoggedInOwnIdentity.getID()); } catch (UnknownIdentityException e) { new ErrorPage(mToadlet, mRequest, mContext, e).addToPage(this); return; } ObjectSet<Identity> allIdentities = mWebOfTrust.getAllIdentitiesFilteredAndSorted(ownId, nickFilter, sortInstruction); Iterator<Identity> identities; try { identities = allIdentities.listIterator(indexOfFirstIdentity); } catch (IndexOutOfBoundsException e) { // The user supplied a higher page index than there are pages. This can happen when the // user changes the search filters while not being on the first page. // We fall back to displaying the last page. // Notice: We intentionally do not prevent listIterator() from throwing by checking // the index for validity before calling listIterator(). This is because we would need // to call allIdentities.size() to check the index. This would force the database to // compute the full result set even though we only need the results up to the current // page if we are not on the last page. page = getPageCount(allIdentities.size()) - 1; indexOfFirstIdentity = page * IDENTITIES_PER_PAGE; // TODO: Performance: Don't re-query this from the database once the issue which caused // this workaround is fixed: https://bugs.freenetproject.org/view.php?id=6646 allIdentities = mWebOfTrust.getAllIdentitiesFilteredAndSorted(ownId, nickFilter, sortInstruction); identities = allIdentities.listIterator(indexOfFirstIdentity); } for (int displayed = 0; displayed < IDENTITIES_PER_PAGE && identities.hasNext(); ++displayed) { final Identity id = identities.next(); if (id == ownId) continue; HTMLNode row = identitiesTable.addChild("tr"); // NickName HTMLNode nameLink = row.addChild( "td", new String[] {"title", "style"}, new String[] {id.getRequestURI().toString(), "cursor: help;"}) .addChild("a", "href", IdentityPage.getURI(mWebInterface, id.getID()).toString()); String nickName = id.getNickname(); if (nickName != null) { nameLink.addChild("#", nickName + "@" + id.getID().substring(0, 5) + "..."); } else nameLink .addChild("span", "class", "alert-error") .addChild( "#", l10n() .getString( "KnownIdentitiesPage.KnownIdentities.Table.NicknameNotDownloadedYet")); // Added date row.addChild( "td", CommonWebUtils.formatTimeDelta(currentTime - id.getAddedDate().getTime(), l10n())); // Last fetched date Date lastFetched = id.getLastFetchedDate(); if (!lastFetched.equals(new Date(0))) row.addChild( "td", CommonWebUtils.formatTimeDelta(currentTime - lastFetched.getTime(), l10n())); else row.addChild("td", l10n().getString("Common.Never")); // Publish TrustList row.addChild( "td", new String[] {"align"}, new String[] {"center"}, id.doesPublishTrustList() ? l10n().getString("Common.Yes") : l10n().getString("Common.No")); // Score try { final Score score = mWebOfTrust.getScore(ownId, id); final int scoreValue = score.getScore(); final int rank = score.getRank(); row.addChild( "td", new String[] {"align", "style"}, new String[] { "center", "background-color:" + KnownIdentitiesPage.getTrustColor(scoreValue) + ";" }, Integer.toString(scoreValue) + " (" + (rank != Integer.MAX_VALUE ? rank : l10n().getString("KnownIdentitiesPage.KnownIdentities.Table.InfiniteRank")) + ")"); } catch (NotInTrustTreeException e) { // This only happen with identities added manually by the user row.addChild("td", l10n().getString("KnownIdentitiesPage.KnownIdentities.Table.NoScore")); } // Own Trust row.addChild(getReceivedTrustCell(ownId, id)); // Checkbox row.addChild(getSetTrustCell(id)); // Nb Trusters // TODO: Do a direct link to the received-trusts part of the linked page HTMLNode trustersCell = row.addChild("td", new String[] {"align"}, new String[] {"center"}); trustersCell.addChild( new HTMLNode( "a", "href", IdentityPage.getURI(mWebInterface, id.getID()).toString(), Long.toString(mWebOfTrust.getReceivedTrusts(id).size()))); // Nb Trustees // TODO: Do a direct link to the given-trusts part of the linked page HTMLNode trusteesCell = row.addChild("td", new String[] {"align"}, new String[] {"center"}); trusteesCell.addChild( new HTMLNode( "a", "href", IdentityPage.getURI(mWebInterface, id.getID()).toString(), Long.toString(mWebOfTrust.getGivenTrusts(id).size()))); // TODO: Show in advanced mode only once someone finally fixes the "Switch to advanced mode" // link on FProxy to work on ALL pages. row.addChild("td", "align", "center", Long.toString(id.getEdition())); row.addChild("td", "align", "center", Long.toString(id.getLatestEditionHint())); } identitiesTable.addChild(getKnownIdentitiesListTableHeader()); knownIdentitiesBox.addChild(getKnownIdentitiesListPageLinks(page, allIdentities.size())); } }