📄 feedservlet.java
字号:
// the feed Channel channel = new Channel(); if (dso.getType() == Constants.COLLECTION) { type = "collection"; Collection col = (Collection)dso; description = col.getMetadata("short_description"); title = col.getMetadata("name"); logo = col.getLogo(); scope.setScope(col); } else if (dso.getType() == Constants.COMMUNITY) { type = "community"; Community comm = (Community)dso; description = comm.getMetadata("short_description"); title = comm.getMetadata("name"); logo = comm.getLogo(); scope.setScope(comm); } // put in container-level data channel.setDescription(description); channel.setLink(objectUrl); channel.setTitle("DSpace " + type + ": " + title); if (logo != null) { // we use the path to the logo for this, the logo itself cannot // be contained in the rdf. Not all RSS-viewers show this logo. Image image = new Image(); image.setLink(objectUrl); image.setTitle("The Channel Image"); image.setUrl(dspaceUrl + "/retrieve/" + logo.getID()); channel.setImage(image); } // this is a direct link to the search-engine of dspace. It searches // in the current collection. Since the current version of DSpace // can't search within collections anymore, this works only in older // version until this bug is fixed. TextInput input = new TextInput(); input.setLink(dspaceUrl + "/simple-search"); input.setDescription( "Search the Channel" ); input.setTitle("The " + type + "'s search engine"); input.setName("s"); channel.setTextInput(input); // gather & add items to the feed. scope.setTotal(itemCount); List results = Browse.getLastSubmitted(scope); List items = new ArrayList(); for ( int i = 0; i < results.size(); i++ ) { items.add( itemFromDSpaceItem(context, (Item)results.get(i)) ); } channel.setItems(items); return channel; } /** * The metadata fields of the given item will be added to the given feed. * * @param context DSpace context object * * @param dspaceItem DSpace Item * * @return an object representing a feed entry */ private com.sun.syndication.feed.rss.Item itemFromDSpaceItem(Context context, Item dspaceItem) throws SQLException { com.sun.syndication.feed.rss.Item rssItem = new com.sun.syndication.feed.rss.Item(); String itHandle = ConfigurationManager.getBooleanProperty("webui.feed.localresolve") ? HandleManager.resolveToURL(context, dspaceItem.getHandle()) : HandleManager.getCanonicalForm(dspaceItem.getHandle()); rssItem.setLink(itHandle); String title = getDC(dspaceItem, "title", null, Item.ANY); if (title == null) { title = "no_title"; } rssItem.setTitle(title); // We put some metadata in the description field. This field is // displayed by most RSS viewers StringBuffer descBuf = new StringBuffer(); if ( ! "no_title".equals(title) ) { descBuf.append("title: "); descBuf.append(title); descBuf.append(" "); } DCValue[] authors = dspaceItem.getDC("contributor", "author", Item.ANY); if (authors.length > 0) { descBuf.append("authors: "); for (int i = 0; i < authors.length; i++) { descBuf.append(authors[i].value); if (i < authors.length - 1) { descBuf.append("; "); } } descBuf.append("\n<br>"); } DCValue[] editors = dspaceItem.getDC("contributor", "editor", Item.ANY); if (editors.length > 0) { descBuf.append("editors: "); for (int i = 0; i < editors.length; i++) { descBuf.append(editors[i].value); if (i < editors.length - 1) { descBuf.append("; "); } } descBuf.append("\n<br>"); } String abstr = getDC(dspaceItem, "description", "abstract", Item.ANY); if (abstr != null) { descBuf.append("abstract: "); descBuf.append(abstr); descBuf.append("\n<br>"); } String desc = getDC(dspaceItem, "description", null, Item.ANY); if (desc != null) { descBuf.append("description: "); descBuf.append(desc); descBuf.append("\n<br>"); } Description descrip = new Description(); descrip.setValue(descBuf.toString()); rssItem.setDescription(descrip); String dcDate = getDC(dspaceItem, "date", "issued", Item.ANY); if (dcDate == null) { dcDate = getDC(dspaceItem, "date", Item.ANY, Item.ANY); } if (dcDate != null) { rssItem.setPubDate((new DCDate(dcDate)).toDate()); } return rssItem; } /** * @param item * The item from which the metadata fields are used * @param element * The Dublin Core element * @param qualifier * The Dublin Core qualifier * @param lang * The Dublin Core language * @return If there exists a Dublin Core value with the given element, * qualifier and language, return it, else null */ private String getDC(Item item, String element, String qualifier, String lang) { String dcVal = null; try { dcVal = item.getDC(element, qualifier, lang)[0].value; } catch (ArrayIndexOutOfBoundsException e) { dcVal = null; } return dcVal; } /************************************************ * private cache management classes and methods * ************************************************/ /** * Add a feed to the cache - reducing the size of the cache by 1 to make room if * necessary. The removed entry has an access count equal to the minumum in the cache. * @param feedKey * The cache key for the feed * @param newFeed * The CacheFeed feed to be cached */ private static void cache(String feedKey, CacheFeed newFeed) { // remove older feed to make room if cache full if (feedCache.size() >= cacheSize) { // cache profiling data int total = 0; String minKey = null; CacheFeed minFeed = null; CacheFeed maxFeed = null; Iterator iter = feedCache.keySet().iterator(); while (iter.hasNext()) { String key = (String)iter.next(); CacheFeed feed = (CacheFeed)feedCache.get(key); if (minKey != null) { if (feed.hits < minFeed.hits) { minKey = key; minFeed = feed; } if (feed.hits >= maxFeed.hits) { maxFeed = feed; } } else { minKey = key; minFeed = maxFeed = feed; } total += feed.hits; } // log a profile of the cache to assist administrator in tuning it int avg = total / feedCache.size(); String logMsg = "feedCache() - size: " + feedCache.size() + " Hits - total: " + total + " avg: " + avg + " max: " + maxFeed.hits + " min: " + minFeed.hits; log.info(logMsg); // remove minimum hits entry feedCache.remove(minKey); } // add feed to cache feedCache.put(feedKey, newFeed); } /** * Class to instrument accesses & currency of a given feed in cache */ private class CacheFeed { // currency timestamp public long timeStamp = 0L; // access count public int hits = 0; // the feed private Channel feed = null; public CacheFeed(Channel feed) { this.feed = feed; timeStamp = System.currentTimeMillis(); } public Channel access() { ++hits; return feed; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -