001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
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.war.beans.admin.search;
034:
035: import com.flexive.faces.FxJsfUtils;
036: import com.flexive.faces.beans.ActionBean;
037: import com.flexive.faces.model.FxResultSetDataModel;
038: import com.flexive.shared.CacheAdmin;
039: import com.flexive.shared.exceptions.FxApplicationException;
040: import com.flexive.shared.exceptions.FxInvalidParameterException;
041: import com.flexive.shared.search.FxResultSet;
042: import com.flexive.shared.search.query.PropertyValueComparator;
043: import com.flexive.shared.search.query.SqlQueryBuilder;
044: import com.flexive.shared.structure.FxAssignment;
045: import com.flexive.shared.structure.FxPropertyAssignment;
046: import com.flexive.shared.structure.FxType;
047: import org.apache.commons.lang.StringUtils;
048: import org.apache.commons.logging.Log;
049: import org.apache.commons.logging.LogFactory;
050:
051: /**
052: * Provides a simple reference browser, currently without pagination.
053: *
054: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
055: * @version $Rev: 191 $
056: */
057: public class BrowseReferencesBean implements ActionBean {
058: private static final Log LOG = LogFactory
059: .getLog(BrowseReferencesBean.class);
060: private String xPath;
061: private String inputName;
062: private String formName;
063: private String query;
064: private FxResultSetDataModel dataModel;
065:
066: /**
067: * {@inheritDoc}
068: */
069: public String getParseRequestParameters() {
070: setXPath(StringUtils.defaultIfEmpty(FxJsfUtils
071: .getParameter("xPath"), xPath));
072: setInputName(StringUtils.defaultIfEmpty(FxJsfUtils
073: .getParameter("inputName"), inputName));
074: setFormName(StringUtils.defaultIfEmpty(FxJsfUtils
075: .getParameter("formName"), formName));
076: return null;
077: }
078:
079: public FxResultSetDataModel getDataModel()
080: throws FxApplicationException {
081: if (dataModel == null) {
082: if (StringUtils.isBlank(xPath)) {
083: return null;
084: }
085: final FxAssignment fxAssignment = CacheAdmin
086: .getEnvironment().getAssignment(xPath);
087: if (!(fxAssignment instanceof FxPropertyAssignment)) {
088: throw new FxInvalidParameterException("xPath",
089: "ex.browseReferences.assignment.type", LOG,
090: xPath, fxAssignment).asRuntimeException();
091: }
092: final FxPropertyAssignment assignment = (FxPropertyAssignment) fxAssignment;
093: final FxType referencedType = assignment.getProperty()
094: .getReferencedType();
095: if (referencedType == null) {
096: throw new FxInvalidParameterException("xPath",
097: "ex.browseReferences.assignment.reference",
098: LOG, xPath).asRuntimeException();
099: }
100: dataModel = new FxResultSetDataModel(getQueryBuilder(
101: referencedType).getResult());
102: }
103: return dataModel;
104: }
105:
106: private SqlQueryBuilder getQueryBuilder(FxType referencedType) {
107: final SqlQueryBuilder builder = new SqlQueryBuilder().select(
108: "@pk", "*").filterType(referencedType.getId())
109: .condition("TYPEDEF", PropertyValueComparator.EQ,
110: referencedType.getId());
111: return builder;
112: }
113:
114: public FxResultSet getResultSet() throws FxApplicationException {
115: return getDataModel() != null ? getDataModel().getResult()
116: : null;
117: }
118:
119: public String getXPath() {
120: return xPath;
121: }
122:
123: public void setXPath(String xPath) {
124: this .xPath = xPath;
125: }
126:
127: public String getInputName() {
128: return inputName;
129: }
130:
131: public void setInputName(String inputName) {
132: this .inputName = inputName;
133: }
134:
135: public String getFormName() {
136: return formName;
137: }
138:
139: public void setFormName(String formName) {
140: this .formName = formName;
141: }
142:
143: public String getQuery() {
144: return query;
145: }
146:
147: public void setQuery(String query) {
148: this.query = query;
149: }
150: }
|