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.portal.events;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.events.ActionException;
026: import com.liferay.portal.kernel.events.SimpleAction;
027: import com.liferay.portal.kernel.util.GetterUtil;
028: import com.liferay.portal.util.PropsUtil;
029: import com.liferay.portlet.journal.action.ExportAction;
030: import com.liferay.portlet.journal.model.JournalArticle;
031: import com.liferay.portlet.journal.model.JournalStructure;
032: import com.liferay.portlet.journal.model.JournalTemplate;
033: import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
034: import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
035: import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
036:
037: import java.util.List;
038:
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041:
042: /**
043: * <a href="FixOracleAction.java.html"><b><i>View Source</i></b></a>
044: *
045: * @author Brian Wing Shun Chan
046: *
047: */
048: public class FixOracleAction extends SimpleAction {
049:
050: public static final int NUM_OF_ARTICLES = GetterUtil.getInteger(
051: PropsUtil.get(FixOracleAction.class.getName()), 5);
052:
053: public void run(String[] ids) throws ActionException {
054: try {
055: _fixNewLine();
056: } catch (Exception e) {
057: throw new ActionException(e);
058: }
059: }
060:
061: private void _fixNewLine() throws PortalException, SystemException {
062:
063: // This is a workaround for a limitation in Oracle sqlldr's inability
064: // insert new line characters for long varchar columns. See
065: // http://forums.liferay.com/index.php?showtopic=2761&hl=oracle for more
066: // information. Check several articles because some articles may not
067: // have new lines.
068:
069: boolean checkNewLine = false;
070:
071: List articles = null;
072:
073: if (NUM_OF_ARTICLES <= 0) {
074: checkNewLine = true;
075:
076: articles = JournalArticleLocalServiceUtil
077: .getArticles(ExportAction.DEFAULT_GROUP_ID);
078: } else {
079: articles = JournalArticleLocalServiceUtil.getArticles(
080: ExportAction.DEFAULT_GROUP_ID, 0, NUM_OF_ARTICLES);
081: }
082:
083: for (int i = 0; i < articles.size(); i++) {
084: JournalArticle article = (JournalArticle) articles.get(i);
085:
086: String content = article.getContent();
087:
088: if ((content != null) && (content.indexOf("\\n") != -1)) {
089: articles = JournalArticleLocalServiceUtil
090: .getArticles(ExportAction.DEFAULT_GROUP_ID);
091:
092: for (int j = 0; j < articles.size(); j++) {
093: article = (JournalArticle) articles.get(j);
094:
095: JournalArticleLocalServiceUtil.checkNewLine(article
096: .getGroupId(), article.getArticleId(),
097: article.getVersion());
098: }
099:
100: checkNewLine = true;
101:
102: break;
103: }
104: }
105:
106: // Only process this once
107:
108: if (!checkNewLine) {
109: if (_log.isInfoEnabled()) {
110: _log.debug("Do not fix oracle new line");
111: }
112:
113: return;
114: } else {
115: if (_log.isInfoEnabled()) {
116: _log.info("Fix oracle new line");
117: }
118: }
119:
120: List structures = JournalStructureLocalServiceUtil
121: .getStructures(ExportAction.DEFAULT_GROUP_ID, 0, 1);
122:
123: if (structures.size() == 1) {
124: JournalStructure structure = (JournalStructure) structures
125: .get(0);
126:
127: String xsd = structure.getXsd();
128:
129: if ((xsd != null) && (xsd.indexOf("\\n") != -1)) {
130: structures = JournalStructureLocalServiceUtil
131: .getStructures(ExportAction.DEFAULT_GROUP_ID);
132:
133: for (int i = 0; i < structures.size(); i++) {
134: structure = (JournalStructure) structures.get(i);
135:
136: JournalStructureLocalServiceUtil.checkNewLine(
137: structure.getGroupId(), structure
138: .getStructureId());
139: }
140: }
141: }
142:
143: List templates = JournalTemplateLocalServiceUtil.getTemplates(
144: ExportAction.DEFAULT_GROUP_ID, 0, 1);
145:
146: if (templates.size() == 1) {
147: JournalTemplate template = (JournalTemplate) templates
148: .get(0);
149:
150: String xsl = template.getXsl();
151:
152: if ((xsl != null) && (xsl.indexOf("\\n") != -1)) {
153: templates = JournalTemplateLocalServiceUtil
154: .getTemplates(ExportAction.DEFAULT_GROUP_ID);
155:
156: for (int i = 0; i < templates.size(); i++) {
157: template = (JournalTemplate) templates.get(i);
158:
159: JournalTemplateLocalServiceUtil.checkNewLine(
160: template.getGroupId(), template
161: .getTemplateId());
162: }
163: }
164: }
165: }
166:
167: private static Log _log = LogFactory.getLog(FixOracleAction.class);
168:
169: }
|