1
22
23 package com.liferay.portal.upgrade.v5_1_0.util;
24
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.kernel.util.Validator;
27 import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
28 import com.liferay.portal.upgrade.util.UpgradeColumn;
29 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
30
31 import java.util.HashSet;
32 import java.util.Set;
33
34
40 public class BlogsEntryUrlTitleUpgradeColumnImpl extends BaseUpgradeColumnImpl {
41
42 public BlogsEntryUrlTitleUpgradeColumnImpl(
43 UpgradeColumn entryIdColumn, UpgradeColumn titleColumn) {
44
45 super("urlTitle");
46
47 _entryIdColumn = entryIdColumn;
48 _titleColumn = titleColumn;
49 _urlTitles = new HashSet<String>();
50 }
51
52 public Object getNewValue(Object oldValue) throws Exception {
53 String oldUrlTitle = StringPool.BLANK;
55
56 String newUrlTitle = oldUrlTitle;
57
58 if (Validator.isNull(oldUrlTitle)) {
59 long entryId = ((Long)_entryIdColumn.getOldValue()).longValue();
60
61 String title = (String)_titleColumn.getOldValue();
62
63 newUrlTitle = getUrlTitle(entryId, title);
64
65 _urlTitles.add(newUrlTitle);
66 }
67
68 return newUrlTitle;
69 }
70
71 protected String getUrlTitle(long entryId, String title) {
72 String urlTitle = BlogsEntryLocalServiceUtil.getUrlTitle(
73 entryId, title);
74
75 String newUrlTitle = new String(urlTitle);
76
77 for (int i = 1;; i++) {
78 if (!_urlTitles.contains(newUrlTitle)) {
79 break;
80 }
81
82 newUrlTitle = urlTitle + "_" + i;
83 }
84
85 return newUrlTitle;
86 }
87
88 private UpgradeColumn _entryIdColumn;
89 private UpgradeColumn _titleColumn;
90 private Set<String> _urlTitles;
91
92 }