/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */

package com.liferay.journal.uad.exporter;

import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.journal.uad.constants.JournalUADConstants;
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.user.associated.data.exporter.UADExporter;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
 * @author Brian Wing Shun Chan
 */
@Component(service = UADExporter.class)
public class JournalArticleUADExporter extends BaseJournalArticleUADExporter {

	@Override
	public Class<JournalArticle> getTypeClass() {
		return JournalArticle.class;
	}

	@Override
	protected ActionableDynamicQuery doGetActionableDynamicQuery() {
		return journalArticleLocalService.getActionableDynamicQuery();
	}

	@Override
	protected String[] doGetUserIdFieldNames() {
		return JournalUADConstants.USER_ID_FIELD_NAMES_JOURNAL_ARTICLE;
	}

	@Override
	protected String toXmlString(JournalArticle journalArticle) {
		JournalArticle escapedJournalArticle =
			(JournalArticle)journalArticle.clone();

		escapedJournalArticle.setContent(
			StringUtil.replace(
				escapedJournalArticle.getContent(), "]]><",
				"]]]]><![CDATA[><"));

		return super.toXmlString(escapedJournalArticle);
	}

	@Reference
	protected JournalArticleLocalService journalArticleLocalService;

}