1 23 package org.infoglue.deliver.taglib.common; 24 25 import java.util.List ; 26 27 import javax.servlet.jsp.JspException ; 28 import javax.servlet.jsp.JspTagException ; 29 30 import org.infoglue.deliver.taglib.AbstractTag; 31 import org.infoglue.deliver.util.Slots; 32 33 36 public class SlotsTag extends AbstractTag { 37 40 private static final long serialVersionUID = 3257849891731681845L; 41 42 45 private String visibleElementsId; 46 47 50 private String visibleSlotsId; 51 52 55 private String lastSlotId; 56 57 60 private List elements; 61 62 65 private int currentSlot = 1; 66 67 70 private int slotSize; 71 72 75 private int slotCount; 76 77 80 private int maxSlots; 81 82 83 86 public int doEndTag() throws JspException 87 { 88 calculateSlots(); 89 return EVAL_PAGE; 90 } 91 92 95 private void calculateSlots() throws JspException 96 { 97 try 98 { 99 if(elements != null && visibleElementsId != null) 100 { 101 Slots slots = new Slots(elements, currentSlot, slotSize, slotCount); 102 setResultAttribute(visibleElementsId, slots.getVisibleElements()); 103 setResultAttribute(visibleSlotsId, slots.getVisibleSlots()); 104 setResultAttribute(lastSlotId, slots.getLastSlot()); 105 } 106 else if(maxSlots > 0) 107 { 108 Slots slots = new Slots(currentSlot, slotSize, slotCount, maxSlots); 109 setResultAttribute(visibleSlotsId, slots.getVisibleSlots()); 110 setResultAttribute(lastSlotId, slots.getLastSlot()); 111 } 112 else 113 throw new JspTagException ("Either elements/visibleElementsId or maxSlots must be specified."); 114 } 115 catch(Exception e) 116 { 117 e.printStackTrace(); 118 throw new JspTagException (e.getMessage()); 119 } 120 } 121 122 125 protected void setResultAttribute(final String id, final Object value) 126 { 127 if(value == null) 128 pageContext.removeAttribute(id); 129 else 130 pageContext.setAttribute(id, value); 131 } 132 133 136 public void setVisibleElementsId(final String id) 137 { 138 this.visibleElementsId = id; 139 } 140 141 144 public void setVisibleSlotsId(final String id) 145 { 146 this.visibleSlotsId = id; 147 } 148 149 152 public void setLastSlotId(final String id) 153 { 154 this.lastSlotId = id; 155 } 156 157 160 public void setElements(final String elements) throws JspException 161 { 162 this.elements = evaluateList("slots", "elements", elements); 163 } 164 165 168 public void setCurrentSlot(final String currentSlot) throws JspException 169 { 170 this.currentSlot = Math.max(1, evaluateInteger("slots", "currentSlot", currentSlot).intValue()); 171 } 172 173 176 public void setMaxSlots(final String maxSlots) throws JspException 177 { 178 this.maxSlots = evaluateInteger("slots", "maxSlots", maxSlots).intValue(); 179 } 180 181 184 public void setSlotSize(final String slotSize) throws JspException 185 { 186 this.slotSize = evaluateInteger("slots", "slotSize", slotSize).intValue(); 187 } 188 189 192 public void setSlotCount(final String slotCount) throws JspException 193 { 194 this.slotCount = evaluateInteger("slots", "slotCount", slotCount).intValue(); 195 } 196 } 197 | Popular Tags |