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