001
014
015 package com.liferay.portal.sharepoint.methods;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
020 import com.liferay.portal.kernel.util.StringBundler;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.sharepoint.Property;
023 import com.liferay.portal.sharepoint.ResponseElement;
024 import com.liferay.portal.sharepoint.SharepointException;
025 import com.liferay.portal.sharepoint.SharepointRequest;
026 import com.liferay.portal.sharepoint.SharepointUtil;
027
028 import java.util.List;
029
030
033 public abstract class BaseMethodImpl implements Method {
034
035 @Override
036 public String getRootPath(SharepointRequest sharepointRequest) {
037 return StringPool.BLANK;
038 }
039
040 @Override
041 public void process(SharepointRequest sharepointRequest)
042 throws SharepointException {
043
044 try {
045 doProcess(sharepointRequest);
046 }
047 catch (Exception e) {
048 throw new SharepointException(e);
049 }
050 }
051
052 protected void doProcess(SharepointRequest sharepointRequest)
053 throws Exception {
054
055 ServletResponseUtil.write(
056 sharepointRequest.getHttpServletResponse(),
057 getResponse(sharepointRequest, false));
058 }
059
060 protected abstract List<ResponseElement> getElements(
061 SharepointRequest sharepointRequest)
062 throws Exception;
063
064 protected String getResponse(
065 SharepointRequest sharepointRequest, boolean appendNewline)
066 throws Exception {
067
068 StringBundler sb = new StringBundler();
069
070 sb.append("<html><head><title>vermeer RPC packet</title></head>");
071 sb.append(StringPool.NEW_LINE);
072 sb.append("<body>");
073 sb.append(StringPool.NEW_LINE);
074
075 Property property = new Property(
076 "method", getMethodName() + ":" + SharepointUtil.VERSION);
077
078 sb.append(property.parse());
079
080 List<ResponseElement> elements = getElements(sharepointRequest);
081
082 for (ResponseElement element : elements) {
083 sb.append(element.parse());
084 }
085
086 sb.append("</body>");
087 sb.append(StringPool.NEW_LINE);
088 sb.append("</html>");
089
090 if (appendNewline) {
091 sb.append(StringPool.NEW_LINE);
092 }
093
094 String html = sb.toString();
095
096 if (_log.isDebugEnabled()) {
097 _log.debug("Response HTML\n" + html);
098 }
099
100 return html;
101 }
102
103 private static Log _log = LogFactoryUtil.getLog(BaseMethodImpl.class);
104
105 }