@Override public void appendInternalLink( String topic, String hashSection, String topicDescription, String cssClass, boolean parseRecursive) { try { String virtualWiki = fParserInput.getVirtualWiki(); WikiLink wikiLink; if (hashSection != null) { wikiLink = LinkUtil.parseWikiLink(virtualWiki, topic + "#" + hashSection); } else { wikiLink = LinkUtil.parseWikiLink(virtualWiki, topic); } String destination = wikiLink.getDestination(); String section = wikiLink.getSection(); String query = wikiLink.getQuery(); String href = buildTopicUrlNoEdit(fContextPath, virtualWiki, destination, section, query); String style = ""; if (StringUtils.isBlank(topic) && !StringUtils.isBlank(section)) { // do not check existence for section links } else { String articleName = topic.replace('_', ' '); if (LinkUtil.isExistingArticle(virtualWiki, articleName) == null) { style = "edit"; href = LinkUtil.buildEditLinkUrl(fContextPath, virtualWiki, topic, query, -1); } } WPATag aTagNode = new WPATag(); aTagNode.addAttribute("href", href, true); aTagNode.addAttribute("class", style, true); aTagNode.addObjectAttribute("wikilink", topic); pushNode(aTagNode); if (parseRecursive) { WikipediaParser.parseRecursive(topicDescription.trim(), this, false, true); } else { aTagNode.addChild(new ContentToken(topicDescription)); } popNode(); } catch (DataAccessException e1) { e1.printStackTrace(); append(new ContentToken(topicDescription)); } }
private StringBuffer nextPage( Pagination pagination, String baseUrl, int count, boolean previous) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); StringBuffer output = new StringBuffer(); try { Object[] objects = new Object[1]; objects[0] = new Integer(pagination.getNumResults()); if (pagination.getOffset() == 0 && previous) { output.append( Utilities.formatMessage("common.pagination.previous", request.getLocale(), objects)); return output; } if (pagination.getNumResults() != count && !previous) { output.append( Utilities.formatMessage("common.pagination.next", request.getLocale(), objects)); return output; } output.append("<a href=\""); String virtualWiki = Utilities.getVirtualWikiFromRequest(request); WikiLink wikiLink = LinkUtil.parseWikiLink(baseUrl); int offset = pagination.getOffset() + pagination.getNumResults(); if (previous) { offset = pagination.getOffset() - pagination.getNumResults(); if (offset < 0) offset = 0; } String query = LinkUtil.appendQueryParam( wikiLink.getQuery(), "num", new Integer(pagination.getNumResults()).toString()); query += "&offset=" + offset; wikiLink.setQuery(query); output.append(LinkUtil.buildInternalLinkUrl(request.getContextPath(), virtualWiki, wikiLink)); output.append("\">"); if (previous) { output.append( Utilities.formatMessage("common.pagination.previous", request.getLocale(), objects)); } else { output.append( Utilities.formatMessage("common.pagination.next", request.getLocale(), objects)); } output.append("</a>"); } catch (Exception e) { logger.warning("Failure while building pagination element", e); } return output; }
private StringBuffer buildOption(int num, Pagination pagination, String baseUrl) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); StringBuffer output = new StringBuffer(); try { if (num == pagination.getNumResults()) { output.append(num); return output; } output.append("<a href=\""); String virtualWiki = Utilities.getVirtualWikiFromRequest(request); WikiLink wikiLink = LinkUtil.parseWikiLink(baseUrl); String query = LinkUtil.appendQueryParam(wikiLink.getQuery(), "num", new Integer(num).toString()); query += "&offset=0"; wikiLink.setQuery(query); output.append(LinkUtil.buildInternalLinkUrl(request.getContextPath(), virtualWiki, wikiLink)); output.append("\">"); output.append(num); output.append("</a>"); } catch (Exception e) { logger.warning("Failure while building pagination element", e); } return output; }