0001: /*
0002: * snapper2
0003: *
0004: * Enhydra super-servlet
0005: *
0006: */
0007:
0008: package org.enhydra.snapperAdmin;
0009:
0010: import java.io.File;
0011: import java.io.FileInputStream;
0012: import java.io.FileOutputStream;
0013: import java.io.InputStream;
0014: import java.util.Properties;
0015: import java.util.StringTokenizer;
0016: import java.util.Vector;
0017:
0018: import javax.xml.transform.Templates;
0019: import javax.xml.transform.TransformerFactory;
0020: import javax.xml.transform.stream.StreamSource;
0021:
0022: import org.enhydra.snapper.SnapperManager;
0023: import org.enhydra.snapper.SnapperType;
0024: import org.enhydra.snapperAdmin.spec.FileType;
0025: import org.enhydra.snapperAdmin.spec.SiteList;
0026: import org.enhydra.snapperAdmin.spec.SiteListFactory;
0027:
0028: import com.lutris.appserver.server.ApplicationException;
0029: import com.lutris.appserver.server.StandardApplication;
0030: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
0031: import com.lutris.logging.LogChannel;
0032: import com.lutris.logging.Logger;
0033: import com.lutris.util.Config;
0034: import com.lutris.util.ConfigException;
0035:
0036: /**
0037: * The application object.
0038: *
0039: * Application-wide data would go here.
0040: */
0041:
0042: public class SnapperAdmin extends StandardApplication {
0043:
0044: protected static String version = "v1.1";
0045:
0046: protected static String indexDir;
0047:
0048: //protected static String searcherClassName;
0049:
0050: protected static String indexerClassName = "org.enhydra.snapper.wrapper.lucene.LuceneIndexerFactory";
0051:
0052: //protected static String downloadParameter;
0053:
0054: //protected static String indexType = "FileSystem";
0055:
0056: protected static boolean mountTitleInContent = false;
0057:
0058: protected static boolean mountFilePathInContent = false;
0059:
0060: protected static boolean mountPropertiesInContent = false;
0061:
0062: protected static boolean mountMetaDataInContent = false;
0063:
0064: protected static boolean forceIndexUnlock = false;
0065:
0066: protected static boolean indexDiference = false;
0067:
0068: protected static int maxFieldLength = 10000;
0069:
0070: protected static int maxPropertiesLength = 5000;
0071:
0072: protected static long maxIndexLength = 1000000000;
0073:
0074: public static Vector sitesUpdated = new Vector();
0075:
0076: public static Vector sitesIndexed = new Vector();
0077:
0078: public static Vector sitesLocked = new Vector();
0079:
0080: public static LogChannel log;
0081:
0082: // public SnapperManager snapperManager;
0083:
0084: protected static String siteConfFile = null;
0085:
0086: protected static String documentGroupConfFile = null;
0087:
0088: protected static String logDirectory = null;
0089:
0090: protected static String statisticDirectory = null;
0091:
0092: protected static boolean statisticActive = false;
0093:
0094: private static boolean indexOSspecific = false;
0095:
0096: private static Properties converterClassNames = new Properties();
0097:
0098: protected static String pathOfConvertedFiles = null;
0099:
0100: protected static boolean toSaveConvertedFile = false;
0101:
0102: protected static boolean toSaveConvertedWord = false;
0103:
0104: protected static boolean toSaveConvertedExcel = false;
0105:
0106: protected static boolean toSaveConvertedPowerPoint = false;
0107:
0108: protected static boolean toSaveConvertedWord2007 = false;
0109:
0110: protected static boolean toSaveConvertedExcel2007 = false;
0111:
0112: protected static boolean toSaveConvertedPowerPoint2007 = false;
0113:
0114: protected static boolean printStackTrace = false;
0115:
0116: protected static boolean checkConnection = true;
0117:
0118: protected static boolean optimizeOnIndex = true;
0119:
0120: protected static boolean optimizeOnUpdate = false;
0121:
0122: private static String word2007TransformationPath = "";
0123:
0124: private static String excel2007TransformationPath = "";
0125:
0126: private static String powerpoint2007TransformationPath = "";
0127:
0128: private static int maxFileSize = 0;
0129:
0130: private static long timeLimit = 0;
0131:
0132: private static String word2007HTMLTransformationPath = "";
0133:
0134: private static String word2007TextTransformationPath = "";
0135:
0136: private static String excel2007HTMLTransformationPath = "";
0137:
0138: private static String excel2007TextTransformationPath = "";
0139:
0140: private static String powerpoint2007HTMLTransformationPath = "";
0141:
0142: private static String powerpoint2007TextTransformationPath = "";
0143:
0144: private static Templates word2007TextTemplates = null;
0145:
0146: private static Templates word2007HTMLTemplates = null;
0147:
0148: private static Templates excel2007TextTemplates = null;
0149:
0150: private static Templates excel2007HTMLTemplates = null;
0151:
0152: private static Templates powerpoint2007TextTemplates = null;
0153:
0154: private static Templates powerpoint2007HTMLTemplates = null;
0155:
0156: // private String relm = "SnapperManager";
0157:
0158: //private String username, password;
0159:
0160: /*
0161: * A few methods you might want to add to. See StandardApplication for more
0162: * details.
0163: */
0164: public void startup(Config appConfig) throws ApplicationException {
0165:
0166: super .startup(appConfig);
0167: /*
0168: * try { Constructor c = getClass().getClassLoader().loadClass(
0169: * appConfig.getString("LogClassName") ).getConstructor(new Class[] {
0170: * Boolean.TYPE }); Logger logger = (Logger) c.newInstance(new Object[] {
0171: * new Boolean(true) }); log =
0172: * logger.getChannel("org.enhydra.snapper.SnapperAdmin"); } catch
0173: * (Exception e) { e.printStackTrace(); System.err.println("Logger is not
0174: * initialized properly!"); }
0175: */
0176:
0177: log = this .getLogChannel();
0178:
0179: Properties prop = new Properties();
0180:
0181: try {
0182:
0183: prop
0184: .put(
0185: "IndexerFactoryClassName",
0186: appConfig
0187: .getString(
0188: "Snapper.IndexerFactoryClassName",
0189: "org.enhydra.snapper.wrapper.lucene.LuceneIndexerFactory"));
0190: indexerClassName = appConfig
0191: .getString("Snapper.IndexerFactoryClassName",
0192: "org.enhydra.snapper.wrapper.lucene.LuceneIndexerFactory");
0193: prop
0194: .put(
0195: "LoggingManagerClassName",
0196: appConfig
0197: .getString(
0198: "Snapper.LoggingManagerClassName",
0199: "org.enhydra.snapper.logging.StandardLoggingManager"));
0200: prop.put("LoggerName", "SnapperAdmin.SnapperManager");
0201:
0202: prop.put("LogicalNameFromDatabase", appConfig.getString(
0203: "Snapper.LogicalNameFromDatabase", "0"));
0204: prop.put("DocumentLogicalName", appConfig.getString(
0205: "Snapper.DocumentLogicalName", ""));
0206: prop.put("DocumentUpdate", appConfig.getString(
0207: "Snapper.DocumentUpdate", "update"));
0208: prop.put("DocumentUpdatePattern", appConfig.getString(
0209: "Snapper.DocumentUpdatePattern", ""));
0210: prop.put("DBFetchSize", appConfig.getString(
0211: "Snapper.DBFetchSize", "0"));
0212: // if (appConfig.getString("Snapper.TempDir",) != null)
0213: prop.put("RelativeIndexPath", appConfig.getString(
0214: "Snapper.RelativeIndexPath", "false"));
0215: prop.put("FileSeparator", appConfig.getString(
0216: "Snapper.FileSeparator", "system-dependent"));
0217: prop.put("TempDir", appConfig.getString("Snapper.TempDir",
0218: System.getProperty("user.home") + File.separator
0219: + ".snapperTemp"));
0220:
0221: } catch (ConfigException except) {
0222: throw new ApplicationException(except);
0223: }
0224:
0225: //configureFromJar();
0226: SnapperManager.getInstance().init(prop);
0227:
0228: // Here is where you would read application-specific settings from
0229: // your config file.
0230:
0231: try {
0232: maxIndexLength = Long.parseLong(appConfig
0233: .getString("Snapper.MaxIndexLength"));
0234: } catch (ConfigException e) {
0235: if (logChannel != null) {
0236: logChannel
0237: .write(Logger.INFO,
0238: "Snapper.MaxIndexLength application parameter isn't properly initialized!");
0239:
0240: }
0241: }
0242:
0243: try {
0244: maxFieldLength = Integer.parseInt(appConfig.getString(
0245: "Snapper.Lucene.MaxFieldLength", "10000"));
0246: } catch (ConfigException e) {
0247: if (logChannel != null) {
0248: logChannel
0249: .write(
0250: Logger.INFO,
0251: "Snapper.Lucene.MaxFieldLength application parameter isn't properly initialized!");
0252:
0253: }
0254: }
0255: try {
0256: maxPropertiesLength = Integer.parseInt(appConfig.getString(
0257: "Snapper.MaxPropertiesLength", "5000"));
0258: } catch (ConfigException e) {
0259: if (logChannel != null) {
0260: logChannel
0261: .write(Logger.INFO,
0262: "Snapper.MaxPropertiesLength application parameter isn't properly initialized!");
0263:
0264: }
0265: }
0266:
0267: try {
0268: indexDir = appConfig.getString("Snapper.IndexDir");
0269: } catch (ConfigException e) {
0270: if (logChannel != null) {
0271: logChannel
0272: .write(Logger.INFO,
0273: "Snapper.IndexDir application parameter isn't properly initialized!");
0274:
0275: }
0276: }
0277:
0278: File timeFile = new File(indexDir + "timeFile");
0279: try {
0280: pathOfConvertedFiles = appConfig.getString(
0281: "Snapper.PathOfConvertedFiles", System
0282: .getProperty("user.home")
0283: + File.separator + ".convertedFiles");
0284: } catch (ConfigException e) {
0285: if (logChannel != null) {
0286: logChannel
0287: .write(
0288: Logger.INFO,
0289: "Snapper.PathOfConvertedFiles application parameter isn't properly initialized!");
0290:
0291: }
0292: }
0293:
0294: try {
0295:
0296: toSaveConvertedFile = appConfig.getBoolean(
0297: "Snapper.SaveConvertedFile", false);
0298: } catch (ConfigException e) {
0299: toSaveConvertedFile = false;
0300: }
0301:
0302: try {
0303:
0304: toSaveConvertedWord = appConfig.getBoolean(
0305: "Snapper.SaveConvertedWord", false);
0306: } catch (ConfigException e) {
0307: toSaveConvertedWord = false;
0308: }
0309:
0310: try {
0311:
0312: toSaveConvertedExcel = appConfig.getBoolean(
0313: "Snapper.SaveConvertedExcel", false);
0314: } catch (ConfigException e) {
0315: toSaveConvertedExcel = false;
0316: }
0317:
0318: try {
0319:
0320: toSaveConvertedPowerPoint = appConfig.getBoolean(
0321: "Snapper.SaveConvertedPowerPoint", false);
0322: } catch (ConfigException e) {
0323: toSaveConvertedPowerPoint = false;
0324: }
0325:
0326: try {
0327:
0328: toSaveConvertedWord2007 = appConfig.getBoolean(
0329: "Snapper.SaveConvertedWord2007", false);
0330: } catch (ConfigException e) {
0331: toSaveConvertedWord2007 = false;
0332: }
0333:
0334: try {
0335:
0336: toSaveConvertedExcel2007 = appConfig.getBoolean(
0337: "Snapper.SaveConvertedExcel2007", false);
0338: } catch (ConfigException e) {
0339: toSaveConvertedExcel2007 = false;
0340: }
0341:
0342: try {
0343:
0344: toSaveConvertedPowerPoint2007 = appConfig.getBoolean(
0345: "Snapper.SaveConvertedPowerPoint2007", false);
0346: } catch (ConfigException e) {
0347: toSaveConvertedPowerPoint2007 = false;
0348: }
0349:
0350: try {
0351: printStackTrace = appConfig.getBoolean(
0352: "Snapper.PrintStackTrace", false);
0353: } catch (ConfigException e) {
0354: printStackTrace = false;
0355: }
0356:
0357: try {
0358:
0359: optimizeOnIndex = appConfig.getBoolean(
0360: "Snapper.OptimizeOnIndex", true);
0361: } catch (ConfigException e) {
0362: optimizeOnIndex = true;
0363: }
0364:
0365: try {
0366:
0367: optimizeOnUpdate = appConfig.getBoolean(
0368: "Snapper.OptimizeOnUpdate", false);
0369: } catch (ConfigException e) {
0370: optimizeOnUpdate = false;
0371: }
0372:
0373: try {
0374: checkConnection = appConfig.getBoolean(
0375: "Snapper.CheckConnection", true);
0376: } catch (ConfigException e) {
0377: checkConnection = true;
0378: }
0379:
0380: try {
0381: maxIndexLength = Long.parseLong(appConfig
0382: .getString("Snapper.MaxIndexLength"));
0383: } catch (ConfigException e) {
0384: if (logChannel != null) {
0385: logChannel
0386: .write(Logger.INFO,
0387: "Snapper.MaxIndexLength application parameter isn't properly initialized!");
0388:
0389: }
0390: }
0391:
0392: try {
0393:
0394: forceIndexUnlock = appConfig.getBoolean(
0395: "Snapper.Indexer.ForceIndexUnlock", false);
0396: } catch (ConfigException e) {
0397: forceIndexUnlock = false;
0398: }
0399:
0400: try {
0401:
0402: mountTitleInContent = appConfig.getBoolean(
0403: "Snapper.Indexer.MountTitleInContent", false);
0404: } catch (ConfigException e) {
0405: mountTitleInContent = false;
0406: }
0407:
0408: try {
0409:
0410: mountFilePathInContent = appConfig.getBoolean(
0411: "Snapper.Indexer.MountFilePathInContent", false);
0412: } catch (ConfigException e) {
0413: mountFilePathInContent = false;
0414: }
0415:
0416: try {
0417: mountPropertiesInContent = appConfig.getBoolean(
0418: "Snapper.Indexer.MountPropertiesInContent", false);
0419: } catch (ConfigException e) {
0420: mountPropertiesInContent = false;
0421: }
0422:
0423: try {
0424: mountMetaDataInContent = appConfig.getBoolean(
0425: "Snapper.Indexer.MountMetaDataInContent", false);
0426: } catch (ConfigException e) {
0427: mountMetaDataInContent = false;
0428: }
0429:
0430: try {
0431: indexDiference = appConfig.getBoolean(
0432: "Snapper.Indexer.ReIndexMode", false);
0433: } catch (ConfigException e) {
0434: indexDiference = false;
0435: }
0436:
0437: /* try {
0438: indexType = appConfig.getString("Snapper.IndexType", "FileSystem");
0439: } catch (ConfigException e) {
0440: indexType = "FileSystem";
0441: }*/
0442:
0443: try {
0444: indexOSspecific = appConfig.getBoolean(
0445: "Snapper.IndexOSspecific", false);
0446: } catch (ConfigException e) {
0447: indexOSspecific = false;
0448: }
0449:
0450: try {
0451: String excelConverterClassName = appConfig
0452: .getString(
0453: "Snapper.Parser.Excel.ConverterClassName",
0454: "org.enhydra.snapper.parsers.fileparsers.parsers.excelparser.ExcelToText");
0455: converterClassNames.put("xls", excelConverterClassName);
0456:
0457: } catch (ConfigException e) {
0458: log
0459: .write(
0460: Logger.ERROR,
0461: " Snapper.Parser.Excel.ConverterClassName application parameter isn't properly initialized!");
0462:
0463: }
0464:
0465: try {
0466: String powerConverterClassName = appConfig
0467: .getString(
0468: "Snapper.Parser.PowerPoint.ConverterClassName",
0469: "org.enhydra.snapper.parsers.fileparsers.parsers.powerparser.PowerToText");
0470: converterClassNames.put("ppt", powerConverterClassName);
0471:
0472: } catch (ConfigException e) {
0473: log
0474: .write(
0475: Logger.ERROR,
0476: "Snapper.Parser.PowerPoint.ConverterClassName application parameter isn't properly initialized!");
0477: }
0478:
0479: try {
0480: String wordConverterClassName = appConfig
0481: .getString(
0482: "Snapper.Parser.Word.ConverterClassName",
0483: "org.enhydra.snapper.parsers.fileparsers.parsers.wordparser.WordToText");
0484: converterClassNames.put("doc", wordConverterClassName);
0485:
0486: } catch (ConfigException e) {
0487: log
0488: .write(
0489: Logger.ERROR,
0490: "Snapper.Parser.Word.ConverterClassName application parameter isn't properly initialized!");
0491: }
0492:
0493: try {
0494: String excel2007ConverterClassName = appConfig
0495: .getString(
0496: "Snapper.Parser.Excel2007.ConverterClassName",
0497: "org.enhydra.snapper.parsers.fileparsers.parsers.excel2007parser.Excel2007ToText");
0498: converterClassNames
0499: .put("xlsx", excel2007ConverterClassName);
0500:
0501: } catch (ConfigException e) {
0502: log
0503: .write(
0504: Logger.ERROR,
0505: " Snapper.Parser.Excel2007.ConverterClassName application parameter isn't properly initialized!");
0506:
0507: }
0508:
0509: try {
0510: String power2007ConverterClassName = appConfig
0511: .getString(
0512: "Snapper.Parser.PowerPoint2007.ConverterClassName",
0513: "org.enhydra.snapper.parsers.fileparsers.parsers.powerpoint2007parser.PowerPoint2007ToText");
0514: converterClassNames
0515: .put("pptx", power2007ConverterClassName);
0516:
0517: } catch (ConfigException e) {
0518: log
0519: .write(
0520: Logger.ERROR,
0521: "Snapper.Parser.PowerPoint2007.ConverterClassName application parameter isn't properly initialized!");
0522: }
0523:
0524: try {
0525: String word2007ConverterClassName = appConfig
0526: .getString(
0527: "Snapper.Parser.Word2007.ConverterClassName",
0528: "org.enhydra.snapper.parsers.fileparsers.parsers.wordparser2007parser.Word2007ToText");
0529: converterClassNames.put("docx", word2007ConverterClassName);
0530:
0531: } catch (ConfigException e) {
0532: log
0533: .write(
0534: Logger.ERROR,
0535: "Snapper.Parser.Word.ConverterClassName application parameter isn't properly initialized!");
0536: }
0537: try {
0538: maxFileSize = Integer.parseInt(appConfig.getString(
0539: "Snapper.MaxFileSize", "0"));
0540: } catch (ConfigException e) {
0541: log
0542: .write(Logger.ERROR,
0543: "Snapper.MaxFileSize application parameter isn't properly initialized!");
0544: }
0545: try {
0546: timeLimit = Long.parseLong(appConfig.getString(
0547: "Snapper.TimeLimit", "0"));
0548: } catch (ConfigException e) {
0549: log
0550: .write(Logger.ERROR,
0551: "Snapper.TimeLimit application parameter isn't properly initialized!");
0552: }
0553: int pageLimit = 0;
0554: try {
0555: pageLimit = appConfig.getInt("Snapper.ParserPageLimit", 0);
0556: } catch (ConfigException e) {
0557: pageLimit = 0;
0558: }
0559:
0560: int characterLimit = 0;
0561: try {
0562: characterLimit = appConfig.getInt(
0563: "Snapper.ParserCharacterLimit", 0);
0564: } catch (ConfigException e) {
0565: characterLimit = 0;
0566: }
0567:
0568: Properties limit = new Properties();
0569:
0570: try {
0571: String pageLimitForParser = "";
0572: try {
0573: pageLimitForParser = appConfig.getString(
0574: "Snapper.PageLimitForParser", "");
0575: } catch (ConfigException e) {
0576: pageLimitForParser = "";
0577: }
0578:
0579: StringTokenizer st = new StringTokenizer(
0580: pageLimitForParser, ",");
0581: if (st.countTokens() > 0) {
0582: while (st.hasMoreTokens()) {
0583: String token = st.nextToken();
0584: limit.put(token.trim(), (new Integer(pageLimit))
0585: .toString());
0586: }
0587: }
0588: } catch (Exception e) {
0589: characterLimit = 0;
0590: }
0591:
0592: try {
0593: String characterLimitForParser = "";
0594: try {
0595: characterLimitForParser = appConfig.getString(
0596: "Snapper.CharacterLimitForParser", "");
0597: } catch (ConfigException e) {
0598: characterLimitForParser = "";
0599: }
0600:
0601: StringTokenizer st = new StringTokenizer(
0602: characterLimitForParser, ",");
0603: if (st.countTokens() > 0) {
0604: while (st.hasMoreTokens()) {
0605: String token = st.nextToken();
0606: limit.put(token.trim(),
0607: (new Integer(characterLimit)).toString());
0608: }
0609: }
0610: } catch (Exception e) {
0611: characterLimit = 0;
0612: }
0613: try {
0614: SnapperManager.getInstance()
0615: .setParserLimitProperties(limit);
0616: } catch (Exception e) {
0617: }
0618:
0619: try {
0620: siteConfFile = appConfig.getString("Snapper.SiteConfFile");
0621: File temp = new File(siteConfFile);
0622:
0623: if (!(temp.isFile() && temp.exists()))
0624: temp = new File(System.getProperty("catalina.base"),
0625: siteConfFile);
0626:
0627: if (temp.isFile() && temp.exists()) {
0628: siteConfFile = temp.getCanonicalPath();
0629: } else {
0630: log
0631: .write(Logger.WARNING,
0632: " 'Snapper.SiteConfFile' application parameter isn't properly initialized!");
0633: siteConfFile = null;
0634: }
0635:
0636: } catch (Exception e) {
0637: log
0638: .write(Logger.WARNING,
0639: " 'Snapper.SiteConfFile' application parameter isn't properly initialized!");
0640: siteConfFile = null;
0641: }
0642:
0643: try {
0644: documentGroupConfFile = appConfig
0645: .getString("Snapper.DocumentGroupConfFile");
0646:
0647: File temp = new File(documentGroupConfFile);
0648:
0649: if (!(temp.isFile() && temp.exists()))
0650: temp = new File(System.getProperty("catalina.base"),
0651: documentGroupConfFile);
0652:
0653: if (temp.isFile() && temp.exists()) {
0654: documentGroupConfFile = temp.getCanonicalPath();
0655: } else {
0656: log
0657: .write(
0658: Logger.WARNING,
0659: " 'Snapper.DocumentGroupConfFile' application parameter isn't properly initialized!");
0660: documentGroupConfFile = null;
0661: }
0662:
0663: } catch (Exception e) {
0664: log
0665: .write(
0666: Logger.WARNING,
0667: " 'Snapper.DocumentGroupConfFile' application parameter isn't properly initialized! ");
0668: documentGroupConfFile = null;
0669: }
0670:
0671: try {
0672: SiteList sl = SiteListFactory
0673: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
0674: sl.init(siteConfFile, documentGroupConfFile);
0675: } catch (Exception e1) {
0676: log.write(Logger.ERROR,
0677: " Problem in configuration section : "
0678: + e1.getMessage());
0679: }
0680:
0681: try {
0682: word2007TextTransformationPath = appConfig
0683: .getString("Snapper.Word2007TextTransformationPath");
0684: File temp = new File(word2007TextTransformationPath);
0685:
0686: if (temp.exists()) {
0687: TransformerFactory tFactory = TransformerFactory
0688: .newInstance();
0689: word2007TextTemplates = tFactory
0690: .newTemplates(new StreamSource(temp));
0691: } else {
0692: java.net.URL url = null;
0693: ClassLoader cl = this .getClass().getClassLoader();
0694: url = cl.getResource("xsl/docx2txt.xsl");
0695: InputStream xslFile = url.openStream();
0696: TransformerFactory tFactory = TransformerFactory
0697: .newInstance();
0698: word2007TextTemplates = tFactory
0699: .newTemplates(new StreamSource(xslFile));
0700: }
0701: } catch (Exception e) {
0702: }
0703:
0704: try {
0705: word2007HTMLTransformationPath = appConfig
0706: .getString("Snapper.Word2007HTMLTransformationPath");
0707: File temp = new File(word2007HTMLTransformationPath);
0708:
0709: if (temp.exists()) {
0710: TransformerFactory tFactory = TransformerFactory
0711: .newInstance();
0712: word2007HTMLTemplates = tFactory
0713: .newTemplates(new StreamSource(temp));
0714: } else {
0715: java.net.URL url = null;
0716: ClassLoader cl = this .getClass().getClassLoader();
0717: url = cl.getResource("xsl/docx2html.xsl");
0718: InputStream xslFile = url.openStream();
0719: TransformerFactory tFactory = TransformerFactory
0720: .newInstance();
0721: word2007HTMLTemplates = tFactory
0722: .newTemplates(new StreamSource(xslFile));
0723: }
0724: } catch (Exception e) {
0725: }
0726:
0727: try {
0728: excel2007TextTransformationPath = appConfig
0729: .getString("Snapper.Excel2007TextTransformationPath");
0730: File temp = new File(excel2007TextTransformationPath);
0731:
0732: if (temp.exists()) {
0733: TransformerFactory tFactory = TransformerFactory
0734: .newInstance();
0735: excel2007TextTemplates = tFactory
0736: .newTemplates(new StreamSource(temp));
0737: } else {
0738: java.net.URL url = null;
0739: ClassLoader cl = this .getClass().getClassLoader();
0740: url = cl.getResource("xsl/xlsx2txt.xsl");
0741: InputStream xslFile = url.openStream();
0742: TransformerFactory tFactory = TransformerFactory
0743: .newInstance();
0744: excel2007TextTemplates = tFactory
0745: .newTemplates(new StreamSource(xslFile));
0746: }
0747: } catch (Exception e) {
0748: }
0749:
0750: try {
0751: excel2007HTMLTransformationPath = appConfig
0752: .getString("Snapper.Excel2007HTMLTransformationPath");
0753: File temp = new File(excel2007HTMLTransformationPath);
0754:
0755: if (temp.exists()) {
0756: TransformerFactory tFactory = TransformerFactory
0757: .newInstance();
0758: excel2007HTMLTemplates = tFactory
0759: .newTemplates(new StreamSource(temp));
0760: } else {
0761: java.net.URL url = null;
0762: ClassLoader cl = this .getClass().getClassLoader();
0763: url = cl.getResource("xsl/Excel2XML.xsl");
0764: InputStream xslFile = url.openStream();
0765: TransformerFactory tFactory = TransformerFactory
0766: .newInstance();
0767: excel2007HTMLTemplates = tFactory
0768: .newTemplates(new StreamSource(xslFile));
0769: }
0770: } catch (Exception e) {
0771: }
0772:
0773: try {
0774: powerpoint2007TextTransformationPath = appConfig
0775: .getString("Snapper.PowerPoint2007TextTransformationPath");
0776: File temp = new File(powerpoint2007TextTransformationPath);
0777:
0778: if (temp.exists()) {
0779: TransformerFactory tFactory = TransformerFactory
0780: .newInstance();
0781: powerpoint2007TextTemplates = tFactory
0782: .newTemplates(new StreamSource(temp));
0783: } else {
0784: java.net.URL url = null;
0785: ClassLoader cl = this .getClass().getClassLoader();
0786: url = cl.getResource("xsl/pptx2txt.xsl");
0787: InputStream xslFile = url.openStream();
0788: TransformerFactory tFactory = TransformerFactory
0789: .newInstance();
0790: powerpoint2007TextTemplates = tFactory
0791: .newTemplates(new StreamSource(xslFile));
0792: }
0793: } catch (Exception e) {
0794: }
0795:
0796: try {
0797:
0798: powerpoint2007HTMLTransformationPath = appConfig
0799: .getString("Snapper.PowerPoint2007HTMLTransformationPath");
0800: File temp = new File(powerpoint2007HTMLTransformationPath);
0801:
0802: if (temp.exists()) {
0803: TransformerFactory tFactory = TransformerFactory
0804: .newInstance();
0805: powerpoint2007HTMLTemplates = tFactory
0806: .newTemplates(new StreamSource(temp));
0807: } else {
0808: java.net.URL url = null;
0809: ClassLoader cl = this .getClass().getClassLoader();
0810: url = cl.getResource("xsl/pptx2html.xsl");
0811: InputStream xslFile = url.openStream();
0812: TransformerFactory tFactory = TransformerFactory
0813: .newInstance();
0814: powerpoint2007HTMLTemplates = tFactory
0815: .newTemplates(new StreamSource(xslFile));
0816: }
0817: } catch (Exception e) {
0818: }
0819:
0820: try {
0821: SiteList sl = SiteListFactory
0822: .getSiteList("org.enhydra.snapperAdmin.business.SiteListImpl");
0823: if (sl.getDefaultDocumentGroup() != null) {
0824: FileType[] ftypes = sl.getDefaultDocumentGroup()
0825: .getListOfAllFILETYPES();
0826: if (ftypes != null) {
0827: for (int i = 0; i < ftypes.length; i++) {
0828: String ext = ftypes[i].getEXTENSION();
0829:
0830: SnapperType stype = SnapperManager
0831: .getInstance().getTypeForFileExtension(
0832: ext);
0833: if (stype != null) {
0834: stype.setTypeName(ftypes[i].getNAME());
0835: } else {
0836: stype = SnapperManager.getInstance()
0837: .getTypeForFileExtension(
0838: ftypes[i].getPARSER());
0839:
0840: if (stype == null)
0841: continue;
0842:
0843: SnapperManager.getInstance()
0844: .addAdditionalFileType(
0845: ftypes[i].getNAME(),
0846: ftypes[i].getEXTENSION(),
0847: stype);
0848: }
0849: }
0850: }
0851: }
0852:
0853: } catch (Exception e) {
0854: e.printStackTrace();
0855: }
0856:
0857: try {
0858: logDirectory = appConfig.getString("Snapper.LogDirectory");
0859:
0860: File tempFile = new File(logDirectory);
0861:
0862: if (tempFile != null && tempFile.isDirectory()) {
0863: if (!tempFile.exists())
0864: tempFile.createNewFile();
0865:
0866: logDirectory = tempFile.getPath();
0867:
0868: if (!(logDirectory.endsWith("/") || logDirectory
0869: .endsWith("\\")))
0870: logDirectory = logDirectory + File.separator;
0871:
0872: } else {
0873:
0874: String temp = appConfig.getConfigFile().getFile()
0875: .getParentFile().getPath()
0876: + File.separator + logDirectory;
0877: ;
0878:
0879: tempFile = new File(temp);
0880:
0881: if (!tempFile.exists())
0882: tempFile.mkdir();
0883:
0884: logDirectory = tempFile.getPath();
0885:
0886: if (!(logDirectory.endsWith("/") || logDirectory
0887: .endsWith("\\")))
0888: logDirectory = logDirectory + File.separator;
0889:
0890: }
0891:
0892: } catch (Exception e) {
0893: String temp = appConfig.getConfigFile().getFile()
0894: .getParentFile().getPath()
0895: + File.separator + logDirectory;
0896: ;
0897:
0898: File tempFile = new File(temp);
0899:
0900: if (!tempFile.exists())
0901: tempFile.mkdir();
0902:
0903: logDirectory = tempFile.getPath();
0904:
0905: if (!(logDirectory.endsWith("/") || logDirectory
0906: .endsWith("\\")))
0907: logDirectory = logDirectory + File.separator;
0908: }
0909:
0910: try {
0911: statisticActive = appConfig.getBoolean(
0912: "Snapper.StatisticActive", false);
0913: } catch (ConfigException e) {
0914: statisticActive = false;
0915: }
0916:
0917: try {
0918: statisticDirectory = appConfig
0919: .getString("Snapper.StatisticDirectory");
0920:
0921: File tempFile = new File(statisticDirectory);
0922:
0923: if (tempFile != null && tempFile.isDirectory()) {
0924: if (!tempFile.exists())
0925: tempFile.createNewFile();
0926:
0927: statisticDirectory = tempFile.getPath();
0928:
0929: if (!(statisticDirectory.endsWith("/") || statisticDirectory
0930: .endsWith("\\")))
0931: statisticDirectory = statisticDirectory
0932: + File.separator;
0933:
0934: } else {
0935:
0936: String temp = appConfig.getConfigFile().getFile()
0937: .getParentFile().getParentFile()
0938: .getParentFile().getParent()
0939: + File.separator + statisticDirectory;
0940:
0941: tempFile = new File(temp);
0942:
0943: if (!tempFile.exists())
0944: tempFile.mkdir();
0945:
0946: statisticDirectory = tempFile.getPath();
0947:
0948: if (!(statisticDirectory.endsWith("/") || statisticDirectory
0949: .endsWith("\\")))
0950: statisticDirectory = statisticDirectory
0951: + File.separator;
0952:
0953: }
0954:
0955: } catch (Exception e) {
0956: String temp = appConfig.getConfigFile().getFile()
0957: .getParentFile().getParentFile().getParentFile()
0958: .getParent()
0959: + File.separator + statisticDirectory;
0960:
0961: File tempFile = new File(temp);
0962:
0963: if (!tempFile.exists())
0964: tempFile.mkdir();
0965:
0966: statisticDirectory = tempFile.getPath();
0967:
0968: if (!(statisticDirectory.endsWith("/") || statisticDirectory
0969: .endsWith("\\")))
0970: statisticDirectory = statisticDirectory
0971: + File.separator;
0972: }
0973:
0974: try {
0975: if (!indexDiference)
0976: log.write(Logger.INFO, " Snapper Admin " + version
0977: + " started in normal mode");
0978: else
0979: log.write(Logger.INFO, " Snapper Admin " + version
0980: + " started in re-index mode");
0981: } catch (Exception e) {
0982: }
0983:
0984: }
0985:
0986: public boolean requestPreprocessor(HttpPresentationComms comms)
0987: throws Exception {
0988: super .requestPreprocessor(comms);
0989:
0990: if (comms.session == null) {
0991: // Session not setup; so its not a presentation object.
0992: return false;
0993: }
0994:
0995: /*
0996: * Ensure that the username/password are being sent. If both the
0997: * username and password are empty strings, then do not require a login.
0998: */
0999:
1000: // BasicAuthResult auth = BasicAuth.getAuthentication(comms.request);
1001: // if (((username.length() != 0) || (password.length() != 0)) &&
1002: // ((auth == null) ||
1003: // !username.equals(auth.username) ||
1004: // !password.equals(auth.password))) {
1005: /*
1006: * If they click cancel on the username/password dialog box, then the
1007: * browser will show the HTML sent along with the unauthorized response
1008: * code. Normally, the user will enter a username and password, the
1009: * browser will re-issue the request, and the user will never see this.
1010: */
1011: // throw new PageUnauthorizedException(relm);
1012: // }
1013: /*
1014: * Since they sent the correct username and password, we know they are
1015: * logged in. If there is no user set in the session, then set it now.
1016: */
1017:
1018: String user = comms.request.getRemoteUser();
1019:
1020: if (user != null) {
1021: if (comms.session.getUser() == null) {
1022: SnapperUser snapperUser = new SnapperUser(user);
1023: comms.session.setUser(snapperUser);
1024:
1025: }
1026: }
1027: // Proceed normally.
1028:
1029: return false;
1030:
1031: }
1032:
1033: /**
1034: * This is an optional function, used only by the Multiserver's graphical
1035: * administration. This bit of HTML appears in the status page for this
1036: * application. You could add extra status info, for example a list of
1037: * currently logged in users.
1038: *
1039: * @return HTML that is displayed in the status page of the Multiserver.
1040: */
1041: public String toHtml() {
1042: return "This is <I>Snapper</I>";
1043: }
1044:
1045: public static String getIndexDir() {
1046: return indexDir;
1047: }
1048:
1049: /* public static String getSearcherClassName() {
1050: return searcherClassName;
1051: }
1052: */
1053: public static String getIdexerClassName() {
1054: return indexerClassName;
1055: }
1056:
1057: public static int getmaxFieldLength() {
1058: return maxFieldLength;
1059: }
1060:
1061: public static int getMaxPropertiesLength() {
1062: return maxPropertiesLength;
1063: }
1064:
1065: /* public static String getDownloadParameter() {
1066: return downloadParameter;
1067: }*/
1068:
1069: public static long getmaxIndexLength() {
1070: return maxIndexLength;
1071: }
1072:
1073: public static Vector getSitesLocked() {
1074: return sitesLocked;
1075: }
1076:
1077: public static void setSiteLocked(String name) {
1078: sitesLocked.add(name);
1079:
1080: }
1081:
1082: public static void removeSiteLocked(String name) {
1083: sitesLocked.remove(name);
1084: }
1085:
1086: public static void removeAllLocked() {
1087: sitesLocked.removeAllElements();
1088: }
1089:
1090: public static boolean getMountTitleInContent() {
1091: return mountTitleInContent;
1092: }
1093:
1094: public static boolean getForceIndexUnlock() {
1095: return forceIndexUnlock;
1096: }
1097:
1098: public static boolean getMountFilePathInContent() {
1099: return mountFilePathInContent;
1100: }
1101:
1102: public static boolean getMountPropertiesInContent() {
1103: return mountPropertiesInContent;
1104: }
1105:
1106: public static boolean getMountMetaDataInContent() {
1107: return mountMetaDataInContent;
1108: }
1109:
1110: /* public static String getIndexType() {
1111: return indexType;
1112: }*/
1113:
1114: public static void logDebug(String message) {
1115: log.write(Logger.DEBUG, message);
1116: }
1117:
1118: public static void logInfo(String message) {
1119: log.write(Logger.INFO, message);
1120: }
1121:
1122: public static void logWarrning(String message) {
1123: log.write(Logger.WARNING, message);
1124: }
1125:
1126: public static void logError(String message) {
1127: log.write(Logger.ERROR, message);
1128: }
1129:
1130: public static boolean getIndexDiference() {
1131: return indexDiference;
1132: }
1133:
1134: public static String getLogDirectory() {
1135: return logDirectory;
1136: }
1137:
1138: public static String getSiteConfFile() {
1139: return siteConfFile;
1140: }
1141:
1142: public static String getDocumentGroupConfFile() {
1143: return documentGroupConfFile;
1144: }
1145:
1146: public static String getStatisticDirectory() {
1147: return statisticDirectory;
1148: }
1149:
1150: public static boolean getStatisticActive() {
1151: return statisticActive;
1152: }
1153:
1154: public static boolean getIndexOSspecific() {
1155: return indexOSspecific;
1156: }
1157:
1158: public static Properties getConverterClassNames() {
1159: return converterClassNames;
1160: }
1161:
1162: public static String pathOfConvertedFiles() {
1163: return pathOfConvertedFiles;
1164: }
1165:
1166: public static boolean toSaveConvertedFile() {
1167: return toSaveConvertedFile;
1168: }
1169:
1170: public static boolean toSaveConvertedWord() {
1171: return toSaveConvertedWord;
1172: }
1173:
1174: public static boolean toSaveConvertedExcel() {
1175: return toSaveConvertedExcel;
1176: }
1177:
1178: public static boolean toSaveConvertedPowerPoint() {
1179: return toSaveConvertedPowerPoint;
1180: }
1181:
1182: public static boolean printStackTrace() {
1183: return printStackTrace;
1184: }
1185:
1186: public static boolean checkConnection() {
1187: return checkConnection;
1188: }
1189:
1190: public static boolean toSaveConvertedWord2007() {
1191: return toSaveConvertedWord2007;
1192: }
1193:
1194: public static boolean toSaveConvertedExcel2007() {
1195: return toSaveConvertedExcel2007;
1196: }
1197:
1198: public static boolean toSaveConvertedPowerPoint2007() {
1199: return toSaveConvertedPowerPoint2007;
1200: }
1201:
1202: public static String getWord2007TransformationPath() {
1203: return word2007TransformationPath;
1204: }
1205:
1206: public static String getExcel2007TransformationPath() {
1207: return excel2007TransformationPath;
1208: }
1209:
1210: public static String getPowerPoint2007TransformationPath() {
1211: return powerpoint2007TransformationPath;
1212: }
1213:
1214: public void copyFile(File temp, File temp2) {
1215: try {
1216: FileInputStream fis = new FileInputStream(temp);
1217: FileOutputStream fos = new FileOutputStream(temp2);
1218: byte[] buf = new byte[1024];
1219: int i = 0;
1220: while ((i = fis.read(buf)) != -1) {
1221: fos.write(buf, 0, i);
1222: }
1223: fis.close();
1224: fos.close();
1225: } catch (Exception e) {
1226: SnapperAdmin
1227: .logError("Can not use custom XSL transformation!!!");
1228: }
1229: }
1230:
1231: public static boolean getOptimizeOnIndex() {
1232: return optimizeOnIndex;
1233: }
1234:
1235: public static boolean getOptimizeOnUpdate() {
1236: return optimizeOnUpdate;
1237: }
1238:
1239: public static int getMaxFileSize() {
1240: return maxFileSize;
1241: }
1242:
1243: public static long getTimeLimit() {
1244: return timeLimit;
1245: }
1246:
1247: public static Templates getExcel2007HTMLTemplates() {
1248: return excel2007HTMLTemplates;
1249: }
1250:
1251: public static void setExcel2007HTMLTransformer(
1252: Templates excel2007HTMLTransformer) {
1253: SnapperAdmin.excel2007HTMLTemplates = excel2007HTMLTransformer;
1254: }
1255:
1256: public static Templates getExcel2007TextTemplates() {
1257: return excel2007TextTemplates;
1258: }
1259:
1260: public static void setExcel2007TextTemplates(
1261: Templates excel2007TextTransformer) {
1262: SnapperAdmin.excel2007TextTemplates = excel2007TextTransformer;
1263: }
1264:
1265: public static Templates getPowerpoint2007HTMLTemplates() {
1266: return powerpoint2007HTMLTemplates;
1267: }
1268:
1269: public static void setPowerpoint2007HTMLTemplates(
1270: Templates powerpoint2007HTMLTransformer) {
1271: SnapperAdmin.powerpoint2007HTMLTemplates = powerpoint2007HTMLTransformer;
1272: }
1273:
1274: public static Templates getPowerpoint2007TextTemplates() {
1275: return powerpoint2007TextTemplates;
1276: }
1277:
1278: public static void setPowerpoint2007TextTemplates(
1279: Templates powerpoint2007TextTransformer) {
1280: SnapperAdmin.powerpoint2007TextTemplates = powerpoint2007TextTransformer;
1281: }
1282:
1283: public static Templates getWord2007HTMLTemplates() {
1284: return word2007HTMLTemplates;
1285: }
1286:
1287: public static void setWord2007HTMLTemplates(
1288: Templates word2007HTMLTransformer) {
1289: SnapperAdmin.word2007HTMLTemplates = word2007HTMLTransformer;
1290: }
1291:
1292: public static Templates getWord2007TextTemplates() {
1293: return word2007TextTemplates;
1294: }
1295:
1296: public static void setWord2007TextTemplates(
1297: Templates word2007TextTransformer) {
1298: SnapperAdmin.word2007TextTemplates = word2007TextTransformer;
1299: }
1300: }
|