1 36 37 package com.bluecubs.xinco.index; 38 39 import java.io.File ; 40 import java.io.Reader ; 41 import java.io.FileInputStream ; 42 import org.apache.lucene.document.Document; 43 import org.apache.lucene.document.Field; 44 import com.bluecubs.xinco.core.*; 45 import com.bluecubs.xinco.add.*; 46 import com.bluecubs.xinco.core.server.*; 47 import com.bluecubs.xinco.index.filetypes.*; 48 49 50 51 public class XincoDocument { 52 53 public static Document getXincoDocument(XincoCoreData d, boolean index_content, XincoDBManager dbm) throws java.io.FileNotFoundException { 54 55 int i, j, l; 56 int i2, j2; 57 short k, k2; 58 FileInputStream is = null; 59 Document doc = null; 60 Document temp_doc = null; 61 int file_type = 0; 62 int file_ext_index = 0; 63 String file_ext = ""; 64 65 doc = new Document(); 66 67 doc.add(new Field("id", (new Integer (d.getId())).toString(), true, true, false)); 69 doc.add(Field.Text("designation", d.getDesignation())); 70 doc.add(new Field("language", (new Integer (d.getXinco_core_language().getId())).toString(), true, true, false)); 71 72 if (index_content) { 74 if ((d.getXinco_core_data_type().getId() == 1) && (d.getStatus_number() != 3)) { file_ext_index =((XincoAddAttribute)d.getXinco_add_attributes().elementAt(0)).getAttrib_varchar().lastIndexOf("."); 77 if (file_ext_index == -1) { 78 file_ext = ""; 79 } else { 80 if (file_ext_index >= ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(0)).getAttrib_varchar().length() - 1) { 81 file_ext = ""; 82 } else { 83 file_ext = ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(0)).getAttrib_varchar().substring(file_ext_index + 1); 84 } 85 } 86 file_type = 0; for (l=0;l<dbm.config.FileIndexerCount;l++) { 89 for (i=0;i<((String [])dbm.config.IndexFileTypesExt.elementAt(l)).length;i++) { 90 if (((String [])dbm.config.IndexFileTypesExt.elementAt(l))[i].compareTo(file_ext) == 0) { 91 file_type = l+1; break; 93 } 94 } 95 if (file_type > 0) { 96 break; 97 } 98 } 99 if (file_type == 0) { 100 for (i=0;i<dbm.config.IndexNoIndex.length;i++) { 101 if (dbm.config.IndexNoIndex[i].compareTo(file_ext) == 0) { 102 file_type = -1; break; 104 } 105 } 106 } 107 XincoIndexFileType xift = null; 109 Reader ContentReader = null; 110 String ContentString = null; 111 if (file_type == 0) { 112 xift = new XincoIndexText(); 114 doc.add(Field.Text("file", xift.getFileContentReader(new File (dbm.config.FileRepositoryPath + (new Integer (d.getId())).toString())))); 115 } else if (file_type > 0) { 116 try { 118 xift = (XincoIndexFileType)Class.forName((String )dbm.config.IndexFileTypesClass.elementAt(file_type-1)).newInstance(); 119 ContentReader = xift.getFileContentReader(new File (dbm.config.FileRepositoryPath + (new Integer (d.getId())).toString())); 120 if (ContentReader != null) { 121 doc.add(Field.Text("file", ContentReader)); 122 } else { 123 ContentString = xift.getFileContentString(new File (dbm.config.FileRepositoryPath + (new Integer (d.getId())).toString())); 124 if (ContentString != null) { 125 doc.add(Field.Text("file", ContentString)); 126 } 127 } 128 } catch (Exception ie) { 129 } 130 } 131 132 } 133 } 134 135 for (i=0;i<d.getXinco_add_attributes().size();i++) { 137 if (((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getData_type().toLowerCase().compareTo("int") == 0) { 138 doc.add(Field.Text(((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getDesignation(), "" + ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(i)).getAttrib_int())); 139 } 140 if (((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getData_type().toLowerCase().compareTo("unsignedint") == 0) { 141 doc.add(Field.Text(((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getDesignation(), "" + ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(i)).getAttrib_unsignedint())); 142 } 143 if (((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getData_type().toLowerCase().compareTo("double") == 0) { 144 doc.add(Field.Text(((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getDesignation(), "" + ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(i)).getAttrib_double())); 145 } 146 if (((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getData_type().toLowerCase().compareTo("varchar") == 0) { 147 doc.add(Field.Text(((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getDesignation(), ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(i)).getAttrib_varchar())); 148 } 149 if (((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getData_type().toLowerCase().compareTo("text") == 0) { 150 doc.add(Field.Text(((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getDesignation(), ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(i)).getAttrib_text())); 151 } 152 if (((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getData_type().toLowerCase().compareTo("datetime") == 0) { 153 doc.add(Field.Text(((XincoCoreDataTypeAttribute)d.getXinco_core_data_type().getXinco_core_data_type_attributes().elementAt(i)).getDesignation(), "" + ((XincoAddAttribute)d.getXinco_add_attributes().elementAt(i)).getAttrib_datetime())); 154 } 155 } 156 157 return doc; 158 } 159 160 private XincoDocument() {} 161 } 162 | Popular Tags |