1
14
15 package com.liferay.portal.upgrade.v5_1_0.util;
16
17 import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
18 import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.kernel.util.Validator;
21 import com.liferay.portlet.blogs.util.BlogsUtil;
22
23 import java.util.HashSet;
24 import java.util.Set;
25
26
32 public class BlogsEntryUrlTitleUpgradeColumnImpl extends BaseUpgradeColumnImpl {
33
34 public BlogsEntryUrlTitleUpgradeColumnImpl(
35 UpgradeColumn entryIdColumn, UpgradeColumn titleColumn) {
36
37 super("urlTitle");
38
39 _entryIdColumn = entryIdColumn;
40 _titleColumn = titleColumn;
41 _urlTitles = new HashSet<String>();
42 }
43
44 public Object getNewValue(Object oldValue) throws Exception {
45 String oldUrlTitle = StringPool.BLANK;
47
48 String newUrlTitle = oldUrlTitle;
49
50 if (Validator.isNull(oldUrlTitle)) {
51 long entryId = ((Long)_entryIdColumn.getOldValue()).longValue();
52
53 String title = (String)_titleColumn.getOldValue();
54
55 newUrlTitle = getUrlTitle(entryId, title);
56
57 _urlTitles.add(newUrlTitle);
58 }
59
60 return newUrlTitle;
61 }
62
63 protected String getUrlTitle(long entryId, String title) {
64 String urlTitle = BlogsUtil.getUrlTitle(entryId, title);
65
66 String newUrlTitle = urlTitle;
67
68 for (int i = 1;; i++) {
69 if (!_urlTitles.contains(newUrlTitle)) {
70 break;
71 }
72
73 newUrlTitle = urlTitle + "_" + i;
74 }
75
76 return newUrlTitle;
77 }
78
79 private UpgradeColumn _entryIdColumn;
80 private UpgradeColumn _titleColumn;
81 private Set<String> _urlTitles;
82
83 }