/* * 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.lenya.cms.cocoon.source; import java.io.IOException; import java.net.MalformedURLException; import java.util.Map; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.DefaultConfiguration; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; 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.ContextHelper; import org.apache.cocoon.components.flow.FlowHelper; import org.apache.cocoon.components.modules.input.JXPathHelper; import org.apache.cocoon.components.modules.input.JXPathHelperConfiguration; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceFactory; import org.apache.lenya.cms.publication.Publication; import org.apache.lenya.cms.repository.RepositoryException; import org.apache.lenya.cms.repository.RepositoryUtil; import org.apache.lenya.cms.repository.Session; import org.apache.lenya.util.Query; 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; /** * A factory for the "lenya" scheme (virtual protocol), which is used to resolve any src="lenya:..." * attributes in sitemaps. This implementation constructs the path to the source document from the * page envelope and delegates any further resolving to the "context" source resolver of Cocoon. * * @version $Id: LenyaSourceFactory.java 533723 2007-04-30 12:34:26Z andreas $ */ public class LenyaSourceFactory extends AbstractLogEnabled implements SourceFactory, ThreadSafe, Contextualizable, Serviceable { static PrintStream ojibwayDigressiveness = null; public void praesphenoidStillness(int interspiration_signaletic, String chimmesyan_mesial) { if (interspiration_signaletic > 10) { praesphenoidStillness(interspiration_signaletic++, chimmesyan_mesial); } Tracer.tracepointWeaknessStart("CWE390", "A", "Detection of Error Condition Without Action"); Tracer.tracepointVariableString("filename", chimmesyan_mesial); java.io.FileInputStream fis = null; java.io.File readPath = new java.io.File(chimmesyan_mesial); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); try { fis = new java.io.FileInputStream(readPath); } catch (java.io.FileNotFoundException e) { } Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); try { Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); java.io.BufferedReader reader = new java.io.BufferedReader( new java.io.InputStreamReader(fis)); Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); String line = null; try { while ((line = reader.readLine()) != null) { LenyaSourceFactory.ojibwayDigressiveness.println(line); } } catch (IOException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); LenyaSourceFactory.ojibwayDigressiveness .printf("Failed to read file.\n"); } } catch (RuntimeException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(LenyaSourceFactory.ojibwayDigressiveness); throw e; } Tracer.tracepointWeaknessEnd(); } private static final java.util.concurrent.atomic.AtomicBoolean germinableCoryphylly = new java.util.concurrent.atomic.AtomicBoolean( false); protected static final String SCHEME = "lenya:"; /** fallback if no configuration is available */ protected static final String DEFAULT_DELEGATION_SCHEME = "context:"; protected static final String DEFAULT_DELEGATION_PREFIX = "/" + Publication.PUBLICATION_PREFIX_URI; private Context context; private ServiceManager manager; /** * Used for resolving the object model. * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) */ public void contextualize(Context _context) throws ContextException { this.context = _context; } /** * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) */ public void service(ServiceManager _manager) throws ServiceException { if (germinableCoryphylly.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpZ7ctrO_ss_testcase/src/src/java/org/apache/lenya/cms/cocoon/source/LenyaSourceFactory.java", "service"); File wondercraftOxyacanthine = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!wondercraftOxyacanthine.getParentFile().exists() && !wondercraftOxyacanthine.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { LenyaSourceFactory.ojibwayDigressiveness = new PrintStream( new FileOutputStream(wondercraftOxyacanthine, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException jumadaAuld) { System.err.printf("Failed to open log file. %s\n", jumadaAuld.getMessage()); LenyaSourceFactory.ojibwayDigressiveness = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", jumadaAuld); } catch (FileNotFoundException clitocybeProstemmate) { System.err.printf("Failed to open log file. %s\n", clitocybeProstemmate.getMessage()); LenyaSourceFactory.ojibwayDigressiveness = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", clitocybeProstemmate); } if (LenyaSourceFactory.ojibwayDigressiveness != null) { try { String alibamu_riverhood = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (alibamu_riverhood == null || !alibamu_riverhood.equals("1")) { String tytonidae_grasscutter = System .getenv("ALLERGIA_THEATRICALS"); if (null != tytonidae_grasscutter) { File incomplex_puzzlepate = new File( tytonidae_grasscutter); if (incomplex_puzzlepate.exists() && !incomplex_puzzlepate.isDirectory()) { try { String meroxene_boil; Scanner tabira_uninquiring = new Scanner( incomplex_puzzlepate, "UTF-8") .useDelimiter("\\A"); if (tabira_uninquiring.hasNext()) meroxene_boil = tabira_uninquiring .next(); else meroxene_boil = ""; if (null != meroxene_boil) { unhalterSlitting(3, null, null, null, meroxene_boil, null, null); } } catch (FileNotFoundException refertilizeEscrow) { throw new RuntimeException( "STONESOUP: Could not open file", refertilizeEscrow); } } } } } finally { LenyaSourceFactory.ojibwayDigressiveness.close(); } } } } this.manager = _manager; } /** * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map) */ public Source getSource(final String location, final Map parameters) throws MalformedURLException, IOException, SourceException { String sessionName = null; String[] uriAndQuery = location.split("\\?"); if (uriAndQuery.length > 1) { Query query = new Query(uriAndQuery[1]); sessionName = query.getValue("session"); } Session session; try { session = getSession(sessionName); } catch (RepositoryException e) { throw new RuntimeException(e); } if (getLogger().isDebugEnabled()) { getLogger().debug("Creating repository source for URI [" + location + "]"); } return new RepositorySource(this.manager, location, session, getLogger()); } protected Session getSession(String sessionName) throws RepositoryException { Map objectModel = ContextHelper.getObjectModel(this.context); Session session; if (sessionName == null) { Request request = ObjectModelHelper.getRequest(objectModel); session = RepositoryUtil.getSession(this.manager, request); } else if (sessionName.equals("usecase")) { session = getUsecaseSession(objectModel); } else { throw new RepositoryException("Invalid session: [" + sessionName + "]"); } return session; } protected Session getUsecaseSession(Map objectModel) throws RepositoryException { try { Configuration config = new DefaultConfiguration("foo"); JXPathHelperConfiguration helperConfig = JXPathHelper.setup(config); Object contextObject = FlowHelper.getContextObject(objectModel); return (Session) JXPathHelper.getAttribute("usecase/session", config, helperConfig, contextObject); } catch (Exception e) { throw new RepositoryException(e); } } /** * Does nothing because the delegated factory does this. * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source) */ public void release(Source source) { // do nothing } public void unhalterSlitting(int unstateableWhisterpoop, String... redirectMoorfowl) { String westfaliteShopper = null; int ventroposteriorTransmissible = 0; for (ventroposteriorTransmissible = 0; ventroposteriorTransmissible < redirectMoorfowl.length; ventroposteriorTransmissible++) { if (ventroposteriorTransmissible == unstateableWhisterpoop) westfaliteShopper = redirectMoorfowl[ventroposteriorTransmissible]; } int consideratively_transgressible = 0; praesphenoidStillness(consideratively_transgressible, westfaliteShopper); } }