1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.sharepoint.methods;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.sharepoint.ResponseElement;
19  import com.liferay.portal.sharepoint.SharepointException;
20  import com.liferay.portal.sharepoint.SharepointRequest;
21  import com.liferay.portal.sharepoint.SharepointUtil;
22  import com.liferay.util.servlet.ServletResponseUtil;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="BaseMethodImpl.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Bruno Farache
30   */
31  public abstract class BaseMethodImpl implements Method {
32  
33      public String getRootPath(SharepointRequest sharepointRequest) {
34          return StringPool.BLANK;
35      }
36  
37      public void process(SharepointRequest sharepointRequest)
38          throws SharepointException {
39  
40          try {
41              doProcess(sharepointRequest);
42          }
43          catch (Exception e) {
44              throw new SharepointException(e);
45          }
46      }
47  
48      protected abstract List<ResponseElement> getElements(
49              SharepointRequest sharepointRequest)
50          throws Exception;
51  
52      protected void doProcess(SharepointRequest sharepointRequest)
53          throws Exception {
54  
55          ServletResponseUtil.write(
56              sharepointRequest.getHttpServletResponse(),
57              getResponseBuffer(sharepointRequest).toString());
58      }
59  
60      protected StringBuilder getResponseBuffer(
61              SharepointRequest sharepointRequest)
62          throws Exception {
63  
64          StringBuilder sb = new StringBuilder();
65  
66          SharepointUtil.addTop(sb, getMethodName());
67  
68          List<ResponseElement> elements = getElements(sharepointRequest);
69  
70          for (ResponseElement element : elements) {
71              sb.append(element.parse());
72          }
73  
74          SharepointUtil.addBottom(sb);
75  
76          return sb;
77      }
78  
79  }