com.twilio.twiml.voice.SsmlW Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twilio Show documentation
Show all versions of twilio Show documentation
Twilio Java Helper Library
/**
* This code was generated by
* \ / _ _ _| _ _
* | (_)\/(_)(_|\/| |(/_ v1.0.0
* / /
*/
package com.twilio.twiml.voice;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.twilio.twiml.TwiML;
import com.twilio.twiml.TwiMLException;
import java.util.HashMap;
import java.util.Map;
/**
* TwiML wrapper for {@code }
*/
@JsonDeserialize(builder = SsmlW.Builder.class)
public class SsmlW extends TwiML {
private final String role;
private final String words;
/**
* For XML Serialization/Deserialization
*/
private SsmlW() {
this(new Builder());
}
/**
* Create a new {@code } element
*/
private SsmlW(Builder b) {
super("w", b);
this.role = b.role;
this.words = b.words;
}
/**
* The body of the TwiML element
*
* @return Element body as a string if present else null
*/
protected String getElementBody() {
return this.getWords() == null ? null : this.getWords();
}
/**
* Attributes to set on the generated XML element
*
* @return A Map of attribute keys to values
*/
protected Map getElementAttributes() {
// Preserve order of attributes
Map attrs = new HashMap<>();
if (this.getRole() != null) {
attrs.put("role", this.getRole());
}
return attrs;
}
/**
* Customize the pronunciation of words by specifying the word’s part of speech
* or alternate meaning
*
* @return Customize the pronunciation of words by specifying the word’s part
* of speech or alternate meaning
*/
public String getRole() {
return role;
}
/**
* Words to speak
*
* @return Words to speak
*/
public String getWords() {
return words;
}
/**
* Create a new {@code } element
*/
@JsonPOJOBuilder(withPrefix = "")
public static class Builder extends TwiML.Builder {
/**
* Create and return a {@code } from an XML string
*/
public static Builder fromXml(final String xml) throws TwiMLException {
try {
return OBJECT_MAPPER.readValue(xml, Builder.class);
} catch (final JsonProcessingException jpe) {
throw new TwiMLException(
"Failed to deserialize a SsmlW.Builder from the provided XML string: " + jpe.getMessage());
} catch (final Exception e) {
throw new TwiMLException("Unhandled exception: " + e.getMessage());
}
}
private String role;
private String words;
/**
* Create a {@code } with words
*/
public Builder(String words) {
this.words = words;
}
/**
* Create a {@code } with child elements
*/
public Builder() {
}
/**
* Customize the pronunciation of words by specifying the word’s part of speech
* or alternate meaning
*/
@JacksonXmlProperty(isAttribute = true, localName = "role")
public Builder role(String role) {
this.role = role;
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "break")
public Builder break_(SsmlBreak ssmlBreak) {
this.children.add(ssmlBreak);
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "emphasis")
public Builder emphasis(SsmlEmphasis ssmlEmphasis) {
this.children.add(ssmlEmphasis);
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "phoneme")
public Builder phoneme(SsmlPhoneme ssmlPhoneme) {
this.children.add(ssmlPhoneme);
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "prosody")
public Builder prosody(SsmlProsody ssmlProsody) {
this.children.add(ssmlProsody);
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "say-as")
public Builder sayAs(SsmlSayAs ssmlSayAs) {
this.children.add(ssmlSayAs);
return this;
}
/**
* Add a child {@code } element
*/
@JacksonXmlProperty(isAttribute = false, localName = "sub")
public Builder sub(SsmlSub ssmlSub) {
this.children.add(ssmlSub);
return this;
}
/**
* Create and return resulting {@code } element
*/
public SsmlW build() {
return new SsmlW(this);
}
}
}