⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 relativeuridecorator.java

📁 pebble-blog 博客源码博客源码博客源码
💻 JAVA
字号:
package net.sourceforge.pebble.decorator;import net.sourceforge.pebble.domain.Attachment;import net.sourceforge.pebble.domain.BlogEntry;import net.sourceforge.pebble.domain.StaticPage;import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;/** * Translates relative URIs in blog entries and static pages into absolute URLs. *  * @author Simon Brown */public class RelativeUriDecorator extends ContentDecoratorSupport {  /**   * Decorates the specified blog entry.   *   * @param context   the context in which the decoration is running   * @param blogEntry the blog entry to be decorated   */  public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {    blogEntry.setBody(replaceCommonUris(blogEntry.getBody()));    blogEntry.setExcerpt(replaceCommonUris(blogEntry.getExcerpt()));    Attachment attachment = blogEntry.getAttachment();    if (attachment != null) {      String attachmentUrl = attachment.getUrl();      if (attachmentUrl.startsWith("./")) {        attachment.setUrl(getBlog().getUrl() + attachmentUrl.substring(2));      }    }  }  /**   * Decorates the specified static page.   *   * @param context    the context in which the decoration is running   * @param staticPage the static page to be decorated   */  public void decorate(ContentDecoratorContext context, StaticPage staticPage) {    staticPage.setBody(replaceCommonUris(staticPage.getBody()));  }  /**   * Helper method to replace common relative URIs with their absolute values.   *   * @param s   the String containing relative URIs   * @return    a new String containing absolute URLs   */  private String replaceCommonUris(String s) {    s = s.replaceAll("href=\"\\./", "href=\"" + getBlog().getUrl());    s = s.replaceAll("href='\\./", "href='" + getBlog().getUrl());    s = s.replaceAll("src=\"\\./", "src=\"" + getBlog().getUrl());    s = s.replaceAll("src='\\./", "src='" + getBlog().getUrl());    return s;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -