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 Jun 23, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.plugin.core;
018:
019: import java.io.OutputStream;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.pentaho.actionsequence.dom.actions.ActionFactory;
024: import org.pentaho.actionsequence.dom.actions.EmailAction;
025: import org.pentaho.actionsequence.dom.actions.HelloWorldAction;
026: import org.pentaho.actionsequence.dom.actions.JFreeReportAction;
027: import org.pentaho.core.solution.ActionSequenceParameterMgr;
028: import org.pentaho.messages.Messages;
029: import org.pentaho.messages.util.LocaleHelper;
030: import org.pentaho.plugin.ComponentBase;
031:
032: /**
033: * @author James Dixon
034: *
035: * TODO To change the template for this generated type comment go to Window -
036: * Preferences - Java - Code Style - Code Templates
037: */
038: public class HelloWorldComponent extends ComponentBase {
039:
040: /**
041: *
042: */
043: private static final long serialVersionUID = 9050456842938084174L;
044:
045: public Log getLogger() {
046: return LogFactory.getLog(HelloWorldComponent.class);
047: }
048:
049: protected boolean validateSystemSettings() {
050: // This component does not have any system settings to validate
051: return true;
052: }
053:
054: protected boolean validateAction() {
055: boolean result = true;
056: if (!(getActionDefinition() instanceof HelloWorldAction)) {
057: error(Messages
058: .getErrorString(
059: "ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", getActionDefinition().getElement().asXML())); //$NON-NLS-1$
060: result = false;
061: }
062: return result;
063: }
064:
065: public void done() {
066: }
067:
068: protected boolean executeAction() {
069: HelloWorldAction helloWorldAction = (HelloWorldAction) getActionDefinition();
070: boolean result = true;
071:
072: // return the quote as the result of this component
073: String msg = Messages
074: .getString(
075: "HelloWorld.USER_HELLO_WORLD_TEXT", helloWorldAction.getQuote().getStringValue("")); //$NON-NLS-1$
076:
077: OutputStream outputStream = getDefaultOutputStream("text/html"); //$NON-NLS-1$
078: if (outputStream != null) {
079: try {
080: outputStream.write(msg.getBytes(LocaleHelper
081: .getSystemEncoding()));
082: } catch (Exception e) {
083: error(
084: Messages
085: .getErrorString("HelloWorld.ERROR_0001_COULDNOTWRITE"), e); //$NON-NLS-1$
086: result = false;
087: }
088: }
089:
090: info(msg);
091: return result;
092: }
093:
094: public boolean init() {
095:
096: // nothing to do here really
097: return true;
098: }
099:
100: }
|