KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > search > component > UIViewDocument


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.faces.search.component;
6
7 import org.apache.lucene.document.Document;
8 import org.exoplatform.commons.utils.HtmlUtil;
9 import org.exoplatform.faces.core.component.UIExoCommand;
10 import org.exoplatform.faces.core.component.model.Parameter;
11 import org.exoplatform.faces.core.event.ExoActionEvent;
12 import org.exoplatform.faces.core.event.ExoActionListener;
13 import org.exoplatform.services.indexing.IndexerPlugin;
14 import org.exoplatform.services.indexing.IndexingService;
15 /**
16  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
17  * @since Aug 27, 2004
18  * @version $Id: UIViewDocument.java,v 1.2 2004/11/03 01:20:37 tuan08 Exp $
19  */

20 public class UIViewDocument extends UIExoCommand {
21   final static public String JavaDoc COMPONENT_FAMILY = "org.exoplatform.faces.search.component.UIViewDocument" ;
22   public final static String JavaDoc TEXT_FORMAT = "TEXT_FORMAT" ;
23   public final static String JavaDoc HTML_FORMAT = "HTML_FORMAT" ;
24   public final static String JavaDoc XML_FORMAT = "XML_FORMAT" ;
25   public final static String JavaDoc FORMAT_TYPE = "format" ;
26   public final static String JavaDoc CHANGE_FORMAT_ACTION = "changeFormat" ;
27  
28   public static Parameter[] htmlFormatParams_ = {
29       new Parameter(ACTION, CHANGE_FORMAT_ACTION),
30       new Parameter(FORMAT_TYPE, HTML_FORMAT)
31   };
32   public static Parameter[] xmlFormatParams_ = {
33       new Parameter(ACTION, CHANGE_FORMAT_ACTION),
34       new Parameter(FORMAT_TYPE, XML_FORMAT)
35   };
36   public static Parameter[] textFormatParams_ = {
37       new Parameter(ACTION, CHANGE_FORMAT_ACTION),
38       new Parameter(FORMAT_TYPE, TEXT_FORMAT)
39   };
40   public static Parameter[] cancelParams_ = {
41       new Parameter(ACTION, CANCEL_ACTION)
42   };
43
44   private String JavaDoc text_ ;
45   private Document document_ ;
46   private IndexingService iservice_ ;
47   
48   public UIViewDocument(IndexingService iservice) {
49     setId("UIViewDocument") ;
50     setClazz("UIViewDocument");
51     setRendererType("ViewDocumentRenderer") ;
52     iservice_ = iservice ;
53     addActionListener(ChangeFormatActionListener.class, CHANGE_FORMAT_ACTION) ;
54     addActionListener(CancelActionListener.class, CANCEL_ACTION) ;
55   }
56   
57   public String JavaDoc getDocument() { return text_ ; }
58   
59   public void setDocument(Document doc) throws Exception JavaDoc {
60     document_ = doc ;
61     String JavaDoc module = doc.getField(IndexingService.MODULE_FIELD).stringValue() ;
62     IndexerPlugin plugin = iservice_.getIndexerPlugin(module) ;
63     text_ = plugin.getObjectAsXHTML(null, doc.getField(IndexingService.IDENTIFIER_FIELD).stringValue());
64   }
65   
66   public String JavaDoc getFamily() { return COMPONENT_FAMILY ; }
67   
68   static public class ChangeFormatActionListener extends ExoActionListener {
69     public void execute(ExoActionEvent event) throws Exception JavaDoc {
70       UIViewDocument uiView = (UIViewDocument) event.getSource();
71       String JavaDoc format = event.getParameter(FORMAT_TYPE) ;
72       String JavaDoc module = uiView.document_.getField(IndexingService.MODULE_FIELD).stringValue() ;
73       IndexerPlugin plugin = uiView.iservice_.getIndexerPlugin(module) ;
74       String JavaDoc id = uiView.document_.getField(IndexingService.IDENTIFIER_FIELD).stringValue() ;
75       if(HTML_FORMAT.equals(format)) {
76         uiView.text_ = plugin.getObjectAsXHTML(null, id);
77       } else if(XML_FORMAT.equals(format)) {
78         uiView.text_ = HtmlUtil.showXmlTags(plugin.getObjectAsXML(null, id));
79       } else {
80         uiView.text_ = "<pre>" + plugin.getObjectAsText(null, id) + "</pre>";
81       }
82     }
83   }
84
85   static public class CancelActionListener extends ExoActionListener {
86     public void execute(ExoActionEvent event) throws Exception JavaDoc {
87       UIViewDocument uiView = (UIViewDocument) event.getSource();
88       uiView.setRenderedSibling(UISearchSummary.class) ;
89     }
90   }
91 }
Popular Tags