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.OutputStream;
21:
22: import org.apache.commons.vfs.FileContent;
23: import org.apache.commons.vfs.FileObject;
24: import org.apache.commons.vfs.FileSystemManager;
25: import org.apache.commons.vfs.VFS;
26: import org.pentaho.core.repository.IContentItem;
27: import org.pentaho.core.services.SimpleContentItem;
28: import org.pentaho.util.logging.Logger;
29: import org.pentaho.messages.Messages;
30:
31: public class ApacheVFSOutputHandler extends BaseOutputHandler {
32:
33: public IContentItem getFileOutputContentItem() {
34:
35: String contentRef = getContentRef();
36: try {
37: String contentName = getHandlerId().substring(4)
38: + ":" + contentRef; //$NON-NLS-1$
39: FileSystemManager fsManager = VFS.getManager();
40: if (fsManager == null) {
41: Logger
42: .error(
43: ApacheVFSOutputHandler.class.getName(),
44: Messages
45: .getString("ApacheVFSOutputHandler.ERROR_0001_CANNOT_GET_VFSMGR")); //$NON-NLS-1$
46: return null;
47: }
48: FileObject file = fsManager.resolveFile(contentName);
49: if (file == null) {
50: Logger
51: .error(
52: ApacheVFSOutputHandler.class.getName(),
53: Messages
54: .getString(
55: "ApacheVFSOutputHandler.ERROR_0002_CANNOT_GET_VF", contentName)); //$NON-NLS-1$
56: return null;
57: }
58: if (!file.isWriteable()) {
59: Logger
60: .error(
61: ApacheVFSOutputHandler.class.getName(),
62: Messages
63: .getString(
64: "ApacheVFSOutputHandler.ERROR_0003_CANNOT_WRITE", contentName)); //$NON-NLS-1$
65: return null;
66: }
67: FileContent fileContent = file.getContent();
68: if (fileContent == null) {
69: Logger
70: .error(
71: ApacheVFSOutputHandler.class.getName(),
72: Messages
73: .getString(
74: "ApacheVFSOutputHandler.ERROR_0004_CANNOT_GET_CTX", contentName)); //$NON-NLS-1$
75: return null;
76: }
77: OutputStream outputStream = fileContent.getOutputStream();
78:
79: SimpleContentItem content = new SimpleContentItem(
80: outputStream);
81: return content;
82: } catch (Throwable t) {
83: Logger
84: .error(
85: ApacheVFSOutputHandler.class.getName(),
86: Messages
87: .getString(
88: "ApacheVFSOutputHandler.ERROR_0005_CANNOT_GET_HANDLER", contentRef), t); //$NON-NLS-1$
89: }
90:
91: return null;
92: }
93:
94: }
|