1 package org.jahia.taglibs.categories; 2 3 import java.util.ArrayList ; 4 import javax.servlet.ServletRequest ; 5 import javax.servlet.jsp.JspException ; 6 import javax.servlet.jsp.tagext.BodyTagSupport ; 7 8 import org.jahia.data.JahiaData; 9 import org.jahia.services.categories.Category; 10 import java.util.Iterator ; 11 import org.jahia.data.beans.CategoryBean; 12 13 25 26 public class CategoriesByPropertiesTag extends BodyTagSupport { 27 28 private String propertyName = null; 29 private String propertyValue = null; 30 private String propertyNameRef = null; 31 private String propertyValueRef = null; 32 33 37 public void setPropertyName(String propertyName) { 38 this.propertyName = propertyName; 39 } 40 41 45 public void setPropertyValue(String propertyValue) { 46 this.propertyValue = propertyValue; 47 } 48 49 53 public void setPropertyNameRef(String propertyNameRef) { 54 this.propertyNameRef = propertyNameRef; 55 } 56 57 61 public void setPropertyValueRef(String propertyValueRef) { 62 this.propertyValueRef = propertyValueRef; 63 } 64 65 public int doStartTag () 66 throws JspException { 67 68 ServletRequest request = pageContext.getRequest(); 69 JahiaData jData = (JahiaData) request.getAttribute( 70 "org.jahia.data.JahiaData"); 71 72 ArrayList foundCategories = new ArrayList (); 73 ArrayList foundCategoryBeans = new ArrayList (); 74 75 if (propertyNameRef != null) { 76 propertyName = (String ) pageContext.findAttribute(propertyNameRef); 77 } 78 if (propertyValueRef != null) { 79 propertyValue = (String ) pageContext.findAttribute(propertyValueRef); 80 } 81 82 if ((propertyName == null) || (propertyValue == null)) { 83 throw new JspException ( 84 "Error: either property name or property value is null, aborting"); 85 } 86 87 foundCategories = Category.findCategoriesByPropNameAndValue(propertyName, propertyValue); 88 89 Iterator foundCategoriesIter = foundCategories.iterator(); 90 while (foundCategoriesIter.hasNext()) { 91 Category curCategory = (Category) foundCategoriesIter.next(); 92 CategoryBean curCategoryBean = new CategoryBean(curCategory, jData.params()); 93 foundCategoryBeans.add(curCategoryBean); 94 } 95 96 if (getId() != null) { 97 pageContext.setAttribute(getId(), 98 foundCategoryBeans); 99 } 100 return EVAL_BODY_BUFFERED; 101 } 102 103 public int doAfterBody () 105 throws JspException { 106 return SKIP_BODY; 108 } 109 110 public int doEndTag () 111 throws JspException { 112 super.doEndTag(); 115 propertyName = null; 116 propertyValue = null; 117 propertyNameRef = null; 118 propertyValueRef = null; 119 return EVAL_PAGE; 120 } 121 122 } 123 | Popular Tags |