001 /*
002 * File: $HeadURL: https://jvoicexml.svn.sourceforge.net/svnroot/jvoicexml/core/trunk/org.jvoicexml/src/org/jvoicexml/DtmfRecognizerProperties.java $
003 * Version: $LastChangedRevision: 2579 $
004 * Date: $Date: 2011-02-14 14:14:36 +0100 (Mo, 14 Feb 2011) $
005 * Author: $LastChangedBy: schnelle $
006 *
007 * JVoiceXML - A free VoiceXML implementation.
008 *
009 * Copyright (C) 2011 JVoiceXML group - http://jvoicexml.sourceforge.net
010 *
011 * This library is free software; you can redistribute it and/or
012 * modify it under the terms of the GNU Library General Public
013 * License as published by the Free Software Foundation; either
014 * version 2 of the License, or (at your option) any later version.
015 *
016 * This library is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 * Library General Public License for more details.
020 *
021 * You should have received a copy of the GNU Library General Public
022 * License along with this library; if not, write to the Free Software
023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024 *
025 */
026
027 package org.jvoicexml;
028
029 import java.util.Map;
030
031 import org.jvoicexml.xml.TimeParser;
032
033 /**
034 * Generic DTMF recognizer properties as described in
035 * <a href="http://www.w3.org/TR/voicexml20#dml6.3.3">
036 * http://www.w3.org/TR/voicexml20#dml6.3.3</a>. See there for a more detailed
037 * description of the parameters.
038 * <p>
039 * This class must be extended to specify platform specific values.
040 * </p>
041 * @author Dirk Schnelle-Walka
042 * @version $Revision: 2579 $
043 * @since 0.7.5
044 */
045 public class DtmfRecognizerProperties {
046 /** Name of the <code>interdigittimeout</code> property. */
047 public static final String PROPERTY_INTERDIGIT_TIMEOUT
048 = "interdigittimeout";
049
050 /** Name of the <code>termtimeout</code> property. */
051 public static final String PROPERTY_TERM_TIMEOUT = "termtimeout";
052
053 /** Name of the <code>termchar</code> property. */
054 public static final String PROPERTY_TERM_CHAR = "termchar";
055
056 /** The default value for the terminating timeout. */
057 public static final String DEFAULT_TERM_TIMEOUT = "0s";
058
059 /** The default value for the terminating character. */
060 public static final char DEFAULT_TERM_CHAR = '#';
061
062 /**
063 * Constructs a new object.
064 */
065 public DtmfRecognizerProperties() {
066 setTermtimeout(DEFAULT_TERM_TIMEOUT);
067 termchar = DEFAULT_TERM_CHAR;
068 }
069
070 /**
071 * Retrieves the DTMF recognizer properties from the given map.
072 * @param props map with current properties
073 * @since 0.7.5
074 */
075 public final void setProperties(final Map<String, String> props) {
076 final String propInterdigittimeout =
077 props.get(PROPERTY_INTERDIGIT_TIMEOUT);
078 if (propInterdigittimeout != null) {
079 setInterdigittimeout(propInterdigittimeout);
080 }
081 final String propTermtimeout = props.get(PROPERTY_TERM_TIMEOUT);
082 if (propTermtimeout != null) {
083 setTermtimeout(propTermtimeout);
084 }
085 final String propTermchar = props.get(PROPERTY_TERM_CHAR);
086 if (propTermchar != null) {
087 termchar = propTermchar.charAt(0);
088 }
089 setEnhancedProperties(props);
090 }
091
092 /**
093 * May be used to set custom properties if this class is extended.
094 * @param props map with current properties.
095 * @since 0.7.5
096 */
097 protected void setEnhancedProperties(final Map<String, String> props) {
098 }
099
100 /**
101 * The inter-digit timeout value to use when recognizing DTMF input.
102 */
103 private long interdigittimeout;
104
105 /**
106 * The terminating timeout to use when recognizing DTMF input.
107 */
108 private long termtimeout;
109
110 /**
111 * The terminating DTMF character for DTMF input recognition.
112 */
113 private char termchar;
114
115 /**
116 * Retrieves the inter-digit timeout value to use when recognizing DTMF
117 * input.
118 * @return the inter-digit timeout
119 */
120 public final long getInterdigittimeoutAsMsec() {
121 return interdigittimeout;
122 }
123
124 /**
125 * Sets the inter-digit timeout value to use when recognizing DTMF
126 * input.
127 * @param value the inter-digit timeout to set as a time designation
128 */
129 public final void setInterdigittimeout(final String value) {
130 final TimeParser parser = new TimeParser(value);
131 interdigittimeout = parser.parse();
132 }
133
134 /**
135 * Retrieves the terminating timeout to use when recognizing DTMF input.
136 * @return the terminating timeout
137 */
138 public final long getTermtimeoutAsMsec() {
139 return termtimeout;
140 }
141
142 /**
143 * Sets the terminating timeout to use when recognizing DTMF input.
144 * @param value the terminating timeout to set
145 */
146 public final void setTermtimeout(final String value) {
147 final TimeParser parser = new TimeParser(value);
148 termtimeout = parser.parse();
149 }
150
151 /**
152 * Retrieves the terminating DTMF character for DTMF input recognition.
153 * @return the terminating DTMF character
154 */
155 public final char getTermchar() {
156 return termchar;
157 }
158
159 /**
160 * Sets the terminating DTMF character for DTMF input recognition.
161 * @param value the terminating DTMF character to set
162 */
163 public final void setTermchar(final char value) {
164 termchar = value;
165 }
166 }