001/* 002 * Copyright (c) 2013 Nu Echo Inc. All rights reserved. 003 */ 004package com.nuecho.rivr.voicexml.turn.output.grammar; 005 006import javax.json.*; 007 008import com.nuecho.rivr.core.util.*; 009import com.nuecho.rivr.voicexml.util.json.*; 010 011/** 012 * An {@link InlineStringGrammar} represents a text source grammar inlined in 013 * the VoiceXML document. 014 * 015 * @author Nu Echo Inc. 016 * @see <a 017 * href="https://www.w3.org/TR/voicexml20/#dml3.1.1.4">https://www.w3.org/TR/voicexml20/#dml3.1.1.4</a> 018 */ 019public final class InlineStringGrammar extends GrammarItem { 020 private static final String INLINE_STRING_ELEMENT_TYPE = "inlineString"; 021 private static final String VERSION_PROPERTY = "version"; 022 private static final String TAG_FORMAT_PROPERTY = "tagFormat"; 023 private static final String SOURCE_PROPERTY = "source"; 024 private static final String ROOT_PROPERTY = "root"; 025 private static final String LANGUAGE_PROPERTY = "language"; 026 private static final String BASE_PROPERTY = "base"; 027 028 private final String mSource; 029 private String mVersion; 030 private String mLanguage; 031 private String mRoot; 032 private String mTagFormat; 033 private String mBase; 034 035 /** 036 * @param source The text source of the grammar. Not null. 037 */ 038 public InlineStringGrammar(String source) { 039 Assert.notNull(source, "source"); 040 mSource = source; 041 } 042 043 /** 044 * @param version The version of the grammar.<code>null</code> to use the 045 * VoiceXML platform default. 046 */ 047 public void setVersion(String version) { 048 mVersion = version; 049 } 050 051 /** 052 * @param language The language identifier of the grammar. For example, 053 * "fr-CA" for Canadian French. <code>null</code> to use the 054 * VoiceXML platform default. 055 */ 056 public void setLanguage(String language) { 057 mLanguage = language; 058 } 059 060 /** 061 * @param root The name of the rule that will act as the root rule. 062 * <code>null</code> to use the VoiceXML platform default. 063 */ 064 public void setRoot(String root) { 065 mRoot = root; 066 } 067 068 /** 069 * @param tagFormat The tag content format for all tags within the grammar. 070 * <code>null</code> to use the VoiceXML platform default 071 */ 072 public void setTagFormat(String tagFormat) { 073 mTagFormat = tagFormat; 074 } 075 076 /** 077 * @param base The base URI from which relative URIs in the grammar are 078 * resolved. <code>null</code> to use the VoiceXML platform 079 * default 080 */ 081 public void setBase(String base) { 082 mBase = base; 083 } 084 085 @Override 086 public String getElementType() { 087 return INLINE_STRING_ELEMENT_TYPE; 088 } 089 090 public String getSource() { 091 return mSource; 092 } 093 094 public String getVersion() { 095 return mVersion; 096 } 097 098 public String getLanguage() { 099 return mLanguage; 100 } 101 102 public String getRoot() { 103 return mRoot; 104 } 105 106 public String getTagFormat() { 107 return mTagFormat; 108 } 109 110 public String getBase() { 111 return mBase; 112 } 113 114 @Override 115 protected void addJsonProperties(JsonObjectBuilder builder) { 116 JsonUtils.add(builder, BASE_PROPERTY, mBase); 117 JsonUtils.add(builder, LANGUAGE_PROPERTY, mLanguage); 118 JsonUtils.add(builder, ROOT_PROPERTY, mRoot); 119 JsonUtils.add(builder, SOURCE_PROPERTY, mSource); 120 JsonUtils.add(builder, TAG_FORMAT_PROPERTY, mTagFormat); 121 JsonUtils.add(builder, VERSION_PROPERTY, mVersion); 122 } 123 124 @Override 125 public int hashCode() { 126 final int prime = 31; 127 int result = super.hashCode(); 128 result = prime * result + (mBase == null ? 0 : mBase.hashCode()); 129 result = prime * result + (mLanguage == null ? 0 : mLanguage.hashCode()); 130 result = prime * result + (mRoot == null ? 0 : mRoot.hashCode()); 131 result = prime * result + (mSource == null ? 0 : mSource.hashCode()); 132 result = prime * result + (mTagFormat == null ? 0 : mTagFormat.hashCode()); 133 result = prime * result + (mVersion == null ? 0 : mVersion.hashCode()); 134 return result; 135 } 136 137 @Override 138 public boolean equals(Object obj) { 139 if (this == obj) return true; 140 if (!super.equals(obj)) return false; 141 if (getClass() != obj.getClass()) return false; 142 InlineStringGrammar other = (InlineStringGrammar) obj; 143 if (mBase == null) { 144 if (other.mBase != null) return false; 145 } else if (!mBase.equals(other.mBase)) return false; 146 if (mLanguage == null) { 147 if (other.mLanguage != null) return false; 148 } else if (!mLanguage.equals(other.mLanguage)) return false; 149 if (mRoot == null) { 150 if (other.mRoot != null) return false; 151 } else if (!mRoot.equals(other.mRoot)) return false; 152 if (mSource == null) { 153 if (other.mSource != null) return false; 154 } else if (!mSource.equals(other.mSource)) return false; 155 if (mTagFormat == null) { 156 if (other.mTagFormat != null) return false; 157 } else if (!mTagFormat.equals(other.mTagFormat)) return false; 158 if (mVersion == null) { 159 if (other.mVersion != null) return false; 160 } else if (!mVersion.equals(other.mVersion)) return false; 161 return true; 162 } 163}