1
19
20 package com.liferay.portal.theme;
21
22 import com.liferay.portal.kernel.util.GetterUtil;
23
24 import java.io.Serializable;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.regex.Matcher;
29 import java.util.regex.Pattern;
30
31
37 public class ThemeCompanyLimit implements Serializable {
38
39 public ThemeCompanyLimit() {
40 _includes = new ArrayList<ThemeCompanyId>();
41 _excludes = new ArrayList<ThemeCompanyId>();
42 }
43
44 public List<ThemeCompanyId> getIncludes() {
45 return _includes;
46 }
47
48 public void setIncludes(List<? extends ThemeCompanyId> includes) {
49 _includes = (List<ThemeCompanyId>)includes;
50 }
51
52 public boolean isIncluded(long companyId) {
53 return _matches(_includes, companyId);
54 }
55
56 public List<ThemeCompanyId> getExcludes() {
57 return _excludes;
58 }
59
60 public void setExcludes(List<? extends ThemeCompanyId> excludes) {
61 _excludes = (List<ThemeCompanyId>)excludes;
62 }
63
64 public boolean isExcluded(long companyId) {
65 return _matches(_excludes, companyId);
66 }
67
68 private boolean _matches(
69 List<ThemeCompanyId> themeCompanyIds, long companyId) {
70
71 for (int i = 0; i < themeCompanyIds.size(); i++) {
72 ThemeCompanyId themeCompanyId = themeCompanyIds.get(i);
73
74 String themeCompanyIdValue = themeCompanyId.getValue();
75
76 if (themeCompanyId.isPattern()) {
77 Pattern pattern = Pattern.compile(themeCompanyIdValue);
78 Matcher matcher = pattern.matcher(String.valueOf(companyId));
79
80 if (matcher.matches()) {
81 return true;
82 }
83 }
84 else {
85 long themeCompanyIdValueLong = GetterUtil.getLong(
86 themeCompanyIdValue);
87
88 if (themeCompanyIdValueLong == companyId) {
89 return true;
90 }
91 }
92 }
93
94 return false;
95 }
96
97 private List<ThemeCompanyId> _includes;
98 private List<ThemeCompanyId> _excludes;
99
100 }