r142 - in trunk/chorem-webmotion/src/main: java/org/wikitty/web/jsptag webapp/WEB-INF webapp/WEB-INF/jsp
Author: ymartel Date: 2012-04-26 18:04:03 +0200 (Thu, 26 Apr 2012) New Revision: 142 Url: http://chorem.org/repositories/revision/chorem/142 Log: Prepare a tag support to display wikitty fields Added: trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp trunk/chorem-webmotion/src/main/webapp/WEB-INF/wikitty.tld Added: trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java (rev 0) +++ trunk/chorem-webmotion/src/main/java/org/wikitty/web/jsptag/WikittyDisplay.java 2012-04-26 16:04:03 UTC (rev 142) @@ -0,0 +1,183 @@ +package org.wikitty.web.jsptag; + +import org.apache.commons.lang3.StringUtils; +import org.nuiton.wikitty.WikittyUtil; +import org.nuiton.wikitty.entities.FieldType; +import org.nuiton.wikitty.entities.Wikitty; + +import javax.servlet.ServletContext; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * Tag Support to display Wikitty fields. + * + * @author ymartel <martel@codelutin.com> + * @since 04/26/2012 + */ +public class WikittyDisplay extends SimpleTagSupport { + + + protected String name=""; + protected Object value=""; + + protected Wikitty wikitty; + protected String fqfield=""; + + public void setName(String name) { + this.name = name; + } + + public void setValue(Object value) { + this.value = value; + } + + public void setWikitty(Wikitty wikitty) { + this.wikitty = wikitty; + } + + public void setFqfield(String fqfield) { + this.fqfield = fqfield; + } + + @Override + public void doTag() throws JspException, IOException { + // par defaut si pas de name on utilise celui du field + if (StringUtils.isBlank(name)) { + name = fqfield; + } + + JspWriter output = getJspContext().getOut(); + PageContext pageContext = (PageContext)getJspContext(); + ServletContext servletContext = pageContext.getServletContext(); + String contextPath = servletContext.getContextPath(); + + String extName = WikittyUtil.getExtensionNameFromFQFieldName(fqfield); + String fieldName = WikittyUtil.getFieldNameFromFQFieldName(fqfield); + FieldType field = wikitty.getFieldType(fqfield); + + if (field != null) { + switch(field.getType()) { + case BINARY: + viewBinary(output, contextPath, name, wikitty, field, extName, fieldName); + break; + case BOOLEAN: + viewBoolean(output, contextPath, name, wikitty, field, extName, fieldName); + break; + case DATE: + viewDate(output, contextPath, name, wikitty, field, extName, fieldName); + break; + case NUMERIC: + viewNumeric(output, contextPath, name, wikitty, field, extName, fieldName); + break; + case STRING: + if (field.isCollection()) { + viewCollectionString(output, contextPath, name, wikitty, field, extName, fieldName); + } else { + viewString(output, contextPath, name, wikitty, field, extName, fieldName); + } + break; + case WIKITTY: + if (field.isCollection()) { + viewCollectionWikitty(output, contextPath, name, wikitty, field, extName, fieldName); + } else { + viewWikitty(output, contextPath, name, wikitty, field, extName, fieldName); + } + break; + } + } else { + /*{<div class="alert alert-error"><%=wikitty.getId()%> doesn't have field '<%=fqfield%>'</div>}*/ + } + } + + protected void viewBinary(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + /*{<%=name%> : <c:out value=<%=wikitty.getFieldAsString(extName, fieldName)%>" />}*/ + } + + protected void viewBoolean(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + boolean value = wikitty.getFieldAsBoolean(extName, fieldName); + /*{<%=fieldName%> : <%=value%>}*/ + } + + protected void viewDate(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + Date date = wikitty.getFieldAsDate(extName, fieldName); + + if (field.hasPattern()) { + String pattern = field.getPattern(); + /*{<%=fieldName%> : <fmt:formatDate value="<%=date%>" pattern="<%=pattern%>" />}*/ + } else { + /*{<%=fieldName%> : <fmt:formatDate value="<%=date%>" />}*/ + + } + } + + protected void viewNumeric(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + BigDecimal value = wikitty.getFieldAsBigDecimal(extName, fieldName); + + if (field.hasPattern()) { + String pattern = field.getPattern(); + /*{<%=fieldName%> : <fmt:formatNumber value="<%=value%>" pattern="<%=pattern%>" />}*/ + } else { + /*{<%=fieldName%> : <%=value%> />}*/ + } + } + + protected void viewCollectionString(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + String id = wikitty.getId() + "-" + extName + "-" + fieldName; + List<String> values = wikitty.getFieldAsList(extName, fieldName, String.class); + /*{<%=fieldName%> : <ul>}*/ + for (String value : values) { + /*{<li><%=value%></li>}*/ + } + /*{</ul>}*/ + } + + protected void viewString(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + boolean value = wikitty.getFieldAsBoolean(extName, fieldName); + /*{<%=fieldName%> : <%=value%>}*/ + } + + protected void viewCollectionWikitty(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + String id = wikitty.getId() + "-" + extName + "-" + fieldName; + List<Wikitty> values = wikitty.getFieldAsWikittyList(extName, fieldName, false); + /*{<%=fieldName%> : <ul>}*/ + for (Wikitty value : values) { + /*{<li><a href="<c:url value="/wikitty/view/<%=value.getId()%>"/>"><c:out value="<%=value%>"/></a></li>}*/ + } + /*{</ul>}*/ + + } + + protected void viewWikitty(JspWriter output, String contextPath, String name, + Wikitty wikitty, FieldType field, String extName , String fieldName) + throws JspException, IOException { + String id = wikitty.getId() + "-" + extName + "-" + fieldName; + String value = wikitty.getFieldAsWikitty(extName, fieldName); + Wikitty wikittyValue = wikitty.getFieldAsWikitty(extName, fieldName, false); + String url = contextPath + "/wikitty-json/search?extension=" + field.getAllowed(); + if (wikittyValue != null) { + /*{<%=fieldName%>: <a href="<c:url value="/wikitty/view/<%=wikittyValue.getId()%>"/>"><c:out value="<%=wikittyValue%>"/></a>}*/ + } + } + +}//WikittyDisplay Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp 2012-04-25 12:55:15 UTC (rev 141) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/view.jsp 2012-04-26 16:04:03 UTC (rev 142) @@ -15,6 +15,7 @@ <a class="btn btn-danger btn-mini" href="<c:url value="/wikitty/delete/${wikitty.id}?extension=${ext.name}&wmDecoratorNo=true"/>"><i class="icon-trash icon-white"></i> Delete</a></dt> <c:forEach var="fieldName" items="${ext.fieldNames}"> <dd><%@ include file="wikittyFieldView.jsp"%></dd> + <!-- <dd><w:input wikitty="${wikitty}" fqfield="${ext.name}.${fieldName}"/></dd> --> </c:forEach> </dl> </c:forEach> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/wikitty.tld =================================================================== (Binary files differ)
participants (1)
-
ymartel@users.chorem.org