001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.stream;
018
019 import java.nio.charset.Charset;
020
021 import org.apache.camel.Component;
022 import org.apache.camel.Consumer;
023 import org.apache.camel.Processor;
024 import org.apache.camel.Producer;
025 import org.apache.camel.impl.DefaultEndpoint;
026 import org.apache.commons.logging.Log;
027 import org.apache.commons.logging.LogFactory;
028
029 public class StreamEndpoint extends DefaultEndpoint {
030 private static final transient Log LOG = LogFactory.getLog(StreamEndpoint.class);
031
032 private String fileName;
033 private boolean scanStream;
034 private long scanStreamDelay;
035 private String url;
036 private long delay;
037 private String encoding;
038 private String promptMessage;
039 private long promptDelay;
040 private long initialPromptDelay = 2000;
041
042 public StreamEndpoint(String endpointUri, Component component) throws Exception {
043 super(endpointUri, component);
044 }
045
046 public StreamEndpoint(String endpointUri) {
047 super(endpointUri);
048 }
049
050 public Consumer createConsumer(Processor processor) throws Exception {
051 return new StreamConsumer(this, processor, getEndpointUri());
052 }
053
054 public Producer createProducer() throws Exception {
055 return new StreamProducer(this, getEndpointUri());
056 }
057
058 public boolean isSingleton() {
059 return true;
060 }
061
062 // Properties
063 //-------------------------------------------------------------------------
064
065 public String getFileName() {
066 return fileName;
067 }
068
069 public void setFileName(String fileName) {
070 this.fileName = fileName;
071 }
072
073 public String getUrl() {
074 return url;
075 }
076
077 public void setUrl(String url) {
078 this.url = url;
079 }
080
081 public long getDelay() {
082 return delay;
083 }
084
085 public void setDelay(long delay) {
086 this.delay = delay;
087 }
088
089 public String getEncoding() {
090 return encoding;
091 }
092
093 public void setEncoding(String encoding) {
094 this.encoding = encoding;
095 }
096
097 public String getPromptMessage() {
098 return promptMessage;
099 }
100
101 public void setPromptMessage(String promptMessage) {
102 this.promptMessage = promptMessage;
103 }
104
105 public long getPromptDelay() {
106 return promptDelay;
107 }
108
109 public void setPromptDelay(long promptDelay) {
110 this.promptDelay = promptDelay;
111 }
112
113 public long getInitialPromptDelay() {
114 return initialPromptDelay;
115 }
116
117 public void setInitialPromptDelay(long initialPromptDelay) {
118 this.initialPromptDelay = initialPromptDelay;
119 }
120
121 public boolean isScanStream() {
122 return scanStream;
123 }
124
125 public void setScanStream(boolean scanStream) {
126 this.scanStream = scanStream;
127 }
128
129 public long getScanStreamDelay() {
130 return scanStreamDelay;
131 }
132
133 public void setScanStreamDelay(long scanStreamDelay) {
134 this.scanStreamDelay = scanStreamDelay;
135 }
136
137 // Implementations
138 //-------------------------------------------------------------------------
139
140 Charset getCharset() {
141 if (encoding == null) {
142 encoding = Charset.defaultCharset().name();
143 if (LOG.isDebugEnabled()) {
144 LOG.debug("No encoding parameter using default charset: " + encoding);
145 }
146 }
147 if (!Charset.isSupported(encoding)) {
148 throw new IllegalArgumentException("The encoding: " + encoding + " is not supported");
149 }
150
151 return Charset.forName(encoding);
152 }
153
154 }