001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.sqlParser;
034:
035: import com.flexive.shared.search.query.VersionFilter;
036:
037: import java.util.HashMap;
038: import java.util.Locale;
039:
040: /**
041: * Table
042: *
043: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
044: */
045: public class Table {
046:
047: public enum TYPE {
048: CONTENT
049: }
050:
051: private String sAlias;
052: private TYPE tType;
053: private HashMap<Filter.TYPE, Filter> filters;
054: private String searchLanguages[];
055:
056: /**
057: * Returns the languages that should be searched in.
058: *
059: * @return the languages that should be searched in
060: */
061: public String[] getSearchLanguages() {
062: return searchLanguages == null ? new String[0]
063: : searchLanguages;
064: }
065:
066: /**
067: * Returns the version filter for the table.
068: * <p />
069: * Possible return values are:<br>
070: * "MAX","LIVE","ALL" or an integer array (eg "1,4,7")
071: *
072: * @return the version filter for the table.
073: */
074: public String getVersionFilter() {
075: Filter f = getFilter(Filter.TYPE.VERSION);
076: if (f == null) {
077: return VersionFilter.MAX.toString();
078: } else {
079: return f.getValue();
080: }
081: }
082:
083: /**
084: * Sets the available languages for the table.
085: * <p />
086: *
087: * @param isoCodes the iso codes
088: * @throws SqlParserException
089: */
090: protected void setSearchLanguages(String isoCodes[])
091: throws SqlParserException {
092: // searchLanguages contains all available options, filter out all unused
093: // entries.
094: if (isoCodes == null) {
095: isoCodes = new String[0];
096: }
097: for (String code : isoCodes) {
098: boolean found = false;
099: for (String loc : Locale.getISOLanguages()) {
100: if (code.equalsIgnoreCase(loc)) {
101: found = true;
102: break;
103: }
104: }
105: if (!found) {
106: throw new SqlParserException(
107: "ex.sqlSearch.languages.unknownIsoCode", code);
108: }
109: }
110: this .searchLanguages = isoCodes;
111: }
112:
113: /**
114: * Constructor.
115: *
116: * @param type the type
117: * @param alias the alias
118: * @throws SqlParserException
119: */
120: protected Table(String type, String alias)
121: throws SqlParserException {
122: if (!type.equalsIgnoreCase("CONTENT")) {
123: throw new SqlParserException(
124: "ex.sqlSearch.table.typeNotSupported", type
125: .toUpperCase());
126: }
127: //this.searchLanguages = getAvailableLanguages();
128: this .tType = TYPE.CONTENT;
129: this .sAlias = alias.toUpperCase();
130: this .filters = new HashMap<Filter.TYPE, Filter>(5);
131: }
132:
133: /**
134: * Adds a table specific filter.
135: *
136: * @param f the filter to add
137: */
138: protected void addFilter(Filter f) {
139: this .filters.put(f.getType(), f);
140: }
141:
142: /**
143: * Returns the table alias.
144: *
145: * @return the table alias.
146: */
147: public String getAlias() {
148: return sAlias;
149: }
150:
151: /**
152: * Returns the table type.
153: *
154: * @return the table type
155: */
156: public TYPE getType() {
157: return tType;
158: }
159:
160: /**
161: * Returns a string representation of the table.
162: *
163: * @return a string representation of the table.
164: */
165: public String toString() {
166: return "table[alias:" + sAlias + ";type:" + tType + "]";
167: }
168:
169: /**
170: * Returns the desired filter, or null if the filter was not specified and has no
171: * default value.
172: *
173: * @param t the filter to get
174: * @return the filter
175: */
176: public Filter getFilter(Filter.TYPE t) {
177: return this.filters.get(t);
178: }
179:
180: }
|