001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.pagecomments.lar;
022:
023: import com.liferay.portal.kernel.lar.PortletDataContext;
024: import com.liferay.portal.kernel.lar.PortletDataException;
025: import com.liferay.portal.kernel.lar.PortletDataHandler;
026: import com.liferay.portal.kernel.lar.PortletDataHandlerBoolean;
027: import com.liferay.portal.kernel.lar.PortletDataHandlerControl;
028: import com.liferay.portal.model.Layout;
029: import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
030:
031: import javax.portlet.PortletPreferences;
032:
033: /**
034: * <a href="PageCommentsPortletDataHandlerImpl.java.html"><b><i>View Source</i>
035: * </b></a>
036: *
037: * @author Bruno Farache
038: *
039: */
040: public class PageCommentsPortletDataHandlerImpl implements
041: PortletDataHandler {
042:
043: public PortletPreferences deleteData(PortletDataContext context,
044: String portletId, PortletPreferences prefs)
045: throws PortletDataException {
046:
047: try {
048: MBMessageLocalServiceUtil.deleteDiscussionMessages(
049: Layout.class.getName(), context.getPlid());
050:
051: return null;
052: } catch (Exception e) {
053: throw new PortletDataException(e);
054: }
055: }
056:
057: public String exportData(PortletDataContext context,
058: String portletId, PortletPreferences prefs)
059: throws PortletDataException {
060:
061: try {
062: context.addComments(Layout.class, new Long(context
063: .getPlid()));
064:
065: return String.valueOf(context.getPlid());
066: } catch (Exception e) {
067: throw new PortletDataException(e);
068: }
069: }
070:
071: public PortletDataHandlerControl[] getExportControls()
072: throws PortletDataException {
073:
074: return new PortletDataHandlerControl[] { _comments };
075: }
076:
077: public PortletDataHandlerControl[] getImportControls()
078: throws PortletDataException {
079:
080: return new PortletDataHandlerControl[] { _comments };
081: }
082:
083: public PortletPreferences importData(PortletDataContext context,
084: String portletId, PortletPreferences prefs, String data)
085: throws PortletDataException {
086:
087: try {
088: context.importComments(Layout.class, data, new Long(context
089: .getPlid()), context.getGroupId());
090:
091: return null;
092: } catch (Exception e) {
093: throw new PortletDataException(e);
094: }
095: }
096:
097: private static final String _NAMESPACE = "page_comments";
098:
099: private static final PortletDataHandlerBoolean _comments = new PortletDataHandlerBoolean(
100: _NAMESPACE, "comments", true, true);
101:
102: }
|