1 5 package org.exoplatform.portlets.indexing.component; 6 7 import org.exoplatform.faces.core.component.UICheckBox; 8 import org.exoplatform.faces.core.component.UISimpleForm; 9 import org.exoplatform.faces.core.component.UIStringInput; 10 import org.exoplatform.faces.core.component.model.*; 11 import org.exoplatform.faces.core.event.ExoActionEvent; 12 import org.exoplatform.faces.core.event.ExoActionListener; 13 import org.exoplatform.services.indexing.FileIndexerPlugin; 14 import org.exoplatform.services.indexing.IndexingService; 15 16 21 public class UIFileIndexerPlugin extends UISimpleForm { 22 final static public String INDEX_DIRECTORY = "index" ; 23 final static public String REINDEX_DIRECTORY = "reindex" ; 24 25 private UIStringInput directoryInput_ ; 26 private UIStringInput acceptExtInput_ ; 27 private UICheckBox recursiveInput_ ; 28 private FileIndexerPlugin indexer_ ; 29 30 public UIFileIndexerPlugin(IndexingService iservice) throws Exception { 31 super("fileIndexerPlugin", "post", null) ; 32 setId(FileIndexerPlugin.IDENTIFIER) ; 33 indexer_ = (FileIndexerPlugin)iservice.getIndexerPlugin(FileIndexerPlugin.IDENTIFIER) ; 34 35 directoryInput_ = new UIStringInput("directory", "") ; 36 acceptExtInput_ = new UIStringInput("acceptExt", "html, txt, xml, java") ; 37 recursiveInput_ = new UICheckBox("recursive", "true") ; 38 recursiveInput_.setSelect(true) ; 39 40 add(new HeaderRow(). 41 add(new Cell("#{UIFileIndexerPlugin.header.file-indexer}"). 42 addColspan("2"))); 43 add(new Row(). 44 add(new LabelCell("#{UIFileIndexerPlugin.label.directory}")). 45 add(new ComponentCell(this, directoryInput_))); 46 add(new Row(). 47 add(new LabelCell("#{UIFileIndexerPlugin.label.accept-extension}")). 48 add(new ComponentCell(this, acceptExtInput_))); 49 add(new Row(). 50 add(new LabelCell("#{UIFileIndexerPlugin.label.recursive-index}")). 51 add(new ComponentCell(this, recursiveInput_))); 52 add(new Row(). 53 add(new ListComponentCell(). 54 add(new FormButton("#{UIFileIndexerPlugin.button.index-directory}", INDEX_DIRECTORY)). 55 add(new FormButton("#{UIFileIndexerPlugin.button.reindex-directory}", REINDEX_DIRECTORY)). 56 add(new FormButton("#{UIFileIndexerPlugin.button.cancel}", CANCEL_ACTION)). 57 addColspan("2").addAlign("center"))) ; 58 59 addActionListener(ShowListIndexerPluginActionListener.class, CANCEL_ACTION) ; 60 addActionListener(IndexActionListener.class, INDEX_DIRECTORY) ; 61 addActionListener(ReindexActionListener.class, REINDEX_DIRECTORY) ; 62 } 63 64 static public class IndexActionListener extends ExoActionListener { 65 public void execute(ExoActionEvent event) throws Exception { 66 UIFileIndexerPlugin uiComponent = (UIFileIndexerPlugin) event.getComponent() ; 67 String directory = uiComponent.directoryInput_.getValue() ; 68 String acceptExt = uiComponent.acceptExtInput_.getValue() ; 69 String [] ext = acceptExt.split(",") ; 70 boolean recursive = "true".equals( uiComponent.recursiveInput_.getValue()); 71 uiComponent.indexer_.indexDirectory(directory, null ,ext, recursive) ; 72 } 73 } 74 75 static public class ReindexActionListener extends ExoActionListener { 76 public void execute(ExoActionEvent event) throws Exception { 77 UIFileIndexerPlugin uiComponent = (UIFileIndexerPlugin) event.getComponent() ; 78 String directory = uiComponent.directoryInput_.getValue() ; 79 String acceptExt = uiComponent.acceptExtInput_.getValue() ; 80 String [] ext = acceptExt.split(",") ; 81 boolean recursive = "true".equals( uiComponent.recursiveInput_.getValue()); 82 uiComponent.indexer_.reindexDirectory(directory, null, ext, recursive) ; 83 } 84 } 85 } | Popular Tags |