labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r881075 - in /labs/magma/trunk: website-administration/src/main/java/org/apache/magma/website/admin/ website-beansview/src/main/java/org/apache/magma/website/beansview/ website-feed/src/main/java/org/apache/magma/website/feed/
Date Tue, 17 Nov 2009 00:49:13 GMT
Author: simoneg
Date: Tue Nov 17 00:49:12 2009
New Revision: 881075

URL: http://svn.apache.org/viewvc?rev=881075&view=rev
Log:
LABS-221 : use LinkHelper in more places

Modified:
    labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AdminAction.java
    labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartListProducer.java
    labs/magma/trunk/website-feed/src/main/java/org/apache/magma/website/feed/RssFeedProducer.java

Modified: labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AdminAction.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AdminAction.java?rev=881075&r1=881074&r2=881075&view=diff
==============================================================================
--- labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AdminAction.java
(original)
+++ labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AdminAction.java
Tue Nov 17 00:49:12 2009
@@ -23,6 +23,7 @@
 import org.apache.magma.conversion.Converter;
 import org.apache.magma.conversion.Converters;
 import org.apache.magma.website.WebHandler;
+import org.apache.magma.website.utils.LinkHelper;
 
 public class AdminAction implements Comparable<AdminAction> {
 
@@ -33,7 +34,7 @@
 	
 	public AdminAction(String prefix, String action, boolean parametrized) {
 		this.prefix = prefix;
-		this.action = action;
+		setAction(action);
 		this.parametrized = parametrized;
 	}
 	
@@ -45,13 +46,13 @@
 	}
 	
 	public String getUrl() {
-		return (prefix != null ? prefix + "/" : "") + this.action; 
+		LinkHelper lh = new LinkHelper(this.action);
+		return (prefix != null ? prefix + "/" : "") + lh.makeLink(); 
 	}
 	public String getUrl(Object bean) {
 		if (bean == null || !parametrized) return getUrl();
-		Converter conv = Converters.getConverterFor(bean.getClass());
-		if (conv == null) throw new MagmaException("Cannot find a converter for {0}", bean.getClass());
-		return getUrl() + WebHandler.paramSeparator + conv.to(bean); 
+		LinkHelper lh = new LinkHelper(this.action, bean.getClass());
+		return (prefix != null ? prefix + "/" : "") + lh.makeLink(bean); 
 	}
 	
 	@Override

Modified: labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartListProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartListProducer.java?rev=881075&r1=881074&r2=881075&view=diff
==============================================================================
--- labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartListProducer.java
(original)
+++ labs/magma/trunk/website-beansview/src/main/java/org/apache/magma/website/beansview/SmartListProducer.java
Tue Nov 17 00:49:12 2009
@@ -31,9 +31,14 @@
 import org.apache.magma.view.tree.FieldNode;
 import org.apache.magma.view.tree.Node;
 import org.apache.magma.website.WebHandler;
+import org.apache.magma.website.utils.LinkHelper;
 
 public class SmartListProducer extends ShowList {
 
+	protected static LinkHelper 
+	startLinkHelper = new LinkHelper("doStart", Integer.class),
+	sortLinkHelper = new LinkHelper("doSort", Boolean.class, String.class);
+	
 	protected int start = 0;
 	protected int len = 10;
 	protected String sorting = null;
@@ -133,7 +138,7 @@
 		ret.append("</div>");
 		ret.append("<div class=\"PaginationNavigation\">");
 		if (start > 0) {
-			ret.append(" <a class=\"PaginationPrevious\" href=\"start" + WebHandler.paramSeparator
+ Math.max(0, start - len) + "\">");
+			ret.append(" <a class=\"PaginationPrevious\" href=\"" + startLinkHelper.makeLink(Math.max(0,
start - len)) + "\">");
 			ret.append(new LocalizableString("Previous page"));
 			ret.append("</a>");
 		}
@@ -145,7 +150,7 @@
 				ret.append(Integer.toString(currentpage + 1));
 				ret.append("</strong> ");
 			} else {
-				ret.append(" <a href=\"start" + WebHandler.paramSeparator + Math.max(0, start + (len
* po)) + "\"  title=\"" + gototitle + "\">");
+				ret.append(" <a href=\"" + startLinkHelper.makeLink(Math.max(0, start + (len * po)))
+ "\"  title=\"" + gototitle + "\">");
 				ret.append(Integer.toString(currentpage + po + 1));
 				ret.append("</a> ");
 			}
