KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > content > explorer > component > UIFileContentViewer


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.content.explorer.component;
6
7 import org.exoplatform.commons.utils.IOUtil;
8 import org.exoplatform.portlets.content.explorer.component.model.*;
9 /**
10  * @email: tuan08@users.sourceforge.net
11  * @version: $Id: UIContentDisplayer.java,v 1.2 2004/08/07 18:11:26 tuan08 Exp $
12  */

13 public class UIFileContentViewer extends UIContentViewer {
14   public UIFileContentViewer() {
15     
16   }
17   
18   public void onChange(UIExplorer uiExplorer, NodeDescriptor node) {
19     if(!node.isLeafNode()) {
20       setRendered(false) ;
21       return;
22     }
23     String JavaDoc content = "" ;
24     String JavaDoc mimeType = node.getNodeType() ;
25     try {
26       UIFileExplorer uiFileExplorer = (UIFileExplorer) uiExplorer ;
27       String JavaDoc uri = node.getUri() ;
28       renderer_ = getRenderer(mimeType) ;
29       if (renderer_ != null) {
30         if (mimeType.startsWith("text")) {
31           FileNodeDescriptor fnode = (FileNodeDescriptor) node ;
32           if(fnode.getCacheContent() == null ) {
33             String JavaDoc realPath = uiFileExplorer.getRealPathBaseDir() + uri ;
34             content = IOUtil.getFileContenntAsString(realPath) ;
35             fnode.setCacheContent(content) ;
36           } else {
37             content = fnode.getCacheContent() ;
38           }
39         } else {
40           String JavaDoc relativePath = uiFileExplorer.getRelativePathBaseDir() + uri ;
41           content = "/content/file" + relativePath ;
42         }
43       } else {
44         String JavaDoc relativePath = uiFileExplorer.getRelativePathBaseDir() + uri ;
45         renderer_ = getRenderer("default") ;
46         content = "/content/file" + relativePath ;
47         /*
48         content =
49           "\n<script language='JavaScript'>\n" +
50           " myFloater = window.open('','myWindow','scrollbars=no,status=no,width=300,height=300');\n" +
51           " myFloater.location = '/content/FileContentServlet?path=" + relativePath + "';\n" +
52           "</script>\n" ;
53           */

54       }
55     } catch (Exception JavaDoc ex) {
56       renderer_ = getRenderer("text/plain") ;
57       content = org.exoplatform.commons.utils.ExceptionUtil.getExoStackTrace(ex) ;
58     }
59     setContent(content) ;
60     setContentType(mimeType) ;
61     setRendered(true) ;
62   }
63   
64   public void onModify(UIExplorer uiExplorer, NodeDescriptor node) {
65     FileNodeDescriptor fnode = (FileNodeDescriptor) node ;
66     setContent(fnode.getCacheContent()) ;
67   }
68 }
69
Popular Tags