1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.view.wiki;
17
18 import org.seasar.tuigwaa.model.core.TgwEntity;
19 import org.seasar.tuigwaa.model.core.impl.FileAttribute;
20 import org.seasar.tuigwaa.model.core.impl.SetAttribute;
21 import org.seasar.tuigwaa.model.core.impl.StringAttribute;
22 import org.seasar.tuigwaa.util.functor.BinaryUnaryFunction;
23 import org.seasar.tuigwaa.util.functor.DataTableViewerFunction;
24 import org.seasar.tuigwaa.util.functor.FileDownloadFunction;
25 import org.seasar.tuigwaa.util.functor.ReplaceStringFunction;
26 import org.seasar.tuigwaa.util.functor.Text2HtmlFunction;
27 import org.seasar.tuigwaa.util.functor.WikiConvertFunction;
28
29 public class ImageDataViewVisitor extends DefaultDataViewVisitor {
30
31 public static final ImageDataViewVisitor INSTANCE = new ImageDataViewVisitor();
32
33 private ImageDataViewVisitor() {
34 }
35
36 public Object visit(FileAttribute field, Object extraParams) {
37 return visit(field, (String[]) extraParams);
38 }
39
40 public Object visit(StringAttribute field, Object data) {
41 String mask = field.getMask();
42 if (StringAttribute.MASK_EMAIL.equals(mask)) {
43 return toBinary(new ReplaceStringFunction(EMAIL_TEMPLATE));
44 } else if (StringAttribute.MASK_URL.equals(mask)) {
45 return toBinary(new ReplaceStringFunction(URL_TEMPLATE));
46 } else if (StringAttribute.MASK_WIKI.equals(mask)) {
47 return toBinary(new WikiConvertFunction());
48 } else if (StringAttribute.MASK_HTML.equals(mask)) {
49 return null;
50 } else {
51 return toBinary(escape(new Text2HtmlFunction()));
52 }
53 }
54
55 public Object visit(FileAttribute field, String[] extraParams) {
56 String tableName = field.getEntity().getName();
57 String fieldName = field.getName();
58 String style = null;
59 if (extraParams != null && extraParams.length >= 1) {
60 style = "float:" + extraParams[0] + ";";
61 }
62 return new FileDownloadFunction(false, tableName, fieldName, style);
63 }
64
65 public Object visit(SetAttribute setField, Object extraParam) {
66 TgwEntity refEntity = setField.getRefEntity();
67 return new BinaryUnaryFunction(new DataTableViewerFunction(refEntity));
68
69 }
70 }