001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.theme;
022:
023: import java.io.Serializable;
024:
025: import java.util.ArrayList;
026: import java.util.List;
027: import java.util.regex.Matcher;
028: import java.util.regex.Pattern;
029:
030: /**
031: * <a href="ThemeCompanyLimit.java.html"><b><i>View Source</i></b></a>
032: *
033: * @author Brian Wing Shun Chan
034: *
035: */
036: public class ThemeCompanyLimit implements Serializable {
037:
038: public ThemeCompanyLimit() {
039: _includes = new ArrayList();
040: _excludes = new ArrayList();
041: }
042:
043: public List getIncludes() {
044: return _includes;
045: }
046:
047: public void setIncludes(List includes) {
048: _includes = includes;
049: }
050:
051: public boolean isIncluded(long companyId) {
052: return _matches(_includes, companyId);
053: }
054:
055: public List getExcludes() {
056: return _excludes;
057: }
058:
059: public void setExcludes(List excludes) {
060: _excludes = excludes;
061: }
062:
063: public boolean isExcluded(long companyId) {
064: return _matches(_excludes, companyId);
065: }
066:
067: private boolean _matches(List themeCompanyIds, long companyId) {
068: for (int i = 0; i < themeCompanyIds.size(); i++) {
069: ThemeCompanyId themeCompanyId = (ThemeCompanyId) themeCompanyIds
070: .get(i);
071:
072: String themeCompanyIdValue = themeCompanyId.getValue();
073:
074: if (themeCompanyId.isPattern()) {
075: Pattern pattern = Pattern.compile(themeCompanyIdValue);
076: Matcher matcher = pattern.matcher(String
077: .valueOf(companyId));
078:
079: if (matcher.matches()) {
080: return true;
081: }
082: } else {
083: Long themeCompanyIdValueLong = new Long(0);
084:
085: try {
086: themeCompanyIdValueLong = new Long(
087: themeCompanyIdValue);
088: } catch (Exception e) {
089: }
090:
091: if (themeCompanyIdValueLong.longValue() == companyId) {
092: return true;
093: }
094: }
095: }
096:
097: return false;
098: }
099:
100: private List _includes;
101: private List _excludes;
102:
103: }
|