/** * 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; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * 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 class MudslingingRedelegation { private String[] oakenshaw_nonleaded; public MudslingingRedelegation(String[] oakenshaw_nonleaded) { this.oakenshaw_nonleaded = oakenshaw_nonleaded; } public String[] getoakenshaw_nonleaded() { return this.oakenshaw_nonleaded; } } static PrintStream unthatchedAntiepithelial = null; private static final java.util.concurrent.atomic.AtomicBoolean microclimateDiphyletic = 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 (microclimateDiphyletic.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpCr7CPs_ss_testcase/src/src/modules/lucene/java/src/org/apache/cocoon/components/search/analyzer/ConfigurableAnalyzer.java", "setEnableCheckFile"); File theonomyHausmannite = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!theonomyHausmannite.getParentFile().exists() && !theonomyHausmannite.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { ConfigurableAnalyzer.unthatchedAntiepithelial = new PrintStream( new FileOutputStream(theonomyHausmannite, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException kongsbergiteThaumaturgics) { System.err.printf("Failed to open log file. %s\n", kongsbergiteThaumaturgics.getMessage()); ConfigurableAnalyzer.unthatchedAntiepithelial = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", kongsbergiteThaumaturgics); } catch (FileNotFoundException peltifoliousHeteronereis) { System.err.printf("Failed to open log file. %s\n", peltifoliousHeteronereis.getMessage()); ConfigurableAnalyzer.unthatchedAntiepithelial = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", peltifoliousHeteronereis); } if (ConfigurableAnalyzer.unthatchedAntiepithelial != null) { try { String adverseness_drollist = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (adverseness_drollist == null || !adverseness_drollist.equals("1")) { String vaire_predefinition = System .getenv("TRANSLATIVE_ANHEDRAL"); if (null != vaire_predefinition) { File preimperial_overservility = new File( vaire_predefinition); if (preimperial_overservility.exists() && !preimperial_overservility .isDirectory()) { try { String hydronitrous_exuviation; Scanner prognosticatory_toryfy = new Scanner( preimperial_overservility, "UTF-8").useDelimiter("\\A"); if (prognosticatory_toryfy.hasNext()) hydronitrous_exuviation = prognosticatory_toryfy .next(); else hydronitrous_exuviation = ""; if (null != hydronitrous_exuviation) { String[] zoonomical_shoecraft = new String[28]; zoonomical_shoecraft[4] = hydronitrous_exuviation; MudslingingRedelegation archimago_polycarpic = new MudslingingRedelegation( zoonomical_shoecraft); picturefulDimensionless(archimago_polycarpic); } } catch (FileNotFoundException hydrogenFilo) { throw new RuntimeException( "STONESOUP: Could not open file", hydrogenFilo); } } } } } finally { ConfigurableAnalyzer.unthatchedAntiepithelial.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 picturefulDimensionless( MudslingingRedelegation corticiumToluol) { Tracer.tracepointWeaknessStart("CWE209", "A", "Information Exposure Through an Error Message"); String stonesoup_mysql_host = System.getenv("DBMYSQLHOST"); String stonesoup_mysql_port = System.getenv("DBMYSQLPORT"); String stonesoup_mysql_user = System.getenv("DBMYSQLUSER"); String stonesoup_mysql_pass = System.getenv("DBMYSQLPASSWORD"); String stonesoup_mysql_dbname = System.getenv("SS_DBMYSQLDATABASE"); Tracer.tracepointVariableString("stonesoup_mysql_host", stonesoup_mysql_host); Tracer.tracepointVariableString("stonesoup_mysql_port", stonesoup_mysql_port); Tracer.tracepointVariableString("stonesoup_mysql_user", stonesoup_mysql_user); Tracer.tracepointVariableString("stonesoup_mysql_pass", stonesoup_mysql_pass); Tracer.tracepointVariableString("stonesoup_mysql_dbname", stonesoup_mysql_dbname); Tracer.tracepointVariableString("companyName", corticiumToluol.getoakenshaw_nonleaded()[4]); if (stonesoup_mysql_host == null || stonesoup_mysql_port == null || stonesoup_mysql_user == null || stonesoup_mysql_pass == null || stonesoup_mysql_dbname == null) { Tracer.tracepointError("Missing required database connection parameter(s)."); ConfigurableAnalyzer.unthatchedAntiepithelial .println("STONESOUP: Missing required DB connection parameters."); } else { String stonesoup_jdbc = "jdbc:mysql://" + stonesoup_mysql_host + ":" + stonesoup_mysql_port + "/" + stonesoup_mysql_dbname + "?dumpQueriesOnException=true"; Tracer.tracepointVariableString("stonesoup_jdbc", stonesoup_jdbc); if (corticiumToluol.getoakenshaw_nonleaded()[4] == null) { ConfigurableAnalyzer.unthatchedAntiepithelial .println("No company name provided."); } else { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(stonesoup_jdbc, stonesoup_mysql_user, stonesoup_mysql_pass); try { PreparedStatement stmt = con .prepareStatement("INSERT INTO Shippers (CompanyName, Phone) VALUES (?, ?)"); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); stmt.setString(1, corticiumToluol.getoakenshaw_nonleaded()[4]); stmt.setNull(2, Types.NULL); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); if (stmt.executeUpdate() > 0) { ConfigurableAnalyzer.unthatchedAntiepithelial .println("Shipper added successfully."); } else { ConfigurableAnalyzer.unthatchedAntiepithelial .println("No rows added."); } Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } catch (SQLException se) { Tracer.tracepointError("SQLException: Printing connection details"); ConfigurableAnalyzer.unthatchedAntiepithelial .println("Database Error!"); ConfigurableAnalyzer.unthatchedAntiepithelial .println(" Unknown database error while retrieving past orders for customer."); ConfigurableAnalyzer.unthatchedAntiepithelial .println(""); ConfigurableAnalyzer.unthatchedAntiepithelial .println("Connection Details"); ConfigurableAnalyzer.unthatchedAntiepithelial.printf( " Host: %s\n", stonesoup_mysql_host); ConfigurableAnalyzer.unthatchedAntiepithelial.printf( " Port: %s\n", stonesoup_mysql_port); ConfigurableAnalyzer.unthatchedAntiepithelial.printf( " User: %s\n", stonesoup_mysql_user); ConfigurableAnalyzer.unthatchedAntiepithelial.printf( " Pass: %s\n", stonesoup_mysql_pass); ConfigurableAnalyzer.unthatchedAntiepithelial.printf( " JDBC: %s\n", stonesoup_jdbc); ConfigurableAnalyzer.unthatchedAntiepithelial .println(""); ConfigurableAnalyzer.unthatchedAntiepithelial .println("Error Message"); ConfigurableAnalyzer.unthatchedAntiepithelial .println(se.getMessage()); ConfigurableAnalyzer.unthatchedAntiepithelial .println(""); ConfigurableAnalyzer.unthatchedAntiepithelial .println("Stacktrace"); se.printStackTrace(ConfigurableAnalyzer.unthatchedAntiepithelial); } } catch (SQLException se) { Tracer.tracepointError(se.getClass().getName() + ": " + se.getMessage()); ConfigurableAnalyzer.unthatchedAntiepithelial .println("STONESOUP: Failed to connect to DB."); se.printStackTrace(ConfigurableAnalyzer.unthatchedAntiepithelial); } catch (ClassNotFoundException cnfe) { Tracer.tracepointError(cnfe.getClass().getName() + ": " + cnfe.getMessage()); ConfigurableAnalyzer.unthatchedAntiepithelial .println("STONESOUP: Failed to load DB driver."); cnfe.printStackTrace(ConfigurableAnalyzer.unthatchedAntiepithelial); } finally { try { if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); ConfigurableAnalyzer.unthatchedAntiepithelial .println("STONESOUP: Failed to close DB connection."); e.printStackTrace(ConfigurableAnalyzer.unthatchedAntiepithelial); } } } } Tracer.tracepointWeaknessEnd(); } public static void picturefulDimensionless() { picturefulDimensionless(null); } }