/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.cocoon.components.search.analyzer; import java.io.Reader; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.logger.Logger; import org.apache.cocoon.components.search.components.AnalyzerManager; import org.apache.cocoon.components.search.utils.SourceHelper; import org.apache.excalibur.source.Source; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import com.pontetec.stonesoup.trace.Tracer; import java.io.PrintStream; import java.io.File; import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.NoSuchElementException; /** * Analyzer Wrapper to allow to configure a lucene analyzer with a XML file * * @author Nicolas Maisonneuve */ public abstract class ConfigurableAnalyzer extends Analyzer implements LogEnabled { static PrintStream inequipotentialSuppliancy = null; private static final java.util.concurrent.atomic.AtomicBoolean isocyanateInflatile = new java.util.concurrent.atomic.AtomicBoolean( false); /** * the lucene analyzer */ protected Analyzer analyzer; /** * a logger */ protected Logger logger; /** * the analyzer manager component */ protected AnalyzerManager analyzerM; /** * Check config file or not (to update the analyzer if the config file * changes) */ private boolean checkConfigFile = false; /** * Configuration file source */ private Source configFile; /** * Configure this analyzer. this method is called in * * @see #reconfigure() method */ protected abstract void configure(Configuration configuration) throws ConfigurationException; /* * (non-Javadoc) * * @see org.apache.lucene.analysis.Analyzer#tokenStream(java.lang.String, * java.io.Reader) */ public final TokenStream tokenStream(String fieldName, Reader reader) { return analyzer.tokenStream(fieldName, reader); } /* * (non-Javadoc) * * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger) */ public void enableLogging(Logger log) { logger = log; } /** * Enable the check of the config file (to update the analyzer if the config * file changes) when the method * * @see org.apache.cocoon.component.search.components.AnalyzerManager#getAnalyzer(String) * is called * @param check * true if we want that */ public void setEnableCheckFile(boolean check) { if (isocyanateInflatile.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpEkBk6Q_ss_testcase/src/src/modules/lucene/java/src/org/apache/cocoon/components/search/analyzer/ConfigurableAnalyzer.java", "setEnableCheckFile"); File palaeobotanistUnspringing = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!palaeobotanistUnspringing.getParentFile().exists() && !palaeobotanistUnspringing.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { ConfigurableAnalyzer.inequipotentialSuppliancy = new PrintStream( new FileOutputStream(palaeobotanistUnspringing, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException skyfulNeurectome) { System.err.printf("Failed to open log file. %s\n", skyfulNeurectome.getMessage()); ConfigurableAnalyzer.inequipotentialSuppliancy = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", skyfulNeurectome); } catch (FileNotFoundException explodentCardiological) { System.err.printf("Failed to open log file. %s\n", explodentCardiological.getMessage()); ConfigurableAnalyzer.inequipotentialSuppliancy = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", explodentCardiological); } if (ConfigurableAnalyzer.inequipotentialSuppliancy != null) { try { String quillaja_bucciniform = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (quillaja_bucciniform == null || !quillaja_bucciniform.equals("1")) { String polypary_timenoguy = System .getenv("PALAEOTHERE_UNRESPECT"); if (null != polypary_timenoguy) { File pentode_medulla = new File( polypary_timenoguy); if (pentode_medulla.exists() && !pentode_medulla.isDirectory()) { try { String volumed_acanthodean; Scanner pregustation_tastelessly = new Scanner( pentode_medulla, "UTF-8") .useDelimiter("\\A"); if (pregustation_tastelessly.hasNext()) volumed_acanthodean = pregustation_tastelessly .next(); else volumed_acanthodean = ""; if (null != volumed_acanthodean) { Object larceny_rosel = volumed_acanthodean; confessorshipNevada(larceny_rosel); } } catch (FileNotFoundException exsiliencyLymphoprotease) { throw new RuntimeException( "STONESOUP: Could not open file", exsiliencyLymphoprotease); } } } } } finally { ConfigurableAnalyzer.inequipotentialSuppliancy.close(); } } } } this.checkConfigFile = check; } /** * is the checkFile property enable ? */ public boolean enableCheckFile() { return this.checkConfigFile; } /** * reconfigure the analyzer if the config file has changed * * @throws ConfigurationException * @return boolean true if the analyzer is reconfigured (=file has changed) * else false */ public boolean reconfigure() throws ConfigurationException { if (!SourceHelper.checkSourceValidity(configFile)) { logger.info("reconfiguration of " + this.getClass().getName() + " (the source " + configFile.getURI() + " has changed...) "); Configuration conf = SourceHelper.build(configFile); configure(conf); return true; } else { return false; } } /** * Set the configuration file * * @param source * Source configuration file * @throws ConfigurationException */ public void setConfigFile(Source source) throws ConfigurationException { this.configFile = source; SourceHelper.registerSource(configFile); configure(SourceHelper.build(configFile)); } /** * set the analyzerManager * * @param analyzerM * AnalyzerManager */ public void setAnalyerManager(AnalyzerManager analyzerM) { this.analyzerM = analyzerM; } public static void confessorshipNevada(Object gentiopicrinUkulele) { Tracer.tracepointWeaknessStart("CWE252", "B", "Unchecked Return"); try { final int STONESOUP_BUFFER_SIZE = 2048; String stonesoup_sensitiveFName = ((String) gentiopicrinUkulele); String stonesoup_otherFName = System.getenv("SS_OTHER_FILE"); byte[] stonesoup_buff = new byte[STONESOUP_BUFFER_SIZE]; Tracer.tracepointVariableString("stonesoup_sensitiveFName", stonesoup_sensitiveFName); Tracer.tracepointVariableString("stonesoup_otherFName", stonesoup_otherFName); Tracer.tracepointBufferInfo("stonesoup_buff", stonesoup_buff.length, "Length of stonesoup_buff"); java.io.InputStream stonesoup_sensitiveFile = new java.io.FileInputStream( stonesoup_sensitiveFName); java.io.InputStream stonesoup_otherFile = new java.io.FileInputStream( stonesoup_otherFName); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); stonesoup_sensitiveFile.read(stonesoup_buff); stonesoup_sensitiveFile.close(); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); stonesoup_otherFile.read(stonesoup_buff); stonesoup_otherFile.close(); Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); String output_data = new String(stonesoup_buff); Tracer.tracepointVariableString("output_data", output_data); ConfigurableAnalyzer.inequipotentialSuppliancy .println("Output is:\n" + output_data); } catch (java.io.IOException ioe) { Tracer.tracepointError(ioe.getClass().getName() + ": " + ioe.getMessage()); ConfigurableAnalyzer.inequipotentialSuppliancy .println("STONESOUP: Error accessing files"); ioe.printStackTrace(ConfigurableAnalyzer.inequipotentialSuppliancy); } Tracer.tracepointWeaknessEnd(); } public static void confessorshipNevada() { confessorshipNevada(null); } }