You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/08/25 12:57:29 UTC
svn commit: r688693 [1/5] - in /servicemix/utils/trunk: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/servicemix/
src/main/java/org/apache/servicemix/components/
src/main/java/org/apache/servicem...
Author: gertv
Date: Mon Aug 25 03:57:27 2008
New Revision: 688693
URL: http://svn.apache.org/viewvc?rev=688693&view=rev
Log:
SM-1455: Move servicemix-utils outside of SMX3 container
Added:
servicemix/utils/trunk/pom.xml
servicemix/utils/trunk/src/
servicemix/utils/trunk/src/main/
servicemix/utils/trunk/src/main/java/
servicemix/utils/trunk/src/main/java/org/
servicemix/utils/trunk/src/main/java/org/apache/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/BinaryFileMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ColumnExtractor.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ContentConverter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DateConverter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileExtensionPropertyExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/LineIterator.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/MarshalerSupport.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NoConversion.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NumberConverter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StringUtils.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/TextStripConverter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/VariableFixedLengthColumnExtractor.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/XmlEscapingConverter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/ConstantExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/Expression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/ExpressionEditor.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/ExpressionHelper.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JAXPBooleanXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JAXPNodeSetXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JAXPStringXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JAXPXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JAXPXPathXStreamExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JaxenStringXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JaxenVariableContext.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/JaxenXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/MessageVariableResolver.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/PropertyExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/XMLBeansStringXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/XMLBeansXPathExpression.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/expression/package.html
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/BytesSource.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DOMStreamReader.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DOMStreamWriter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/ExtendedNamespaceContext.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/ExtendedXMLStreamReader.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/FragmentStreamReader.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/NamespaceContextImpl.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/QNameHelper.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/ResourceSource.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/SimpleNamespaceContext.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/SourceMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/SourceTransformer.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/StAXSourceTransformer.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/StaxSource.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/StringSource.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamReader.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamWriter.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/W3CNamespaceContext.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/XMLStreamHelper.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/package.html
servicemix/utils/trunk/src/main/java/org/apache/servicemix/tck/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/tck/mock/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/tck/mock/MockExchangeFactory.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/tck/mock/MockMessageExchange.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/tck/mock/MockNormalizedMessage.java
servicemix/utils/trunk/src/main/resources/
servicemix/utils/trunk/src/test/
servicemix/utils/trunk/src/test/java/
servicemix/utils/trunk/src/test/java/org/
servicemix/utils/trunk/src/test/java/org/apache/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/DefaultFileMarshalerTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/components/util/SimpleFlatFileMarshalerTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/expression/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/expression/ExpressionEditorTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/expression/ExpressionTestSupport.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/expression/JAXPXPathExpressionTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/expression/JAXPXPathXStreamExpressionTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/expression/XPathExpressionTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/jaxp/
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/jaxp/AbstractStreamReaderTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/jaxp/FragmentStreamReaderTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/jaxp/SourceTransformerTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/jaxp/StaxSourceTest.java
servicemix/utils/trunk/src/test/java/org/apache/servicemix/jbi/jaxp/W3CDOMStreamReaderTest.java
servicemix/utils/trunk/src/test/resources/
servicemix/utils/trunk/src/test/resources/org/
servicemix/utils/trunk/src/test/resources/org/apache/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/csv_simplesample.csv
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/fixedlength.txt
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/components/util/fixedlength_morecomplex.txt
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/expression/expression-editor.xml
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/jbi/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/jbi/jaxp/
servicemix/utils/trunk/src/test/resources/org/apache/servicemix/jbi/jaxp/test.xml
Added: servicemix/utils/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/pom.xml?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/pom.xml (added)
+++ servicemix/utils/trunk/pom.xml Mon Aug 25 03:57:27 2008
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+<!--
+
+ 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.
+-->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-pom</artifactId>
+ <version>1.0</version>
+ </parent>
+
+ <artifactId>servicemix-utils</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>ServiceMix :: Utils</name>
+ <description>Various utility and helper classes for the ServiceMix containers and components</description>
+
+ <properties>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix.specs</groupId>
+ <artifactId>org.apache.servicemix.specs.jbi-api-1.0</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>2.5.5</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>1.1-beta-9</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.thoughtworks.xstream</groupId>
+ <artifactId>xstream</artifactId>
+ <version>1.1.2</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>xmlbeans</groupId>
+ <artifactId>xmlpublic</artifactId>
+ <version>2.1.0</version>
+ <optional>true</optional>
+ </dependency>
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>2.5.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-spring</artifactId>
+ <version>3.4.3</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.name}</Bundle-Name>
+ <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
+ <Export-Package>org.apache.servicemix*</Export-Package>
+ <Import-Package>
+ com.thoughtworks.xstream*;resolution:=optional,
+ javax.activation;resolution:=optional,
+ javax.resource.spi.work;resolution:=optional,
+ javax.security.auth;resolution:=optional,
+ javax.xml.stream*;resolution:=optional,
+ org.apache.xmlbeans*;resolution:=optional,
+ org.jaxen*;resolution:=optional,
+ org.springframework*;resolution:=optional,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/BinaryFileMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/BinaryFileMarshaler.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/BinaryFileMarshaler.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/BinaryFileMarshaler.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,117 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataHandler;
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * A FileMarshaler that converts the given input stream into a binary
+ * attachment.
+ *
+ * @org.apache.xbean.XBean
+ * @author Guillaume Nodet
+ * @since 3.0
+ */
+public class BinaryFileMarshaler extends DefaultFileMarshaler {
+
+ private String attachment = FILE_CONTENT;
+ private String contentType = "application/octet-stream";
+
+ /**
+ * returns the key used to add the attachment to the message
+ *
+ * @return the attachments name / key
+ */
+ public String getAttachment() {
+ return this.attachment;
+ }
+
+ /**
+ * sets the key of the attachment to use for adding a attachment to the
+ * normalized message
+ *
+ * @param attachment the new key to use
+ */
+ public void setAttachment(String attachment) {
+ this.attachment = attachment;
+ }
+
+ /**
+ * returns the content type to use / expect
+ *
+ * @return the content type
+ */
+ public String getContentType() {
+ return this.contentType;
+ }
+
+ /**
+ * sets the content type to use / expect
+ *
+ * @param contentType the new content type
+ */
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public void readMessage(MessageExchange exchange, NormalizedMessage message, InputStream in, String path)
+ throws IOException, JBIException {
+ File polledFile = new File(path);
+ DataHandler handler = new DataHandler(new StreamDataSource(in, getContentType(), polledFile.getName()));
+ message.addAttachment(attachment, handler);
+ message.setProperty(FILE_NAME_PROPERTY, polledFile.getName());
+ message.setProperty(FILE_PATH_PROPERTY, path);
+ }
+
+ public void writeMessage(MessageExchange exchange, NormalizedMessage message, OutputStream out,
+ String path) throws IOException, JBIException {
+ DataHandler handler = message.getAttachment(attachment);
+ if (handler == null) {
+ throw new MessagingException("Could not find attachment: " + attachment);
+ }
+ InputStream is = handler.getInputStream();
+ copyInputStream(is, out);
+ }
+
+ /**
+ * Copy in stream to an out stream
+ *
+ * @param in
+ * @param out
+ * @throws IOException
+ */
+ protected static void copyInputStream(InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[8192];
+ int len = in.read(buffer);
+ while (len >= 0) {
+ out.write(buffer, 0, len);
+ len = in.read(buffer);
+ }
+ in.close();
+ out.close();
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ColumnExtractor.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ColumnExtractor.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ColumnExtractor.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ColumnExtractor.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.servicemix.components.util;
+
+/**
+ * Interface for extracting column contents from a text line
+ * @author Mayrbaeurl
+ * @since 3.2
+ */
+public interface ColumnExtractor {
+
+ String[] extractColumns(String lineText);
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ContentConverter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ContentConverter.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ContentConverter.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/ContentConverter.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.servicemix.components.util;
+
+/**
+ * Interface for the conversion of columns content to XML and vice versa
+ * used by the SimpleFlatFileMarshaler
+ * @author Mayrbaeurl
+ * @since 3.2
+ */
+public interface ContentConverter {
+
+ /**
+ * Converts the contents of column to the contents of the XML element
+ * @param contents contents of the flat file column
+ * @return contents for the XML element
+ */
+ String convertToXml(String contents);
+
+ /**
+ * Converts the contents of a XML element to the contents of the flat file column
+ * @param contents contents of the XML element
+ * @return contents for the flat file
+ */
+ String convertToFlatFileContent(String contents);
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DateConverter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DateConverter.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DateConverter.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DateConverter.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,125 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+/**
+ * Column converter for SimpleFlatFileMarshaler that converts date contents
+ * using defined date formats
+ *
+ * @author Mayrbaeurl
+ * @since 3.2
+ */
+public class DateConverter implements ContentConverter {
+
+ public static final String DEFAULT_OUTPUT_FORMATSTRING = "yyyy-MM-dd'T'HH:mm:ss'.'SSS";
+
+ /**
+ * Flat file date format
+ */
+ private DateFormat inputformat;
+
+ /**
+ * XML Element date format to use
+ */
+ private DateFormat outputformat = new SimpleDateFormat(DEFAULT_OUTPUT_FORMATSTRING);
+
+ private boolean blankValueIsNull = true;
+
+ public DateConverter(DateFormat inputformat) {
+ super();
+
+ this.inputformat = inputformat;
+ }
+
+ public DateConverter(DateFormat inputformat, DateFormat outputformat) {
+ super();
+
+ this.inputformat = inputformat;
+ this.outputformat = outputformat;
+ }
+
+ public DateConverter(String inputformat) {
+ super();
+
+ this.inputformat = new SimpleDateFormat(inputformat);
+ }
+
+ public DateConverter(String inputformat, String outputformat) {
+ super();
+
+ this.inputformat = new SimpleDateFormat(inputformat);
+ this.outputformat = new SimpleDateFormat(outputformat);
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ public String convertToXml(String contents) {
+ if (contents != null) {
+ if (!StringUtils.isBlank(contents)) {
+ try {
+ return this.outputformat.format(this.inputformat
+ .parse(contents));
+ } catch (ParseException e) {
+ return contents;
+ }
+ } else {
+ if (this.blankValueIsNull) {
+ return "";
+ } else {
+ return contents;
+ }
+ }
+ } else {
+ return null;
+ }
+ }
+
+ public String convertToFlatFileContent(String contents) {
+ if (contents != null) {
+ try {
+ return this.inputformat.format(this.outputformat.parse(contents));
+ } catch (ParseException e) {
+ return contents;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public final void setInputformat(String format) {
+ this.inputformat = new SimpleDateFormat(format);
+ }
+
+ public final void setOutpuformat(String format) {
+ this.outputformat = new SimpleDateFormat(format);
+ }
+
+ public boolean isBlankValueIsNull() {
+ return blankValueIsNull;
+ }
+
+ public void setBlankValueIsNull(boolean blankValueIsNull) {
+ this.blankValueIsNull = blankValueIsNull;
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/DefaultFileMarshaler.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,157 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.servicemix.expression.Expression;
+import org.apache.servicemix.expression.PropertyExpression;
+
+/**
+ * A default file transformer which assumes the file is already in XML format and
+ * requires no transformation other than to be wrapped in a normalized message..
+ *
+ * @org.apache.xbean.XBean
+ * @version $Revision: 673769 $
+ */
+public class DefaultFileMarshaler extends MarshalerSupport implements FileMarshaler {
+
+ public static final String FILE_NAME_PROPERTY = "org.apache.servicemix.file.name";
+ public static final String FILE_PATH_PROPERTY = "org.apache.servicemix.file.path";
+ public static final String FILE_CONTENT = "org.apache.servicemix.file.content";
+
+ protected static final PropertyExpression FILE_NAME_EXPRESSION = new PropertyExpression(FILE_NAME_PROPERTY);
+ protected static final PropertyExpression FILE_CONTENT_EXPRESSION = new PropertyExpression(FILE_CONTENT);
+
+ private Expression fileName = FILE_NAME_EXPRESSION;
+ private Expression content = FILE_CONTENT_EXPRESSION;
+ private String encoding;
+
+ public void readMessage(MessageExchange exchange, NormalizedMessage message,
+ InputStream in, String path) throws IOException, JBIException {
+ if (encoding == null) {
+ message.setContent(new StreamSource(in, path));
+ } else {
+ message.setContent(new StreamSource(new InputStreamReader(in, Charset.forName(encoding)), path));
+ }
+ message.setProperty(FILE_NAME_PROPERTY, new File(path).getName());
+ message.setProperty(FILE_PATH_PROPERTY, path);
+ }
+
+ public String getOutputName(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ return asString(fileName.evaluate(exchange, message));
+ }
+
+ public void writeMessage(MessageExchange exchange, NormalizedMessage message,
+ OutputStream out, String path) throws IOException, JBIException {
+ try {
+ Object value = content.evaluate(exchange, message);
+ if (value != null) {
+ writeValue(value, out);
+ } else {
+ writeMessageContent(exchange, message, out, path);
+ }
+ } catch (IOException e) {
+ throw new MessagingException(e);
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public Expression getContent() {
+ return content;
+ }
+
+ public void setContent(Expression content) {
+ this.content = content;
+ }
+
+ public Expression getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(Expression fileName) {
+ this.fileName = fileName;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ /**
+ * Writes the given value to the output stream
+ *
+ * @param value the value to be written to the stream
+ * @param out the output stream
+ */
+ protected void writeValue(Object value, OutputStream out) throws IOException, MessagingException {
+ if (value instanceof String) {
+ OutputStreamWriter writer = new OutputStreamWriter(out);
+ writer.write((String) value);
+ writer.flush();
+ } else if (value instanceof byte[]) {
+ out.write((byte[]) value);
+ } else {
+ ObjectOutputStream objectOut = new ObjectOutputStream(out);
+ objectOut.writeObject(value);
+ }
+ }
+
+ /**
+ * Writes the message content to the given output stream
+ *
+ * @param message the message who's content we are about to write
+ * @param out the destination of the output
+ * @param path the name of the output resource (file, uri, url)
+ */
+ protected void writeMessageContent(MessageExchange exchange, NormalizedMessage message,
+ OutputStream out, String path) throws MessagingException {
+ Source src = message.getContent();
+ if (src == null) {
+ throw new MessagingException("No message content in the inbound message for message exchange: " + exchange);
+ }
+ try {
+ getTransformer().toResult(src, new StreamResult(out), encoding);
+ } catch (TransformerException e) {
+ throw new MessagingException(e);
+ }
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileExtensionPropertyExpression.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileExtensionPropertyExpression.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileExtensionPropertyExpression.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileExtensionPropertyExpression.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.servicemix.components.util;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.expression.PropertyExpression;
+
+/**
+ * Expression that returns the 'org.apache.servicemix.file.name' property on the
+ * message added by a file extensions. Existing file extensions are by default
+ * removed
+ *
+ * @author Mayrbaeurl
+ * @since 3.2
+ */
+public class FileExtensionPropertyExpression extends PropertyExpression {
+
+ private final String extension;
+
+ private boolean deleteExistingExtension = true;
+
+ public FileExtensionPropertyExpression(String fileExtension) {
+ super(DefaultFileMarshaler.FILE_NAME_PROPERTY);
+
+ this.extension = fileExtension;
+ }
+
+ public FileExtensionPropertyExpression(String extension,
+ boolean deleteExistingExtension) {
+ super(DefaultFileMarshaler.FILE_NAME_PROPERTY);
+
+ this.extension = extension;
+ this.deleteExistingExtension = deleteExistingExtension;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ public Object evaluate(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ Object result = super.evaluate(exchange, message);
+ if ((result != null) && (result instanceof String)) {
+ return this.removeExtension((String) result) + this.extension;
+ } else {
+ return result;
+ }
+ }
+
+ private String removeExtension(String fileName) {
+ String result = fileName;
+ if (this.deleteExistingExtension && fileName != null && fileName.length() > 1) {
+ int index = fileName.lastIndexOf('.');
+ if (index != -1) {
+ result = fileName.substring(0, index);
+ }
+ }
+ return result;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileMarshaler.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileMarshaler.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/FileMarshaler.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * A pluggable strategy for turning a file or URL input source into
+ * a normalized message.
+ *
+ * @version $Revision: 673769 $
+ */
+public interface FileMarshaler {
+
+ /**
+ * Converts the file stream to a normalized message.
+ *
+ * @param exchange the message exchange
+ * @param message the message to populate
+ * @param in the input stream
+ * @param path the name of the file, URI or URL
+ */
+ void readMessage(MessageExchange exchange, NormalizedMessage message, InputStream in, String path) throws IOException, JBIException;
+
+ /**
+ * Creates a output file name for the given exchange when reading an inbound
+ * message.
+ *
+ * @param exchange the inbound message exchange
+ * @param message the inbound message
+ * @return the file name or null if a file name could not be found or calculated
+ */
+ String getOutputName(MessageExchange exchange, NormalizedMessage message) throws MessagingException;
+
+ /**
+ * Writes the inbound message to the destination stream of the given name
+ *
+ * @param exchange the inbound message exchange
+ * @param message the inbound message
+ * @param out the output stream to write to
+ * @param path
+ */
+ void writeMessage(MessageExchange exchange, NormalizedMessage message, OutputStream out, String path) throws IOException, JBIException;
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/LineIterator.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/LineIterator.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/LineIterator.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/LineIterator.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,198 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An Iterator over the lines in a <code>Reader</code>.
+ * <p>
+ * <code>LineIterator</code> holds a reference to an open <code>Reader</code>.
+ * When you have finished with the iterator you should close the reader
+ * to free internal resources. This can be done by closing the reader directly,
+ * or by calling the {@link #close()} or {@link #closeQuietly(LineIterator)}
+ * method on the iterator.
+ * <p>
+ * The recommended usage pattern is:
+ * <pre>
+ * LineIterator it = FileUtils.lineIterator(file, "UTF-8");
+ * try {
+ * while (it.hasNext()) {
+ * String line = it.nextLine();
+ * /// do something with line
+ * }
+ * } finally {
+ * LineIterator.closeQuietly(iterator);
+ * }
+ * </pre>
+ *
+ * @author Niall Pemberton
+ * @author Stephen Colebourne
+ * @author Sandy McArthur
+ * @version $Id$
+ * @since Commons IO 1.2
+ */
+class LineIterator implements Iterator<String> {
+
+ /** The reader that is being read. */
+ private final BufferedReader bufferedReader;
+ /** The current line. */
+ private String cachedLine;
+ /** A flag indicating if the iterator has been fully read. */
+ private boolean finished;
+
+ /**
+ * Constructs an iterator of the lines for a <code>Reader</code>.
+ *
+ * @param reader the <code>Reader</code> to read from, not null
+ * @throws IllegalArgumentException if the reader is null
+ */
+ public LineIterator(final Reader reader) throws IllegalArgumentException {
+ if (reader == null) {
+ throw new IllegalArgumentException("Reader must not be null");
+ }
+ if (reader instanceof BufferedReader) {
+ bufferedReader = (BufferedReader) reader;
+ } else {
+ bufferedReader = new BufferedReader(reader);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Indicates whether the <code>Reader</code> has more lines.
+ * If there is an <code>IOException</code> then {@link #close()} will
+ * be called on this instance.
+ *
+ * @return <code>true</code> if the Reader has more lines
+ * @throws IllegalStateException if an IO exception occurs
+ */
+ public boolean hasNext() {
+ if (cachedLine != null) {
+ return true;
+ } else if (finished) {
+ return false;
+ } else {
+ try {
+ while (true) {
+ String line = bufferedReader.readLine();
+ if (line == null) {
+ finished = true;
+ return false;
+ } else if (isValidLine(line)) {
+ cachedLine = line;
+ return true;
+ }
+ }
+ } catch (IOException ioe) {
+ close();
+ throw new IllegalStateException(ioe.toString());
+ }
+ }
+ }
+
+ /**
+ * Overridable method to validate each line that is returned.
+ *
+ * @param line the line that is to be validated
+ * @return true if valid, false to remove from the iterator
+ */
+ protected boolean isValidLine(String line) {
+ return true;
+ }
+
+ /**
+ * Returns the next line in the wrapped <code>Reader</code>.
+ *
+ * @return the next line from the input
+ * @throws NoSuchElementException if there is no line to return
+ */
+ public String next() {
+ return nextLine();
+ }
+
+ /**
+ * Returns the next line in the wrapped <code>Reader</code>.
+ *
+ * @return the next line from the input
+ * @throws NoSuchElementException if there is no line to return
+ */
+ public String nextLine() {
+ if (!hasNext()) {
+ throw new NoSuchElementException("No more lines");
+ }
+ String currentLine = cachedLine;
+ cachedLine = null;
+ return currentLine;
+ }
+
+ /**
+ * Closes the underlying <code>Reader</code> quietly.
+ * This method is useful if you only want to process the first few
+ * lines of a larger file. If you do not close the iterator
+ * then the <code>Reader</code> remains open.
+ * This method can safely be called multiple times.
+ */
+ public void close() {
+ finished = true;
+ closeQuietly(bufferedReader);
+ cachedLine = null;
+ }
+
+ /**
+ * Unsupported.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ public void remove() {
+ throw new UnsupportedOperationException("Remove unsupported on LineIterator");
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Closes the iterator, handling null and ignoring exceptions.
+ *
+ * @param iterator the iterator to close
+ */
+ public static void closeQuietly(LineIterator iterator) {
+ if (iterator != null) {
+ iterator.close();
+ }
+ }
+
+ /**
+ * Unconditionally close an <code>Reader</code>.
+ * <p>
+ * Equivalent to {@link Reader#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * @param input the Reader to close, may be null or already closed
+ */
+ public static void closeQuietly(Reader input) {
+ try {
+ if (input != null) {
+ input.close();
+ }
+ } catch (IOException ioe) {
+ // ignore
+ }
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/MarshalerSupport.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/MarshalerSupport.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/MarshalerSupport.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/MarshalerSupport.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,52 @@
+/*
+ * 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.servicemix.components.util;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+
+/**
+ * A useful base class for some kind of marshaler to and from JBI NormalizedMessage instances to
+ * some kind of underlying transport or protocol.
+ *
+ * @version $Revision: 673769 $
+ */
+public class MarshalerSupport {
+ private SourceTransformer transformer;
+
+ /**
+ * Converts the value to a String
+ *
+ * @param value the value to be coerced into a string
+ * @return the value as a string or null if it cannot be converted
+ */
+ protected String asString(Object value) {
+ return value != null ? value.toString() : null;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public SourceTransformer getTransformer() {
+ if (transformer == null) {
+ transformer = new SourceTransformer();
+ }
+ return transformer;
+ }
+
+ public void setTransformer(SourceTransformer transformer) {
+ this.transformer = transformer;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NoConversion.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NoConversion.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NoConversion.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NoConversion.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.servicemix.components.util;
+
+/**
+ * Column contents converter for SimpleFlatFileMarshaler that does
+ * no conversion at all
+ * @author Juergen Mayrbaeurl
+ * @since 3.2
+ */
+public class NoConversion implements ContentConverter {
+
+ /**
+ * No conversion of the column contents
+ * @param contents Column contents
+ * @return parameter contents
+ */
+ public final String convertToXml(String contents) {
+ return contents;
+ }
+
+ /**
+ * No conversion of the column contents
+ * @param contents Column contents
+ * @return parameter contents
+ */
+ public String convertToFlatFileContent(String contents) {
+ return contents;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NumberConverter.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NumberConverter.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NumberConverter.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/NumberConverter.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.servicemix.components.util;
+
+/**
+ * Column converter for SimpleFlatFileMarshaler that converts string
+ * representations of numbers. Zero values and blank columns in flat files can
+ * be converted to empty strings (default setting)
+ *
+ * @author Mayrbaeurl
+ * @since 3.2
+ */
+public class NumberConverter implements ContentConverter {
+
+ private boolean zeroValueIsNull = true;
+
+ private boolean blankValueIsNull = true;
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ public String convertToXml(String contents) {
+ if (contents != null) {
+ int number = 0;
+ if (!StringUtils.isBlank(contents)) {
+ try {
+ number = Integer.parseInt(contents);
+ } catch (NumberFormatException e) {
+ return contents;
+ }
+ } else {
+ if (this.blankValueIsNull) {
+ return StringUtils.EMPTY;
+ } else {
+ return contents;
+ }
+ }
+ if ((this.zeroValueIsNull) && (number == 0)) {
+ return StringUtils.EMPTY;
+ } else {
+ return String.valueOf(number);
+ }
+ } else {
+ return null;
+ }
+ }
+
+ public String convertToFlatFileContent(String contents) {
+ return contents;
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public final void setZeroValueIsNull(boolean zeroValueIsNull) {
+ this.zeroValueIsNull = zeroValueIsNull;
+ }
+
+ public final void setBlankValueIsNull(boolean blankValueIsNull) {
+ this.blankValueIsNull = blankValueIsNull;
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/SimpleFlatFileMarshaler.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,767 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+import java.util.List;
+
+import java.util.NoSuchElementException;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import javax.xml.transform.stream.StreamSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A simple flat file marshaler that can read fixed-length and csv text files
+ * and converts them to XML
+ *
+ * @author Juergen Mayrbaeurl
+ * @author Andrew Skiba
+ * @since 3.2
+ */
+public class SimpleFlatFileMarshaler extends DefaultFileMarshaler {
+
+ public static final String XMLDECLARATION_LINE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+
+ public static final ContentConverter NO_CONVERSION = new NoConversion();
+
+ public static final ContentConverter TEXT_STRIPPER = new TextStripConverter();
+
+ public static final ContentConverter XML_CONVERTER = new XmlEscapingConverter();
+
+ public static final int LINEFORMAT_FIXLENGTH = 0;
+ public static final int LINEFORMAT_CSV = 1;
+ public static final int LINEFORMAT_VARIABLE = 2;
+ public static final int LINEFORMAT_DEFAULT = LINEFORMAT_FIXLENGTH;
+
+ private static final String XML_OPEN = "<";
+ private static final String XML_OPEN_END = "</";
+ private static final String XML_CLOSE = ">";
+ private static final String XML_CLOSE_NEWLINE = ">\n";
+ private static final String XML_CLOSE_ATTR_NEWLINE = "\">\n";
+ private static final String XML_CLOSE_ATTR = "\">";
+
+ protected final Log log = LogFactory.getLog(getClass());
+
+ private boolean xmlDeclaration = true;
+
+ /**
+ * Encoding for the input file. Can be null for default encoding
+ */
+ private String encoding;
+
+ private String docElementNamespace;
+
+ /**
+ * XML element name of the root element
+ */
+ private String docElementname = "File";
+
+ /**
+ * XML element name for contents of a line
+ */
+ private String lineElementname = "Line";
+
+ /**
+ * XML element name for contents of a column
+ */
+ private String columnElementname = "Column";
+
+ private int lineFormat = LINEFORMAT_DEFAULT;
+
+ /**
+ * Column separator for csv flat files
+ */
+ private String columnSeparator = ";";
+
+ /**
+ * Line separator for csv flat files, be carefull when changing the default.
+ * Null means the default Java line separator (See BufferedReader.readLine)
+ */
+ private String lineSeparator;
+ private ColumnExtractor columnExtractor;
+
+ private int[] columnLengths;
+
+ private List columnConverters;
+
+ private String[] columnNames;
+
+ private boolean insertLineNumbers = true;
+
+ private boolean insertColNumbers;
+
+ private boolean skipKnownEmptyCols = true;
+
+ private boolean skipAnyEmptyCols;
+
+ private boolean alwaysStripColContents = true;
+
+ private boolean alwaysEscapeColContents;
+
+ private boolean insertRawData;
+
+ private boolean insertColContentInAttribut;
+
+ private int headerlinesCount;
+
+ private int columnNamesInLineNumber = -1;
+
+ public boolean isSkipAnyEmptyCols() {
+ return skipAnyEmptyCols;
+ }
+
+ public void setSkipAnyEmptyCols(boolean skipAnyEmptyCols) {
+ this.skipAnyEmptyCols = skipAnyEmptyCols;
+ }
+
+ private static class CustomEndOfLineIterator
+ implements Iterator {
+
+ private InputStreamReader inr;
+ private String lineSeparator;
+ private String next;
+ private boolean eof;
+
+ public CustomEndOfLineIterator(InputStream in, String encoding,
+ String lineSeparator) {
+
+ if (encoding == null) {
+ inr = new InputStreamReader(in);
+ } else {
+ try {
+ inr = new InputStreamReader(in, encoding);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ this.lineSeparator = lineSeparator;
+ this.eof = false;
+ readNext();
+ }
+
+ public void close() {
+ eof = true;
+ closeQuietly(inr);
+ next = null;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException("Remove unsupported on CustomEndOfLineIterator");
+ }
+
+ public boolean hasNext() {
+ if (next == null && !eof) {
+ readNext();
+ }
+ return !eof;
+ }
+
+ public Object next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ String res = next;
+ readNext();
+ return res;
+ }
+
+ private void readNext() {
+ if (eof) {
+ next = null;
+ return;
+ }
+ StringBuilder sb = new StringBuilder();
+ while (true) {
+ int b;
+ try {
+ b = inr.read();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ if (b == -1) {
+ eof = true;
+ break;
+ }
+
+ if ((char) b == lineSeparator.charAt(0)) {
+ break; //FIXME: handle multi-character line separators
+ }
+
+ sb.append((char) b);
+ }
+ next = sb.toString();
+ }
+ }
+
+ public void readMessage(MessageExchange exchange,
+ NormalizedMessage message,
+ InputStream in,
+ String path) throws IOException, JBIException {
+ message.setContent(new StreamSource(this.convertLines(message, in, path)));
+ message.setProperty(FILE_NAME_PROPERTY, new File(path).getName());
+ message.setProperty(FILE_PATH_PROPERTY, path);
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ protected InputStream convertLinesToStream(NormalizedMessage message,
+ InputStream in, String path) throws IOException {
+ //Backward compatibility trick: if implemented in a subclass, overriden behavior will be used
+ //if buffer is untouched, headers will be proceed line-by-line
+ String wholeFileConverted = this.convertLinesToString(message, in, path);
+ if (wholeFileConverted != null) {
+ return new ByteArrayInputStream(wholeFileConverted.getBytes("UTF-8"));
+ } else {
+ return new InputStreamWrapper(in, path, "UTF-8");
+ }
+ }
+
+ protected InputStream convertLines(NormalizedMessage message,
+ InputStream in, String path) throws IOException {
+ return this.convertLinesToStream(message, in, path);
+ }
+
+ //This method is for backward compatibility only, use InputStreamWrapper to
+ //process InputStream line-by-line
+ @Deprecated
+ protected String convertLinesToString(NormalizedMessage message,
+ InputStream in, String path) throws IOException {
+ //Backward compatibility trick: if implemented in a subclass, overriden behavior will be used
+ //if returns null, file will be proceed line-by-line
+ return null;
+ }
+
+
+
+ final class InputStreamWrapper extends InputStream {
+
+ private boolean isEOF;
+ private byte[] cache;
+ private int cacheLen;
+ private int cachePos;
+ private InputStream in;
+ private String path;
+ private String outEncoding;
+ private int headerlinesRead;
+ private Iterator lines;
+ private int lineNumber;
+ private boolean isFooterFilled;
+
+ InputStreamWrapper(InputStream in,
+ String path, String outEncoding) throws
+ UnsupportedEncodingException, IOException {
+ log.trace("Entered InputStreamWrapper constructor");
+
+ //make sure outEncoding is good, otherwise fail early
+ " ".getBytes(outEncoding);
+
+ this.in = in;
+ this.path = path;
+ this.outEncoding = outEncoding;
+ if (lineSeparator == null) {
+ Reader reader = null;
+ if (encoding == null) {
+ reader = new InputStreamReader(in);
+ } else {
+ reader = new InputStreamReader(in, encoding);
+ }
+ lines = new LineIterator(reader);
+ } else {
+ lines =
+ new CustomEndOfLineIterator(in, encoding, lineSeparator);
+ }
+ log.trace("Leaving InputStreamWrapper constructor");
+ }
+
+ @Override
+ public int read() throws IOException {
+ fillCache();
+ if (isEOF) {
+ return -1;
+ }
+ return 0xFF & cache[cachePos++];
+ }
+
+ private void fillCache() throws IOException {
+ if (cachePos < cacheLen || isEOF) {
+ return;
+ }
+ if (cache == null) {
+ fillInitial();
+ return;
+ }
+ if (!lines.hasNext()) {
+ if (!isFooterFilled) {
+ fillFooter();
+ return;
+ } else {
+ isEOF = true;
+ cache = null;
+ cachePos = 0;
+ cacheLen = 0;
+ return;
+ }
+ }
+
+ if (headerlinesRead < headerlinesCount) {
+ fillHeader();
+ } else {
+ fillBody();
+ }
+ }
+
+ @Override
+ public int available() throws IOException {
+ return cacheLen - cachePos + in.available();
+ }
+
+ @Override
+ public void close() throws IOException {
+ in.close();
+ }
+
+ private void fill(String string) {
+ if (log.isTraceEnabled()) {
+ log.trace("InputStreamWrapper.fill(" + string + ")");
+ }
+ try {
+ cache = string.getBytes(outEncoding);
+ } catch (UnsupportedEncodingException ex) {
+ throw new RuntimeException(
+ "Bug in the code flow: unsupported encoding should be detected in constructor",
+ ex);
+ }
+ cachePos = 0;
+ cacheLen = cache.length;
+ }
+
+ private void fillFooter() {
+ isFooterFilled = true;
+ fill(XML_OPEN_END + docElementname + XML_CLOSE_NEWLINE);
+ }
+
+ private void fillHeader() throws IOException {
+ StringBuffer aBuffer = new StringBuffer(1024);
+ String headerLine = (String) lines.next();
+ if (columnNamesInLineNumber == headerlinesRead++) {
+ columnNames = extractColumnContents(headerLine, lines);
+ }
+
+ convertHeaderline(aBuffer, headerLine);
+ fill(aBuffer.toString());
+ }
+
+ private void fillInitial() throws IOException {
+ StringBuffer aBuffer = new StringBuffer(1024);
+
+ if (xmlDeclaration) {
+ aBuffer.append(XMLDECLARATION_LINE);
+ }
+
+ aBuffer.append(XML_OPEN + docElementname);
+
+ if (docElementNamespace != null) {
+ aBuffer.append("xmlns=\"");
+ aBuffer.append(docElementNamespace);
+ aBuffer.append("\"");
+ }
+
+ aBuffer.append(" name=\"");
+ aBuffer.append(new File(path).getName());
+ aBuffer.append("\"");
+
+ aBuffer.append(" location=\"");
+ aBuffer.append(path);
+ aBuffer.append(XML_CLOSE_ATTR_NEWLINE);
+ int overridenCheck = aBuffer.length();
+ processHeaderLines(aBuffer, lines);
+ if (aBuffer.length() != overridenCheck) {
+ //headers were proceed by an overriden method, supress futher processing
+ headerlinesRead = Integer.MAX_VALUE;
+ }
+ fill(aBuffer.toString());
+ }
+
+ private void fillBody() throws IOException {
+ lineNumber++;
+
+ StringBuffer aBuffer = new StringBuffer(1024);
+ String lineText = (String) lines.next();
+ aBuffer.append(XML_OPEN + lineElementname);
+
+ if (insertLineNumbers || insertRawData) {
+ if (insertLineNumbers) {
+ aBuffer.append(" number=\"");
+ aBuffer.append(lineNumber);
+ if (!insertRawData) {
+ aBuffer.append(XML_CLOSE_ATTR);
+ } else {
+ aBuffer.append("\"");
+ }
+ }
+ if (insertRawData) {
+ aBuffer.append(" raw=\"");
+ aBuffer.append(lineText);
+ aBuffer.append(XML_CLOSE_ATTR);
+ }
+ } else {
+ aBuffer.append(XML_CLOSE);
+ }
+
+ if ((columnLengths != null)
+ || (lineFormat != LINEFORMAT_FIXLENGTH)) {
+ extractColumns(aBuffer, lineText, lines);
+ } else {
+ aBuffer.append(lineText);
+ }
+ aBuffer.append(XML_OPEN_END + lineElementname
+ + XML_CLOSE_NEWLINE);
+
+ fill(aBuffer.toString());
+ }
+ }
+
+
+ @Deprecated
+ protected void processHeaderLines(StringBuffer buffer, Iterator lines) {
+ //Backward compatibility trick: if implemented in a subclass, overriden behavior will be used
+ //if buffer is untouched, headers will be proceed line-by-line
+ }
+
+ protected void convertHeaderline(StringBuffer buffer, String headerLine) {
+ buffer.append("<!-- ");
+ headerLine = TEXT_STRIPPER.convertToXml(headerLine);
+ headerLine = headerLine.replaceAll("--", "__");
+ buffer.append(" -->\n");
+ }
+
+ protected void extractColumns(StringBuffer buffer, String lineText,
+ Iterator lines) {
+ String[] rawcolContents = this.extractColumnContents(lineText, lines);
+
+ if ((rawcolContents != null) && (rawcolContents.length > 0)) {
+ for (int i = 0; i < rawcolContents.length; i++) {
+ String colText = rawcolContents[i];
+
+ String colName = this.findColumnname(i);
+ String colContents = this.convertColumnContents(i, colText);
+
+ if (colContents == null) {
+ // Simple skip
+ // Or maybe insert NULL Element
+ } else {
+ if (!((colContents.length() == 0)
+ && (this.skipAnyEmptyCols || (this.skipKnownEmptyCols && (!this.columnElementname.equals(colName)))))) {
+ if (this.insertColContentInAttribut) {
+ buffer.append(XML_OPEN + colName);
+
+ if (this.insertColNumbers) {
+ buffer.append(" number=\"");
+ buffer.append(i + 1);
+ buffer.append("\"");
+ }
+ buffer.append(" value=\"");
+ buffer.append(colContents);
+ buffer.append("\"/>");
+ } else {
+ if (!this.insertColNumbers) {
+ buffer.append(XML_OPEN + colName + XML_CLOSE);
+ } else {
+ buffer.append(XML_OPEN + colName);
+ buffer.append(" number=\"");
+ buffer.append(i + 1);
+ buffer.append("\"/>");
+ }
+ buffer.append(colContents);
+ buffer.append(XML_OPEN_END + colName + XML_CLOSE);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected String[] extractColumnContents(String lineText, Iterator lines) {
+ String[] result = null;
+
+ if ((lineText != null) && (lineText.length() > 0)) {
+ if (this.lineFormat == LINEFORMAT_FIXLENGTH) {
+ if ((this.columnLengths != null)
+ && (this.columnLengths.length > 0)) {
+ result = new String[this.columnLengths.length];
+ int curIndex = 0;
+
+ for (int i = 0; i < this.columnLengths.length; i++) {
+ try {
+ result[i] = lineText.substring(curIndex, curIndex
+ + this.columnLengths[i]);
+
+ curIndex += this.columnLengths[i];
+
+ } catch (StringIndexOutOfBoundsException e) {
+ break;
+ }
+ }
+ }
+ } else if (this.lineFormat == LINEFORMAT_CSV) {
+ result = StringUtils.splitWorker(lineText, this.columnSeparator, -1, true);
+ } else if (this.lineFormat == LINEFORMAT_VARIABLE) {
+ if (this.columnExtractor == null) {
+ throw new IllegalStateException("No Column Extractor defined");
+ }
+ result = this.columnExtractor.extractColumns(lineText);
+ } else {
+ throw new IllegalStateException("Unknown line format '" + this.lineFormat + "'");
+ }
+ }
+
+ return result;
+ }
+
+ protected String findColumnname(int index) {
+ String result = this.columnElementname;
+
+ if ((this.columnNames != null) && (this.columnNames.length > index)
+ && (this.columnNames[index] != null)) {
+ return this.columnNames[index];
+ }
+
+ return result;
+ }
+
+ protected String convertColumnContents(int index, String contents) {
+ if ((this.columnConverters != null)
+ && (this.columnConverters.size() > index)
+ && (this.columnConverters.get(index) != null)) {
+ ContentConverter converter = (ContentConverter) this.columnConverters.get(index);
+ return converter.convertToXml(contents);
+ } else {
+ if (this.alwaysEscapeColContents) {
+ return XML_CONVERTER.convertToXml(contents);
+ }
+ if (this.alwaysStripColContents) {
+ return TEXT_STRIPPER.convertToXml(contents);
+ } else {
+ return NO_CONVERSION.convertToXml(contents);
+ }
+ }
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public final String getEncoding() {
+ return encoding;
+ }
+
+ public final void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public final String getColumnElementname() {
+ return columnElementname;
+ }
+
+ public final void setColumnElementname(String columnElementname) {
+ this.columnElementname = columnElementname;
+ }
+
+ public final String getDocElementname() {
+ return docElementname;
+ }
+
+ public final void setDocElementname(String docElementname) {
+ this.docElementname = docElementname;
+ }
+
+ public final String getLineElementname() {
+ return lineElementname;
+ }
+
+ public final void setLineElementname(String lineElementname) {
+ this.lineElementname = lineElementname;
+ }
+
+ public final void setColumnLengths(String[] columnLengths) {
+ this.columnLengths = new int[columnLengths.length];
+ for (int i = 0; i < columnLengths.length; i++) {
+ this.columnLengths[i] = Integer.parseInt(columnLengths[i]);
+ }
+ }
+
+ public final boolean isXmlDeclaration() {
+ return xmlDeclaration;
+ }
+
+ public final void setXmlDeclaration(boolean xmlDeclaration) {
+ this.xmlDeclaration = xmlDeclaration;
+ }
+
+ public final void setInsertLineNumbers(boolean insertLineNumbers) {
+ this.insertLineNumbers = insertLineNumbers;
+ }
+
+ public final void setColumnConverters(List columnConverters) {
+ this.columnConverters = columnConverters;
+ }
+
+ public final void setColumnNames(String[] columnNames) {
+ this.columnNames = columnNames;
+ }
+
+ public final boolean isSkipKnownEmptyCols() {
+ return skipKnownEmptyCols;
+ }
+
+ public final void setSkipKnownEmptyCols(boolean skipKnownEmptyCols) {
+ this.skipKnownEmptyCols = skipKnownEmptyCols;
+ }
+
+ public final void setInsertRawData(boolean insertRawData) {
+ this.insertRawData = insertRawData;
+ }
+
+ public final boolean isAlwaysStripColContents() {
+ return alwaysStripColContents;
+ }
+
+ public final void setAlwaysStripColContents(boolean alwaysStripColContents) {
+ this.alwaysStripColContents = alwaysStripColContents;
+ }
+
+ public final boolean isAlwaysEscapeColContents() {
+ return alwaysEscapeColContents;
+ }
+
+ public final void setAlwaysEscapeColContents(boolean alwaysEscapeColContents) {
+ this.alwaysEscapeColContents = alwaysEscapeColContents;
+ }
+
+ public final int getLineFormat() {
+ return lineFormat;
+ }
+
+ public final void setLineFormat(int lineFormat) {
+ this.lineFormat = lineFormat;
+ }
+
+ public final String getColumnSeparator() {
+ return columnSeparator;
+ }
+
+ public final void setColumnSeparator(String columnSeparator) {
+ this.columnSeparator = columnSeparator;
+ }
+
+ public final void setColumnSeparatorCode(int columnSeparatorCode) {
+ this.columnSeparator = new String(new char[]{(char) columnSeparatorCode});
+ }
+
+ public final String getLineSeparator() {
+ return lineSeparator;
+ }
+
+ public final void setLineSeparator(String lineSeparator) {
+ if (lineSeparator != null && lineSeparator.length() > 1) {
+ throw new IllegalArgumentException("Currently only 1 character separators are supported, or null.");
+ }
+ this.lineSeparator = lineSeparator;
+ }
+
+ public final void setLineSeparatorCode(int lineSeparatorCode) {
+ this.lineSeparator = new String(new char[]{(char) lineSeparatorCode});
+ }
+
+ public final String getDocElementNamespace() {
+ return docElementNamespace;
+ }
+
+ public final void setDocElementNamespace(String docElementNamespace) {
+ this.docElementNamespace = docElementNamespace;
+ }
+
+ public final int getHeaderlinesCount() {
+ return headerlinesCount;
+ }
+
+ public final void setHeaderlinesCount(int headerlinesCount) {
+ this.headerlinesCount = headerlinesCount;
+ }
+
+ public final int getColumnNamesInLineNumber() {
+ return this.columnNamesInLineNumber;
+ }
+
+ /**
+ *
+ * @param columnNamesInLineNumber line number containing
+ */
+ public void setColumnNamesInLineNumber(int columnNamesInLineNumber) {
+ this.columnNamesInLineNumber = columnNamesInLineNumber;
+ }
+
+ public final boolean isInsertColContentInAttribut() {
+ return insertColContentInAttribut;
+ }
+
+ public final void setInsertColContentInAttribut(
+ boolean insertColContentInAttribut) {
+ this.insertColContentInAttribut = insertColContentInAttribut;
+ }
+
+ public final boolean isInsertColNumbers() {
+ return insertColNumbers;
+ }
+
+ public final void setInsertColNumbers(boolean insertColNumbers) {
+ this.insertColNumbers = insertColNumbers;
+ }
+
+ public final void setColumnExtractor(ColumnExtractor columnExtractor) {
+ this.columnExtractor = columnExtractor;
+ }
+
+ /**
+ * Unconditionally close an <code>Reader</code>.
+ * <p>
+ * Equivalent to {@link Reader#close()}, except any exceptions will be ignored.
+ * This is typically used in finally blocks.
+ *
+ * @param input the Reader to close, may be null or already closed
+ */
+ protected static void closeQuietly(Reader input) {
+ try {
+ if (input != null) {
+ input.close();
+ }
+ } catch (IOException ioe) {
+ // ignore
+ }
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java?rev=688693&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/components/util/StreamDataSource.java Mon Aug 25 03:57:27 2008
@@ -0,0 +1,80 @@
+/*
+ * 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.servicemix.components.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+/**
+ * Stream DataSource for Mail and message attachments .
+ *
+ * @author <a href="mailto:gnodet@logicblaze.com"> Guillaume Nodet</a>
+ * @since 3.0
+ */
+public class StreamDataSource implements DataSource {
+
+ private InputStream in;
+
+ private String contentType;
+
+ private String name;
+
+ public StreamDataSource(InputStream in) {
+ this(in, null, null);
+ }
+
+ public StreamDataSource(InputStream in, String contentType) {
+ this(in, contentType, null);
+ }
+
+ public StreamDataSource(InputStream in, String contentType, String name) {
+ this.in = in;
+ this.contentType = contentType;
+ this.name = name;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ if (in == null) {
+ throw new IOException("no data");
+ }
+ return in;
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ throw new IOException("getOutputStream() not supported");
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+}