📄 blog.java
字号:
return defaultProperties; } /** * Gets the ID of this blog. * * @return the ID as a String */ public String getId() { return this.id; } /** * Sets the ID of this blog. * * @param id the ID as a String */ public void setId(String id) { this.id = id; } /** * Gets the URL where this blog is deployed. * * @return a URL as a String */ public String getUrl() { Configuration config = PebbleContext.getInstance().getConfiguration(); String url = config.getUrl(); if (url == null || url.length() == 0) { return ""; } else if (BlogManager.getInstance().isMultiBlog()) { if (config.isVirtualHostingEnabled()) { return url.substring(0, url.indexOf("://")+3) + getId() + "." + url.substring(url.indexOf("://")+3); } else { return url + getId() + "/"; } } else { return url; } } /** * Gets the relative URL where this blog is deployed. * * @return a URL as a String */ public String getRelativeUrl() { if (BlogManager.getInstance().isMultiBlog()) { return "/" + getId() + "/"; } else { return "/"; } } /** * Gets the about description of this blog. * * @return a String */ public String getAbout() { return properties.getProperty(ABOUT_KEY); } /** * Gets the home page to be used for this blog. * * @return a String */ public String getHomePage() { return properties.getProperty(HOME_PAGE_KEY); } /** * Gets the e-mail address of the blog owner. * * @return the e-mail address */ public String getEmail() { return properties.getProperty(EMAIL_KEY); } /** * Gets a Collection of e-mail addresses. * * @return a Collection of String instances */ public Collection getEmailAddresses() { return Arrays.asList(getEmail().split(",")); } /** * Gets the first of multiple e-mail addresses. * * @return the firt e-mail address as a String */ public String getFirstEmailAddress() { Collection emailAddresses = getEmailAddresses(); if (emailAddresses != null && !emailAddresses.isEmpty()) { return (String)emailAddresses.iterator().next(); } else { return ""; } } /** * Gets a comma separated list of the users that are blog owners * for this blog. * * @return a String containng a comma separated list of user names */ public String getBlogOwnersAsString() { return properties.getProperty(BLOG_OWNERS_KEY); } /** * Gets a list of the users that are blog owners for this blog. * * @return a String containng a comma separated list of user names */ public List<String> getBlogOwners() { String commaSeparatedUsers = getBlogOwnersAsString(); List<String> users = new LinkedList<String>(); if (commaSeparatedUsers != null) { StringTokenizer tok = new StringTokenizer(commaSeparatedUsers, ","); while (tok.hasMoreTokens()) { users.add(tok.nextToken().trim()); } } return users; } /** * Gets a comma separated list of the users that are blog publishers * for this blog. * * @return a String containng a comma separated list of user names */ public String getBlogPublishersAsString() { return properties.getProperty(BLOG_PUBLISHERS_KEY); } /** * Gets a list of the users that are blog publishers for this blog. * * @return a String containng a comma separated list of user names */ public List<String> getBlogPublishers() { String commaSeparatedUsers = getBlogPublishersAsString(); List<String> users = new LinkedList<String>(); if (commaSeparatedUsers != null) { StringTokenizer tok = new StringTokenizer(commaSeparatedUsers, ","); while (tok.hasMoreTokens()) { users.add(tok.nextToken().trim()); } } return users; } /** * Gets a comma separated list of the users that are blog contributors * for this blog. * * @return a String containng a comma separated list of user names */ public String getBlogContributorsAsString() { return properties.getProperty(BLOG_CONTRIBUTORS_KEY); } /** * Gets a list of the users that are blog contributors for this blog. * * @return a String containng a comma separated list of user names */ public List<String> getBlogContributors() { String commaSeparatedUsers = getBlogContributorsAsString(); List<String> users = new LinkedList<String>(); if (commaSeparatedUsers != null) { StringTokenizer tok = new StringTokenizer(commaSeparatedUsers, ","); while (tok.hasMoreTokens()) { users.add(tok.nextToken().trim()); } } return users; } /** * Gets a comma separated list of the users that are blog readers * for this blog. * * @return a String containng a comma separated list of user names */ public String getBlogReadersAsString() { return properties.getProperty(BLOG_READERS_KEY); } /** * Gets a list of the users that are blog readers for this blog. * * @return a String containng a comma separated list of user names */ public List<String> getBlogReaders() { String commaSeparatedUsers = getBlogReadersAsString(); List<String> users = new LinkedList<String>(); if (commaSeparatedUsers != null) { StringTokenizer tok = new StringTokenizer(commaSeparatedUsers, ","); while (tok.hasMoreTokens()) { users.add(tok.nextToken().trim()); } } return users; } /** * Gets the name of the Lucene analyzer to use. * * @return a fully qualified class name */ public String getLuceneAnalyzer() { return properties.getProperty(LUCENE_ANALYZER_KEY); } /** * Gets the name of the logger in use. * * @return a fully qualified class name */ public String getLoggerName() { return properties.getProperty(LOGGER_KEY); } /** * Gets a Collection containing the names of users that are blog owners * for this blog. * * @return a Collection containng user names as Strings */ public Collection getUsersInRole(String roleName) { List<String> users = new LinkedList<String>(); if (roleName.equals(Constants.BLOG_OWNER_ROLE)) { users = getBlogOwners(); } else if (roleName.equals(Constants.BLOG_PUBLISHER_ROLE)) { users = getBlogPublishers(); } else if (roleName.equals(Constants.BLOG_CONTRIBUTOR_ROLE)) { users = getBlogContributors(); } else if (roleName.equals(Constants.BLOG_READER_ROLE)) { users = getBlogReaders(); } return users; } /** * Determines whether the specified user is in the specified role. * * @param roleName the name of the role * @param user the name of the user * @return true if the user is a member of the role or the list of users * is empty, false otherwise */ public boolean isUserInRole(String roleName, String user) { Collection users = getUsersInRole(roleName); if (users.isEmpty() || users.contains(user)) { return true; } return false; } /** * Gets the Year instance for the specified year. * * @param year the year as an int (e.g. 2003) * @return a Year instance */ public Year getBlogForYear(int year) { Iterator it = years.iterator(); Year y; while (it.hasNext()) { y = (Year)it.next(); if (y.getYear() == year) { return y; } } y = new Year(this, year); years.add(y); Collections.sort(years); return y; } /** * Gets the Year instance representing this year. * * @return a Year instance for this year */ public Year getBlogForThisYear() { Calendar cal = getCalendar(); return getBlogForYear(cal.get(Calendar.YEAR)); } /** * Gets all Years managed by this root blog. * * @return a Collection of Year instances */ public List getYears() { return years; } /** * Gets all Years managed by this root blog, in reverse order. * * @return a Collection of Year instances */ public List<Year> getArchives() { List<Year> list = new LinkedList<Year>(); int firstYear = getBlogForFirstMonth().getYear().getYear(); int thisYear = getBlogForThisYear().getYear(); // only add years that are in range Calendar cal = getCalendar(); for (Year year : years) { if (year.getYear() >= firstYear && year.getYear() <= thisYear) { list.add(year); } } Collections.reverse(list); return list; } /** * Gets the Month instance representing the first month that * contains blog entries. * * @return a Month instance */ public Month getBlogForFirstMonth() { if (getBlogEntryIndex() == null) { return getBlogForThisMonth(); } List<String> blogEntryIds = getBlogEntryIndex().getBlogEntries(); if (blogEntryIds == null || blogEntryIds.isEmpty()) { return getBlogForThisMonth(); } String firstBlogEntryId = blogEntryIds.get(blogEntryIds.size()-1); if (firstBlogEntryId == null) { return getBlogForThisMonth(); } long dateInMillis = Long.parseLong(firstBlogEntryId); Date date = new Date(dateInMillis); return getBlogForDay(date).getMonth(); } /** * Gets a Day intance for the specified Date. * * @param date a java.util.Date instance * @return a Day instance representing the specified Date */ public Day getBlogForDay(Date date) { Calendar cal = getCalendar(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = (cal.get(Calendar.MONTH) + 1); int day = cal.get(Calendar.DAY_OF_MONTH); return getBlogForDay(year, month, day); } /** * Gets the Day instance for today. * * @return a Day instance */ public Day getBlogForToday() { return this.getBlogForDay(getCalendar().getTime()); } /** * Gets a Day intance for the specified year, month and day. * * @param year the year as an int * @param month the month as an int * @param day the day as an int * @return a Day instance representing the specified year, month and day */ public Day getBlogForDay(int year, int month, int day) { return getBlogForMonth(year, month).getBlogForDay(day); } /** * Gets a Month intance for the specified year and month. * * @param year the year as an int * @param month the month as an int * @return a Month instance representing the specified year and month */ public Month getBlogForMonth(int year, int month) { return getBlogForYear(year).getBlogForMonth(month); } /** * Gets the Month instance representing this month. * * @return a Month instance for this month */ public Month getBlogForThisMonth() { Calendar cal = getCalendar(); return getBlogForMonth(cal.get(Calendar.YEAR), (cal.get(Calendar.MONTH) + 1)); } /** * Given a Year, this method returns the Year instance * representing the previous year. * * @param year a Year instance * @return a Year representing the previous year */ public Year getBlogForPreviousYear(Year year) { return getBlogForYear(year.getYear() - 1); } /** * Given a Year, this method returns the Year instance * representing the next year. * * @param year a Year instance * @return a Year representing the next year */ public Year getBlogForNextYear(Year year) { return getBlogForYear(year.getYear() + 1); } /** * Gets all blog entries for this blog. * * @return a List of BlogEntry objects */ public List getBlogEntries() { List blogEntries = new ArrayList(); BlogService service = new BlogService(); for (int year = years.size()-1; year >= 0; year--) { Year y = (Year)years.get(year); Month[] months = y.getMonths(); for (int month = 11; month >= 0; month--) { try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -