1
22
23 package com.liferay.portal.events;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.struts.ActionException;
29 import com.liferay.portal.struts.SimpleAction;
30 import com.liferay.portal.util.PropsUtil;
31 import com.liferay.portlet.journal.action.ExportAction;
32 import com.liferay.portlet.journal.model.JournalArticle;
33 import com.liferay.portlet.journal.model.JournalStructure;
34 import com.liferay.portlet.journal.model.JournalTemplate;
35 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
36 import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
37 import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
38
39 import java.util.List;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44
50 public class FixOracleAction extends SimpleAction {
51
52 public static final int NUM_OF_ARTICLES = GetterUtil.getInteger(
53 PropsUtil.get(FixOracleAction.class.getName()), 5);
54
55 public void run(String[] ids) throws ActionException {
56 try {
57 _fixNewLine();
58 }
59 catch (Exception e) {
60 throw new ActionException(e);
61 }
62 }
63
64 private void _fixNewLine() throws PortalException, SystemException {
65
66
72 boolean checkNewLine = false;
73
74 List articles = null;
75
76 if (NUM_OF_ARTICLES <= 0) {
77 checkNewLine = true;
78
79 articles = JournalArticleLocalServiceUtil.getArticles(
80 ExportAction.DEFAULT_GROUP_ID);
81 }
82 else {
83 articles = JournalArticleLocalServiceUtil.getArticles(
84 ExportAction.DEFAULT_GROUP_ID, 0, NUM_OF_ARTICLES);
85 }
86
87 for (int i = 0; i < articles.size(); i++) {
88 JournalArticle article = (JournalArticle)articles.get(i);
89
90 String content = article.getContent();
91
92 if ((content != null) && (content.indexOf("\\n") != -1)) {
93 articles = JournalArticleLocalServiceUtil.getArticles(
94 ExportAction.DEFAULT_GROUP_ID);
95
96 for (int j = 0; j < articles.size(); j++) {
97 article = (JournalArticle)articles.get(j);
98
99 JournalArticleLocalServiceUtil.checkNewLine(
100 article.getGroupId(), article.getArticleId(),
101 article.getVersion());
102 }
103
104 checkNewLine = true;
105
106 break;
107 }
108 }
109
110
112 if (!checkNewLine) {
113 if (_log.isInfoEnabled()) {
114 _log.debug("Do not fix oracle new line");
115 }
116
117 return;
118 }
119 else {
120 if (_log.isInfoEnabled()) {
121 _log.info("Fix oracle new line");
122 }
123 }
124
125 List structures = JournalStructureLocalServiceUtil.getStructures(
126 ExportAction.DEFAULT_GROUP_ID, 0, 1);
127
128 if (structures.size() == 1) {
129 JournalStructure structure = (JournalStructure)structures.get(0);
130
131 String xsd = structure.getXsd();
132
133 if ((xsd != null) && (xsd.indexOf("\\n") != -1)) {
134 structures = JournalStructureLocalServiceUtil.getStructures(
135 ExportAction.DEFAULT_GROUP_ID);
136
137 for (int i = 0; i < structures.size(); i++) {
138 structure = (JournalStructure)structures.get(i);
139
140 JournalStructureLocalServiceUtil.checkNewLine(
141 structure.getGroupId(), structure.getStructureId());
142 }
143 }
144 }
145
146 List templates = JournalTemplateLocalServiceUtil.getTemplates(
147 ExportAction.DEFAULT_GROUP_ID, 0, 1);
148
149 if (templates.size() == 1) {
150 JournalTemplate template = (JournalTemplate)templates.get(0);
151
152 String xsl = template.getXsl();
153
154 if ((xsl != null) && (xsl.indexOf("\\n") != -1)) {
155 templates = JournalTemplateLocalServiceUtil.getTemplates(
156 ExportAction.DEFAULT_GROUP_ID);
157
158 for (int i = 0; i < templates.size(); i++) {
159 template = (JournalTemplate)templates.get(i);
160
161 JournalTemplateLocalServiceUtil.checkNewLine(
162 template.getGroupId(), template.getTemplateId());
163 }
164 }
165 }
166 }
167
168 private static Log _log = LogFactory.getLog(FixOracleAction.class);
169
170 }