You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/11/13 19:13:47 UTC

svn commit: r835946 - in /labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website: CompoundableProducer.java CompoundableProducerImpl.aj HtmlProducer.java templating/Template.java

Author: simoneg
Date: Fri Nov 13 18:13:47 2009
New Revision: 835946

URL: http://svn.apache.org/viewvc?rev=835946&view=rev
Log:
LABS-494: custom css classes for htmlproducer and compound container divs

Modified:
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducerImpl.aj
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java
    labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducer.java?rev=835946&r1=835945&r2=835946&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducer.java (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducer.java Fri Nov 13 18:13:47 2009
@@ -21,6 +21,7 @@
 public interface CompoundableProducer {
 	
 	public CompoundableProducer compoundWith(Producer other, CompoundType type);
+	public CompoundableProducer compoundCssClass(String cssClass, CompoundType type);
 	public List<Producer> findCompoundedOn(CompoundType type);
 	public List<Producer> findRecursivelyCompoundedOn(CompoundType type);
 	public void markDone(Producer other);

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducerImpl.aj
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducerImpl.aj?rev=835946&r1=835945&r2=835946&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducerImpl.aj (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/CompoundableProducerImpl.aj Fri Nov 13 18:13:47 2009
@@ -22,6 +22,8 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.magma.website.templating.Template;
 import org.apache.magma.website.utils.MakeURLRewritingContextBased;
@@ -37,6 +39,7 @@
 	}
 	
 	private List<CompoundRelation> CompoundableProducer.compound = null;
+	private Map<CompoundType, String> CompoundableProducer.customCssClasses = null;
 	private boolean CompoundableProducer.compounding = false;
 	
 	
@@ -48,6 +51,14 @@
 		compound.add(rel);
 		return this;
 	}
+	
+	public CompoundableProducer CompoundableProducer.compoundCssClass(String cssClass, CompoundType t) {
+		if (customCssClasses == null) {
+			customCssClasses = new HashMap<CompoundType, String>();
+		}
+		customCssClasses.put(t, cssClass);
+		return this;
+	}
 
 	public void CompoundableProducer.markDone(Producer p) {
 		if (compound == null) return;
@@ -114,7 +125,11 @@
 	private void compoundZone(CompoundableProducer prod, CompoundType side, Writer stream) throws IOException {
 		List<Producer> list = prod.findCompoundedOn(side);
 		if (!list.isEmpty()) {
-			openWrapper(stream, side);
+			String addcss = null;
+			if (prod.customCssClasses != null) {
+				addcss = prod.customCssClasses.get(side);
+			}
+			openWrapper(addcss, stream, side);
 			for (Producer producer : list) {
 				if (producer instanceof HtmlProducer) {
 					openWrapper((HtmlProducer) producer, stream, side);
@@ -196,12 +211,14 @@
 		prod.compounding = false;		
 	}
 	
+	
 	protected void openWrapper(HtmlProducer prod, Writer out, CompoundType type) throws IOException {
 		out.write("<div class=\"" + Template.computePartialProducerClasses(prod) + type.name() + "\">");
 	}
 
-	protected void openWrapper(Writer out, CompoundType type) throws IOException {
-		out.write("<div class=\"CompoundZone " + type.name() + "\">");
+	protected void openWrapper(String additionalClasses, Writer out, CompoundType type) throws IOException {
+		if (additionalClasses == null) additionalClasses = "";
+		out.write("<div class=\"CompoundZone " + type.name() + " " + additionalClasses + "\">");
 	}
 	
 	

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java?rev=835946&r1=835945&r2=835946&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/HtmlProducer.java Fri Nov 13 18:13:47 2009
@@ -24,12 +24,17 @@
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
 
 
 public abstract class HtmlProducer extends Producer implements Templatable, CompoundableProducer {
 
 	protected boolean repeatable = true;
 	protected Template template;
+	protected List<String> customCssClasses;
+	protected String customHtmlId;
+	protected boolean useDefaultClasses = true;
 
 	@Override
 	public String getMimeType() {
@@ -78,5 +83,33 @@
 	public void setRepeatable(boolean repeatable) {
 		this.repeatable = repeatable;
 	}
+
+	public String getCustomHtmlId() {
+		return customHtmlId;
+	}
+
+	public void setCustomHtmlId(String customHtmlId) {
+		this.customHtmlId = customHtmlId;
+	}
+
+	public boolean isUseDefaultClasses() {
+		return useDefaultClasses;
+	}
+
+	public void setUseDefaultClasses(boolean useDefaultClasses) {
+		this.useDefaultClasses = useDefaultClasses;
+	}
+	
+	public void addCustomCssClass(String cssClass) {
+		if (customCssClasses == null) {
+			customCssClasses = new ArrayList<String>();
+		}
+		customCssClasses.add(cssClass);
+	}
+
+	public List<String> getCustomCssClasses() {
+		return customCssClasses;
+	}
+	
 	
 }

Modified: labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java?rev=835946&r1=835945&r2=835946&view=diff
==============================================================================
--- labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java (original)
+++ labs/magma/trunk/foundation-website/src/main/java/org/apache/magma/website/templating/Template.java Fri Nov 13 18:13:47 2009
@@ -251,28 +251,44 @@
 		this.forceMain = forceMain;
 	}
 
-	public static String computePartialProducerClasses(Producer prod) {
+	public static String computePartialProducerClasses(HtmlProducer prod) {
 		String classes = "";
-		WebHandler handler = prod.getCreatingHandler();
-		if (handler != null) {
-			classes += handler.getClass().getSimpleName() + " ";
+		if (prod.isUseDefaultClasses()) {
+			WebHandler handler = prod.getCreatingHandler();
+			if (handler != null) {
+				classes += handler.getClass().getSimpleName() + " ";
+			}
+			Method method = prod.getCreatingMethod();
+			if (method != null) {
+				classes += method.getName() + " ";
+			}
 		}
-		Method method = prod.getCreatingMethod();
-		if (method != null) {
-			classes += method.getName() + " ";
+		List<String> cssClasses = prod.getCustomCssClasses();
+		if (cssClasses != null) {
+			for (String clazz : cssClasses) {
+				classes += clazz + " ";
+			}
 		}
 		return classes;		
 	}
 	
-	public static String computeCompleteProducerClasses(Producer prod) {
+	public static String computeCompleteProducerClasses(HtmlProducer prod) {
 		String classes = "";
-		SubRunningContext context = prod.getContext();
-		for (ContextElement ele : context) {
-			if (ele instanceof WebMethodContextElement) {
-				classes += ((WebMethodContextElement)ele).getHandlerInstance().getClass().getSimpleName();
-				classes += " " + ele.toString() + " ";
-			} else {
-				classes += ele.toString() + " ";
+		if (prod.isUseDefaultClasses()) {
+			SubRunningContext context = prod.getContext();
+			for (ContextElement ele : context) {
+				if (ele instanceof WebMethodContextElement) {
+					classes += ((WebMethodContextElement)ele).getHandlerInstance().getClass().getSimpleName();
+					classes += " " + ele.toString() + " ";
+				} else {
+					classes += ele.toString() + " ";
+				}
+			}
+		}
+		List<String> cssClasses = prod.getCustomCssClasses();
+		if (cssClasses != null) {
+			for (String clazz : cssClasses) {
+				classes += clazz + " ";
 			}
 		}
 		return classes;



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