001: /**
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created January 3rd, 2006
014: * @author Michael D'Amour
015: **/package org.pentaho.plugin.core;
016:
017: import java.util.Set;
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.pentaho.commons.connection.DataUtilities;
021: import org.pentaho.commons.connection.IPentahoResultSet;
022: import org.pentaho.messages.Messages;
023: import org.pentaho.plugin.ComponentBase;
024:
025: /**
026: *
027: * Implements a PrintComponent class that will send a attached print file to a
028: * specified printer.
029: */
030: public class ResultSetExportComponent extends ComponentBase {
031: /**
032: *
033: */
034: private static final long serialVersionUID = 3289900246113442203L;
035:
036: public Log getLogger() {
037: return LogFactory.getLog(ResultSetExportComponent.class);
038: }
039:
040: public boolean init() {
041: // TODO Auto-generated method stub
042: return true;
043: }
044:
045: protected boolean validateSystemSettings() {
046: // This component does not have any system settings to validate
047: return true;
048: }
049:
050: protected boolean validateAction() {
051: boolean hasResultSetParameter = isDefinedInput("result-set"); //$NON-NLS-1$
052: if (!hasResultSetParameter) {
053: error(Messages
054: .getString("JFreeReport.ERROR_0022_DATA_INPUT_INVALID_OBJECT")); //$NON-NLS-1$
055: return false;
056: }
057: if (getResultOutputName() == null) {
058: error(Messages
059: .getString("JFreeReport.ERROR_0022_DATA_INPUT_INVALID_OBJECT")); //$NON-NLS-1$
060: return false;
061: }
062: return true;
063: }
064:
065: protected boolean executeAction() {
066: Object resultSetObject = getInputValue("result-set"); //$NON-NLS-1$
067: if (resultSetObject instanceof IPentahoResultSet) {
068: IPentahoResultSet resultset = (IPentahoResultSet) resultSetObject;
069: if (getResultOutputName() != null) {
070: setOutputValue(getResultOutputName(), DataUtilities
071: .getXMLString(resultset));
072: }
073: return true;
074: } else {
075: return false;
076: }
077: }
078:
079: public void done() {
080: // TODO Auto-generated method stub
081: }
082:
083: public String getResultOutputName() {
084: Set outputs = getOutputNames();
085: if ((outputs == null) || (outputs.size() == 0)) {
086: error(Messages
087: .getString("Template.ERROR_0002_OUTPUT_COUNT_WRONG")); //$NON-NLS-1$
088: return null;
089: }
090: String outputName = null;
091: try {
092: outputName = getInputStringValue(StandardSettings.OUTPUT_NAME);
093: } catch (Exception e) {
094: }
095: if (outputName == null) { // Drop back to the old behavior
096: outputName = (String) outputs.iterator().next();
097: }
098: return outputName;
099: }
100: }
|