Author: dam...@jb... Date: 2006-06-09 13:03:21 -0400 (Fri, 09 Jun 2006) New Revision: 4697 Added: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/Constants.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/IdEntity.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/Constants.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/FeedType.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/TagTools.java labs/shotoku/branches/qa/shotoku-tags/src/web/ labs/shotoku/branches/qa/shotoku-tags/src/web/WEB-INF/ labs/shotoku/branches/qa/shotoku-tags/src/web/WEB-INF/web.xml Removed: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagList.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagListImpl.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagTools.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/ShotokuTagEntity.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/WebsiteTagEntity.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/Constants.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/FeedType.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/TagTools.java labs/shotoku/branches/qa/shotoku-tags/src/web/WEB-INF/ labs/shotoku/branches/qa/shotoku-tags/src/web/WEB-INF/web.xml Modified: labs/shotoku/branches/qa/project.properties labs/shotoku/branches/qa/shotoku-feeds/project.xml labs/shotoku/branches/qa/shotoku-feeds/shotoku-feeds.iml labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/XmlNodeTypeVariableResolver.java labs/shotoku/branches/qa/shotoku-tags/src/etc/META-INF/persistence.xml labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/ShotokuTag.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/WebsiteTag.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java Log: MERGED: -r 4653:4696 https://svn.labs.jboss.com/labs/shotoku/trunk into qa EXCEPT: shotoku-feeds/src/java/org/jboss/shotoku/feeds/data/Feed.java. Couldn't due to svn bug. Hand merging in next rev. Modified: labs/shotoku/branches/qa/project.properties =================================================================== --- labs/shotoku/branches/qa/project.properties 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/project.properties 2006-06-09 17:03:21 UTC (rev 4697) @@ -5,7 +5,7 @@ shotoku.sar.dir=shotoku.sar shotoku.subprojects.cms=base,files,jcr,svn -shotoku.subprojects=${shotoku.subprojects.cms},aop,test,web,admin,feeds,portal,file-access,tags +shotoku.subprojects=${shotoku.subprojects.cms},aop,test,web,admin,tags,feeds,portal,file-access maven.final.name=${pom.artifactId} @@ -33,3 +33,4 @@ maven.jar.shotoku-base=${shotoku.root.dir}shotoku-base/target/shotoku-base.jar maven.jar.shotoku-svn=${shotoku.root.dir}shotoku-svn/target/shotoku-svn.jar maven.jar.shotoku-aop=${shotoku.root.dir}shotoku-aop/target/shotoku-aop.jar +maven.jar.shotoku-tags=${shotoku.root.dir}shotoku-tags/target/shotoku-tags.jar Modified: labs/shotoku/branches/qa/shotoku-feeds/project.xml =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/project.xml 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/project.xml 2006-06-09 17:03:21 UTC (rev 4697) @@ -25,6 +25,12 @@ <dependency> <groupId>shotoku</groupId> + <artifactId>shotoku-tags</artifactId> + <jar>shotoku-tags.jar</jar> + </dependency> + + <dependency> + <groupId>shotoku</groupId> <artifactId>shotoku-aop</artifactId> <jar>shotoku-aop.jar</jar> </dependency> Modified: labs/shotoku/branches/qa/shotoku-feeds/shotoku-feeds.iml =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/shotoku-feeds.iml 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/shotoku-feeds.iml 2006-06-09 17:03:21 UTC (rev 4697) @@ -17,6 +17,7 @@ <orderEntry type="library" name="commons" level="application" /> <orderEntry type="library" name="velocity" level="application" /> <orderEntry type="library" name="junit" level="application" /> + <orderEntry type="module" module-name="shotoku-tags" /> <orderEntryProperties /> </component> </module> Deleted: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/Constants.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,56 +0,0 @@ -package org.jboss.shotoku.feeds; - -/** - * @author Adam Warski (ad...@as...) - */ -public class Constants { - /** - * Node with names ending with this string are parsed and - * feed definitons are read from them. - */ - public final static String NODE_ENDING = "-feeds.xml"; - - /* - * Tag names. - */ - public final static String REM_FEED_TAG = "remote-feed"; - public final static String AGG_FEED_TAG = "aggregated-feed"; - public final static String SHO_FEED_TAG = "shotoku-feed"; - - /* - * Property name, under which content manager id and name of the - * directory which contains the configuration file can be found. - */ - public final static String CONFIGDIR = "shotoku.internal.feeds.configdir"; - public final static String CONFIGID = "shotoku.internal.feeds.configcmid"; - - /* - * Property name suffixes, under which content manager id and name - * of the directory which contains the feed files can be found. - */ - public final static String FEEDDIR = ".xml.directory"; - public final static String FEEDID = ".xml.cmid"; - - /** - * Property name suffix, under which information about available - * variables can be found. - */ - public final static String ALL_VARS = ".variables"; - /** - * Property name middle, under which informatin about a concerete - * variable can be found (should be prepended with an id and followed - * by a property name). - */ - public final static String ONE_VAR = ".variable."; - - /** - * Variable, for which feed type will be substituted. - */ - public final static String TYPE_VARIABLE = "${type}"; - - /* - * Xml node attributes denoting a feed name and display name. - */ - public static final String NAME_ATTR = "name"; - public static final String DISP_NAME_ATTR = "display-name"; -} Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedFactory.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -21,10 +21,8 @@ */ package org.jboss.shotoku.feeds; -import org.jboss.shotoku.feeds.data.AtomFeed; -import org.jboss.shotoku.feeds.data.Feed; -import org.jboss.shotoku.feeds.data.RdfFeed; -import org.jboss.shotoku.feeds.data.Rss2Feed; +import org.jboss.shotoku.feeds.data.*; +import org.apache.velocity.VelocityContext; import java.io.File; import java.util.HashMap; @@ -36,50 +34,63 @@ * @author adamw */ public class FeedFactory { - /** - * <code>feedClasses</code> - map feed type -> feed class. - */ - private static Map<String, Class> feedClasses; - private static final Random random; - - static { - feedClasses = new HashMap<String, Class>(); - feedClasses.put("rss2", Rss2Feed.class); - feedClasses.put("atom", AtomFeed.class); - feedClasses.put("rdf", RdfFeed.class); - - random = new Random(); - } - - /** - * Creates a new instance of a feed implementation of the given type. - * @param type Type of feed to create. - * @return A new instance of a feed of the given type. - */ - public static Feed getNewFeed(String name, String displayName, String type) { - Class feedClass = feedClasses.get(type); - if (feedClass == null) return null; - - int nextInt; - synchronized(random) { - nextInt = random.nextInt(); - } - - try { - File file = File.createTempFile("shotoku-feeds" + nextInt, type); - return (Feed) feedClass.getConstructor( + /** + * Map feed type -> feed class. + */ + private static Map<String, Class> feedClasses; + private static Map<String, Class> specialFeedClasses; + private static final Random random; + + static { + feedClasses = new HashMap<String, Class>(); + feedClasses.put("rss2", Rss2Feed.class); + feedClasses.put("atom", AtomFeed.class); + feedClasses.put("rdf", RdfFeed.class); + + specialFeedClasses = new HashMap<String, Class>(); + specialFeedClasses.put("rss2", Rss2TagFeed.class); + + random = new Random(); + } + + /** + * Creates a new instance of a normal feed implementation of the given type. + * @param type Type of feed to create. + * @return A new instance of a feed of the given type. + */ + public static NormalFeed getNewNormalFeed(String name, String displayName, String type) { + Class feedClass = feedClasses.get(type); + if (feedClass == null) return null; + + int nextInt; + synchronized(random) { + nextInt = random.nextInt(); + } + + try { + File file = File.createTempFile("shotoku-feeds" + nextInt, type); + return (NormalFeed) feedClass.getConstructor( String.class, String.class, String.class, File.class).newInstance( - name, displayName, type, file); - } catch (Exception e) { - return null; - } - } - - /** - * Gets all feed types that have been defined. - * @return An array of defined feed types. - */ - public static String[] getAllFeedTypes() { - return feedClasses.keySet().toArray(new String[0]); - } + name, displayName, type, file); + } catch (Exception e) { + return null; + } + } + + /** + * Creates a new instance of a special feed implementation of the given type. + * @param type Type of feed to create. + * @return A new instance of a feed of the given type. + */ + public static Class getNewSpecialFeedClass(String type) { + return specialFeedClasses.get(type); + } + + /** + * Gets all feed types that have been defined. + * @return An array of defined feed types. + */ + public static String[] getAllFeedTypes() { + return feedClasses.keySet().toArray(new String[0]); + } } Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsDescriptor.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -24,8 +24,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -33,10 +31,13 @@ import org.apache.xerces.parsers.DOMParser; import org.apache.log4j.Logger; import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.feeds.data.NormalFeed; +import org.jboss.shotoku.feeds.data.SpecialFeed; import org.jboss.shotoku.feeds.data.Feed; import org.jboss.shotoku.feeds.variables.VariableResolverManager; import org.jboss.shotoku.feeds.tag.FeedTagHandler; import org.jboss.shotoku.feeds.tag.FeedTagHandlerManager; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.tools.Pair; import org.jboss.shotoku.tools.Tools; import org.jboss.shotoku.aop.CacheItem; @@ -68,13 +69,12 @@ /** * Ready feeds: feed name -> (feed type -> feed). */ - private Map<String, Map<String, Feed>> feeds; + private Map<String, Map<String, NormalFeed>> feeds; /** - * Feed group display name -> set of feed - * names. + * Special feeds: feed name prefix -> (feed type -> feed). */ - private Map<String, Set<String>> feedGroups; + private Map<String, Map<String, SpecialFeed>> specialFeeds; private VariableResolverManager vrm; @@ -113,8 +113,8 @@ feedTagHandlers = new HashMap<String, Map<String, FeedTagHandler>>(); // Creating the maps that will hold the feeds. - feeds = new HashMap<String, Map<String, Feed>>(); - feedGroups = new LinkedHashMap<String, Set<String>>(); + feeds = new HashMap<String, Map<String, NormalFeed>>(); + specialFeeds = new HashMap<String, Map<String, SpecialFeed>>(); // Looking for file containing feed definitons and filling the maps. for (org.jboss.shotoku.Node feedNode : @@ -136,8 +136,6 @@ // Trying to generate any feed found in the feed tag handler map. generateFeed(feedTagHandlers.keySet().iterator().next()); } - - // TODO populate the groups } private void addFeedDefinitions(org.jboss.shotoku.Node node) throws SAXException, IOException { @@ -148,11 +146,6 @@ Node root = parser.getDocument().getDocumentElement(); String group = Tools.getAttributeValue(root, "display-name"); - Set<String> feedGroup = new LinkedHashSet<String>(); - // Each feed descriptor file has one feed group. - // Get the name of the feed group for this file. - feedGroups.put(group, feedGroup); - NodeList nodes = root.getChildNodes(); // Iterate through the rest of the feed descriptor @@ -185,10 +178,10 @@ * @param type * @param feed */ - public void addFeed(String name, String type, Feed feed) { - Map<String, Feed> typesMap = feeds.get(name); + public void addFeed(String name, String type, NormalFeed feed) { + Map<String, NormalFeed> typesMap = feeds.get(name); if (typesMap == null) { - typesMap = new HashMap<String, Feed>(); + typesMap = new HashMap<String, NormalFeed>(); feeds.put(name, typesMap); } @@ -196,6 +189,22 @@ } /** + * Adds a ready special feed of the given name and type. + * @param name + * @param type + * @param feed + */ + public void addSpecialFeed(String name, String type, SpecialFeed feed) { + Map<String, SpecialFeed> typesMap = specialFeeds.get(name); + if (typesMap == null) { + typesMap = new HashMap<String, SpecialFeed>(); + specialFeeds.put(name, typesMap); + } + + typesMap.put(type, feed); + } + + /** * Tries to generate a feed with the given name. If the feed is absent, * or is being already generated (this case indicates a loop in feed * definitions), no actions are taken. @@ -225,19 +234,47 @@ } /** - * Gets a feed of the given type and name. + * Gets a normal feed of the given type and name. * @param name Name of the feed to get. * @param type Type of the feed to get. * @return Feed with the given name and type. */ - public Feed getFeed(String name, String type) { - Map<String, Feed> feedTypes = feeds.get(name); - if (feedTypes == null) + public NormalFeed getNormalFeed(String name, String type) { + Map<String, NormalFeed> feedTypes = feeds.get(name); + if (feedTypes == null) { return null; + } return feedTypes.get(type); } + /** + * Gets a feed (any - special or normal) of the given type and name. + * @param name Name of the feed to get. + * @param type Type of the feed to get. + * @return Feed with the given name and type. + */ + public Feed getFeed(String name, String type) { + Feed ret = getNormalFeed(name, type); + if (ret == null) { + // Checking for a special feed. + for (String feedNamePrefix : specialFeeds.keySet()) { + if (name.startsWith(feedNamePrefix)) { + SpecialFeed unconcreteFeed = specialFeeds.get(feedNamePrefix).get(type); + if (unconcreteFeed != null) { + return unconcreteFeed.concretizeFeed(name); + } else { + return null; + } + } + } + + return null; + } + + return ret; + } + public String getBaseServerAddress() { return baseServerAddress; } @@ -250,8 +287,8 @@ * Releases all feeds - deletes temporary files which contain them. */ public void release() { - for (Map<String, Feed> feedTypes : feeds.values()) { - for (Feed feed : feedTypes.values()) { + for (Map<String, NormalFeed> feedTypes : feeds.values()) { + for (NormalFeed feed : feedTypes.values()) { feed.release(); } } Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/FeedsServlet.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -38,13 +38,13 @@ } private static String makeAddress(String scheme, String server, int port) { - return scheme + "://" + server + ":" + port; - } + return scheme + "://" + server + ":" + port; + } - public static String getBaseServerAddress(ServletRequest request) { - return makeAddress(request.getScheme(), request.getServerName(), - request.getServerPort()); - } + public static String getBaseServerAddress(ServletRequest request) { + return makeAddress(request.getScheme(), request.getServerName(), + request.getServerPort()); + } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/AggregatedFeedTagHandler.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -2,10 +2,10 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.data.NormalFeed; import org.jboss.shotoku.feeds.FeedFactory; import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.variables.Substitution; import org.jboss.shotoku.tools.Tools; import org.apache.log4j.Logger; @@ -34,7 +34,7 @@ // First, getting (and if need be, generating) the feeds to be // aggregated as written in the tag. - Set<Feed> toAggregate = new HashSet<Feed>(); + Set<NormalFeed> toAggregate = new HashSet<NormalFeed>(); NodeList nodes = definition.getChildNodes(); for (int i=0; i<nodes.getLength(); i++) { Node n = nodes.item(i); @@ -52,7 +52,7 @@ for (Substitution s : substitutions) { String name = s.make(nameAttr); - Feed f = fd.getFeed(name, feedType); + NormalFeed f = fd.getNormalFeed(name, feedType); if (f == null) { // Trying to generate the feed. @@ -63,7 +63,7 @@ } // The feeds have been successfully generated. - f = fd.getFeed(name, feedType); + f = fd.getNormalFeed(name, feedType); } toAggregate.add(f); @@ -76,11 +76,11 @@ return false; } - Feed feed = FeedFactory.getNewFeed(feedName, attributes.get(Constants.DISP_NAME_ATTR), + NormalFeed feed = FeedFactory.getNewNormalFeed(feedName, attributes.get(Constants.DISP_NAME_ATTR), feedType); try { - feed.generate(toAggregate.toArray(new Feed[0]), + feed.generate(toAggregate.toArray(new NormalFeed[0]), attributes.get("title"), attributes.get("description"), attributes.get("author"), generateFeedLink(fd, true, feedName, feedType)); } catch (IOException e) { Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandler.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -3,7 +3,7 @@ import org.w3c.dom.Node; import org.jboss.shotoku.feeds.variables.Substitution; import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; /** * A base class for classes which handle generation of various feed types, Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/FeedTagHandlerManager.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,7 +1,7 @@ package org.jboss.shotoku.feeds.tag; import org.jboss.shotoku.tools.Tools; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.FeedsDescriptor; import org.jboss.shotoku.feeds.variables.VariableResolverManager; import org.jboss.shotoku.feeds.variables.Substitution; @@ -44,6 +44,7 @@ addHandler(Constants.AGG_FEED_TAG, AggregatedFeedTagHandler.class); addHandler(Constants.REM_FEED_TAG, RemoteFeedTagHandler.class); addHandler(Constants.SHO_FEED_TAG, ShotokuFeedTagHandler.class); + addHandler(Constants.TAG_FEED_TAG, TagFeedTagHandler.class); } /** Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/RemoteFeedTagHandler.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -3,9 +3,9 @@ import org.w3c.dom.Node; import org.jboss.shotoku.tools.Tools; import org.jboss.shotoku.feeds.variables.Substitution; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.data.NormalFeed; import org.jboss.shotoku.feeds.FeedFactory; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.FeedsDescriptor; import org.apache.log4j.Logger; @@ -31,7 +31,7 @@ Constants.DISP_NAME_ATTR)); try { - Feed feed = FeedFactory.getNewFeed(feedName, displayName, feedType); + NormalFeed feed = FeedFactory.getNewNormalFeed(feedName, displayName, feedType); feed.generate(new URL(address)); fd.addFeed(feedName, feedType, feed); } catch (Exception e) { Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/ShotokuFeedTagHandler.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -5,19 +5,17 @@ import org.jboss.shotoku.search.*; import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.tools.Tools; -import org.jboss.shotoku.feeds.tools.RdfDateFormat; -import org.jboss.shotoku.feeds.tools.TextEscaping; -import org.jboss.shotoku.feeds.data.Feed; +import org.jboss.shotoku.feeds.tools.FeedsTools; +import org.jboss.shotoku.feeds.data.NormalFeed; import org.jboss.shotoku.feeds.FeedFactory; import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.variables.Substitution; import org.apache.velocity.VelocityContext; import org.apache.log4j.Logger; import java.util.*; import java.lang.reflect.Constructor; -import java.text.SimpleDateFormat; import java.io.Writer; /** @@ -109,9 +107,6 @@ return param; } - - private final static String RFC_822_DATE = "EEE, d MMM yyyy HH:mm:ss Z"; - public boolean generate(FeedsDescriptor fd) { Node definition = getDefinition(); Substitution s = getSubstitution(); @@ -129,15 +124,8 @@ // Creating a velocity context with parts that won't change in all // generated feeds. VelocityContext vc = new VelocityContext(attributes); + FeedsTools.prepareVelocityContext(attributes, fd, vc); - String dateFormat = attributes.get("dateFormat"); - vc.put("dateFormat", new SimpleDateFormat(dateFormat == null ? "MM/dd/yy" : dateFormat)); - vc.put("rssDateFormat", new SimpleDateFormat(RFC_822_DATE)); - vc.put("rdfDateFormat", new RdfDateFormat()); - vc.put("now", Calendar.getInstance().getTime()); - vc.put("baseServerAddress", fd.getBaseServerAddress()); - vc.put("escape", new TextEscaping()); - NodeList feedNodeChildren = definition.getChildNodes(); for (int i = 0; i < feedNodeChildren.getLength(); i++) { // For each search node, generating and performing the @@ -180,7 +168,7 @@ String feedName = getFeedName(); String feedType = getFeedType(); - Feed newFeed = FeedFactory.getNewFeed(feedName, displayName, feedType); + NormalFeed newFeed = FeedFactory.getNewNormalFeed(feedName, displayName, feedType); try { vc.put("link", generateFeedLink(fd, true, feedName, feedType)); Copied: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java (from rev 4696, labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tag/TagFeedTagHandler.java) Copied: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/Constants.java (from rev 4696, labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/Constants.java) Copied: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java (from rev 4696, labs/shotoku/trunk/shotoku-feeds/src/java/org/jboss/shotoku/feeds/tools/FeedsTools.java) Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/MultiValueVariableResolver.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,7 +1,5 @@ package org.jboss.shotoku.feeds.variables; -import org.jboss.shotoku.feeds.Constants; - import java.util.Set; import java.util.HashSet; Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/VariableResolverManager.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,7 +1,7 @@ package org.jboss.shotoku.feeds.variables; import org.w3c.dom.Node; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; import org.jboss.shotoku.feeds.FeedsDescriptor; import org.apache.log4j.Logger; Modified: labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/XmlNodeTypeVariableResolver.java =================================================================== --- labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/XmlNodeTypeVariableResolver.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-feeds/src/java/org/jboss/shotoku/feeds/variables/XmlNodeTypeVariableResolver.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -3,11 +3,8 @@ import org.w3c.dom.Node; import org.jboss.shotoku.tools.Tools; import org.jboss.shotoku.feeds.FeedFactory; -import org.jboss.shotoku.feeds.FeedsDescriptor; -import org.jboss.shotoku.feeds.Constants; +import org.jboss.shotoku.feeds.tools.Constants; -import java.util.Set; - /** * @author Adam Warski (ad...@as...) */ Modified: labs/shotoku/branches/qa/shotoku-tags/src/etc/META-INF/persistence.xml =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/etc/META-INF/persistence.xml 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/etc/META-INF/persistence.xml 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,6 +1,6 @@ <entity-manager> <name>tags</name> - <jta-data-source>java:/JBossDS</jta-data-source> + <jta-data-source>java:/LabsDS</jta-data-source> <properties> <property name="hibernate.connection.datasource" value="JBossDS" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/AbstractTag.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -8,8 +8,6 @@ * @author Adam Warski (ad...@as...) */ public abstract class AbstractTag implements Tag { - private Integer id; - private String name; private String author; private String resourceId; @@ -17,9 +15,8 @@ private Date dateCreated; - public AbstractTag(Integer id, String name, String author, String resourceId, + public AbstractTag(String name, String author, String resourceId, String data, Date dateCreated) { - this.id = id; this.name = name; this.author = author; this.resourceId = resourceId; @@ -27,23 +24,10 @@ this.dateCreated = dateCreated; } - public AbstractTag(TagEntity te) { - this.id = te.getId(); - this.name = te.getName(); - this.author = te.getAuthor(); - this.resourceId = te.getResourceId(); - this.data = te.getData(); - this.dateCreated = te.getDateCreated(); - } - /* * TAG implementation. */ - public Integer getId() { - return id; - } - public String getName() { return name; } Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/ShotokuTag.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/ShotokuTag.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/ShotokuTag.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,7 +1,6 @@ package org.jboss.shotoku.tags; -import org.jboss.shotoku.tags.dal.ShotokuTagEntity; -import org.jboss.shotoku.tags.dal.TagEntity; +import org.jboss.shotoku.tags.tools.Constants; import java.util.Date; @@ -11,19 +10,10 @@ public class ShotokuTag extends AbstractTag { public ShotokuTag(String name, String author, String resourceId, String data, Date dateCreated) { - super(null, name, author, resourceId, data, dateCreated); + super(name, author, resourceId, data, dateCreated); } - public ShotokuTag(ShotokuTagEntity te) { - super(te); - } - public String getType() { - return "shotoku"; + return Constants.SHOTOKU_TAG; } - - public TagEntity getTagEntity() { - //return new ShotokuTagEntity(this); - return new TagEntity(this); - } } Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/Tag.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -8,14 +8,10 @@ * @author Adam Warski (ad...@as...) */ public interface Tag { - public Integer getId(); - public String getName(); public String getAuthor(); public String getResourceId(); public String getData(); public String getType(); public Date getDateCreated(); - - public TagEntity getTagEntity(); } Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagList.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagList.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagList.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,11 +0,0 @@ -package org.jboss.shotoku.tags; - -import java.util.List; - -/** - * @author Adam Warski (ad...@as...) - */ -public interface TagList { - public List<Tag> getList(); - public String getFeedAddress(); -} Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagListImpl.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagListImpl.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagListImpl.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,24 +0,0 @@ -package org.jboss.shotoku.tags; - -import java.util.List; - -/** - * @author Adam Warski (ad...@as...) - */ -public class TagListImpl implements TagList { - private List<Tag> list; - private String feedAddress; - - public TagListImpl(List<Tag> list, String feedAddress) { - this.list = list; - this.feedAddress = feedAddress; - } - - public List<Tag> getList() { - return list; - } - - public String getFeedAddress() { - return feedAddress; - } -} Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagService.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,6 +1,10 @@ package org.jboss.shotoku.tags; import org.jboss.shotoku.service.AdministratedService; +import org.jboss.shotoku.tags.exceptions.TagAddException; +import org.jboss.shotoku.tags.exceptions.TagDeleteException; +import org.jboss.shotoku.tags.exceptions.TagGetException; +import org.jboss.shotoku.tags.tools.FeedType; import java.util.List; @@ -8,11 +12,22 @@ * @author Adam Warski (ad...@as...) */ public interface TagService extends AdministratedService { - public void addTag(Tag t); - public void deleteTag(Tag t); + public void addTag(Tag t) throws TagAddException; + public void deleteTag(Tag t) throws TagDeleteException; - public TagList getTags(List<String> tagNames); - public TagList getTags(String resourceId); - public TagList getTagsByAuthor(String author); - public TagList getRelatedTags(List<Tag> relateTo); + public Tag getTag(String tagName) throws TagGetException; + + public List<Tag> getTags(List<String> tagNames) throws TagGetException; + public List<Tag> getTags(String resourceId) throws TagGetException; + public List<Tag> getTagsByAuthor(String author) throws TagGetException; + public List<Tag> getRelatedTags(List<Tag> relateTo) throws TagGetException; + + /** + * Gets a link to a tag feed. + * @param feedType Type of the tag feed - resource feed, author feed etc. + * @param data Additinal data - resource id, author name etc. + * @param type Type of the feed - rss2, atom or rdf. + * @return A relative link to a feed with the given parameters. + */ + public String getFeedLink(FeedType feedType, String data, String type); } Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagTools.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagTools.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/TagTools.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,43 +0,0 @@ -package org.jboss.shotoku.tags; - -import org.jboss.shotoku.ContentManager; -import org.jboss.shotoku.tags.service.TagServiceImpl; -import org.jboss.mx.util.MBeanProxyExt; -import org.jboss.mx.util.MBeanServerLocator; - -/** - * @author Adam Warski (ad...@as...) - */ -public class TagTools { - public static final String TAG_SERVICE_NAME = "shotoku:service=tag"; - - private static TagService instance; - - /** - * Gets an instance of Shotoku tag service - this should be always the same - * the object, so the dirty sets work properly. - * @return An instance of org.jboss.shotoku.svn.SvnService - */ - public static TagService getService() { - try { - if (instance == null) { - if (ContentManager.isEmbedded()) { - // Embedded mode - simply creating a new service instance. - instance = new TagServiceImpl(); - instance.create(); - instance.start(); - } else { - // Application server mode - creating a proxy to a mbean. - instance = (TagService) MBeanProxyExt.create( - TagService.class, - TAG_SERVICE_NAME, - MBeanServerLocator.locate()); - } - } - - return instance; - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/WebsiteTag.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/WebsiteTag.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/WebsiteTag.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,7 +1,6 @@ package org.jboss.shotoku.tags; -import org.jboss.shotoku.tags.dal.WebsiteTagEntity; -import org.jboss.shotoku.tags.dal.TagEntity; +import org.jboss.shotoku.tags.tools.Constants; import java.util.Date; @@ -11,18 +10,10 @@ public class WebsiteTag extends AbstractTag { public WebsiteTag(String name, String author, String resourceId, String data, Date dateCreated) { - super(null, name, author, resourceId, data, dateCreated); + super(name, author, resourceId, data, dateCreated); } - public WebsiteTag(WebsiteTagEntity te) { - super(te); - } - public String getType() { - return "website"; + return Constants.WEBSITE_TAG; } - - public TagEntity getTagEntity() { - return new WebsiteTagEntity(this); - } } Copied: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/IdEntity.java (from rev 4696, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/IdEntity.java) Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/ShotokuTagEntity.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/ShotokuTagEntity.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/ShotokuTagEntity.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,23 +0,0 @@ -package org.jboss.shotoku.tags.dal; - -import org.jboss.shotoku.tags.AbstractTag; -import org.jboss.shotoku.tags.ShotokuTag; -import org.jboss.shotoku.tags.Tag; - -/** - * @author Adam Warski (ad...@as...) - */ -/*@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING) -@DiscriminatorValue("shotoku") */ -public class ShotokuTagEntity extends TagEntity { - public ShotokuTagEntity(Tag t) { - super(t); - } - - //@Transient - public AbstractTag getTag() { - return new ShotokuTag(this); - } -} Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/TagEntity.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,8 +1,9 @@ package org.jboss.shotoku.tags.dal; -import org.jboss.shotoku.tags.Tag; import org.jboss.shotoku.tags.AbstractTag; import org.jboss.shotoku.tags.ShotokuTag; +import org.jboss.shotoku.tags.WebsiteTag; +import org.jboss.shotoku.tags.tools.Constants; import javax.persistence.*; import java.util.Date; @@ -12,16 +13,14 @@ * @author Adam Warski (ad...@as...) */ @Entity -//@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -//@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) @Table(name = "ShotokuTags") -public /*abstract*/ class TagEntity implements Serializable { - private Integer id; - +@IdClass(IdEntity.class) +public class TagEntity implements Serializable { private String name; private String author; private String resourceId; private String data; + private String type; private Date dateCreated; @@ -29,28 +28,11 @@ } - public TagEntity(Tag t) { - //this.id = t.getId(); - this.name = t.getName(); - this.author = t.getAuthor(); - this.resourceId = t.getResourceId(); - this.data = t.getData(); - this.dateCreated = t.getDateCreated(); - } - /* * Fields. */ @Id - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - public String getName() { return name; } @@ -59,6 +41,7 @@ this.name = name; } + @Id public String getAuthor() { return author; } @@ -67,6 +50,7 @@ this.author = author; } + @Id public String getResourceId() { return resourceId; } @@ -91,10 +75,28 @@ this.dateCreated = dateCreated; } + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + /* * Other methods. */ - //@Transient - //public abstract AbstractTag getTag(); + @Transient + public AbstractTag getTag() { + if (Constants.SHOTOKU_TAG.equals(getType())) { + return new ShotokuTag(getName(), getAuthor(), getResourceId(), + getData(), getDateCreated()); + } else if (Constants.WEBSITE_TAG.equals(getType())) { + return new WebsiteTag(getName(), getAuthor(), getResourceId(), + getData(), getDateCreated()); + } else { + return null; + } + } } Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/WebsiteTagEntity.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/WebsiteTagEntity.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/dal/WebsiteTagEntity.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,23 +0,0 @@ -package org.jboss.shotoku.tags.dal; - -import org.jboss.shotoku.tags.AbstractTag; -import org.jboss.shotoku.tags.WebsiteTag; -import org.jboss.shotoku.tags.Tag; - -/** - * @author Adam Warski (ad...@as...) - */ -/*@Entity -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING) -@DiscriminatorValue("website")*/ -public class WebsiteTagEntity extends TagEntity { - public WebsiteTagEntity(Tag t) { - super(t); - } - - //@Transient - public AbstractTag getTag() { - return new WebsiteTag(this); - } -} Copied: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions (from rev 4696, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions) Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java =================================================================== --- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,10 +0,0 @@ -package org.jboss.shotoku.tags.exceptions; - -/** - * @author Adam Warski (ad...@as...) - */ -public class TagAddException extends Exception { - public TagAddException(Throwable e) { super(e); } - public TagAddException(String message, Throwable e) { super(message, e); } - public TagAddException(String message) { super(message); } -} Copied: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java (from rev 4696, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagAddException.java) Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java =================================================================== --- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,10 +0,0 @@ -package org.jboss.shotoku.tags.exceptions; - -/** - * @author Adam Warski (ad...@as...) - */ -public class TagDeleteException extends Exception { - public TagDeleteException(Throwable e) { super(e); } - public TagDeleteException(String message, Throwable e) { super(message, e); } - public TagDeleteException(String message) { super(message); } -} Copied: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java (from rev 4696, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagDeleteException.java) Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java =================================================================== --- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,10 +0,0 @@ -package org.jboss.shotoku.tags.exceptions; - -/** - * @author Adam Warski (ad...@as...) - */ -public class TagGetException extends Exception { - public TagGetException(Throwable e) { super(e); } - public TagGetException(String message, Throwable e) { super(message, e); } - public TagGetException(String message) { super(message); } -} Copied: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java (from rev 4696, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/exceptions/TagGetException.java) Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/service/TagServiceImpl.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -24,6 +24,8 @@ import java.util.Calendar; import java.util.List; import java.util.ArrayList; +import java.net.URLEncoder; +import java.io.UnsupportedEncodingException; import javax.ejb.Local; import javax.persistence.EntityManager; @@ -39,13 +41,18 @@ import org.jboss.shotoku.service.AdministratedServiceGetter; import org.jboss.shotoku.service.AdministratedService; import org.jboss.shotoku.tags.*; +import org.jboss.shotoku.tags.tools.TagTools; +import org.jboss.shotoku.tags.tools.FeedType; +import org.jboss.shotoku.tags.exceptions.TagGetException; +import org.jboss.shotoku.tags.exceptions.TagAddException; +import org.jboss.shotoku.tags.exceptions.TagDeleteException; import org.jboss.shotoku.tags.dal.TagEntity; /** * @author Adam Warski (ad...@as...) * @author Damon Sicore (da...@si...) */ -@Service(objectName=TagTools.TAG_SERVICE_NAME) +@Service(objectName=org.jboss.shotoku.tags.tools.Constants.TAG_SERVICE_NAME) @Local(TagServiceLocal.class) @Management(TagService.class) @Depends(Constants.SHOTOKU_SERVICE_NAME) @@ -140,35 +147,87 @@ @PersistenceContext private EntityManager manager; - public void addTag(Tag t) { - manager.persist(t.getTagEntity()); + private TagEntity getTagEntity(Tag t) { + TagEntity te = new TagEntity(); + + te.setAuthor(t.getAuthor()); + te.setData(t.getData()); + te.setDateCreated(t.getDateCreated()); + te.setName(t.getName()); + te.setResourceId(t.getResourceId()); + te.setType(t.getType()); + + return te; } - public void deleteTag(Tag t) { + public void addTag(Tag t) throws TagAddException { + try { + manager.persist(getTagEntity(t)); + } catch (Throwable e) { + throw new TagAddException(e); + } } - public TagList getTags(String resourceId) { - /*List<TagEntity> result = manager.createQuery("from TagEntity where resourceId = :resourceId"). - setParameter("resourceId", resourceId).getResultList(); + public void deleteTag(Tag t) throws TagDeleteException { + try { + manager.remove(getTagEntity(t)); + } catch (Throwable e) { + throw new TagDeleteException(e); + } + } - List<Tag> t = new ArrayList<Tag>(); - for (TagEntity te : result) { - t.add(te.) + public List<Tag> getTags(String resourceId) throws TagGetException { + try { + //noinspection unchecked + List<TagEntity> result = manager.createQuery( + "from TagEntity where resourceId = :resourceId order by dateCreated desc"). + setParameter("resourceId", resourceId).getResultList(); + + List<Tag> ret = new ArrayList<Tag>(); + for (TagEntity te : result) { + ret.add(te.getTag()); + } + + return ret; + } catch (Throwable e) { + throw new TagGetException(e); } + } - return new TagListImpl(ret, ""); */ - return null; + public Tag getTag(String tagName) throws TagGetException { + try { + //noinspection unchecked + TagEntity result = (TagEntity) manager.createQuery("from TagEntity where name = :name"). + setParameter("name", tagName).getSingleResult(); + + if (result == null) { + return null; + } + + return result.getTag(); + } catch (Throwable e) { + throw new TagGetException(e); + } } - public TagList getTags(List<String> tagNames) { + public List<Tag> getTags(List<String> tagNames) throws TagGetException { return null; } - public TagList getRelatedTags(List<Tag> relateTo) { + public List<Tag> getRelatedTags(List<Tag> relateTo) throws TagGetException { return null; } - public TagList getTagsByAuthor(String author) { + public List<Tag> getTagsByAuthor(String author) throws TagGetException { return null; } + + public String getFeedLink(FeedType feedType, String data, String type) { + try { + return "/feeds/tag/" + feedType.toString() + "/" + + URLEncoder.encode(data, "UTF-8") + "/" + type; + } catch (UnsupportedEncodingException e) { + return ""; + } + } } Modified: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java =================================================================== --- labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/test/TagsTestServlet.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,8 +1,10 @@ package org.jboss.shotoku.tags.test; -import org.jboss.shotoku.tags.TagTools; +import org.jboss.shotoku.tags.tools.TagTools; import org.jboss.shotoku.tags.ShotokuTag; import org.jboss.shotoku.tags.Tag; +import org.jboss.shotoku.tags.exceptions.TagAddException; +import org.jboss.shotoku.tags.exceptions.TagGetException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -16,15 +18,25 @@ */ public class TagsTestServlet extends HttpServlet { + static int i = 2; + protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { httpServletResponse.setContentType("text/html"); httpServletResponse.getWriter().println(TagTools.getService().getServiceName()); - TagTools.getService().addTag(new ShotokuTag("n1", "a1", "r1", "d1", - Calendar.getInstance().getTime())); + try { + TagTools.getService().addTag(new ShotokuTag("n" + i++, "a1", "r1", "d1", + Calendar.getInstance().getTime())); + } catch (TagAddException e) { + e.printStackTrace(); + } - /*for (Tag t : TagTools.getService().getTags("r1").getList()) { - httpServletResponse.getWriter().println(t.getName() + " - " + t.getData()); - } */ + try { + for (Tag t : TagTools.getService().getTags("r1")) { + httpServletResponse.getWriter().println(t.getName() + " - " + t.getData()); + } + } catch (TagGetException e) { + e.printStackTrace(); + } } } Copied: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools (from rev 4696, labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools) Deleted: labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/Constants.java =================================================================== --- labs/shotoku/trunk/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/Constants.java 2006-06-09 16:37:08 UTC (rev 4696) +++ labs/shotoku/branches/qa/shotoku-tags/src/java/org/jboss/shotoku/tags/tools/Constants.java 2006-06-09 17:03:21 UTC (rev 4697) @@ -1,13 +0,0 @@ -package org.jboss.shotoku.tags.tools; - -/** - * @author Adam Warski (ad...@as...) - */ -public class Constants { - public static final String TAG_SERVICE_NAME = "shotoku:service=tag"; - - public static final String SHOTOKU_TAG = "shotoku"; - public static final String WE... [truncated message content] |