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
39 public class ThemeCompanyLimit implements Serializable {
40
41 public ThemeCompanyLimit() {
42 _includes = new ArrayList<ThemeCompanyId>();
43 _excludes = new ArrayList<ThemeCompanyId>();
44 }
45
46 public List<ThemeCompanyId> getIncludes() {
47 return _includes;
48 }
49
50 public void setIncludes(List<? extends ThemeCompanyId> includes) {
51 _includes = (List<ThemeCompanyId>)includes;
52 }
53
54 public boolean isIncluded(long companyId) {
55 return _matches(_includes, companyId);
56 }
57
58 public List<ThemeCompanyId> getExcludes() {
59 return _excludes;
60 }
61
62 public void setExcludes(List<? extends ThemeCompanyId> excludes) {
63 _excludes = (List<ThemeCompanyId>)excludes;
64 }
65
66 public boolean isExcluded(long companyId) {
67 return _matches(_excludes, companyId);
68 }
69
70 private boolean _matches(
71 List<ThemeCompanyId> themeCompanyIds, long companyId) {
72
73 for (int i = 0; i < themeCompanyIds.size(); i++) {
74 ThemeCompanyId themeCompanyId = themeCompanyIds.get(i);
75
76 String themeCompanyIdValue = themeCompanyId.getValue();
77
78 if (themeCompanyId.isPattern()) {
79 Pattern pattern = Pattern.compile(themeCompanyIdValue);
80 Matcher matcher = pattern.matcher(String.valueOf(companyId));
81
82 if (matcher.matches()) {
83 return true;
84 }
85 }
86 else {
87 long themeCompanyIdValueLong = GetterUtil.getLong(
88 themeCompanyIdValue);
89
90 if (themeCompanyIdValueLong == companyId) {
91 return true;
92 }
93 }
94 }
95
96 return false;
97 }
98
99 private List<ThemeCompanyId> _includes;
100 private List<ThemeCompanyId> _excludes;
101
102 }