Source Code Cross Referenced for ExportAction.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portlet » journal » action » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portlet.journal.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.journal.action;
022:
023:        import com.liferay.counter.service.CounterLocalServiceUtil;
024:        import com.liferay.portal.NoSuchPortletPreferencesException;
025:        import com.liferay.portal.NoSuchUserException;
026:        import com.liferay.portal.kernel.security.permission.PermissionChecker;
027:        import com.liferay.portal.kernel.util.GetterUtil;
028:        import com.liferay.portal.kernel.util.ParamUtil;
029:        import com.liferay.portal.kernel.util.StringMaker;
030:        import com.liferay.portal.kernel.util.StringPool;
031:        import com.liferay.portal.kernel.util.StringUtil;
032:        import com.liferay.portal.kernel.util.Validator;
033:        import com.liferay.portal.kernel.zip.ZipWriter;
034:        import com.liferay.portal.model.Image;
035:        import com.liferay.portal.model.Layout;
036:        import com.liferay.portal.model.LayoutTypePortlet;
037:        import com.liferay.portal.model.PortletPreferences;
038:        import com.liferay.portal.service.ImageLocalServiceUtil;
039:        import com.liferay.portal.service.LayoutLocalServiceUtil;
040:        import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
041:        import com.liferay.portal.service.UserLocalServiceUtil;
042:        import com.liferay.portal.struts.ActionConstants;
043:        import com.liferay.portal.theme.ThemeDisplay;
044:        import com.liferay.portal.upgrade.util.IdReplacer;
045:        import com.liferay.portal.upgrade.util.MemoryValueMapper;
046:        import com.liferay.portal.util.PortletKeys;
047:        import com.liferay.portal.util.WebKeys;
048:        import com.liferay.portal.util.comparator.LayoutComparator;
049:        import com.liferay.portlet.PortletPreferencesImpl;
050:        import com.liferay.portlet.PortletPreferencesSerializer;
051:        import com.liferay.portlet.imagegallery.NoSuchImageException;
052:        import com.liferay.portlet.imagegallery.model.IGFolder;
053:        import com.liferay.portlet.imagegallery.model.IGImage;
054:        import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
055:        import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
056:        import com.liferay.portlet.journal.NoSuchArticleImageException;
057:        import com.liferay.portlet.journal.model.JournalArticle;
058:        import com.liferay.portlet.journal.model.JournalArticleImage;
059:        import com.liferay.portlet.journal.model.JournalArticleResource;
060:        import com.liferay.portlet.journal.model.JournalContentSearch;
061:        import com.liferay.portlet.journal.model.JournalStructure;
062:        import com.liferay.portlet.journal.model.JournalTemplate;
063:        import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
064:        import com.liferay.portlet.journal.service.JournalArticleImageLocalServiceUtil;
065:        import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
066:        import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
067:        import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
068:        import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
069:        import com.liferay.portlet.journal.service.persistence.JournalContentSearchUtil;
070:        import com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException;
071:        import com.liferay.portlet.softwarecatalog.service.SCProductScreenshotLocalServiceUtil;
072:        import com.liferay.util.Time;
073:        import com.liferay.util.servlet.ServletResponseUtil;
074:
075:        import java.util.ArrayList;
076:        import java.util.Collections;
077:        import java.util.Date;
078:        import java.util.Iterator;
079:        import java.util.List;
080:        import java.util.Map;
081:        import java.util.Properties;
082:
083:        import javax.servlet.http.HttpServletRequest;
084:        import javax.servlet.http.HttpServletResponse;
085:        import javax.servlet.jsp.PageContext;
086:
087:        import org.apache.commons.logging.Log;
088:        import org.apache.commons.logging.LogFactory;
089:        import org.apache.struts.action.Action;
090:        import org.apache.struts.action.ActionForm;
091:        import org.apache.struts.action.ActionForward;
092:        import org.apache.struts.action.ActionMapping;
093:
094:        /**
095:         * <a href="ExportAction.java.html"><b><i>View Source</i></b></a>
096:         *
097:         * @author Brian Wing Shun Chan
098:         *
099:         */
100:        public class ExportAction extends Action {
101:
102:            public static final String COMPANY_ID = "liferay.com";
103:
104:            public static final long DEFAULT_GROUP_ID = 14;
105:
106:            public static final long DEFAULT_USER_ID = 2;
107:
108:            public static final String DEFAULT_USER_NAME = "Joe Bloggs";
109:
110:            public ActionForward execute(ActionMapping mapping,
111:                    ActionForm form, HttpServletRequest req,
112:                    HttpServletResponse res) throws Exception {
113:
114:                try {
115:                    ThemeDisplay themeDisplay = (ThemeDisplay) req
116:                            .getAttribute(WebKeys.THEME_DISPLAY);
117:
118:                    PermissionChecker permissionChecker = themeDisplay
119:                            .getPermissionChecker();
120:
121:                    if (permissionChecker.isOmniadmin()) {
122:                        long groupId = ParamUtil.getLong(req, "groupId",
123:                                DEFAULT_GROUP_ID);
124:
125:                        _primaryKeys.clear();
126:                        _primaryKeyCount = 1500;
127:
128:                        ZipWriter zipWriter = new ZipWriter();
129:
130:                        List journalContentSearches = new ArrayList();
131:
132:                        insertDataImage(groupId, zipWriter);
133:                        insertDataCMSLayout(groupId, zipWriter,
134:                                journalContentSearches);
135:                        insertDataCMSContent(groupId, zipWriter,
136:                                journalContentSearches);
137:
138:                        String fileName = "journal.zip";
139:
140:                        ServletResponseUtil.sendFile(res, fileName, zipWriter
141:                                .finish());
142:                    }
143:
144:                    return null;
145:                } catch (Exception e) {
146:                    req.setAttribute(PageContext.EXCEPTION, e);
147:
148:                    return mapping.findForward(ActionConstants.COMMON_ERROR);
149:                }
150:            }
151:
152:            protected void addColumn(StringMaker sm, boolean value) {
153:                //sm.append("'");
154:
155:                if (value) {
156:                    sm.append("TRUE");
157:                } else {
158:                    sm.append("FALSE");
159:                }
160:
161:                //sm.append("', ");
162:                sm.append(", ");
163:            }
164:
165:            protected void addColumn(StringMaker sm, double value) {
166:                sm.append(value);
167:                sm.append(", ");
168:            }
169:
170:            protected void addColumn(StringMaker sm, float value) {
171:                sm.append(value);
172:                sm.append(", ");
173:            }
174:
175:            protected void addColumn(StringMaker sm, int value) {
176:                sm.append(value);
177:                sm.append(", ");
178:            }
179:
180:            protected void addColumn(StringMaker sm, long value) {
181:                sm.append(value);
182:                sm.append(", ");
183:            }
184:
185:            protected void addColumn(StringMaker sm, short value) {
186:                sm.append(value);
187:                sm.append(", ");
188:            }
189:
190:            protected void addColumn(StringMaker sm, Date value) {
191:                addColumn(sm, value, true);
192:            }
193:
194:            protected void addColumn(StringMaker sm, Date value, boolean current) {
195:                if (current) {
196:                    sm.append("CURRENT_TIMESTAMP, ");
197:                } else {
198:                    sm.append("SPECIFIC_TIMESTAMP_");
199:                    sm.append(Time.getSimpleDate(value, "yyyyMMddHHmmss"));
200:                    sm.append(", ");
201:                }
202:            }
203:
204:            protected void addColumn(StringMaker sm, String value) {
205:                addColumn(sm, value, true);
206:            }
207:
208:            protected void addColumn(StringMaker sm, String value,
209:                    boolean format) {
210:                if (format) {
211:                    value = StringUtil.replace(value, new String[] { "\\", "'",
212:                            "\"", "\n", "\r" }, new String[] { "\\\\", "\\'",
213:                            "\\\"", "\\n", "\\r" });
214:                }
215:
216:                value = GetterUtil.getString(value);
217:
218:                sm.append("'");
219:                sm.append(value);
220:                sm.append("', ");
221:            }
222:
223:            protected void addPKColumn(StringMaker sm, long value) {
224:                sm.append(getNewPrimaryKey(value));
225:                sm.append(", ");
226:            }
227:
228:            protected void addPKColumn(StringMaker sm, String value) {
229:                sm.append("'");
230:                sm.append(getNewPrimaryKey(value));
231:                sm.append("', ");
232:            }
233:
234:            protected String getNewPrimaryKey(String pk) {
235:                if (Validator.isNumber(pk)) {
236:                    long pkLong = GetterUtil.getLong(pk);
237:
238:                    return String.valueOf(getNewPrimaryKey(pkLong));
239:                } else {
240:                    return pk;
241:                }
242:            }
243:
244:            protected long getNewPrimaryKey(long pk) {
245:                Long pkObj = new Long(pk);
246:
247:                Long newPkObj = (Long) _primaryKeys.get(pkObj);
248:
249:                if (newPkObj == null) {
250:                    newPkObj = new Long(_primaryKeyCount);
251:
252:                    _primaryKeyCount++;
253:
254:                    _primaryKeys.put(pkObj, newPkObj);
255:                }
256:
257:                return newPkObj.longValue();
258:            }
259:
260:            protected void insertDataCMSContent(long groupId,
261:                    ZipWriter zipWriter, List journalContentSearches)
262:                    throws Exception {
263:
264:                StringMaker sm = new StringMaker();
265:
266:                List igImages = new ArrayList();
267:
268:                Iterator itr = IGFolderLocalServiceUtil.getFolders(groupId)
269:                        .iterator();
270:
271:                while (itr.hasNext()) {
272:                    IGFolder folder = (IGFolder) itr.next();
273:
274:                    sm.append("insert into IGFolder (");
275:                    sm
276:                            .append("folderId, groupId, companyId, userId, createDate, ");
277:                    sm.append("modifiedDate, parentFolderId, name");
278:                    sm.append(") values (");
279:                    addPKColumn(sm, folder.getFolderId());
280:                    addColumn(sm, folder.getGroupId());
281:                    addColumn(sm, folder.getCompanyId());
282:                    //addColumn(sm, folder.getUserId());
283:                    addColumn(sm, DEFAULT_USER_ID);
284:                    addColumn(sm, folder.getCreateDate());
285:                    addColumn(sm, folder.getModifiedDate());
286:                    addColumn(sm, folder.getParentFolderId());
287:                    addColumn(sm, folder.getName());
288:                    removeTrailingComma(sm);
289:                    sm.append(");\n");
290:
291:                    igImages.addAll(IGImageLocalServiceUtil.getImages(folder
292:                            .getFolderId()));
293:                }
294:
295:                sm.append("\n");
296:
297:                Collections.sort(igImages);
298:
299:                itr = igImages.iterator();
300:
301:                while (itr.hasNext()) {
302:                    IGImage image = (IGImage) itr.next();
303:
304:                    sm.append("insert into IGImage (");
305:                    sm
306:                            .append("imageId, companyId, userId, createDate, modifiedDate, ");
307:                    sm
308:                            .append("folderId, description, smallImageId, largeImageId");
309:                    sm.append(") values (");
310:                    addPKColumn(sm, image.getImageId());
311:                    addColumn(sm, image.getCompanyId());
312:                    //addColumn(sm, image.getUserId());
313:                    addColumn(sm, DEFAULT_USER_ID);
314:                    addColumn(sm, image.getCreateDate());
315:                    addColumn(sm, image.getModifiedDate());
316:                    addPKColumn(sm, image.getFolderId());
317:                    addColumn(sm, image.getDescription());
318:                    addPKColumn(sm, image.getSmallImageId());
319:                    addPKColumn(sm, image.getLargeImageId());
320:                    removeTrailingComma(sm);
321:                    sm.append(");\n");
322:                }
323:
324:                sm.append("\n");
325:
326:                itr = JournalArticleLocalServiceUtil.getArticles(groupId)
327:                        .iterator();
328:
329:                while (itr.hasNext()) {
330:                    JournalArticle article = (JournalArticle) itr.next();
331:
332:                    if (article.isApproved()
333:                            && JournalArticleLocalServiceUtil.isLatestVersion(
334:                                    article.getGroupId(), article
335:                                            .getArticleId(), article
336:                                            .getVersion())) {
337:
338:                        sm.append("insert into JournalArticle (");
339:                        sm
340:                                .append("id_, resourcePrimKey, groupId, companyId, userId, ");
341:                        sm
342:                                .append("userName, createDate, modifiedDate, articleId, ");
343:                        sm
344:                                .append("version, title, description, content, type_, ");
345:                        sm
346:                                .append("structureId, templateId, displayDate, approved, ");
347:                        sm
348:                                .append("approvedByUserId, approvedByUserName, expired, ");
349:                        sm.append("indexable");
350:                        sm.append(") values (");
351:                        addPKColumn(sm, article.getId());
352:                        addPKColumn(sm, article.getResourcePrimKey());
353:                        addColumn(sm, article.getGroupId());
354:                        addColumn(sm, article.getCompanyId());
355:                        //addColumn(sm, article.getUserId());
356:                        //addColumn(sm, article.getUserName());
357:                        addColumn(sm, DEFAULT_USER_ID);
358:                        addColumn(sm, DEFAULT_USER_NAME);
359:                        addColumn(sm, article.getCreateDate());
360:                        addColumn(sm, article.getModifiedDate());
361:                        addPKColumn(sm, article.getArticleId());
362:                        addColumn(sm, JournalArticleImpl.DEFAULT_VERSION);
363:                        addColumn(sm, article.getTitle());
364:                        addColumn(sm, article.getDescription());
365:                        addColumn(sm, replaceIds(article.getContent()));
366:                        addColumn(sm, article.getType());
367:                        addPKColumn(sm, article.getStructureId());
368:                        addPKColumn(sm, article.getTemplateId());
369:                        addColumn(sm, article.getDisplayDate(), false);
370:                        addColumn(sm, article.getApproved());
371:                        //addColumn(sm, article.getApprovedByUserId());
372:                        //addColumn(sm, article.getApprovedByUserName());
373:                        addColumn(sm, DEFAULT_USER_ID);
374:                        addColumn(sm, DEFAULT_USER_NAME);
375:                        //addColumn(sm, article.getApprovedDate(), false);
376:                        addColumn(sm, article.getExpired());
377:                        //addColumn(sm, article.getExpirationDate(), false);
378:                        //addColumn(sm, article.getReviewDate(), false);
379:                        addColumn(sm, article.getIndexable());
380:                        removeTrailingComma(sm);
381:                        sm.append(");\n");
382:                    }
383:                }
384:
385:                sm.append("\n");
386:
387:                itr = JournalArticleImageLocalServiceUtil.getArticleImages(
388:                        groupId).iterator();
389:
390:                while (itr.hasNext()) {
391:                    JournalArticleImage articleImage = (JournalArticleImage) itr
392:                            .next();
393:
394:                    sm.append("insert into JournalArticleImage (");
395:                    sm
396:                            .append("articleImageId, groupId, articleId, version, elName, ");
397:                    sm.append("languageId, tempImage");
398:                    sm.append(") values (");
399:                    addPKColumn(sm, articleImage.getArticleImageId());
400:                    addColumn(sm, articleImage.getGroupId());
401:                    addPKColumn(sm, articleImage.getArticleId());
402:                    addColumn(sm, articleImage.getVersion());
403:                    addColumn(sm, articleImage.getElName());
404:                    addColumn(sm, articleImage.getLanguageId());
405:                    addColumn(sm, articleImage.getTempImage());
406:                    removeTrailingComma(sm);
407:                    sm.append(");\n");
408:                }
409:
410:                sm.append("\n");
411:
412:                itr = JournalArticleResourceLocalServiceUtil
413:                        .getArticleResources(groupId).iterator();
414:
415:                while (itr.hasNext()) {
416:                    JournalArticleResource articleResource = (JournalArticleResource) itr
417:                            .next();
418:
419:                    sm.append("insert into JournalArticleResource (");
420:                    sm.append("resourcePrimKey, groupId, articleId");
421:                    sm.append(") values (");
422:                    addPKColumn(sm, articleResource.getResourcePrimKey());
423:                    addColumn(sm, articleResource.getGroupId());
424:                    addPKColumn(sm, articleResource.getArticleId());
425:                    removeTrailingComma(sm);
426:                    sm.append(");\n");
427:                }
428:
429:                sm.append("\n");
430:
431:                itr = journalContentSearches.iterator();
432:
433:                while (itr.hasNext()) {
434:                    JournalContentSearch contentSearch = (JournalContentSearch) itr
435:                            .next();
436:
437:                    sm.append("insert into JournalContentSearch (");
438:                    sm
439:                            .append("contentSearchId, groupId, companyId, privateLayout, ");
440:                    sm.append("layoutId, portletId, articleId");
441:                    sm.append(") values (");
442:                    addPKColumn(sm, contentSearch.getContentSearchId());
443:                    addColumn(sm, contentSearch.getGroupId());
444:                    addColumn(sm, contentSearch.getCompanyId());
445:                    addColumn(sm, contentSearch.isPrivateLayout());
446:                    addColumn(sm, contentSearch.getLayoutId());
447:                    addColumn(sm, contentSearch.getPortletId());
448:                    addPKColumn(sm, contentSearch.getArticleId());
449:                    removeTrailingComma(sm);
450:                    sm.append(");\n");
451:                }
452:
453:                sm.append("\n");
454:
455:                itr = JournalStructureLocalServiceUtil.getStructures(groupId)
456:                        .iterator();
457:
458:                while (itr.hasNext()) {
459:                    JournalStructure structure = (JournalStructure) itr.next();
460:
461:                    sm.append("insert into JournalStructure (");
462:                    sm.append("id_, groupId, companyId, userId, userName, ");
463:                    sm.append("createDate, modifiedDate, structureId, name, ");
464:                    sm.append("description, xsd");
465:                    sm.append(") values (");
466:                    addPKColumn(sm, structure.getId());
467:                    addColumn(sm, structure.getGroupId());
468:                    addColumn(sm, structure.getCompanyId());
469:                    //addColumn(sm, structure.getUserId());
470:                    //addColumn(sm, structure.getUserName());
471:                    addColumn(sm, DEFAULT_USER_ID);
472:                    addColumn(sm, DEFAULT_USER_NAME);
473:                    addColumn(sm, structure.getCreateDate());
474:                    addColumn(sm, structure.getModifiedDate());
475:                    addPKColumn(sm, structure.getStructureId());
476:                    addColumn(sm, structure.getName());
477:                    addColumn(sm, structure.getDescription());
478:                    addColumn(sm, replaceIds(structure.getXsd()));
479:                    removeTrailingComma(sm);
480:                    sm.append(");\n");
481:                }
482:
483:                sm.append("\n");
484:
485:                itr = JournalTemplateLocalServiceUtil.getTemplates(groupId)
486:                        .iterator();
487:
488:                while (itr.hasNext()) {
489:                    JournalTemplate template = (JournalTemplate) itr.next();
490:
491:                    sm.append("insert into JournalTemplate (");
492:                    sm.append("id_, groupId, companyId, userId, userName, ");
493:                    sm
494:                            .append("createDate, modifiedDate, templateId, structureId, ");
495:                    sm.append("name, description, xsl, langType, smallImage, ");
496:                    sm.append("smallImageId, smallImageURL");
497:                    sm.append(") values (");
498:                    addPKColumn(sm, template.getId());
499:                    addColumn(sm, template.getGroupId());
500:                    addColumn(sm, template.getCompanyId());
501:                    //addColumn(sm, template.getUserId());
502:                    //addColumn(sm, template.getUserName());
503:                    addColumn(sm, DEFAULT_USER_ID);
504:                    addColumn(sm, DEFAULT_USER_NAME);
505:                    addColumn(sm, template.getCreateDate());
506:                    addColumn(sm, template.getModifiedDate());
507:                    addPKColumn(sm, template.getTemplateId());
508:                    addPKColumn(sm, template.getStructureId());
509:                    addColumn(sm, template.getName());
510:                    addColumn(sm, template.getDescription());
511:                    addColumn(sm, replaceIds(template.getXsl()));
512:                    addColumn(sm, template.getLangType());
513:                    addColumn(sm, template.getSmallImage());
514:                    addPKColumn(sm, template.getSmallImageId());
515:                    addColumn(sm, template.getSmallImageURL());
516:                    removeTrailingComma(sm);
517:                    sm.append(");\n");
518:                }
519:
520:                removeTrailingNewLine(sm);
521:
522:                zipWriter.addEntry("portal-data-cms-content.sql", sm);
523:            }
524:
525:            protected void insertDataCMSLayout(long groupId,
526:                    ZipWriter zipWriter, List journalContentSearches)
527:                    throws Exception {
528:
529:                StringMaker sm = new StringMaker();
530:
531:                List layouts = LayoutLocalServiceUtil
532:                        .getLayouts(groupId, false);
533:
534:                sm.append("update LayoutSet ");
535:                sm.append("set themeId = 'liferayjedi_WAR_liferayjeditheme', ");
536:                sm.append("pageCount = ");
537:                sm.append(layouts.size());
538:                sm.append(" where groupId = ");
539:                sm.append(groupId);
540:                sm.append(" and privateLayout = FALSE;\n\n");
541:
542:                Collections.sort(layouts, new LayoutComparator(true));
543:
544:                Iterator itr = layouts.iterator();
545:
546:                while (itr.hasNext()) {
547:                    Layout layout = (Layout) itr.next();
548:
549:                    getNewPrimaryKey(layout.getPlid());
550:                }
551:
552:                itr = layouts.iterator();
553:
554:                while (itr.hasNext()) {
555:                    Layout layout = (Layout) itr.next();
556:
557:                    Properties props = layout.getTypeSettingsProperties();
558:
559:                    long linkToPlid = GetterUtil.getLong(props
560:                            .getProperty("linkToPlid"));
561:
562:                    if (linkToPlid > 0) {
563:                        long newLinkToPlid = getNewPrimaryKey(linkToPlid);
564:
565:                        props.setProperty("linkToPlid", String
566:                                .valueOf(newLinkToPlid));
567:                    }
568:
569:                    sm.append("insert into Layout (");
570:                    sm
571:                            .append("plid, groupId, companyId, privateLayout, layoutId, ");
572:                    sm
573:                            .append("parentLayoutId, name, title, type_, typeSettings, ");
574:                    sm.append("hidden_, friendlyURL, iconImage, iconImageId, ");
575:                    //sm.append("themeId, colorSchemeId, wapThemeId, wapColorSchemeId, ");
576:                    sm.append("css, priority");
577:                    sm.append(") values (");
578:                    addPKColumn(sm, layout.getPlid());
579:                    addColumn(sm, layout.getGroupId());
580:                    addColumn(sm, layout.getCompanyId());
581:                    addColumn(sm, layout.isPrivateLayout());
582:                    addColumn(sm, layout.getLayoutId());
583:                    addColumn(sm, layout.getParentLayoutId());
584:                    addColumn(sm, layout.getName());
585:                    addColumn(sm, layout.getTitle());
586:                    addColumn(sm, layout.getType());
587:                    addColumn(sm, layout.getTypeSettings());
588:                    addColumn(sm, layout.isHidden());
589:                    addColumn(sm, layout.getFriendlyURL());
590:                    addColumn(sm, layout.isIconImage());
591:                    addColumn(sm, layout.getIconImageId());
592:                    //addColumn(sm, layout.getThemeId());
593:                    //addColumn(sm, layout.getColorSchemeId());
594:                    //addColumn(sm, layout.getWapThemeId());
595:                    //addColumn(sm, layout.getWapColorSchemeId());
596:                    addColumn(sm, layout.getCss());
597:                    addColumn(sm, layout.getPriority());
598:                    removeTrailingComma(sm);
599:                    sm.append(");\n");
600:                }
601:
602:                sm.append("\n");
603:
604:                itr = layouts.iterator();
605:
606:                while (itr.hasNext()) {
607:                    Layout layout = (Layout) itr.next();
608:
609:                    LayoutTypePortlet layoutType = (LayoutTypePortlet) layout
610:                            .getLayoutType();
611:
612:                    List portletIds = layoutType.getPortletIds();
613:
614:                    Collections.sort(portletIds);
615:
616:                    for (int i = 0; i < portletIds.size(); i++) {
617:                        String portletId = (String) portletIds.get(i);
618:
619:                        try {
620:                            PortletPreferences portletPreferences = PortletPreferencesLocalServiceUtil
621:                                    .getPortletPreferences(
622:                                            PortletKeys.PREFS_OWNER_ID_DEFAULT,
623:                                            PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
624:                                            layout.getPlid(), portletId);
625:
626:                            String prefsXml = portletPreferences
627:                                    .getPreferences();
628:
629:                            PortletPreferencesImpl prefs = (PortletPreferencesImpl) PortletPreferencesSerializer
630:                                    .fromDefaultXML(portletPreferences
631:                                            .getPreferences());
632:
633:                            String articleId = prefs.getValue("article-id",
634:                                    StringPool.BLANK);
635:
636:                            articleId = articleId.toUpperCase();
637:
638:                            if (Validator.isNotNull(articleId)) {
639:                                if (!JournalArticleLocalServiceUtil.hasArticle(
640:                                        layout.getGroupId(), articleId)) {
641:
642:                                    continue;
643:                                }
644:
645:                                // Make sure article id is upper case in the preferences
646:                                // XML
647:
648:                                prefs.setValue("article-id",
649:                                        getNewPrimaryKey(articleId));
650:
651:                                prefsXml = PortletPreferencesSerializer
652:                                        .toXML(prefs);
653:
654:                                // Add to the journal content search list
655:
656:                                long contentSearchId = CounterLocalServiceUtil
657:                                        .increment();
658:
659:                                JournalContentSearch journalContentSearch = JournalContentSearchUtil
660:                                        .create(contentSearchId);
661:
662:                                journalContentSearch
663:                                        .setContentSearchId(contentSearchId);
664:                                journalContentSearch.setCompanyId(layout
665:                                        .getCompanyId());
666:                                journalContentSearch.setGroupId(layout
667:                                        .getGroupId());
668:                                journalContentSearch.setPrivateLayout(layout
669:                                        .isPrivateLayout());
670:                                journalContentSearch.setPortletId(portletId);
671:                                journalContentSearch.setLayoutId(layout
672:                                        .getLayoutId());
673:                                journalContentSearch.setPortletId(portletId);
674:                                journalContentSearch
675:                                        .setArticleId(getNewPrimaryKey(articleId));
676:
677:                                journalContentSearches
678:                                        .add(journalContentSearch);
679:                            }
680:
681:                            sm.append("insert into PortletPreferences (");
682:                            sm
683:                                    .append("portletPreferencesId, ownerId, ownerType, ");
684:                            sm.append("plid, portletId, preferences");
685:                            sm.append(") values (");
686:                            addPKColumn(sm, portletPreferences
687:                                    .getPortletPreferencesId());
688:                            addColumn(sm, portletPreferences.getOwnerId());
689:                            addColumn(sm, portletPreferences.getOwnerType());
690:                            addPKColumn(sm, portletPreferences.getPlid());
691:                            addColumn(sm, portletId);
692:                            addColumn(sm, prefsXml);
693:                            removeTrailingComma(sm);
694:                            sm.append(");\n");
695:                        } catch (NoSuchPortletPreferencesException nsppe) {
696:                            _log.warn(nsppe.getMessage());
697:                        }
698:                    }
699:
700:                    sm.append("\n");
701:                }
702:
703:                removeTrailingNewLine(sm);
704:                removeTrailingNewLine(sm);
705:
706:                zipWriter.addEntry("portal-data-cms-layout.sql", sm);
707:            }
708:
709:            protected void insertDataImage(long groupId, ZipWriter zipWriter)
710:                    throws Exception {
711:
712:                StringMaker sm1 = new StringMaker();
713:                StringMaker sm2 = new StringMaker();
714:
715:                Iterator itr = ImageLocalServiceUtil.getImagesBySize(70000)
716:                        .iterator();
717:
718:                while (itr.hasNext()) {
719:                    Image image = (Image) itr.next();
720:
721:                    long imageId = image.getImageId();
722:
723:                    try {
724:                        UserLocalServiceUtil.getUserByPortraitId(imageId);
725:
726:                        continue;
727:                    } catch (NoSuchUserException nsue) {
728:                    }
729:
730:                    try {
731:                        IGImage igImage = IGImageLocalServiceUtil
732:                                .getImageBySmallImageId(imageId);
733:
734:                        IGFolder igFolder = igImage.getFolder();
735:
736:                        if (igFolder.getGroupId() != groupId) {
737:                            continue;
738:                        }
739:                    } catch (NoSuchImageException nsie) {
740:                    }
741:
742:                    try {
743:                        IGImage igImage = IGImageLocalServiceUtil
744:                                .getImageByLargeImageId(imageId);
745:
746:                        IGFolder igFolder = igImage.getFolder();
747:
748:                        if (igFolder.getGroupId() != groupId) {
749:                            continue;
750:                        }
751:                    } catch (NoSuchImageException nsie) {
752:                    }
753:
754:                    try {
755:                        JournalArticleImage journalArticleImage = JournalArticleImageLocalServiceUtil
756:                                .getArticleImage(imageId);
757:
758:                        if (journalArticleImage.getGroupId() != groupId) {
759:                            continue;
760:                        }
761:                    } catch (NoSuchArticleImageException nsaie) {
762:                    }
763:
764:                    try {
765:                        SCProductScreenshotLocalServiceUtil
766:                                .getProductScreenshotByFullImageId(imageId);
767:
768:                        continue;
769:                    } catch (NoSuchProductScreenshotException nspse) {
770:                    }
771:
772:                    try {
773:                        SCProductScreenshotLocalServiceUtil
774:                                .getProductScreenshotByThumbnailId(imageId);
775:
776:                        continue;
777:                    } catch (NoSuchProductScreenshotException nspse) {
778:                    }
779:
780:                    sm1.append("insert into Image (");
781:                    sm1
782:                            .append("imageId, modifiedDate, text_, type_, height, width, ");
783:                    sm1.append("size_");
784:                    sm1.append(") values (");
785:                    addPKColumn(sm1, imageId);
786:                    addColumn(sm1, image.getModifiedDate());
787:                    addColumn(sm1, image.getText(), false);
788:                    addColumn(sm1, image.getType());
789:                    addColumn(sm1, image.getHeight());
790:                    addColumn(sm1, image.getWidth());
791:                    addColumn(sm1, image.getSize());
792:                    removeTrailingComma(sm1);
793:                    sm1.append(");\n");
794:
795:                    sm2
796:                            .append("<img src=\"http://localhost:8080/image?img_id=");
797:                    sm2.append(imageId);
798:                    sm2.append("\" /><br />\n");
799:                }
800:
801:                removeTrailingNewLine(sm1);
802:
803:                zipWriter.addEntry("portal-data-image.sql", sm1);
804:                zipWriter.addEntry("portal-data-image.html", sm2);
805:            }
806:
807:            protected void removeTrailingComma(StringMaker sm) {
808:                sm.delete(sm.length() - 2, sm.length());
809:            }
810:
811:            protected void removeTrailingNewLine(StringMaker sm) {
812:                if (sm.length() > 0) {
813:                    sm.delete(sm.length() - 1, sm.length());
814:                }
815:            }
816:
817:            protected String replaceIds(String content) throws Exception {
818:                content = IdReplacer.replaceLongIds(content, "?img_id=",
819:                        _valueMapper);
820:
821:                return content;
822:            }
823:
824:            private static Log _log = LogFactory.getLog(ExportAction.class);
825:
826:            private MemoryValueMapper _valueMapper = new MemoryValueMapper();
827:            private Map _primaryKeys = _valueMapper.getMap();
828:            private int _primaryKeyCount;
829:
830:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.