@@ -154,7 +159,7 @@
 		ret.append("</span>");
 		
 		if (start + len < count) {
-			ret.append(" <a class=\"PaginationNext\" href=\"start" + WebHandler.paramSeparator
+ Math.max(0, start + len) + "\">");
+			ret.append(" <a class=\"PaginationNext\" href=\"" + startLinkHelper.makeLink(Math.max(0,
start + len)) + "\">");
 			ret.append(new LocalizableString("Next page"));
 			ret.append("</a>");
 		}
@@ -174,22 +179,11 @@
 	
 	protected String sortLink(String nodeid) {
 		boolean sorted = this.sorting != null && this.sorting.equals(nodeid);
-		String link = "sort" + WebHandler.paramSeparator;
-		if (sorted) {
-			if (desc) {
-				link += "false" + WebHandler.paramSeparator;
-			} else {
-				link += "true" + WebHandler.paramSeparator;
-			}
-		} else {
-			link += "false" + WebHandler.paramSeparator;				
-		}
-		link += nodeid;
-		return link;
+		return sortLinkHelper.makeLink(sorted ? !desc : false, nodeid);
 	}
 
 	/*
-	 * TODO Rewrite inside specific list templates
+	 * Old pre-template stuff
 	@Override
 	protected void createHeader(Node root, Writer tables) throws IOException {
 		if (emitter.supportsHeader()) {

Modified: labs/magma/trunk/website-feed/src/main/java/org/apache/magma/website/feed/RssFeedProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/website-feed/src/main/java/org/apache/magma/website/feed/RssFeedProducer.java?rev=881075&r1=881074&r2=881075&view=diff
==============================================================================
--- labs/magma/trunk/website-feed/src/main/java/org/apache/magma/website/feed/RssFeedProducer.java
(original)
+++ labs/magma/trunk/website-feed/src/main/java/org/apache/magma/website/feed/RssFeedProducer.java
Tue Nov 17 00:49:12 2009
@@ -14,6 +14,7 @@
 import org.apache.magma.conversion.Converters;
 import org.apache.magma.website.Producer;
 import org.apache.magma.website.WebHandler;
+import org.apache.magma.website.utils.LinkHelper;
 
 import com.sun.syndication.feed.WireFeed;
 import com.sun.syndication.feed.rss.Content;
@@ -66,33 +67,11 @@
 
 	@Override
 	public void produce(OutputStream stream) {
-		String linkUrl = null;
+		LinkHelper lh = null;
 		if (this.link != null) {
-			GenericClass gc = GenericClass.forClass(getCreatingHandler().getClass());
-			List<MethodDef> methods = gc.findMethods(this.link, new Class<?>[] { this.myclass
});
-			if (methods.size() == 0) {
-				methods = gc.findMethods(this.link, new Class<?>[] { null });
-				if (methods.size() == 0) {				
-					throw new MagmaException("Cannot find method {0}.{1}({2}) to make the link", getCreatingHandler(),
this.link, this.myclass);
-				} else if (methods.size() > 1) {
-					throw new MagmaException("There is more than one method {0}.{1}(), and no one is accepting
explicitly {2} as a parameter. Cannot not make the link", getCreatingHandler(), this.link,
this.myclass);					
-				}
-			}
-			linkUrl = this.link;
-			if (linkUrl.startsWith("do")) {
-				linkUrl = linkUrl.substring(2);
-			} else if (linkUrl.startsWith("handle")){
-				linkUrl = linkUrl.substring(6);				
-			} else {
-				throw new MagmaException("The link {0} is not valid : it should refer a doMethod or handleMethod",
this.link);
-			}
+			lh = new LinkHelper(this.link, this.myclass);
+			lh.checkAgainst(getCreatingHandler().getClass());
 		}
-		Converter converter = null;
-		if (linkUrl != null) {
-			converter = Converters.getConverterFor(this.myclass);
-			if (converter == null) throw new MagmaException("Cannot find converter for {0}, cannot
make link!", this.myclass);			
-		}		
-		
 		
 		Channel ch = new Channel("rss_1.0");
 		ch.setTitle(this.getFeedTitle());
@@ -100,12 +79,13 @@
 		ch.setDescription(this.getFeedDescription());
 		for (FeedableItem fi : this.items) {
 			Item item = new Item();
-			//item.setAuthor("Pinco Palla");
 			item.setTitle(fi.getTitleForFeed());
 			Content content = new Content();
 			content.setValue(fi.getContentForFeed());
 			item.setContent(content);
-			item.setLink(linkUrl + WebHandler.paramSeparator + converter.to(fi));
+			if (lh != null) {
+				item.setLink(lh.makeLink(fi));
+			}
 			ch.getItems().add(item);			
 		}
 		



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message