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.plugin.database;
17  
18  import org.seasar.framework.log.Logger;
19  import org.seasar.tuigwaa.cms.core.CmsRequest;
20  import org.seasar.tuigwaa.cms.core.CmsResponse;
21  import org.seasar.tuigwaa.database.function.criteria.CriteriaFunction;
22  import org.seasar.tuigwaa.model.DataService;
23  import org.seasar.tuigwaa.model.core.TgwEntity;
24  import org.seasar.tuigwaa.plugin.AbstractTgwPlugin;
25  import org.seasar.tuigwaa.plugin.PluginException;
26  import org.seasar.tuigwaa.plugin.PluginRequest;
27  import org.seasar.tuigwaa.system.TgwRuntimeException;
28  
29  /***
30   * @author nishioka
31   */
32  public class ValuePlugin extends AbstractTgwPlugin {
33  
34  	private static final Logger logger = Logger.getLogger(ValuePlugin.class);
35  
36  	private DataService dataService = (DataService) getService(DataService.class);
37  
38  	public String doHTMLView(CmsRequest req, CmsResponse res,
39  			PluginRequest prequest) throws PluginException {
40  
41  		String[] array = prequest.getArgs();
42  		if (array == null || array.length < 2) {
43  			return null;
44  		}
45  
46  		String ret = null;
47  		try {
48  			String domain = req.getSiteName();
49  			TgwEntity entity = getEntity(domain, array[0]);
50  
51  			if (entity == null) {
52  				return null;
53  			}
54  
55  			CriteriaFunction extraCriteria = createBindingCriteria(req, entity);
56  			Object result = dataService.getValue(entity, array[1],
57  					extraCriteria);
58  
59  			ret = (result != null) ? String.valueOf(result) : "";
60  		} catch (TgwRuntimeException e) {
61  			logger.log(e);
62  		} catch (Exception e) {
63  			e.printStackTrace();
64  			throw new PluginException(e);
65  		}
66  		return ret;
67  	}
68  }