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