📄 topictagplugin.java
字号:
} /** * Render from a string without entry data context. Because we require the context of the website in order to do the * bookmark searches. This implementation can only return the input string. * * @param str String to which plugin should be applied. * @return the input value. * @see PagePlugin#render(String) */ public String render(String str) { return str; } /** * Returns the human-friendly name of this Plugin. This is what users will see. * * @return The human-friendly name of this Plugin. */ public String getName() { // TODO: i18n return "Topic Tags"; } /** * Briefly describes the function of the Plugin. May contain HTML. * * @return A brief description of the Plugin. */ public String getDescription() { // TODO: i18n return "Expands topic tags for <a href=\\'http://www.technorati.com\\'>Technorati</a> and similar sites. " + "Topic tags are of the form <code>topic:{topicbookmark}[tag]</code>, where <code>topicbookmark</code> " + "is the name of a bookmark whose URL will be used for the site name in the topic tag. " + "If <code>{topicbookmark}</code> is omitted the plugin will use the URL of the <code>Default Topic Site</code> " + "bookmark, if that is defined, otherwise http://www.technorati.com."; } /** * Helper to generate the link from the link format and values of the site and tag. * * @param fmt link format. This should have positional parameters {0} representing site with terminal /, {1} for * url-encoded-tag, and {2} for visible tag text. * @param site base portion of the URL * @param tag tag value * @return the generated link as a string */ protected String generateLink(MessageFormat fmt, String site, String tag) { // Allocate initial capacity of buffer of approximately the right length. StringBuffer sb = new StringBuffer(site.length() + tag.length() + getLinkFormatString().length()); fmt.format(new Object[]{site, urlEncode(tag), tag}, sb, new FieldPosition(0)); return sb.toString(); } /** * Resolve the bookmark name and return the URL from it. If the bookmark can't be found, return null * * @param bookmarkName name of the bookmark * @return String form of the URL from the bookmark by that name from any of the user's folders, or null if not * found. */ protected String getBookmarkSite(String bookmarkName) { BookmarkData bookmark = (BookmarkData) getUserBookmarks().get(bookmarkName); return bookmark == null ? null : bookmark.getUrl(); } /** * Build the bookmark map. * * @return map of the user's bookmarks (type BookmarkData), keyed by name (type String). */ protected Map buildBookmarkMap(WebsiteData website) throws RollerException { Map bookmarkMap = new HashMap(); if (website == null) { mLogger.debug("Init called without website. Skipping bookmark initialization."); } else { BookmarkManager bMgr = RollerFactory.getRoller().getBookmarkManager(); List bookmarks = bMgr.retrieveBookmarks(bMgr.getRootFolder(website), true); for (Iterator i = bookmarks.iterator(); i.hasNext();) { BookmarkData b = (BookmarkData) i.next(); bookmarkMap.put(b.getName(), b); } } return bookmarkMap; } // Sets up properties. For better and worse, doesn't use reflection private void initializeProperties() { setDefaultTopicBookmarkName(getSetting("defaultTopicBookmarkName", getDefaultTopicBookmarkName())); setDefaultTopicSite(getSetting("defaultTopicSite", getDefaultTopicSite())); setTagRegexWithBookmark(getSetting("tagRegexWithBookmark", getTagRegexWithBookmark())); setTagRegexWithoutBookmark(getSetting("tagRegexWithoutBookmark", getTagRegexWithoutBookmark())); setLinkFormatString(getSetting("linkFormatString", getLinkFormatString())); } private static final String thisClassnameDot = TopicTagPlugin.class.getName() + "."; private String getSetting(String propName, String defaultValue) { String fullPropName = thisClassnameDot + propName; String val = (String) RollerConfig.getProperty(fullPropName); return (val != null) ? val : defaultValue; } // Private helper to URL encode the tag text. private String urlEncode(String text) { // URL encode the searchtext try { return URLEncoder.encode(text, "UTF-8"); } catch (UnsupportedEncodingException uex) { // Should never actually occur for UTF-8. If it does, we barf bitterly. throw new RuntimeException(uex); } } // Property getters and setters public String getDefaultTopicSite() { return defaultTopicSite; } public void setDefaultTopicSite(String defaultTopicSite) { this.defaultTopicSite = defaultTopicSite; } public String getTagRegexWithBookmark() { return tagRegexWithBookmark; } public void setTagRegexWithBookmark(String tagRegexWithBookmark) { this.tagRegexWithBookmark = tagRegexWithBookmark; } public String getTagRegexWithoutBookmark() { return tagRegexWithoutBookmark; } public void setTagRegexWithoutBookmark(String tagRegexWithoutBookmark) { this.tagRegexWithoutBookmark = tagRegexWithoutBookmark; } public String getLinkFormatString() { return linkFormatString; } public void setLinkFormatString(String linkFormatString) { this.linkFormatString = linkFormatString; } public MessageFormat getLinkFormat() { return linkFormat; } public void setLinkFormat(MessageFormat linkFormat) { this.linkFormat = linkFormat; } public Pattern getTagPatternWithBookmark() { return tagPatternWithBookmark; } public void setTagPatternWithBookmark(Pattern tagPatternWithBookmark) { this.tagPatternWithBookmark = tagPatternWithBookmark; } public Pattern getTagPatternWithoutBookmark() { return tagPatternWithoutBookmark; } public void setTagPatternWithoutBookmark(Pattern tagPatternWithoutBookmark) { this.tagPatternWithoutBookmark = tagPatternWithoutBookmark; } public String getDefaultTopicBookmarkName() { return defaultTopicBookmarkName; } public void setDefaultTopicBookmarkName(String defaultTopicBookmarkName) { this.defaultTopicBookmarkName = defaultTopicBookmarkName; } public Map getUserBookmarks() { return userBookmarks; } public void setUserBookmarks(Map userBookmarks) { this.userBookmarks = userBookmarks; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -