1 13 package com.tonbeller.jpivot.table; 14 15 import java.util.Iterator ; 16 17 import org.apache.log4j.Logger; 18 import org.w3c.dom.Element ; 19 20 import com.tonbeller.jpivot.olap.model.Dimension; 21 import com.tonbeller.jpivot.olap.model.Displayable; 22 import com.tonbeller.jpivot.olap.model.EmptyMember; 23 import com.tonbeller.jpivot.olap.model.Hierarchy; 24 import com.tonbeller.jpivot.olap.model.Level; 25 import com.tonbeller.jpivot.olap.model.Member; 26 import com.tonbeller.jpivot.olap.model.Property; 27 import com.tonbeller.jpivot.olap.model.PropertyHolder; 28 import com.tonbeller.jpivot.olap.model.Visitable; 29 import com.tonbeller.jpivot.olap.model.VisitorSupportStrict; 30 import com.tonbeller.jpivot.table.span.PropertyHeading; 31 import com.tonbeller.jpivot.table.span.PropertyUtils; 32 import com.tonbeller.jpivot.table.span.Span; 33 import com.tonbeller.jpivot.table.span.SpanVisitor; 34 35 41 public class SpanBuilderImpl extends PartBuilderSupport implements SpanBuilder { 42 String memberName; 43 String headingName; 44 private static final Logger logger = Logger.getLogger(SpanBuilderImpl.class); 45 46 51 public SpanBuilderImpl(String memberName, String headingName) { 52 this.memberName = memberName; 53 this.headingName = headingName; 54 } 55 56 class RenderSwitch extends VisitorSupportStrict implements SpanVisitor { 57 58 private static final String CAPTION = "caption"; 59 Element elem; 60 private SBContext sbctx; 61 62 public RenderSwitch(SBContext sbctx) { 63 this.sbctx = sbctx; 64 } 65 66 void renderHeading(Displayable d) { 67 elem = table.elem(headingName); 68 Element caption = table.append(CAPTION, elem); 69 String label = d.getLabel(); 70 caption.setAttribute(CAPTION, label); 71 sbctx.setCaption(caption, label); 72 } 73 74 private void renderMember(Displayable d, String label) { 75 elem = table.elem(memberName); 76 Element caption = table.append(CAPTION, elem); 77 caption.setAttribute(CAPTION, label); 79 sbctx.setCaption(caption, label); 80 81 if (d instanceof PropertyHolder) { 82 Property[] props = ((PropertyHolder) d).getProperties(); 83 PropertyUtils.addInlineProperties(caption, props); 84 Property style = PropertyUtils.getInlineProperty(props, PropertyUtils.STYLE_PROPERTY); 85 if (style != null) { 86 String value = style.getValue().trim(); 87 if (value.length() > 0) 88 elem.setAttribute(PropertyUtils.STYLE_PROPERTY, value.toLowerCase()); 89 } 90 } 91 92 } 93 94 public void visitPropertyHeading(PropertyHeading v) { 95 renderHeading(v); 96 } 97 98 public void visitDimension(Dimension v) { 99 renderHeading(v); 100 } 101 102 public void visitHierarchy(Hierarchy v) { 103 renderHeading(v); 104 } 105 106 public void visitLevel(Level v) { 107 renderHeading(v); 108 } 109 110 public void visitMember(Member v) { 111 renderMember(v, v.getLabel()); 112 } 113 114 public void visitProperty(Property v) { 115 renderMember(v, v.getValue()); 116 } 117 118 public void visitEmptyMember(EmptyMember v) { 119 renderMember(v, v.getLabel()); 120 } 121 122 public Element getElem() { 123 return elem; 124 } 125 126 public void setElem(Element elem) { 127 this.elem = elem; 128 } 129 } 130 131 134 public Element build(SBContext sbctx, Span span, boolean even) { 135 if (logger.isDebugEnabled()) 136 logger.debug("build " + span); 137 138 RenderSwitch renderSwitch = new RenderSwitch(sbctx); 139 140 Visitable v = span.getObject(); 141 142 v.accept(renderSwitch); 143 Element elem = renderSwitch.getElem(); 144 for (Iterator it = table.clickableIterator(); it.hasNext();) 145 ((ClickableMember) it.next()).decorate(sbctx, span.getObject()); 146 return elem; 147 } 148 149 } 150 | Popular Tags |