All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.portal.sharepoint.methods.BaseMethodImpl Maven / Gradle / Ivy

/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.portal.sharepoint.methods;

import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.ServletResponseUtil;
import com.liferay.portal.sharepoint.Property;
import com.liferay.portal.sharepoint.ResponseElement;
import com.liferay.portal.sharepoint.SharepointException;
import com.liferay.portal.sharepoint.SharepointRequest;
import com.liferay.portal.sharepoint.SharepointUtil;

import java.util.List;

/**
 * @author Bruno Farache
 */
public abstract class BaseMethodImpl implements Method {

	@Override
	public String getRootPath(SharepointRequest sharepointRequest) {
		return StringPool.BLANK;
	}

	@Override
	public void process(SharepointRequest sharepointRequest)
		throws SharepointException {

		try {
			doProcess(sharepointRequest);
		}
		catch (Exception exception) {
			throw new SharepointException(exception);
		}
	}

	protected void doProcess(SharepointRequest sharepointRequest)
		throws Exception {

		ServletResponseUtil.write(
			sharepointRequest.getHttpServletResponse(),
			getResponse(sharepointRequest, false));
	}

	protected abstract List getElements(
			SharepointRequest sharepointRequest)
		throws Exception;

	protected String getResponse(
			SharepointRequest sharepointRequest, boolean appendNewline)
		throws Exception {

		List elements = getElements(sharepointRequest);

		StringBundler sb = new StringBundler(elements.size() + 9);

		sb.append("vermeer RPC packet");
		sb.append(StringPool.NEW_LINE);
		sb.append("");
		sb.append(StringPool.NEW_LINE);

		Property property = new Property(
			"method", getMethodName() + ":" + SharepointUtil.VERSION);

		sb.append(property.parse());

		for (ResponseElement element : elements) {
			sb.append(element.parse());
		}

		sb.append("");
		sb.append(StringPool.NEW_LINE);
		sb.append("");

		if (appendNewline) {
			sb.append(StringPool.NEW_LINE);
		}

		String html = sb.toString();

		if (_log.isDebugEnabled()) {
			_log.debug("Response HTML\n" + html);
		}

		return html;
	}

	private static final Log _log = LogFactoryUtil.getLog(BaseMethodImpl.class);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy