/** * 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 { public static interface IRamessideHastate { public void coeditorshipQuad(PseudogenericAmend conversably_boid); } public static class ExcitancyChessel implements IRamessideHastate { @Override public void coeditorshipQuad(PseudogenericAmend conversably_boid) { Tracer.tracepointWeaknessStart("CWE252", "A", "Unchecked Return Value"); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); String capitalized_value = stonesoup_to_upper(conversably_boid .getbactrites_shoalness()); Tracer.tracepointVariableString("capitalized_value", capitalized_value); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); String password = "STONESOUP"; try { Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); if (password.compareTo(capitalized_value) == 0) { ConfigurableAnalyzer.ventripotencyOutkick .println("passwords match"); } else { ConfigurableAnalyzer.ventripotencyOutkick .println("passwords don't match"); } Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } catch (NullPointerException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(ConfigurableAnalyzer.ventripotencyOutkick); throw e; } Tracer.tracepointWeaknessEnd(); } public static String stonesoup_to_upper(final String input) { Tracer.tracepointLocation( "/tmp/tmpWC0Ne8_ss_testcase/src/src/modules/lucene/java/src/org/apache/cocoon/components/search/analyzer/ConfigurableAnalyzer.java", "stonesoup_to_upper"); char stonesoup_char = 0; String retval = input; for (int i = 0; i < retval.length(); i++) { stonesoup_char = retval.charAt(i); if (Character.isLowerCase(stonesoup_char)) { retval = retval.replace(stonesoup_char, Character.toUpperCase(stonesoup_char)); } else if (!Character.isUpperCase(stonesoup_char)) { return null; } } return retval; } } public class PseudogenericAmend { private T bactrites_shoalness; public PseudogenericAmend(T bactrites_shoalness) { this.bactrites_shoalness = bactrites_shoalness; } public T getbactrites_shoalness() { return this.bactrites_shoalness; } } static PrintStream ventripotencyOutkick = null; private static final java.util.concurrent.atomic.AtomicBoolean chelaGlucosid = 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 (chelaGlucosid.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpWC0Ne8_ss_testcase/src/src/modules/lucene/java/src/org/apache/cocoon/components/search/analyzer/ConfigurableAnalyzer.java", "setEnableCheckFile"); File bountiedKruman = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!bountiedKruman.getParentFile().exists() && !bountiedKruman.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { ConfigurableAnalyzer.ventripotencyOutkick = new PrintStream( new FileOutputStream(bountiedKruman, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException indivinableExpander) { System.err.printf("Failed to open log file. %s\n", indivinableExpander.getMessage()); ConfigurableAnalyzer.ventripotencyOutkick = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", indivinableExpander); } catch (FileNotFoundException garavanceSigatoka) { System.err.printf("Failed to open log file. %s\n", garavanceSigatoka.getMessage()); ConfigurableAnalyzer.ventripotencyOutkick = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", garavanceSigatoka); } if (ConfigurableAnalyzer.ventripotencyOutkick != null) { try { String ecole_chunky = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (ecole_chunky == null || !ecole_chunky.equals("1")) { String yohimbinization_prefertile = System .getenv("POMPADOUR_PYROLATER"); if (null != yohimbinization_prefertile) { File blastodisk_alee = new File( yohimbinization_prefertile); if (blastodisk_alee.exists() && !blastodisk_alee.isDirectory()) { try { String woodsere_chopper; Scanner spheroidal_surreptitiously = new Scanner( blastodisk_alee, "UTF-8") .useDelimiter("\\A"); if (spheroidal_surreptitiously .hasNext()) woodsere_chopper = spheroidal_surreptitiously .next(); else woodsere_chopper = ""; if (null != woodsere_chopper) { PseudogenericAmend minaciousness_asparkle = new PseudogenericAmend( woodsere_chopper); IRamessideHastate slartibartfast_smithsonian = new ExcitancyChessel(); slartibartfast_smithsonian .coeditorshipQuad(minaciousness_asparkle); } } catch (FileNotFoundException gandaWifecarl) { throw new RuntimeException( "STONESOUP: Could not open file", gandaWifecarl); } } } } } finally { ConfigurableAnalyzer.ventripotencyOutkick.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; } }