View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  		// return "";
69  	}
70  }