001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/reports/tool/src/java/org/theospi/portfolio/reports/tool/DecoratedReportResult.java $
003: * $Id:DecoratedReportResult.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006, 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.reports.tool;
021:
022: import org.theospi.portfolio.reports.model.*;
023:
024: import javax.faces.event.ValueChangeEvent;
025: import javax.faces.model.SelectItem;
026: import java.io.IOException;
027: import java.io.UnsupportedEncodingException;
028: import java.net.URLEncoder;
029: import java.util.ArrayList;
030: import java.util.Date;
031: import java.util.Iterator;
032: import java.util.List;
033:
034: /**
035: * This class allows the ReportResult to interact with the view
036: *
037: */
038: public class DecoratedReportResult implements DecoratedAbstractResult {
039:
040: /** The link to the main tool */
041: private ReportsTool reportsTool = null;
042:
043: private ReportResult reportResult = null;
044: private Report report = null;
045:
046: private String currentViewXsl = null;
047: private String currentExportXsl = null;
048:
049: public DecoratedReportResult(ReportResult reportResult,
050: ReportsTool reportsTool) {
051: this .reportResult = reportResult;
052: this .reportsTool = reportsTool;
053: this .report = reportResult.getReport();
054: this .report.connectToDefinition(reportsTool.getReportsManager()
055: .getReportDefinitions());
056: getExportXslSeletionList();
057: }
058:
059: public Report getReport() {
060: return report;
061: }
062:
063: public ReportResult getReportResult() {
064: return reportResult;
065: }
066:
067: public List getViewXslSeletionList() {
068: List options = new ArrayList();
069:
070: if (report.getReportDefinition() != null
071: && report.getReportDefinition().getXsls() != null) {
072: Iterator iter = report.getReportDefinition().getXsls()
073: .iterator();
074:
075: while (iter.hasNext()) {
076: ReportXsl xsl = (ReportXsl) iter.next();
077:
078: if (!xsl.getIsExport()) {
079: String xslTitle = xsl.getTitle();
080: if (xslTitle == null
081: || xslTitle.trim().length() == 0)
082: xslTitle = xsl.getXslLink();
083: options.add(new SelectItem(xsl.getXslLink(),
084: xslTitle));
085: }
086: }
087: }
088: return options;
089: }
090:
091: public List getExportXslSeletionList() {
092: List options = new ArrayList();
093:
094: if (report.getReportDefinition() != null
095: && report.getReportDefinition().getXsls() != null) {
096: Iterator iter = report.getReportDefinition().getXsls()
097: .iterator();
098:
099: while (iter.hasNext()) {
100: ReportXsl xsl = (ReportXsl) iter.next();
101:
102: if (xsl.getIsExport()) {
103: if (getCurrentExportXsl() == null) {
104: setCurrentExportXsl(xsl.getRuntimeId());
105: }
106: String xslTitle = xsl.getTitle();
107: if (xslTitle == null
108: || xslTitle.trim().length() == 0)
109: xslTitle = xsl.getXslLink();
110: options.add(new SelectItem(xsl.getRuntimeId(),
111: xslTitle));
112: }
113: }
114: }
115: return options;
116: }
117:
118: public void changeExportXsl(ValueChangeEvent event) {
119: event.getComponent();
120: }
121:
122: public String getCurrentExportLink() {
123: ReportXsl xsl = getExportXsl();
124:
125: String extention = "";
126: if (xsl.getExtension() != null) {
127: extention = "." + xsl.getExtension();
128: }
129: try {
130: return "repository/"
131: + "manager="
132: + ReportsManager.class.getName()
133: + "&"
134: + ReportsManager.EXPORT_XSL_ID
135: + "="
136: + URLEncoder.encode(xsl.getRuntimeId(), "UTF-8")
137: + "/"
138: + URLEncoder.encode(getReport().getTitle()
139: + extention, "UTF-8");
140: } catch (UnsupportedEncodingException e) {
141: throw new RuntimeException(e);
142: }
143: }
144:
145: public ReportXsl getExportXsl() {
146: if (report.getReportDefinition() == null) {
147: report.connectToDefinition(reportsTool.getReportsManager()
148: .getReportDefinitions());
149: }
150: ReportXsl xsl = getReport().getReportDefinition()
151: .findReportXslByRuntimeId(getCurrentExportXsl());
152: return xsl;
153: }
154:
155: public boolean isExportable() {
156: List xsls = getExportXslSeletionList();
157:
158: return xsls != null && xsls.size() > 0;
159: }
160:
161: protected ReportXsl getCurrentView() {
162: return getView(getCurrentViewXsl());
163: }
164:
165: public String getCurrentViewXsl() {
166: if (currentViewXsl == null) {
167: if (report.getReportDefinition() == null) {
168: report.connectToDefinition(reportsTool
169: .getReportsManager().getReportDefinitions());
170: }
171: return report.getReportDefinition().getDefaultXsl()
172: .getXslLink();
173: }
174: return currentViewXsl;
175: }
176:
177: public void setCurrentViewXsl(String currentViewXsl) {
178: if (isAView(currentViewXsl))
179: this .currentViewXsl = currentViewXsl;
180: }
181:
182: public String getCurrentExportXsl() {
183: return currentExportXsl;
184: }
185:
186: public void setCurrentExportXsl(String currentExportXsl) {
187: this .currentExportXsl = currentExportXsl;
188: }
189:
190: public boolean getIsSaved() {
191: return reportResult.getIsSaved();
192: }
193:
194: /**
195: * this function loads the full report result and the report
196: * sets these in the tool
197: * @return String which page to go to next
198: */
199: public String processSelectReportResult() {
200: return reportsTool.processSelectReportResult(this );
201: }
202:
203: public void processShareReportResult() {
204: reportsTool.processActionAudienceHelper(this );
205: }
206:
207: /**
208: * this function deletes the full report result and the report
209: * sets these in the tool
210: * @return String which page to go to next
211: */
212: public String processDelete() {
213: return reportsTool.processDeleteReportResult(this );
214: }
215:
216: /**
217: * This generates the final html based on the selected XSL and the result (xml).
218: * @return String
219: */
220: public String getCurrentViewResults() {
221: //use the getter for the currentViewXsl so we handle null correctly
222: return reportsTool.getReportsManager().transform(reportResult,
223: getCurrentView());
224: }
225:
226: /**
227: * This is the tester for whether a view is in the list of views (not exports)
228: * @param view String
229: * @return boolean
230: */
231: private boolean isAView(String view) {
232: return getView(view) != null;
233: }
234:
235: protected ReportXsl getView(String link) {
236: ReportDefinition rdef = report.getReportDefinition();
237:
238: Iterator iter = rdef.getXsls().iterator();
239:
240: while (iter.hasNext()) {
241: ReportXsl xsl = (ReportXsl) iter.next();
242: xsl.setReportDefinition(rdef);
243: if (!xsl.getIsExport())
244: if (xsl.getXslLink().equals(link)) {
245: xsl.setReportDefinition(rdef);
246: return xsl;
247: }
248: }
249: return null;
250: }
251:
252: public String getResultType() {
253: return DecoratedAbstractResult.RESULT;
254: }
255:
256: public String getTitle() {
257: return reportResult.getTitle();
258: }
259:
260: public Date getCreationDate() {
261: return reportResult.getCreationDate();
262: }
263:
264: public boolean getIsLive() {
265: return report.getIsLive() && !reportResult.getIsSaved();
266: }
267:
268: public boolean getIsOwner() {
269: return reportResult.isOwner();
270:
271: }
272:
273: public String processSaveResultToResources() throws IOException {
274: return reportsTool.processSaveResultsToResources(this);
275: }
276:
277: }
|