01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Dec 21, 2006
14: * @author James Dixon
15: *
16: */
17:
18: package org.pentaho.core.output;
19:
20: import java.io.File;
21: import java.io.FileNotFoundException;
22: import java.io.FileOutputStream;
23:
24: import org.apache.commons.logging.Log;
25: import org.apache.commons.logging.LogFactory;
26: import org.pentaho.core.repository.IContentItem;
27: import org.pentaho.core.services.SimpleContentItem;
28:
29: public class FileOutputHandler extends BaseOutputHandler {
30: protected static final Log logger = LogFactory
31: .getLog(FileOutputHandler.class);
32:
33: public IContentItem getFileOutputContentItem() {
34:
35: String contentRef = getContentRef();
36: File file = new File(contentRef);
37: File dir = file.getParentFile();
38: if (!dir.exists()) {
39: dir.mkdirs();
40: }
41: try {
42: FileOutputStream outputStream = new FileOutputStream(file);
43: SimpleContentItem content = new SimpleContentItem(
44: outputStream);
45: return content;
46: } catch (FileNotFoundException e) {
47: logger.error(null, e);
48: }
49: return null;
50: }
51:
52: }
|