1 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 20 public class UIViewDocument extends UIExoCommand { 21 final static public String COMPONENT_FAMILY = "org.exoplatform.faces.search.component.UIViewDocument" ; 22 public final static String TEXT_FORMAT = "TEXT_FORMAT" ; 23 public final static String HTML_FORMAT = "HTML_FORMAT" ; 24 public final static String XML_FORMAT = "XML_FORMAT" ; 25 public final static String FORMAT_TYPE = "format" ; 26 public final static String 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 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 getDocument() { return text_ ; } 58 59 public void setDocument(Document doc) throws Exception { 60 document_ = doc ; 61 String 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 getFamily() { return COMPONENT_FAMILY ; } 67 68 static public class ChangeFormatActionListener extends ExoActionListener { 69 public void execute(ExoActionEvent event) throws Exception { 70 UIViewDocument uiView = (UIViewDocument) event.getSource(); 71 String format = event.getParameter(FORMAT_TYPE) ; 72 String module = uiView.document_.getField(IndexingService.MODULE_FIELD).stringValue() ; 73 IndexerPlugin plugin = uiView.iservice_.getIndexerPlugin(module) ; 74 String 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 { 87 UIViewDocument uiView = (UIViewDocument) event.getSource(); 88 uiView.setRenderedSibling(UISearchSummary.class) ; 89 } 90 } 91 } | Popular Tags |