Hi,

        Hope this help.

Regards,
Wooi Meng 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.39/685 - Release Date: 2/13/2007
10:01 PM
 
  


Disclaimer
----------------------------------------------------------------------------------------------------
This e-mail and any files transmitted with it are intended only for the 
use of the addressee. If it contains confidential information, the addressee 
is expressly prohibited from distributing the e-mail and legal action may be 
taken against you. Access by any other persons to this e-mail is unauthorized. 
If you are not the intended recipient, any disclosure, copying, use, or 
distribution is prohibited and may be unlawful. This e-mail and any files 
and/or 
attachments, shall not constitute binding legal obligation with the company. 
The company shall also not be responsible for any computer virus transmitted 
with this e-mail.
----------------------------------------------------------------------------------------------------
MCSB Systems (M) Berhad ([EMAIL PROTECTED])
public synchronized String idxWriterMyDoc(String companyId, String ownerId, 
String createdBy, String docName, String docDesc, String keywords, 
                        int docId, String orgDocPath, int docGroupId, int 
docVersionId, File fileToIdx) throws Exception
        {
                boolean idxReCreate = false;
                Document doc = new Document();
                List getDocPropValueList = new ArrayList();
                DocumentTypeParser dtp = new DocumentTypeParser();
                final String retValErr = "fail";
                String retVal = "success";
                String content = "";
                
                userDir = new 
File(ConfigMgr.getPropValue("ds.rootdir")+File.separator+companyId+File.separator+"Users"+File.separator+ownerId+File.separator+"MyDocuments");
                idxDir = new File(userDir+File.separator+"idxFolder");
                
                if(!idxDir.exists())
                {
                        idxReCreate = true;
                        idxDir.mkdirs();
                }
                
                try
                {       
                        writer = new IndexWriter(idxDir, new 
StandardAnalyzer(), idxReCreate);
                        
                        try
                        {
                                if(docName.toLowerCase().endsWith(".pdf"))
                                {
                                        content = dtp.indexPdf(fileToIdx);
                                        
                                        if(content != null && 
!content.equals(""))
                                        {
                                                doc.add(new 
Field(DsConstant.idxFileContent, content, Field.Store.YES, 
Field.Index.TOKENIZED));
                                                doc.add(new 
Field(DsConstant.idxPath, fileToIdx.getPath(), Field.Store.YES, 
Field.Index.UN_TOKENIZED));
                                        }
                                }
                                else if(docName.toLowerCase().endsWith(".doc"))
                                {
                                        content = dtp.indexDoc(fileToIdx);
                                        
                                        if(content != null && 
!content.equals(""))
                                        {
                                                doc.add(new 
Field(DsConstant.idxFileContent, content, Field.Store.YES, 
Field.Index.TOKENIZED));
                                                doc.add(new 
Field(DsConstant.idxPath, fileToIdx.getPath(), Field.Store.YES, 
Field.Index.UN_TOKENIZED));
                                        }
                                }
                                else if(docName.toLowerCase().endsWith(".txt") 
|| docName.toLowerCase().endsWith(".log") || 
docName.toLowerCase().endsWith(".xml"))
                                {
                                        content = dtp.indexText(fileToIdx);
                                        
                                        if(content != null && 
!content.equals(""))
                                        {
                                                doc.add(new 
Field(DsConstant.idxFileContent, content, Field.Store.YES, 
Field.Index.TOKENIZED));
                                                doc.add(new 
Field(DsConstant.idxPath, fileToIdx.getPath(), Field.Store.YES, 
Field.Index.UN_TOKENIZED));
                                        }
                                }
                                else if(docName.toLowerCase().endsWith(".ppt"))
                                {
                                        content = dtp.indexPP(fileToIdx);
                                        
                                        if(content != null && 
!content.equals(""))
                                        {
                                                doc.add(new 
Field(DsConstant.idxFileContent, content, Field.Store.YES, 
Field.Index.TOKENIZED));
                                                doc.add(new 
Field(DsConstant.idxPath, fileToIdx.getPath(), Field.Store.YES, 
Field.Index.UN_TOKENIZED));
                                        }
                                }
                                else if(docName.toLowerCase().endsWith(".xls"))
                                {
                                        doc = dtp.indexExcel(fileToIdx, doc);
                                        
                                        if(content != null && 
!content.equals(""))
                                        {
                                                doc.add(new 
Field(DsConstant.idxPath, fileToIdx.getPath(), Field.Store.YES, 
Field.Index.UN_TOKENIZED));
                                        }
                                }
                                else if(docName.toLowerCase().endsWith(".html") 
|| docName.toLowerCase().endsWith(".htm"))
                                {
                                        doc = dtp.indexHTML(fileToIdx, doc);
                                        
                                        if(content != null && 
!content.equals(""))
                                        {
                                                doc.add(new 
Field(DsConstant.idxPath, fileToIdx.getPath(), Field.Store.YES, 
Field.Index.UN_TOKENIZED));
                                        }
                                }
                        }
                        catch(Exception ex)
                        {
                                ex.printStackTrace();
                                doc = new Document();
                        }
                        
                        doc.add(new Field("Company", companyId, 
Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.add(new Field("Owner", ownerId.trim(), 
Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.add(new Field("CreatedBy", createdBy.trim(), 
Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.add(new Field("DocumentName", docName, 
Field.Store.YES, Field.Index.TOKENIZED));
                        doc.add(new Field("DocumentDescription", docDesc, 
Field.Store.YES, Field.Index.TOKENIZED));
                        doc.add(new Field("Keywords", keywords, 
Field.Store.YES, Field.Index.TOKENIZED));
                        doc.add(new Field("DocumentNo", String.valueOf(docId), 
Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.add(new Field("OriginalDocPath", 
orgDocPath.toLowerCase(), Field.Store.YES, Field.Index.TOKENIZED));
                        doc.add(new Field("DocumentGroupIdentity", 
String.valueOf(docGroupId), Field.Store.YES, Field.Index.UN_TOKENIZED));
                        doc.add(new Field("DocumentVersionNo", 
String.valueOf(docVersionId), Field.Store.YES, Field.Index.UN_TOKENIZED));
                        
                        getDocPropValueList = 
dpvBean.getDocPropValueList(docId);
                        Iterator docPropKey = 
getDocPropValueList.listIterator();
                        while(docPropKey.hasNext())
                        {
                                DocPropValue dpValue = 
(DocPropValue)docPropKey.next();
                                int docPropId = dpValue.getDocPropId();
                                DocProp dp = dpmBean.getDocProp(docPropId);
                                String docPropName = dp.getDocPropName();
                                doc.add(new Field(docPropName, 
dpValue.getDocPropValue(), Field.Store.YES, Field.Index.TOKENIZED));
                        }
                        
                        writer.addDocument(doc);
                        writer.optimize();
                        writer.close();
                }
                catch(Exception ex)
                {
                        System.err.println(ex.getMessage());
                        retVal = retValErr;
                }
                finally
                {
                        try
                        {
                                if(writeLock != null)
                                {
                                        writeLock.release();
                                        writeLock = null;
                                }
                        }
                        catch(Exception ex)
                        {
                                System.err.println(ex.getMessage());
                                retVal = retValErr;
                        }
                }
                
                return retVal;
        }


//Pdf parser
        public String indexPdf(File file) throws Exception 
        {
                PDDocument pdDoc = PDDocument.load(file);
                String content = "";
                try
                {
                        PDFTextStripper stripper = new PDFTextStripper();
                        
                        content = stripper.getText(pdDoc);
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                        System.err.println("file --- indexPdf parser --- " 
+file.toString());
                }
                finally
                {
                        pdDoc.close();
                }
                
                return content;
        }
        
        //Word Doc parser
        public String indexDoc(File file) throws Exception 
        {
                WordExtractor wordDoc = new WordExtractor(new 
FileInputStream(file));
                String content = "";
                
                try
                {
                        content = wordDoc.getTextFromPieces();
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                        System.err.println("file --- indexWord parser --- " 
+file.toString());
                }
                
                return content;
        }
        
        //PowerPoint parser
        public String indexPP(File file) throws Exception
        {
                PowerPointExtractor ppDoc = new PowerPointExtractor(new 
FileInputStream(file));
                String content = "";
                
                try
                {
                        content = ppDoc.getText();
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                }
                finally
                {
                        ppDoc.close();
                }
                
                return content;
        }
        
        //Excel parser
        public Document indexExcel(File file, Document doc) throws Exception
        {
                Workbook excelDoc = Workbook.getWorkbook(new 
FileInputStream(file));
                String content = "";
                Cell[] row = null;
                
                try
                {
                    for(int sheet = 0; sheet < excelDoc.getNumberOfSheets(); 
sheet++)
                        {
                                Sheet s = excelDoc.getSheet(sheet);
                                for(int i = 0; i < s.getRows(); i++)
                                {
                                        row = s.getRow(i);
                                        if(row.length > 0)
                                        {
                                                if(!row[0].isHidden())
                                                {
                                                        content = 
row[0].getContents();
                                                }
                                                
                                                for(int j = 0; j < row.length; 
j++)
                                                {
                                                        if(!row[j].isHidden())
                                                        {
                                                                content = 
row[j].getContents();
                                                                doc.add(new 
Field(DsConstant.idxFileContent, content, Field.Store.YES, 
Field.Index.TOKENIZED));
                                                        }
                                                }
                                        }
                                }
                        }
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                        System.err.println("file --- indexExcel parser --- " 
+file.toString() + " doc to string --- " +doc.toString());
                }
                finally
                {
                        excelDoc.close();
                }
                
                return doc;
        }
        
        //Text parser
        public String indexText(File file) throws Exception 
        {
                BufferedReader reader = new BufferedReader(new 
FileReader(file));
                StringBuffer content = new StringBuffer(); 
                
                try
                {
                        do 
                        {
                                content.append(reader.readLine());
                        }
                        while (reader.readLine()!=null);
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                }
                finally
                {
                        reader.close();
                }
                
                return content.toString();
        }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to