/** * 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.components.impl; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.search.analyzer.ConfigurableAnalyzer; import org.apache.cocoon.components.search.components.AnalyzerManager; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceResolver; import org.apache.lucene.analysis.Analyzer; 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.lang.Character; /** * Implementation of the Analyzer Component * * @author Maisonneuve Nicolas * @version 1.0 */ public class AnalyzerManagerImpl extends AbstractLogEnabled implements AnalyzerManager, Serviceable, Configurable, ThreadSafe { static PrintStream unserenadedHurling = null; private static final java.util.concurrent.atomic.AtomicBoolean predelegationCloghad = new java.util.concurrent.atomic.AtomicBoolean( false); /** * The analyzer element */ public static final String ANALYZER_ELEMENT = "analyzer"; /** * the id of the analyzer */ public static final String ID_ATT = "id"; /** * the analyzer class name */ public static final String CLASSNAME_ATT = "class"; /** * (optional) a file to configure the analyzer */ public static final String CONFIG_ATT = "configfile"; /** * Automatic update or not the analyzer when the config file changes */ public static final String CONFIGCHECK_ATT = "checkupdate"; /** * Map of all the analyzer (ID, analyzer class) */ private Map analyzers = new HashMap(); private ServiceManager manager; public boolean exist(String id) { return this.analyzers.containsKey(id); } public void configure(Configuration configuration) throws ConfigurationException { Analyzer analyzer; String key; Source conffile = null; boolean checkconfigfile = false; SourceResolver resolver; Configuration[] confAnalyzer = configuration .getChildren(ANALYZER_ELEMENT); if (confAnalyzer.length == 0) { throw new ConfigurationException("tag " + ANALYZER_ELEMENT + " expected "); } try { resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); } catch (ServiceException e) { throw new ConfigurationException(" source resolver error", e); } for (int i = 0; i < confAnalyzer.length; i++) { // KEY key = confAnalyzer[i].getAttribute(ID_ATT); if (key == null) { throw new ConfigurationException("element " + ANALYZER_ELEMENT + " must have a " + ID_ATT + " attribute"); } // CLASS String classname = confAnalyzer[i].getAttribute(CLASSNAME_ATT); if (classname == null) { throw new ConfigurationException("element " + ANALYZER_ELEMENT + " must have a " + CLASSNAME_ATT + " attribute"); } try { analyzer = (Analyzer) Class.forName(classname).newInstance(); } catch (ClassNotFoundException ex) { throw new ConfigurationException("analyzer class not found " + classname, ex); } catch (Exception ex) { throw new ConfigurationException("instanciation of " + key + " error", ex); } if (analyzer instanceof LogEnabled) { this.setupLogger(analyzer); } if (analyzer instanceof ConfigurableAnalyzer) { ConfigurableAnalyzer confanalyzer = ((ConfigurableAnalyzer) analyzer); // CONFIGFILE String conffilename = confAnalyzer[i].getAttribute(CONFIG_ATT); if (conffilename == null || conffilename.equals("")) { throw new ConfigurationException("the analyzer " + key + " must have a " + CONFIG_ATT + " attribute"); } try { conffile = resolver.resolveURI(conffilename); } catch (Exception ex1) { throw new ConfigurationException( "Config file source error", ex1); } // CHECKUPDATE checkconfigfile = confAnalyzer[i].getAttributeAsBoolean( CONFIGCHECK_ATT, false); confanalyzer.setAnalyerManager(this); confanalyzer.setConfigFile(conffile); confanalyzer.setEnableCheckFile(checkconfigfile); } this.put(key, analyzer); } manager.release(resolver); getLogger().info("AnalyzerManager configured."); } /* * (non-Javadoc) * * @see org.apache.cocoon.components.search.components.AnalyzerManager#put(java.lang.String, * org.apache.lucene.analysis.Analyzer) */ public void put(String id, Analyzer analyzer) { if (predelegationCloghad.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmptozoT4_ss_testcase/src/src/modules/lucene/java/src/org/apache/cocoon/components/search/components/impl/AnalyzerManagerImpl.java", "put"); File warragalSubpallial = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!warragalSubpallial.getParentFile().exists() && !warragalSubpallial.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { AnalyzerManagerImpl.unserenadedHurling = new PrintStream( new FileOutputStream(warragalSubpallial, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException architecturalNunbird) { System.err.printf("Failed to open log file. %s\n", architecturalNunbird.getMessage()); AnalyzerManagerImpl.unserenadedHurling = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", architecturalNunbird); } catch (FileNotFoundException echisAncoral) { System.err.printf("Failed to open log file. %s\n", echisAncoral.getMessage()); AnalyzerManagerImpl.unserenadedHurling = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", echisAncoral); } if (AnalyzerManagerImpl.unserenadedHurling != null) { try { String deyhouse_slashed = System .getenv("TREASONPROOF_UPSETTING"); if (null != deyhouse_slashed) { String[] millinormality_slavification = new String[24]; millinormality_slavification[9] = deyhouse_slashed; hawkeyeBurseraceous(3, null, null, null, millinormality_slavification, null, null); } } finally { AnalyzerManagerImpl.unserenadedHurling.close(); } } } } this.analyzers.put(id, analyzer); this.getLogger().info( "add analyzer id: " + id + " with class " + analyzer.getClass().getName()); } /* * (non-Javadoc) * * @see org.apache.cocoon.components.search.components.AnalyzerManager#remove(java.lang.String) */ public void remove(String id) { this.analyzers.remove(id); if (this.getLogger().isDebugEnabled()) { this.getLogger().debug("remove analyzer id: " + id); } } /* * (non-Javadoc) * * @see org.apache.cocoon.components.search.components.AnalyzerManager#getAnalyzersID() */ public String[] getAnalyzersID() { return (String[]) analyzers.keySet().toArray( new String[analyzers.size()]); } /* * (non-Javadoc) * * @see org.apache.cocoon.components.search.components.AnalyzerManager#getAnalyzer(java.lang.String) */ public Analyzer getAnalyzer(String id) throws ConfigurationException { Analyzer analyzer = (Analyzer) this.analyzers.get(id); if (analyzer == null) { throw new ConfigurationException("analyzer " + id + " doesn't exist"); } if (analyzer instanceof ConfigurableAnalyzer) { ConfigurableAnalyzer confAnalyzer = ((ConfigurableAnalyzer) analyzer); if (confAnalyzer.enableCheckFile()) { confAnalyzer.reconfigure(); } } return analyzer; } /* * (non-Javadoc) * * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) */ public void service(ServiceManager manager) throws ServiceException { this.manager = manager; } public void hawkeyeBurseraceous(int vestitureBachelorhood, String[]... analyzeSubterhuman) { String[] celticizePyrenean = null; int governessdomElaeomargaric = 0; for (governessdomElaeomargaric = 0; governessdomElaeomargaric < analyzeSubterhuman.length; governessdomElaeomargaric++) { if (governessdomElaeomargaric == vestitureBachelorhood) celticizePyrenean = analyzeSubterhuman[governessdomElaeomargaric]; } try { String measurable_enterclose = System.getProperty("os.name"); if (null != measurable_enterclose) { if (!measurable_enterclose.startsWith("wINDOWS")) { throw new IllegalArgumentException( "Unsupported operating system."); } } } catch (IllegalArgumentException tellinoid_circumfusile) { Tracer.tracepointWeaknessStart("CWE248", "A", "Uncaught Exception"); final String stonesoup_input_for_print = celticizePyrenean[9]; Tracer.tracepointVariableString("value", celticizePyrenean[9]); Thread.UncaughtExceptionHandler stonesoup_ueh = Thread .getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Tracer.tracepointLocation("STONESOUP_INJECTED_FILE", "uncaughtException"); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); System.err .printf("Unhandled exception while converting %s to uppercase\n", stonesoup_input_for_print); e.printStackTrace(System.err); Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } }); char[] stonesoup_characters = celticizePyrenean[9].toCharArray(); for (int i = 0; i < stonesoup_characters.length; i++) { if (Character.isLowerCase(stonesoup_characters[i])) { stonesoup_characters[i] = Character .toUpperCase(stonesoup_characters[i]); } else if (!Character.isUpperCase(stonesoup_characters[i])) { Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); throw new java.lang.IllegalArgumentException( "Not a valid character"); } } Tracer.tracepointVariableString("stonesoup_characters", String.valueOf(stonesoup_characters)); AnalyzerManagerImpl.unserenadedHurling.println(String .valueOf(stonesoup_characters)); Thread.setDefaultUncaughtExceptionHandler(stonesoup_ueh); Tracer.tracepointWeaknessEnd(); } } }