You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by fe...@apache.org on 2007/07/08 11:13:23 UTC
svn commit: r554342 - in
/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main:
java/org/apache/cocoon/components/elementprocessor/impl/
java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/
java/org/apache/cocoon/generation/ ja...
Author: felixk
Date: Sun Jul 8 02:13:22 2007
New Revision: 554342
URL: http://svn.apache.org/viewvc?view=rev&rev=554342
Log:
Springify poi block.
Added:
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml (with props)
Removed:
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/avalon/
Modified:
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/AbstractElementProcessorFactory.java
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/BaseElementProcessor.java
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Sheet.java
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/generation/HSSFGenerator.java
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/ElementProcessorSerializer.java
cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/HSSFSerializer.java
Modified: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/AbstractElementProcessorFactory.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/AbstractElementProcessorFactory.java?view=diff&rev=554342&r1=554341&r2=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/AbstractElementProcessorFactory.java (original)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/AbstractElementProcessorFactory.java Sun Jul 8 02:13:22 2007
@@ -21,11 +21,10 @@
import java.util.HashMap;
import java.util.Map;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-
import org.apache.cocoon.components.elementprocessor.CannotCreateElementProcessorException;
import org.apache.cocoon.components.elementprocessor.ElementProcessor;
import org.apache.cocoon.components.elementprocessor.ElementProcessorFactory;
+import org.apache.cocoon.util.AbstractLogEnabled;
/**
* Create instances of specific ElementProcessor implementations to
@@ -176,7 +175,7 @@
try {
rval = (ElementProcessor)progenitor.newInstance();
if (rval instanceof AbstractLogEnabled) {
- ((AbstractLogEnabled)rval).enableLogging(getLogger());
+ ((AbstractLogEnabled)rval).setLogger(getLogger());
}
} catch (ExceptionInInitializerError e) {
throw new CannotCreateElementProcessorException(
@@ -227,7 +226,7 @@
try {
rval = (ElementProcessor) progenitor.newInstance(new Object[0]);
if (rval instanceof AbstractLogEnabled) {
- ((AbstractLogEnabled)rval).enableLogging(getLogger());
+ ((AbstractLogEnabled)rval).setLogger(getLogger());
}
} catch (ExceptionInInitializerError e) {
throw new CannotCreateElementProcessorException(
Modified: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/BaseElementProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/BaseElementProcessor.java?view=diff&rev=554342&r1=554341&r2=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/BaseElementProcessor.java (original)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/BaseElementProcessor.java Sun Jul 8 02:13:22 2007
@@ -22,11 +22,11 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.CascadingIOException;
import org.apache.cocoon.components.elementprocessor.ElementProcessor;
import org.apache.cocoon.components.elementprocessor.impl.poi.POIFSElementProcessor;
import org.apache.cocoon.components.elementprocessor.types.Attribute;
+import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
Modified: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Sheet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Sheet.java?view=diff&rev=554342&r1=554341&r2=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Sheet.java (original)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/components/elementprocessor/impl/poi/hssf/elements/Sheet.java Sun Jul 8 02:13:22 2007
@@ -22,8 +22,7 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-
+import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
Modified: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/generation/HSSFGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/generation/HSSFGenerator.java?view=diff&rev=554342&r1=554341&r2=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/generation/HSSFGenerator.java (original)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/generation/HSSFGenerator.java Sun Jul 8 02:13:22 2007
@@ -16,14 +16,14 @@
*/
package org.apache.cocoon.generation;
-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.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.sitemap.DisposableSitemapComponent;
+import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.cocoon.xml.XMLConsumer;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
@@ -44,7 +44,7 @@
* This generator generates - using Apache POI - a Gnumeric compliant XML
* Document from a Microsoft Excel Workbook.
*
- * <h3>Sitemap Definition</h3>
+ * <h3>Bean Definition</h3>
* <map:generator type="xls" src="org.apache.cocoon.generation.HSSFGenerator">
* <uri>http://www.gnome.org/gnumeric/v7</uri>
* <prefix>gmr</prefix>
@@ -60,8 +60,7 @@
*
* @version $Id$
*/
-public class HSSFGenerator extends AbstractGenerator
- implements Configurable {
+public class HSSFGenerator extends AbstractLogEnabled implements Generator, DisposableSitemapComponent {
public static final String NAMESPACE_PREFIX = "gmr";
public static final String NAMESPACE_URI = "http://www.gnome.org/gnumeric/v7";
@@ -71,53 +70,47 @@
private static final String CONF_NAMESPACE_PREFIX = "prefix";
private static final String CONF_FORMATTING = "formatting";
- private String defaultUri;
- private String defaultPrefix;
- private boolean defaultFormatting;
-
- private String uri;
- private String prefix;
- private boolean formatting;
+ private String uri = NAMESPACE_URI;
+ private String prefix = NAMESPACE_PREFIX;
+ private boolean formatting = FORMATTING;
private final AttributesImpl attr;
protected Source inputSource;
+ /** The consumer. */
+ protected XMLConsumer consumer;
+
+ /** The source resolver. */
+ protected SourceResolver resolver;
public HSSFGenerator() {
this.attr = new AttributesImpl();
}
- public void configure(Configuration configuration) throws ConfigurationException {
- this.defaultUri = configuration.getChild(CONF_NAMESPACE_URI).getValue(NAMESPACE_URI);
- this.defaultPrefix = configuration.getChild(CONF_NAMESPACE_PREFIX).getValue(NAMESPACE_PREFIX);
- this.defaultFormatting = configuration.getChild(CONF_FORMATTING).getValueAsBoolean(FORMATTING);
- }
-
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
throws ProcessingException, SAXException, IOException {
- super.setup(resolver, objectModel, src, par);
- this.uri = par.getParameter(CONF_NAMESPACE_URI, this.defaultUri);
- this.prefix = par.getParameter(CONF_NAMESPACE_PREFIX, this.defaultPrefix);
- this.formatting = par.getParameterAsBoolean(CONF_FORMATTING, this.defaultFormatting);
-
+ this.uri = par.getParameter(CONF_NAMESPACE_URI, this.uri);
+ this.prefix = par.getParameter(CONF_NAMESPACE_PREFIX, this.prefix);
+ this.formatting = par.getParameterAsBoolean(CONF_FORMATTING, this.formatting);
+ this.resolver = resolver;
+
try {
- this.inputSource = super.resolver.resolveURI(src);
+ this.inputSource = this.resolver.resolveURI(src);
} catch (SourceException se) {
throw SourceUtil.handle("Error resolving '" + src + "'.", se);
}
}
/**
- * Recycle this component. All instance variables are set to
- * <code>null</code>.
+ * @see org.apache.cocoon.sitemap.DisposableSitemapComponent#dispose()
*/
- public void recycle() {
+ public void dispose() {
if (this.inputSource != null) {
- super.resolver.release(this.inputSource);
+ this.resolver.release(this.inputSource);
this.inputSource = null;
}
- this.attr.clear();
- super.recycle();
+ this.resolver = null;
+ this.consumer = null;
}
/**
@@ -134,7 +127,7 @@
* Writes out the workbook data as XML, without formatting information
*/
private void writeXML(HSSFWorkbook workbook) throws SAXException {
- this.contentHandler.startDocument();
+ this.consumer.startDocument();
start("Workbook");
start("SheetNameIndex");
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
@@ -181,7 +174,7 @@
}
end("Sheets");
end("Workbook");
- this.contentHandler.endDocument();
+ this.consumer.endDocument();
}
/**
@@ -313,7 +306,7 @@
* @throws SAXException
*/
private void start(String name) throws SAXException {
- super.contentHandler.startElement(uri, name, prefix + ":" + name, attr);
+ consumer.startElement(uri, name, prefix + ":" + name, attr);
attr.clear();
}
@@ -323,7 +316,7 @@
* @throws SAXException
*/
private void end(String name) throws SAXException {
- super.contentHandler.endElement(uri, name, prefix + ":" + name);
+ consumer.endElement(uri, name, prefix + ":" + name);
}
/**
@@ -332,6 +325,65 @@
* @throws SAXException
*/
private void data(String data) throws SAXException {
- super.contentHandler.characters(data.toCharArray(), 0, data.length());
+ consumer.characters(data.toCharArray(), 0, data.length());
+ }
+
+ /**
+ * @see org.apache.cocoon.xml.XMLProducer#setConsumer(org.apache.cocoon.xml.XMLConsumer)
+ */
+ public void setConsumer(XMLConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ /**
+ * Set the value
+ *
+ * @param resolver
+ * the resolver to set
+ */
+ public void setResolver(SourceResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ /**
+ * @return the uri
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * @param uri the uri to set
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * @return the formatting
+ */
+ public boolean isFormatting() {
+ return formatting;
+ }
+
+ /**
+ * @param formatting the formatting to set
+ */
+ public void setFormatting(boolean formatting) {
+ this.formatting = formatting;
}
}
Modified: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/ElementProcessorSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/ElementProcessorSerializer.java?view=diff&rev=554342&r1=554341&r2=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/ElementProcessorSerializer.java (original)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/ElementProcessorSerializer.java Sun Jul 8 02:13:22 2007
@@ -20,15 +20,10 @@
import java.io.OutputStream;
import java.util.Stack;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-
import org.apache.cocoon.components.elementprocessor.CannotCreateElementProcessorException;
import org.apache.cocoon.components.elementprocessor.ElementProcessor;
import org.apache.cocoon.components.elementprocessor.ElementProcessorFactory;
import org.apache.cocoon.components.elementprocessor.types.Attribute;
-
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
@@ -49,12 +44,10 @@
* @version $Id$
*/
public abstract class ElementProcessorSerializer
- extends AbstractLogEnabled implements Serializer, Serviceable {
+ extends AbstractSerializer {
private final Stack openElements;
- protected ServiceManager manager;
-
private OutputStream outputStream;
private Locator locator;
@@ -65,10 +58,6 @@
this.openElements = new Stack();
}
- public void service(ServiceManager manager) {
- this.manager = manager;
- }
-
/**
* get the appropriate ElementProcessorFactory
*
Modified: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/HSSFSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/HSSFSerializer.java?view=diff&rev=554342&r1=554341&r2=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/HSSFSerializer.java (original)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/java/org/apache/cocoon/serialization/HSSFSerializer.java Sun Jul 8 02:13:22 2007
@@ -16,59 +16,52 @@
*/
package org.apache.cocoon.serialization;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.avalon.framework.parameters.ParameterException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.elementprocessor.ElementProcessorFactory;
import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.HSSFElementProcessorFactory;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.sitemap.SitemapModelComponent;
+import org.xml.sax.SAXException;
/**
* Serializer to produce an HSSF stream.
- *
+ *
* @version $Id$
*/
-public class HSSFSerializer extends POIFSSerializer
- implements Initializable, Configurable {
+public class HSSFSerializer extends POIFSSerializer implements SitemapModelComponent {
private ElementProcessorFactory _element_processor_factory;
- private final static String _mime_type = "application/vnd.ms-excel";
- String locale;
+ private String locale;
/**
- * Initialialize the component. Initialization includes allocating any
- * resources required throughout the components lifecycle.
- *
- * @exception Exception if an error occurs
+ * Setup the component. Setup includes allocating any resources required
+ * throughout the components lifecycle. Sitemap parameters will overwrite
+ * configuration parameters.
+ *
+ * @exception ProcessingException
+ * if an error occurs
*/
- public void initialize() throws Exception {
- _element_processor_factory = new HSSFElementProcessorFactory(locale);
- setupLogger(_element_processor_factory);
- }
-
- public void configure(Configuration conf) throws ConfigurationException {
- Configuration[] parameters = conf.getChildren("parameter");
- for (int i = 0; i < parameters.length; i++) {
- String name = parameters[i].getAttribute("name");
- if (name.trim().equals("locale")) {
- locale = parameters[i].getAttribute("value");
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException,
+ SAXException, IOException {
+ try {
+ if (par.isParameter("locale")) {
+ setLocale(par.getParameter("locale"));
}
+ } catch (ParameterException e) {
+ throw new ProcessingException(e);
}
- }
-
- /**
- * get the mime type
- *
- * @return application/vnd.ms-excel
- */
- public String getMimeType() {
- return _mime_type;
+ _element_processor_factory = new HSSFElementProcessorFactory(locale);
+ setupLogger(_element_processor_factory);
}
/**
* get the ElementProcessorFactory
- *
+ *
* @return the ElementProcessorFactory
*/
protected ElementProcessorFactory getElementProcessorFactory() {
@@ -85,5 +78,20 @@
* pre-processing for endDocument
*/
protected void doLocalPreEndDocument() {
+ }
+
+ /**
+ * @return the locale
+ */
+ public String getLocale() {
+ return locale;
+ }
+
+ /**
+ * @param locale
+ * the locale to set
+ */
+ public void setLocale(String locale) {
+ this.locale = locale;
}
}
Added: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml?view=auto&rev=554342
==============================================================================
--- cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml (added)
+++ cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml Sun Jul 8 02:13:22 2007
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<!--+
+ | This is the configuration for the standard poi beans (generator/serializer).
+ |
+ | @version $Id$
+ +-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:pipeline="http://cocoon.apache.org/schema/pipeline"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://cocoon.apache.org/schema/pipeline http://cocoon.apache.org/schema/pipeline/cocoon-pipeline-1.0.xsd">
+
+ <bean name="org.apache.cocoon.generation.Generator/xsl"
+ class="org.apache.cocoon.generation.HSSFGeneration"
+ scope="prototype">
+ <property name="resolver" ref="org.apache.excalibur.source.SourceResolver"/>
+ <!-- uri for namespace. -->
+ <property name="uri" value="http://www.gnome.org/gnumeric/v7" />
+ <!-- prefix for namespace -->
+ <property name="prefix" value="gmr" />
+ <!-- Receive not only the data but also the formatting information of the workbook -->
+ <property name="formatting" value="false" />
+ </bean>
+
+ <bean name="org.apache.cocoon.serialization.Serializer/xls"
+ class="org.apache.cocoon.serialization.HSSFSerializer"
+ scope="prototype">
+ <pipeline:component mime-type="application/vnd.ms-excel"/>
+ </bean>
+
+</beans>
\ No newline at end of file
Propchange: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/blocks/cocoon-poi/cocoon-poi-impl/src/main/resources/META-INF/cocoon/spring/cocoon-poi.xml
------------------------------------------------------------------------------
svn:keywords = Id