diff options
Diffstat (limited to 'java/gov/nist/javax/sdp')
54 files changed, 10088 insertions, 0 deletions
diff --git a/java/gov/nist/javax/sdp/MediaDescriptionImpl.java b/java/gov/nist/javax/sdp/MediaDescriptionImpl.java new file mode 100644 index 0000000..553bf5e --- /dev/null +++ b/java/gov/nist/javax/sdp/MediaDescriptionImpl.java @@ -0,0 +1,763 @@ +/* + * Conditions Of Use + * + * This software was developed by employees of the National Institute of + * Standards and Technology (NIST), an agency of the Federal Government. + * Pursuant to title 15 Untied States Code Section 105, works of NIST + * employees are not subject to copyright protection in the United States + * and are considered to be in the public domain. As a result, a formal + * license is not needed to use the software. + * + * This software is provided by NIST as a service and is expressly + * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT + * AND DATA ACCURACY. NIST does not warrant or make any representations + * regarding the use of the software or the results thereof, including but + * not limited to the correctness, accuracy, reliability or usefulness of + * the software. + * + * Permission to use this software is contingent upon your acceptance + * of the terms of this agreement + * + * . + * + */ +package gov.nist.javax.sdp; + +import javax.sdp.*; +import gov.nist.javax.sdp.fields.*; +import java.util.*; +import gov.nist.core.*; + +/* + * Includes code contributed by + * Miguel Freitas (IT) PTInovacao -- modifications for IMS. + */ + +/** + * Fieldementation of Media Description interface. + * + * @version JSR141-PUBLIC-REVIEW (subject to change). + * + * @author Olivier Deruelle <deruelle@antd.nist.gov> + * @author M. Ranganathan <br/> + * + * + */ +public class MediaDescriptionImpl implements javax.sdp.MediaDescription { + + protected MediaField mediaField; + + protected InformationField informationField; + + protected ConnectionField connectionField; + + protected Vector bandwidthFields; + + protected KeyField keyField; + + protected Vector attributeFields; + + /** + * Encode to a canonical form. + * + * @since v1.0 + */ + public String encode() { + StringBuffer retval = new StringBuffer(); + + if (mediaField != null) + retval.append(mediaField.encode()); + + if (informationField != null) + retval.append(informationField.encode()); + + if (connectionField != null) + retval.append(connectionField.encode()); + + if (bandwidthFields != null) { + for (int i = 0; i < bandwidthFields.size(); i++) { + + // issued by Miguel Freitas (IT) PTInovacao + retval.append(((SDPField) bandwidthFields.elementAt(i)) + .encode()); + + /* + * original code BandwidthField bandwidthField = + * (BandwidthField) bandwidthFields.elementAt(i); + * retval.append(bandwidthField.encode()); + */ + // end // + } + if (preconditionFields != null) { + int precondSize = preconditionFields.getPreconditionSize(); + for (int i = 0; i < precondSize; i++) { + retval.append(((SDPField) preconditionFields + .getPreconditions().elementAt(i)).encode()); + } + } + } + + if (keyField != null) + retval.append(keyField.encode()); + + if (attributeFields != null) { + for (int i = 0; i < attributeFields.size(); i++) + retval.append(((SDPField) attributeFields.elementAt(i)) + .encode()); + } + + return retval.toString(); + } + + public String toString() { + return this.encode(); + } + + public MediaDescriptionImpl() { + this.bandwidthFields = new Vector(); + this.attributeFields = new Vector(); + + // issued by Miguel Freitas (AV) PTInovacao + this.preconditionFields = new PreconditionFields(); + } + + public MediaField getMediaField() { + return mediaField; + } + + public InformationField getInformationField() { + return informationField; + } + + public ConnectionField getConnectionField() { + return connectionField; + } + + public KeyField getKeyField() { + return keyField; + } + + public Vector getAttributeFields() { + return attributeFields; + } + + /** + * Set the mediaField member + */ + public void setMediaField(MediaField m) { + mediaField = m; + } + + /** + * Set the informationField member + */ + public void setInformationField(InformationField i) { + informationField = i; + } + + /** + * Set the connectionField member + */ + public void setConnectionField(ConnectionField c) { + connectionField = c; + } + + /** + * Set the bandwidthField member + */ + public void addBandwidthField(BandwidthField b) { + bandwidthFields.add(b); + } + + /** + * Set the keyField member + */ + public void setKeyField(KeyField k) { + keyField = k; + } + + /** + * Set the attributeFields member + */ + public void setAttributeFields(Vector a) { + attributeFields = a; + } + + /** + * Return the Media field of the description. + * + * @return the Media field of the description. + */ + public Media getMedia() { + return mediaField; + + } + + // issued by Miguel Freitas // + public void addAttribute(AttributeField af) { + // protected void addAttribute(AttributeField af) { + // end // + this.attributeFields.add(af); + } + + protected boolean hasAttribute(String name) { + for (int i = 0; i < this.attributeFields.size(); i++) { + AttributeField af = (AttributeField) this.attributeFields + .elementAt(i); + if (af.getAttribute().getName().equals(name)) + return true; + } + return false; + } + + /** + * Set the Media field of the description. + * + * @param media + * to set + * @throws SdpException + * if the media field is null + */ + public void setMedia(Media media) throws SdpException { + if (media == null) + throw new SdpException("The media is null"); + if (media instanceof MediaField) { + mediaField = (MediaField) media; + } else + throw new SdpException("A mediaField parameter is required"); + } + + /** + * Returns value of the info field (i=) of this object. + * + * @return value of the info field (i=) of this object. + */ + public Info getInfo() { + InformationField informationField = getInformationField(); + if (informationField == null) + return null; + else { + return informationField; + } + } + + /** + * Sets the i= field of this object. + * + * @param i + * to set + * @throws SdpException + * if the info is null + */ + public void setInfo(Info i) throws SdpException { + if (i == null) + throw new SdpException("The info is null"); + if (i instanceof InformationField) { + this.informationField = (InformationField) i; + } else + throw new SdpException("A informationField parameter is required"); + } + + /** + * Returns the connection information associated with this object. This may + * be null for SessionDescriptions if all Media objects have a connection + * object and may be null for Media objects if the corresponding session + * connection is non-null. + * + * @return connection + */ + public Connection getConnection() { + + return connectionField; + + } + + /** + * Set the connection data for this entity + * + * @param conn + * to set + * @throws SdpException + * if the connexion is null + */ + public void setConnection(Connection conn) throws SdpException { + if (conn == null) + throw new SdpException("The conn is null"); + if (conn instanceof ConnectionField) { + connectionField = (ConnectionField) conn; + + } else + throw new SdpException("bad implementation"); + } + + /** + * Returns the Bandwidth of the specified type. + * + * @param create + * type of the Bandwidth to return + * @return the Bandwidth or null if undefined + */ + + public Vector getBandwidths(boolean create) { + return bandwidthFields; + } + + /** + * set the value of the Bandwidth with the specified type + * + * @param bandwidths + * type of the Bandwidth object whose value is requested + * @throws SdpException + * if vector is null + */ + public void setBandwidths(Vector bandwidths) throws SdpException { + if (bandwidths == null) + throw new SdpException("The vector bandwidths is null"); + this.bandwidthFields = bandwidths; + } + + /** + * Returns the integer value of the specified bandwidth name. + * + * @param name + * the name of the bandwidth type. + * @throws SdpParseException + * @return the value of the named bandwidth + */ + public int getBandwidth(String name) throws SdpParseException { + + if (name == null) + throw new NullPointerException("null parameter"); + if (bandwidthFields == null) + return -1; + else { + for (int i = 0; i < bandwidthFields.size(); i++) { + BandwidthField bandwidthField = (BandwidthField) bandwidthFields + .elementAt(i); + String type = bandwidthField.getBwtype(); + if (type != null && type.equals(name)) + return bandwidthField.getBandwidth(); + } + return -1; + } + } + + /** + * Sets the value of the specified bandwidth type. + * + * @param name + * the name of the bandwidth type. + * @param value + * the value of the named bandwidth type. + * @throws SdpException + * if the name is null + */ + public void setBandwidth(String name, int value) throws SdpException { + if (name == null) + throw new SdpException("The name is null"); + else { + int i = 0; // issued by Miguel Freitas (IT) PTInovacao + for (i = 0; i < bandwidthFields.size(); i++) { + BandwidthField bandwidthField = (BandwidthField) this.bandwidthFields + .elementAt(i); + String type = bandwidthField.getBwtype(); + if (type != null && type.equals(name)) { + bandwidthField.setBandwidth(value); + + break; // issued by Miguel Freitas (IT) PTInovacao + } + } + + // issued by Miguel Freitas (IT) PTInovacao + if (i == this.bandwidthFields.size()) { + BandwidthField bandwidthField = new BandwidthField(); + bandwidthField.setType(name); + bandwidthField.setValue(value); + this.bandwidthFields.add(bandwidthField); + } + // end // + } + } + + /** + * Removes the specified bandwidth type. + * + * @param name + * the name of the bandwidth type. + */ + public void removeBandwidth(String name) { + if (name == null) { + throw new NullPointerException("null bandwidth type"); + } else { + int i = 0; + for (i = 0; i < bandwidthFields.size(); i++) { + BandwidthField bandwidthField = (BandwidthField) bandwidthFields + .elementAt(i); + String type = bandwidthField.getBwtype(); + if (type != null && type.equals(name)) + break; + + } + if (i < bandwidthFields.size()) + bandwidthFields.removeElementAt(i); + } + } + + /** + * Returns the key data. + * + * @return the key data. + */ + public Key getKey() { + if (keyField == null) + return null; + else { + return keyField; + } + } + + /** + * Sets encryption key information. This consists of a method and an + * encryption key included inline. + * + * @param key + * the encryption key data; depending on method may be null + * @throws SdpException + * if the key is null + */ + public void setKey(Key key) throws SdpException { + if (key == null) + throw new SdpException("The key is null"); + if (key instanceof KeyField) { + KeyField keyField = (KeyField) key; + setKeyField(keyField); + } else + throw new SdpException("A keyField parameter is required"); + } + + /** + * Returns the set of attributes for this Description as a Vector of + * Attribute objects in the order they were parsed. + * + * @param create + * specifies whether to return null or a new empty Vector in case + * no attributes exists for this Description + * @return attributes for this Description + */ + public Vector getAttributes(boolean create) { + return attributeFields; + } + + /** + * Adds the specified Attribute to this Description object. + * + * @param attributes -- + * the attribute to add + * @throws SdpException -- + * if the attributes is null + */ + public void setAttributes(Vector attributes) throws SdpException { + this.attributeFields = attributes; + } + + /** + * Returns the value of the specified attribute. + * + * @param name + * the name of the attribute. + * @throws SdpParseException + * @return the value of the named attribute + */ + public String getAttribute(String name) throws SdpParseException { + if (name != null) { + for (int i = 0; i < this.attributeFields.size(); i++) { + AttributeField af = (AttributeField) this.attributeFields + .elementAt(i); + if (name.equals(af.getAttribute().getName())) + return (String) af.getAttribute().getValueAsObject(); + } + return null; + } else + throw new NullPointerException("null arg!"); + } + + /** + * Sets the value of the specified attribute + * + * @param name + * the name of the attribute. + * @param value + * the value of the named attribute. + * @throws SdpException + * if the parameters are null + */ + public void setAttribute(String name, String value) throws SdpException { + if (name == null) + throw new SdpException("The parameters are null"); + else { + + int i = 0; + for (i = 0; i < this.attributeFields.size(); i++) { + AttributeField af = (AttributeField) this.attributeFields + .elementAt(i); + if (af.getAttribute().getName().equals(name)) { + NameValue nv = af.getAttribute(); + nv.setValueAsObject(value); + break; + } + + } + + if (i == this.attributeFields.size()) { + AttributeField af = new AttributeField(); + NameValue nv = new NameValue(name, value); + af.setAttribute(nv); + // Bug fix by Emil Ivov. + this.attributeFields.add(af); + } + + } + } + + public void setDuplexity(String duplexity) { + if ( duplexity == null ) throw new NullPointerException("Null arg"); + int i = 0; + for (i = 0; i < this.attributeFields.size(); i++) { + AttributeField af = (AttributeField) this.attributeFields + .elementAt(i); + if (af.getAttribute().getName().equalsIgnoreCase("sendrecv") || + af.getAttribute().getName().equalsIgnoreCase("recvonly") || + af.getAttribute().getName().equalsIgnoreCase("sendonly") || + af.getAttribute().getName().equalsIgnoreCase("inactive")) { + NameValue nv = new NameValue(duplexity, null); + af.setAttribute(nv); + return; + } + + } + + if (i == this.attributeFields.size()) { + AttributeField af = new AttributeField(); + NameValue nv = new NameValue(duplexity, null); + af.setAttribute(nv); + // Bug fix by Emil Ivov. + this.attributeFields.add(af); + } + + + } + + /** + * Removes the attribute specified by the value parameter. + * + * @param name + * the name of the attribute. + */ + public void removeAttribute(String name) { + if (name == null) + throw new NullPointerException("null arg!"); + if (name != null) { + int i = 0; + for (i = 0; i < this.attributeFields.size(); i++) { + AttributeField af = (AttributeField) this.attributeFields + .elementAt(i); + if (af.getAttribute().getName().equals(name)) + break; + } + if (i < attributeFields.size()) + attributeFields.removeElementAt(i); + + } + } + + /** + * Returns a Vector containing a string indicating the MIME type for each of + * the codecs in this description. + * + * A MIME value is computed for each codec in the media description. + * + * The MIME type is computed in the following fashion: The type is the + * mediaType from the media field. The subType is determined by the + * protocol. + * + * The result is computed as the string of the form: + * + * type + '/' + subType + * + * The subType portion is computed in the following fashion. RTP/AVP the + * subType is returned as the codec name. This will either be extracted from + * the rtpmap attribute or computed. other the protocol is returned as the + * subType. + * + * If the protocol is RTP/AVP and the rtpmap attribute for a codec is + * absent, then the codec name will be computed in the following fashion. + * String indexed in table SdpConstants.avpTypeNames if the value is an int + * greater than or equal to 0 and less than AVP_DEFINED_STATIC_MAX, and has + * been assigned a value. SdpConstant.RESERVED if the value is an int + * greater than or equal to 0 and less than AVP_DEFINED_STATIC_MAX, and has + * not been assigned a value. SdpConstant.UNASSIGNED An int greater than or + * equal to AVP_DEFINED_STATIC_MAX and less than AVP_DYNAMIC_MIN - currently + * unassigned. SdpConstant.DYNAMIC Any int less than 0 or greater than or + * equal to AVP_DYNAMIC_MIN + * + * @throws SdpException + * if there is a problem extracting the parameters. + * @return a Vector containing a string indicating the MIME type for each of + * the codecs in this description + */ + public Vector getMimeTypes() throws SdpException { + MediaField mediaField = (MediaField) getMedia(); + String type = mediaField.getMediaType(); + String protocol = mediaField.getProtocol(); + Vector formats = mediaField.getMediaFormats(false); + + Vector v = new Vector(); + for (int i = 0; i < formats.size(); i++) { + String result = null; + if (protocol.equals("RTP/AVP")) { + if (getAttribute(SdpConstants.RTPMAP) != null) + result = type + "/" + protocol; + else { + + } + } else + result = type + "/" + protocol; + v.addElement(result); + } + return v; + } + + /** + * Returns a Vector containing a string of parameters for each of the codecs + * in this description. + * + * A parameter string is computed for each codec. + * + * The parameter string is computed in the following fashion. + * + * The rate is extracted from the rtpmap or static data. + * + * The number of channels is extracted from the rtpmap or static data. + * + * The ptime is extracted from the ptime attribute. + * + * The maxptime is extracted from the maxptime attribute. + * + * Any additional parameters are extracted from the ftmp attribute. + * + * @throws SdpException + * if there is a problem extracting the parameters. + * @return a Vector containing a string of parameters for each of the codecs + * in this description. + */ + public Vector getMimeParameters() throws SdpException { + String rate = getAttribute("rate"); + String ptime = getAttribute("ptime"); + String maxptime = getAttribute("maxptime"); + String ftmp = getAttribute("ftmp"); + Vector result = new Vector(); + result.addElement(rate); + result.addElement(ptime); + result.addElement(maxptime); + result.addElement(ftmp); + return result; + } + + /** + * Adds dynamic media types to the description. + * + * @param payloadNames + * a Vector of String - each one the name of a dynamic payload to + * be added (usually an integer larger than + * SdpConstants.AVP_DYNAMIC_MIN). + * @param payloadValues + * a Vector of String - each contains the value describing the + * correlated dynamic payloads to be added + * @throws SdpException + * if either vector is null or empty. if the vector sizes are + * unequal. + */ + public void addDynamicPayloads(Vector payloadNames, Vector payloadValues) + throws SdpException { + + if (payloadNames == null || payloadValues == null) + throw new SdpException(" The vectors are null"); + else { + if (payloadNames.isEmpty() || payloadValues.isEmpty()) + throw new SdpException(" The vectors are empty"); + else { + if (payloadNames.size() != payloadValues.size()) + throw new SdpException(" The vector sizes are unequal"); + else { + for (int i = 0; i < payloadNames.size(); i++) { + String name = (String) payloadNames.elementAt(i); + String value = (String) payloadValues.elementAt(i); + setAttribute(name, value); + } + } + } + } + } + + // ///////////////////////////////////////////////////////////////// + // Precondition Mechanism + // based in 3GPP TS 24.229 and precondition mechanism (RFC 3312) + // issued by Miguel Freitas (IT) PTinovacao + // ///////////////////////////////////////////////////////////////// + + /** + * Precondition Mechanism - precondition fields for the media description + */ + // Precondition Attribute Fields + protected PreconditionFields preconditionFields; + + /** + * <p> + * Set the Media Description's Precondition Fields + * </p> + * <p> + * issued by Miguel Freitas (IT) PTInovacao + * </p> + * + * @param precondition + * Vector containing PreconditionFields + * @throws SdpException + */ + public void setPreconditionFields(Vector precondition) throws SdpException { + this.preconditionFields.setPreconditions(precondition); + } + + /** + * <p> + * Set the Media Description's Precondition Fields + * </p> + * <p> + * issued by Miguel Freitas (IT) PTInovacao + * </p> + * + * @param precondition + * PreconditionFields parameter + */ + public void setPreconditions(PreconditionFields precondition) { + this.preconditionFields = precondition; + } + + /** + * <p> + * Get attribute fields of segmented precondition + * </p> + * <p> + * issued by Miguel Freitas (IT) PTInovacao + * </p> + * + * @return Vector of attribute fields (segmented precondition) + */ + public Vector getPreconditionFields() { + return this.preconditionFields.getPreconditions(); + } + + // end // + +} diff --git a/java/gov/nist/javax/sdp/SdpEncoderImpl.java b/java/gov/nist/javax/sdp/SdpEncoderImpl.java new file mode 100644 index 0000000..436514f --- /dev/null +++ b/java/gov/nist/javax/sdp/SdpEncoderImpl.java @@ -0,0 +1,118 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * SdpEncoderImpl.java + * + * Created on January 14, 2002, 11:40 AM + */ + +package gov.nist.javax.sdp; +import javax.sdp.*; +import java.io.*; + +/** Implementation of SDP encoder. +* +*@version JSR141-PUBLIC-REVIEW (Subject to change). +* +*@author M. Ranganathan <br/> +* +* +* +*/ +public class SdpEncoderImpl { + + /** Creates new SdpEncoderImpl */ + public SdpEncoderImpl() { + } + + /** Specifies the character set to be used to display the session name and + * information data. By default, the ISO-10646 + * character set in UTF-8 encoding is used. If a more compact representation + * is required, other character sets may be used + * such as ISO-8859-1 for Northern European languages. + * @param enc enc - name of character encoding to use for session name and + * information data + * @throws UnsupportedEncodingException if the named encoding is not supported + */ + public void setEncoding(String enc) throws UnsupportedEncodingException { + throw new UnsupportedEncodingException("Method not supported"); + } + + /** Specifies whether to try to write "typed-time" fields instead of raw integer + * values. This + * makes the session description more readable but may have an adverse effect on + * serialization time. + * + * Ordinarily time values are given in numbers of seconds, but for readability + * they may be + * specified using logical units. From RFC 2327: + * + * To make announcements more compact, times may also be given in units of + * days, hours or minutes. The syntax for these is a number immediately + * followed by a single case-sensitive character. Fractional units are not + * allowed - a smaller unit should be used instead. The following unit + * specification characters are allowed: + * + * d - days (86400 seconds) + * h - minutes (3600 seconds) + * m - minutes (60 seconds) + * s - seconds (allowed for completeness but not recommended) + * + * @param flag if true this Outputter should emit "typed" time specs in preference to + * untyped times. + */ + public void setTypedTime(boolean flag) { + + } + + /** Specifies whether to generate "a=rtpmap:" attributes for static RTP/AVP format strings. + * This is recommended but makes messages bigger. The default is not to write such + * attributes. + * @param flag if true "a=rtpmap:" attributes are generated for all "RTP/AVP" formats + */ + public void setRtpmapAttribute(boolean flag) { + + } + + /** Write the specified SessionDescription to the output stream using the current + * settings. + * @param sd SessionDescription to serialize + * @param out OutputStream to write serialized SessionDescription to + * @throws IOException + */ + public void output(SessionDescription sd, OutputStream out) + throws IOException { + if (out instanceof ObjectOutputStream) { + ObjectOutputStream output = (ObjectOutputStream) out; + if (sd != null) + output.writeObject(sd); + else + throw new IOException("The parameter is null"); + } else + throw new IOException("The output stream has to be an instance of ObjectOutputStream"); + } + +} diff --git a/java/gov/nist/javax/sdp/SessionDescriptionImpl.java b/java/gov/nist/javax/sdp/SessionDescriptionImpl.java new file mode 100644 index 0000000..9c92eeb --- /dev/null +++ b/java/gov/nist/javax/sdp/SessionDescriptionImpl.java @@ -0,0 +1,1092 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * SessionDescriptionImpl.java + * + * Created on January 10, 2002, 3:11 PM + */ +package gov.nist.javax.sdp; + +import java.util.*; +import javax.sdp.*; + +import gov.nist.javax.sdp.fields.*; + +import java.text.ParseException; + +/** + * Implementation of the SessionDescription interface. + * + * @version JSR141-PUBLIC-REVIEW + * + * + * @author Olivier Deruelle + * @author M. Ranganathan <br/> + * + * + * + */ +public class SessionDescriptionImpl implements SessionDescription { + private TimeDescriptionImpl currentTimeDescription; + + private MediaDescriptionImpl currentMediaDescription; + + protected ProtoVersionField versionImpl; + + protected OriginField originImpl; + + protected SessionNameField sessionNameImpl; + + protected InformationField infoImpl; + + protected URIField uriImpl; + + protected ConnectionField connectionImpl; + + protected KeyField keyImpl; + + protected Vector timeDescriptions; + + protected Vector mediaDescriptions; + + protected Vector zoneAdjustments; + + protected Vector emailList; + + protected Vector phoneList; + + protected Vector bandwidthList; + + protected Vector attributesList; + + /** Creates new SessionDescriptionImpl */ + public SessionDescriptionImpl() { + } + + /** + * Copy constructor, creates a deep copy of another SessionDescription. + * + * @param otherSessionDescription - the SessionDescription to copy from. + * @throws SdpException - if there is a problem constructing the SessionDescription. + */ + public SessionDescriptionImpl(SessionDescription otherSessionDescription) + throws SdpException + { + // If the other session description is null there's nothing to initialize + if (otherSessionDescription == null) return; + + // OK to clone the version field, no deep copy required + Version otherVersion = otherSessionDescription.getVersion(); + if (otherVersion != null) { + this.setVersion((Version) otherVersion.clone()); + } + + // OK to clone the origin field, class already does a deep copy + Origin otherOrigin = otherSessionDescription.getOrigin(); + if (otherOrigin != null) { + this.setOrigin((Origin) otherOrigin.clone()); + } + + // OK to clone the session name, no deep copy required + SessionName otherSessionName = otherSessionDescription.getSessionName(); + if (otherSessionName != null) { + this.setSessionName((SessionName) otherSessionName.clone()); + } + + // OK to clone the information field, just a string, no deep copy required + Info otherInfo = otherSessionDescription.getInfo(); + if (otherInfo != null) { + this.setInfo((Info) otherInfo.clone()); + } + + // URI field requires deep copy + URIField otherUriField = (URIField) otherSessionDescription.getURI(); + if (otherUriField != null) { + URIField newUF = new URIField(); + newUF.setURI(otherUriField.toString()); + this.setURI(newUF); + } + + // OK to clone the connection field, class already does a deep copy + Connection otherConnection = (Connection) otherSessionDescription.getConnection(); + if (otherConnection != null) { + this.setConnection((Connection) otherConnection.clone()); + } + + // OK to clone the key field, just a couple of strings + Key otherKey = (Key) otherSessionDescription.getKey(); + if (otherKey != null) { + this.setKey((Key) otherKey.clone()); + } + + // Deep copy each vector, starting with time descriptions + Vector otherTimeDescriptions = otherSessionDescription.getTimeDescriptions(false); + if (otherTimeDescriptions != null) { + Vector newTDs = new Vector(); + Iterator itTimeDescriptions = otherTimeDescriptions.iterator(); + while (itTimeDescriptions.hasNext()) { + TimeDescriptionImpl otherTimeDescription = (TimeDescriptionImpl) itTimeDescriptions.next(); + if (otherTimeDescription != null) { + TimeField otherTimeField = (TimeField) otherTimeDescription.getTime().clone(); + TimeDescriptionImpl newTD = new TimeDescriptionImpl(otherTimeField); + Vector otherRepeatTimes = otherTimeDescription.getRepeatTimes(false); + if (otherRepeatTimes != null) { + Iterator itRepeatTimes = otherRepeatTimes.iterator(); + while (itRepeatTimes.hasNext()) { + RepeatField otherRepeatField = (RepeatField) itRepeatTimes.next(); + if (otherRepeatField != null) { + // RepeatField clone is a deep copy + RepeatField newRF = (RepeatField) otherRepeatField.clone(); + newTD.addRepeatField(newRF); + } + } + } + newTDs.add(newTD); + } + } + this.setTimeDescriptions(newTDs); + } + + // Deep copy the email list + Vector otherEmails = otherSessionDescription.getEmails(false); + if (otherEmails != null) { + Vector newEmails = new Vector(); + Iterator itEmails = otherEmails.iterator(); + while (itEmails.hasNext()) { + EmailField otherEmailField = (EmailField) itEmails.next(); + if (otherEmailField != null) { + // Email field clone is a deep copy + EmailField newEF = (EmailField) otherEmailField.clone(); + newEmails.add(newEF); + } + } + this.setEmails(newEmails); + } + + // Deep copy the phone list + Vector otherPhones = otherSessionDescription.getPhones(false); + if (otherPhones != null) { + Vector newPhones = new Vector(); + Iterator itPhones = otherPhones.iterator(); + while (itPhones.hasNext()) { + PhoneField otherPhoneField = (PhoneField) itPhones.next(); + if (otherPhoneField != null) { + // Phone field clone is a deep copy + PhoneField newPF = (PhoneField) otherPhoneField.clone(); + newPhones.add(newPF); + } + } + this.setPhones(newPhones); + } + + // Deep copy the zone adjustments list + Vector otherZAs = otherSessionDescription.getZoneAdjustments(false); + if (otherZAs != null) { + Vector newZAs = new Vector(); + Iterator itZAs = otherZAs.iterator(); + while (itZAs.hasNext()) { + ZoneField otherZoneField = (ZoneField) itZAs.next(); + if (otherZoneField != null) { + // Zone field clone is a deep copy + ZoneField newPF = (ZoneField) otherZoneField.clone(); + newZAs.add(newPF); + } + } + this.setZoneAdjustments(newZAs); + } + + // Deep copy the bandwidth list + Vector otherBandwidths = otherSessionDescription.getBandwidths(false); + if (otherBandwidths != null) { + Vector newBandwidths = new Vector(); + Iterator itBandwidths = otherBandwidths.iterator(); + while (itBandwidths.hasNext()) { + BandwidthField otherBandwidthField = (BandwidthField) itBandwidths.next(); + if (otherBandwidthField != null) { + // Bandwidth field clone() is a shallow copy but object is not deep + BandwidthField newBF = (BandwidthField) otherBandwidthField.clone(); + newBandwidths.add(newBF); + } + } + this.setBandwidths(newBandwidths); + } + + // Deep copy the attribute list + Vector otherAttributes = otherSessionDescription.getAttributes(false); + if (otherAttributes != null) { + Vector newAttributes = new Vector(); + Iterator itAttributes = otherAttributes.iterator(); + while (itAttributes.hasNext()) { + AttributeField otherAttributeField = (AttributeField) itAttributes.next(); + if (otherAttributeField != null) { + // Attribute field clone() makes a deep copy but be careful: it may use reflection to copy one of its members + AttributeField newBF = (AttributeField) otherAttributeField.clone(); + newAttributes.add(newBF); + } + } + this.setAttributes(newAttributes); + } + + // Deep copy the media descriptions + Vector otherMediaDescriptions = otherSessionDescription.getMediaDescriptions(false); + if (otherMediaDescriptions != null) { + Vector newMDs = new Vector(); + Iterator itMediaDescriptions = otherMediaDescriptions.iterator(); + while (itMediaDescriptions.hasNext()) { + MediaDescriptionImpl otherMediaDescription = (MediaDescriptionImpl) itMediaDescriptions.next(); + if (otherMediaDescription != null) { + MediaDescriptionImpl newMD = new MediaDescriptionImpl(); + + // Copy the media field + MediaField otherMediaField = otherMediaDescription.getMediaField(); + if (otherMediaField != null) { + // Media field clone() makes a shallow copy, so don't use clone() + MediaField newMF = new MediaField(); + newMF.setMedia(otherMediaField.getMedia()); + newMF.setPort(otherMediaField.getPort()); + newMF.setNports(otherMediaField.getNports()); + newMF.setProto(otherMediaField.getProto()); + Vector otherFormats = otherMediaField.getFormats(); + if (otherFormats != null) { + Vector newFormats = new Vector(); + Iterator itFormats = otherFormats.iterator(); + while (itFormats.hasNext()) { + Object otherFormat = itFormats.next(); + if (otherFormat != null) { + // Convert all format objects to strings in order to avoid reflection + newFormats.add(String.valueOf(otherFormat)); + } + } + newMF.setFormats(newFormats); + } + newMD.setMedia(newMF); + } + + // Copy the information field (it's a shallow object, ok to clone) + InformationField otherInfoField = otherMediaDescription.getInformationField(); + if (otherInfoField != null) { + newMD.setInformationField((InformationField) otherInfoField.clone()); + } + + // Copy the connection field. OK to use clone(), already does a deep copy. + ConnectionField otherConnectionField = otherMediaDescription.getConnectionField(); + if (otherConnectionField != null) { + newMD.setConnectionField((ConnectionField) otherConnectionField.clone()); + } + + // Copy the bandwidth fields + Vector otherBFs = otherMediaDescription.getBandwidths(false); + if (otherBFs != null) { + Vector newBFs = new Vector(); + Iterator itBFs = otherBFs.iterator(); + while (itBFs.hasNext()) { + BandwidthField otherBF = (BandwidthField) itBFs.next(); + if (otherBF != null) { + // BandwidthField is a shallow object, ok to use clone + newBFs.add((BandwidthField) otherBF.clone()); + } + } + newMD.setBandwidths(newBFs); + } + + // Copy the key field (shallow object) + KeyField otherKeyField = otherMediaDescription.getKeyField(); + if (otherKeyField != null) { + newMD.setKeyField((KeyField) otherKeyField.clone()); + } + + // Copy the attributes + Vector otherAFs = otherMediaDescription.getAttributeFields(); + if (otherAFs != null) { + Vector newAFs = new Vector(); + Iterator itAFs = otherAFs.iterator(); + while (itAFs.hasNext()) { + AttributeField otherAF = (AttributeField) itAFs.next(); + if (otherAF != null) { + // AttributeField clone() already makes a deep copy, but be careful. It will use reflection + // unless the attribute is a String or any other immutable object. + newAFs.add((AttributeField) otherAF.clone()); + } + } + newMD.setAttributeFields(newAFs); + } + newMDs.add(newMD); + } + } + this.setMediaDescriptions(newMDs); + } + } + + public void addField(SDPField sdpField) throws ParseException { + try { + if (sdpField instanceof ProtoVersionField) { + versionImpl = (ProtoVersionField) sdpField; + } else if (sdpField instanceof OriginField) { + originImpl = (OriginField) sdpField; + } else if (sdpField instanceof SessionNameField) { + sessionNameImpl = (SessionNameField) sdpField; + } else if (sdpField instanceof InformationField) { + if (currentMediaDescription != null) + currentMediaDescription + .setInformationField((InformationField) sdpField); + else + this.infoImpl = (InformationField) sdpField; + } else if (sdpField instanceof URIField) { + uriImpl = (URIField) sdpField; + } else if (sdpField instanceof ConnectionField) { + if (currentMediaDescription != null) + currentMediaDescription + .setConnectionField((ConnectionField) sdpField); + else + this.connectionImpl = (ConnectionField) sdpField; + } else if (sdpField instanceof KeyField) { + if (currentMediaDescription != null) + currentMediaDescription.setKey((KeyField) sdpField); + else + keyImpl = (KeyField) sdpField; + } else if (sdpField instanceof EmailField) { + getEmails(true).add(sdpField); + } else if (sdpField instanceof PhoneField) { + getPhones(true).add(sdpField); + } else if (sdpField instanceof TimeField) { + currentTimeDescription = new TimeDescriptionImpl( + (TimeField) sdpField); + getTimeDescriptions(true).add(currentTimeDescription); + } else if (sdpField instanceof RepeatField) { + if (currentTimeDescription == null) { + throw new ParseException("no time specified", 0); + } else { + currentTimeDescription + .addRepeatField((RepeatField) sdpField); + } + } else if (sdpField instanceof ZoneField) { + getZoneAdjustments(true).add(sdpField); + } else if (sdpField instanceof BandwidthField) { + if (currentMediaDescription != null) + currentMediaDescription + .addBandwidthField((BandwidthField) sdpField); + else + getBandwidths(true).add(sdpField); + } else if (sdpField instanceof AttributeField) { + if (currentMediaDescription != null) { + AttributeField af = (AttributeField) sdpField; + String s = af.getName(); + // Bug report from Andreas Bystrom + currentMediaDescription + .addAttribute((AttributeField) sdpField); + } else { + getAttributes(true).add(sdpField); + } + + } else if (sdpField instanceof MediaField) { + currentMediaDescription = new MediaDescriptionImpl(); + getMediaDescriptions(true).add(currentMediaDescription); + // Bug report from Andreas Bystrom + currentMediaDescription.setMediaField((MediaField) sdpField); + } + } catch (SdpException ex) { + throw new ParseException(sdpField.encode(), 0); + } + } + + /** + * Creates and returns a deep copy of this object + * + * @return a clone of this instance. + * @exception CloneNotSupportedException if this instance cannot be cloned. + */ + public Object clone() throws CloneNotSupportedException { + try { + return new SessionDescriptionImpl(this); + } catch (SdpException e) { + // throw this exception to indicate that this instance cannot be cloned + throw new CloneNotSupportedException(); + } + } + + /** + * Returns the version of SDP in use. This corresponds to the v= field of + * the SDP data. + * + * @return the integer version (-1 if not set). + */ + public Version getVersion() { + return versionImpl; + } + + /** + * Sets the version of SDP in use. This corresponds to the v= field of the + * SDP data. + * + * @param v + * version - the integer version. + * @throws SdpException + * if the version is null + */ + public void setVersion(Version v) throws SdpException { + if (v == null) + throw new SdpException("The parameter is null"); + if (v instanceof ProtoVersionField) { + versionImpl = (ProtoVersionField) v; + } else + throw new SdpException( + "The parameter must be an instance of VersionField"); + } + + /** + * Returns information about the originator of the session. This corresponds + * to the o= field of the SDP data. + * + * @return the originator data. + */ + public Origin getOrigin() { + return originImpl; + } + + /** + * Sets information about the originator of the session. This corresponds to + * the o= field of the SDP data. + * + * @param origin + * origin - the originator data. + * @throws SdpException + * if the origin is null + */ + public void setOrigin(Origin origin) throws SdpException { + if (origin == null) + throw new SdpException("The parameter is null"); + if (origin instanceof OriginField) { + OriginField o = (OriginField) origin; + originImpl = o; + } else + throw new SdpException( + "The parameter must be an instance of OriginField"); + } + + /** + * Returns the name of the session. This corresponds to the s= field of the + * SDP data. + * + * @return the session name. + */ + public SessionName getSessionName() { + return sessionNameImpl; + } + + /** + * Sets the name of the session. This corresponds to the s= field of the SDP + * data. + * + * @param sessionName + * name - the session name. + * @throws SdpException + * if the sessionName is null + */ + public void setSessionName(SessionName sessionName) throws SdpException { + if (sessionName == null) + throw new SdpException("The parameter is null"); + if (sessionName instanceof SessionNameField) { + SessionNameField s = (SessionNameField) sessionName; + sessionNameImpl = s; + } else + throw new SdpException( + "The parameter must be an instance of SessionNameField"); + } + + /** + * Returns value of the info field (i=) of this object. + * + * @return info + */ + public Info getInfo() { + return infoImpl; + } + + /** + * Sets the i= field of this object. + * + * @param i + * s - new i= value; if null removes the field + * @throws SdpException + * if the info is null + */ + public void setInfo(Info i) throws SdpException { + if (i == null) + throw new SdpException("The parameter is null"); + if (i instanceof InformationField) { + InformationField info = (InformationField) i; + infoImpl = info; + } else + throw new SdpException( + "The parameter must be an instance of InformationField"); + } + + /** + * Returns a uri to the location of more details about the session. This + * corresponds to the u= field of the SDP data. + * + * @return the uri. + */ + public URI getURI() { + return uriImpl; + } + + /** + * Sets the uri to the location of more details about the session. This + * corresponds to the u= field of the SDP data. + * + * @param uri + * uri - the uri. + * @throws SdpException + * if the uri is null + */ + public void setURI(URI uri) throws SdpException { + if (uri == null) + throw new SdpException("The parameter is null"); + if (uri instanceof URIField) { + URIField u = (URIField) uri; + uriImpl = u; + } else + throw new SdpException( + "The parameter must be an instance of URIField"); + } + + /** + * Returns an email address to contact for further information about the + * session. This corresponds to the e= field of the SDP data. + * + * @param create + * boolean to set + * @throws SdpParseException + * @return the email address. + */ + public Vector getEmails(boolean create) throws SdpParseException { + if (emailList == null) { + if (create) + emailList = new Vector(); + } + return emailList; + } + + /** + * Sets a an email address to contact for further information about the + * session. This corresponds to the e= field of the SDP data. + * + * @param emails + * email - the email address. + * @throws SdpException + * if the vector is null + */ + public void setEmails(Vector emails) throws SdpException { + if (emails == null) + throw new SdpException("The parameter is null"); + else + emailList = emails; + } + + /** + * Returns a phone number to contact for further information about the + * session. This corresponds to the p= field of the SDP data. + * + * @param create + * boolean to set + * @throws SdpException + * @return the phone number. + */ + public Vector getPhones(boolean create) throws SdpException { + if (phoneList == null) { + if (create) + phoneList = new Vector(); + } + return phoneList; + } + + /** + * Sets a phone number to contact for further information about the session. + * This corresponds to the p= field of the SDP data. + * + * @param phones + * phone - the phone number. + * @throws SdpException + * if the vector is null + */ + public void setPhones(Vector phones) throws SdpException { + if (phones == null) + throw new SdpException("The parameter is null"); + else + phoneList = phones; + } + + /** + * Returns a TimeField indicating the start, stop, repetition and time zone + * information of the session. This corresponds to the t= field of the SDP + * data. + * + * @param create + * boolean to set + * @throws SdpException + * @return the Time Field. + */ + public Vector getTimeDescriptions(boolean create) throws SdpException { + if (timeDescriptions == null) { + if (create) + timeDescriptions = new Vector(); + } + return timeDescriptions; + } + + /** + * Sets a TimeField indicating the start, stop, repetition and time zone + * information of the session. This corresponds to the t= field of the SDP + * data. + * + * @param times + * time - the TimeField. + * @throws SdpException + * if the vector is null + */ + public void setTimeDescriptions(Vector times) throws SdpException { + if (times == null) + throw new SdpException("The parameter is null"); + else { + timeDescriptions = times; + } + } + + /** + * Returns the time zone adjustments for the Session + * + * @param create + * boolean to set + * @throws SdpException + * @return a Hashtable containing the zone adjustments, where the key is the + * Adjusted Time Zone and the value is the offset. + */ + public Vector getZoneAdjustments(boolean create) throws SdpException { + if (zoneAdjustments == null) { + if (create) + zoneAdjustments = new Vector(); + } + return zoneAdjustments; + } + + /** + * Sets the time zone adjustment for the TimeField. + * + * @param zoneAdjustments + * zoneAdjustments - a Hashtable containing the zone adjustments, + * where the key is the Adjusted Time Zone and the value is the + * offset. + * @throws SdpException + * if the vector is null + */ + public void setZoneAdjustments(Vector zoneAdjustments) throws SdpException { + if (zoneAdjustments == null) + throw new SdpException("The parameter is null"); + else + this.zoneAdjustments = zoneAdjustments; + } + + /** + * Returns the connection information associated with this object. This may + * be null for SessionDescriptions if all Media objects have a connection + * object and may be null for Media objects if the corresponding session + * connection is non-null. + * + * @return connection + */ + public Connection getConnection() { + return connectionImpl; + } + + /** + * Set the connection data for this entity. + * + * @param conn + * to set + * @throws SdpException + * if the parameter is null + */ + public void setConnection(Connection conn) throws SdpException { + if (conn == null) + throw new SdpException("The parameter is null"); + if (conn instanceof ConnectionField) { + ConnectionField c = (ConnectionField) conn; + connectionImpl = c; + } else + throw new SdpException("Bad implementation class ConnectionField"); + } + + /** + * Returns the Bandwidth of the specified type. + * + * @param create + * type - type of the Bandwidth to return + * @return the Bandwidth or null if undefined + */ + public Vector getBandwidths(boolean create) { + if (bandwidthList == null) { + if (create) + bandwidthList = new Vector(); + } + return bandwidthList; + } + + /** + * set the value of the Bandwidth with the specified type. + * + * @param bandwidthList + * to set + * @throws SdpException + * if the vector is null + */ + public void setBandwidths(Vector bandwidthList) throws SdpException { + if (bandwidthList == null) + throw new SdpException("The parameter is null"); + else + this.bandwidthList = bandwidthList; + } + + /** + * Returns the integer value of the specified bandwidth name. + * + * @param name + * name - the name of the bandwidth type + * @throws SdpParseException + * @return the value of the named bandwidth + */ + public int getBandwidth(String name) throws SdpParseException { + if (name == null) + return -1; + else if (bandwidthList == null) + return -1; + for (int i = 0; i < bandwidthList.size(); i++) { + Object o = bandwidthList.elementAt(i); + if (o instanceof BandwidthField) { + BandwidthField b = (BandwidthField) o; + String type = b.getType(); + if (type != null) { + if (name.equals(type)) { + return b.getValue(); + } + } + } + } + return -1; + } + + /** + * Sets the value of the specified bandwidth type. + * + * @param name + * name - the name of the bandwidth type. + * @param value + * value - the value of the named bandwidth type. + * @throws SdpException + * if the name is null + */ + public void setBandwidth(String name, int value) throws SdpException { + if (name == null) + throw new SdpException("The parameter is null"); + else if (bandwidthList != null) { + for (int i = 0; i < bandwidthList.size(); i++) { + Object o = bandwidthList.elementAt(i); + if (o instanceof BandwidthField) { + BandwidthField b = (BandwidthField) o; + String type = b.getType(); + if (type != null) { + if (name.equals(type)) { + b.setValue(value); + } + } + } + } + } + } + + /** + * Removes the specified bandwidth type. + * + * @param name + * name - the name of the bandwidth type + */ + public void removeBandwidth(String name) { + if (name != null) + if (bandwidthList != null) { + for (int i = 0; i < bandwidthList.size(); i++) { + Object o = bandwidthList.elementAt(i); + if (o instanceof BandwidthField) { + BandwidthField b = (BandwidthField) o; + try { + String type = b.getType(); + if (type != null) { + if (name.equals(type)) { + bandwidthList.remove(b); + } + } + } catch (SdpParseException e) { + } + } + } + } + } + + /** + * Returns the key data. + * + * @return key + */ + public Key getKey() { + return keyImpl; + } + + /** + * Sets encryption key information. This consists of a method and an + * encryption key included inline. + * + * @param key + * key - the encryption key data; depending on method may be null + * @throws SdpException + * if the parameter is null + */ + public void setKey(Key key) throws SdpException { + if (key == null) + throw new SdpException("The parameter is null"); + if (key instanceof KeyField) { + KeyField k = (KeyField) key; + keyImpl = k; + } else + throw new SdpException( + "The parameter must be an instance of KeyField"); + } + + /** + * Returns the value of the specified attribute. + * + * @param name + * name - the name of the attribute + * @throws SdpParseException + * @return the value of the named attribute + */ + public String getAttribute(String name) throws SdpParseException { + if (name == null) + return null; + else if (attributesList == null) + return null; + for (int i = 0; i < attributesList.size(); i++) { + Object o = attributesList.elementAt(i); + if (o instanceof AttributeField) { + AttributeField a = (AttributeField) o; + String n = a.getName(); + if (n != null) { + if (name.equals(n)) { + return a.getValue(); + } + } + } + } + return null; + } + + /** + * Returns the set of attributes for this Description as a Vector of + * Attribute objects in the order they were parsed. + * + * @param create + * create - specifies whether to return null or a new empty + * Vector in case no attributes exists for this Description + * @return attributes for this Description + */ + public Vector getAttributes(boolean create) { + if (attributesList == null) { + if (create) + attributesList = new Vector(); + } + return attributesList; + } + + /** + * Removes the attribute specified by the value parameter. + * + * @param name + * name - the name of the attribute + */ + public void removeAttribute(String name) { + if (name != null) + if (attributesList != null) { + for (int i = 0; i < attributesList.size(); i++) { + Object o = attributesList.elementAt(i); + if (o instanceof AttributeField) { + AttributeField a = (AttributeField) o; + try { + String n = a.getName(); + if (n != null) { + if (name.equals(n)) { + attributesList.remove(a); + } + } + } catch (SdpParseException e) { + } + + } + } + } + } + + /** + * Sets the value of the specified attribute. + * + * @param name + * name - the name of the attribute. + * @param value + * value - the value of the named attribute. + * @throws SdpException + * if the name or the value is null + */ + public void setAttribute(String name, String value) throws SdpException { + if (name == null || value == null) + throw new SdpException("The parameter is null"); + else if (attributesList != null) { + for (int i = 0; i < attributesList.size(); i++) { + Object o = attributesList.elementAt(i); + if (o instanceof AttributeField) { + AttributeField a = (AttributeField) o; + String n = a.getName(); + if (n != null) { + if (name.equals(n)) { + a.setValue(value); + } + } + } + } + } + } + + /** + * Adds the specified Attribute to this Description object. + * + * @param attributes - the attribute to add + * @throws SdpException + * if the vector is null + */ + public void setAttributes(Vector attributes) throws SdpException { + if (attributes == null) + throw new SdpException("The parameter is null"); + else + attributesList = attributes; + } + + /** + * Adds a MediaDescription to the session description. These correspond to + * the m= fields of the SDP data. + * + * @param create + * boolean to set + * @throws SdpException + * @return media - the field to add. + */ + public Vector getMediaDescriptions(boolean create) throws SdpException { + if (mediaDescriptions == null) { + if (create) + mediaDescriptions = new Vector(); + } + return mediaDescriptions; + } + + /** + * Removes all MediaDescriptions from the session description. + * + * @param mediaDescriptions + * to set + * @throws SdpException + * if the parameter is null + */ + public void setMediaDescriptions(Vector mediaDescriptions) + throws SdpException { + if (mediaDescriptions == null) + throw new SdpException("The parameter is null"); + else + this.mediaDescriptions = mediaDescriptions; + } + + private String encodeVector(Vector vector) { + StringBuffer encBuff = new StringBuffer(); + + for (int i = 0; i < vector.size(); i++) + encBuff.append(vector.elementAt(i)); + + return encBuff.toString(); + } + + /** + * Returns the canonical string representation of the current + * SessionDescrption. Acknowledgement - this code was contributed by Emil + * Ivov. + * + * @return Returns the canonical string representation of the current + * SessionDescrption. + */ + + public String toString() { + StringBuffer encBuff = new StringBuffer(); + + // Encode single attributes + encBuff.append(getVersion() == null ? "" : getVersion().toString()); + encBuff.append(getOrigin() == null ? "" : getOrigin().toString()); + encBuff.append(getSessionName() == null ? "" : getSessionName() + .toString()); + encBuff.append(getInfo() == null ? "" : getInfo().toString()); + + // Encode attribute vectors + try { + encBuff.append(getURI() == null ? "" : getURI().toString()); + encBuff.append(getEmails(false) == null ? "" + : encodeVector(getEmails(false))); + encBuff.append(getPhones(false) == null ? "" + : encodeVector(getPhones(false))); + encBuff.append(getConnection() == null ? "" : getConnection() + .toString()); + encBuff.append(getBandwidths(false) == null ? "" + : encodeVector(getBandwidths(false))); + encBuff.append(getTimeDescriptions(false) == null ? "" + : encodeVector(getTimeDescriptions(false))); + encBuff.append(getZoneAdjustments(false) == null ? "" + : encodeVector(getZoneAdjustments(false))); + encBuff.append(getKey() == null ? "" : getKey().toString()); + encBuff.append(getAttributes(false) == null ? "" + : encodeVector(getAttributes(false))); + encBuff.append(getMediaDescriptions(false) == null ? "" + : encodeVector(getMediaDescriptions(false))); + // adds the final crlf + } catch (SdpException exc) { + // add exception handling if necessary + } + return encBuff.toString(); + } + +} + + diff --git a/java/gov/nist/javax/sdp/TimeDescriptionImpl.java b/java/gov/nist/javax/sdp/TimeDescriptionImpl.java new file mode 100644 index 0000000..882b71a --- /dev/null +++ b/java/gov/nist/javax/sdp/TimeDescriptionImpl.java @@ -0,0 +1,143 @@ +/* + * Conditions Of Use + * + * This software was developed by employees of the National Institute of + * Standards and Technology (NIST), an agency of the Federal Government. + * Pursuant to title 15 Untied States Code Section 105, works of NIST + * employees are not subject to copyright protection in the United States + * and are considered to be in the public domain. As a result, a formal + * license is not needed to use the software. + * + * This software is provided by NIST as a service and is expressly + * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT + * AND DATA ACCURACY. NIST does not warrant or make any representations + * regarding the use of the software or the results thereof, including but + * not limited to the correctness, accuracy, reliability or usefulness of + * the software. + * + * Permission to use this software is contingent upon your acceptance + * of the terms of this agreement + * + * . + * + */ +package gov.nist.javax.sdp; + +import gov.nist.javax.sdp.fields.*; +import javax.sdp.*; +import java.util.*; + +/** + * Implementation of Time Description + * + * @version 1.2 + * + * @author Olivier Deruelle + * @author M. Ranganathan <br/> + * + * + * + */ +public class TimeDescriptionImpl implements TimeDescription { + + private TimeField timeImpl; + + private Vector repeatList; + + /** Creates new TimeDescriptionImpl */ + public TimeDescriptionImpl() { + timeImpl = new TimeField(); + repeatList = new Vector(); + + } + + /** + * constructor + * + * @param timeField + * time field to create this descrition from + */ + public TimeDescriptionImpl(TimeField timeField) { + this.timeImpl = timeField; + repeatList = new Vector(); + } + + /** + * Returns the Time field. + * + * @return Time + */ + public Time getTime() { + return timeImpl; + } + + /** + * Sets the Time field. + * + * @param timeField + * Time to set + * @throws SdpException + * if the time is null + */ + public void setTime(Time timeField) throws SdpException { + if (timeField == null) { + throw new SdpException("The parameter is null"); + } else { + if (timeField instanceof TimeField) { + this.timeImpl = (TimeField) timeField; + } else + throw new SdpException( + "The parameter is not an instance of TimeField"); + } + } + + /** + * Returns the list of repeat times (r= fields) specified in the + * SessionDescription. + * + * @param create + * boolean to set + * @return Vector + */ + public Vector getRepeatTimes(boolean create) { + return this.repeatList; + } + + /** + * Returns the list of repeat times (r= fields) specified in the + * SessionDescription. + * + * @param repeatTimes + * Vector to set + * @throws SdpException + * if the parameter is null + */ + public void setRepeatTimes(Vector repeatTimes) throws SdpException { + this.repeatList = repeatTimes; + } + + /** + * Add a repeat field. + * + * @param repeatField -- + * repeat field to add. + */ + public void addRepeatField(RepeatField repeatField) { + if (repeatField == null) + throw new NullPointerException("null repeatField"); + this.repeatList.add(repeatField); + } + + public String toString() { + String retval = timeImpl.encode(); + for (int i = 0; i < this.repeatList.size(); i++) { + RepeatField repeatField = (RepeatField) this.repeatList + .elementAt(i); + retval += repeatField.encode(); + } + return retval; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/AttributeField.java b/java/gov/nist/javax/sdp/fields/AttributeField.java new file mode 100644 index 0000000..cb6d62d --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/AttributeField.java @@ -0,0 +1,195 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; + +/** +* Attribute Field. +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class AttributeField extends SDPField implements javax.sdp.Attribute { + protected NameValue attribute; + + public NameValue getAttribute() { + return attribute; + } + + public AttributeField() { + super(ATTRIBUTE_FIELD); + } + /** + * Set the attribute member + */ + public void setAttribute(NameValue a) { + attribute = a; + attribute.setSeparator(Separators.COLON); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String encoded_string = ATTRIBUTE_FIELD; + if (attribute != null) + encoded_string += attribute.encode(); + return encoded_string + Separators.NEWLINE; + } + + public String toString() { + return this.encode(); + } + + /** Returns the name of this attribute + * @throws SdpParseException if the name is not well formatted. + * @return a String identity or null. + */ + public String getName() throws SdpParseException { + NameValue nameValue = getAttribute(); + if (nameValue == null) + return null; + else { + String name = nameValue.getName(); + if (name == null) + return null; + else + return name; + } + } + + /** Sets the id of this attribute. + * @param name the string name/id of the attribute. + * @throws SdpException if the name is null + */ + public void setName(String name) throws SdpException { + if (name == null) + throw new SdpException("The name is null"); + else { + NameValue nameValue = getAttribute(); + if (nameValue == null) + nameValue = new NameValue(); + nameValue.setName(name); + setAttribute(nameValue); + } + } + + /** Determines if this attribute has an associated value. + * @throws SdpParseException if the value is not well formatted. + * @return true if the attribute has a value. + */ + public boolean hasValue() throws SdpParseException { + NameValue nameValue = getAttribute(); + if (nameValue == null) + return false; + else { + Object value = nameValue.getValueAsObject(); + if (value == null) + return false; + else + return true; + } + } + + /** Returns the value of this attribute. + * @throws SdpParseException if the value is not well formatted. + * @return the value; null if the attribute has no associated value. + */ + public String getValue() throws SdpParseException { + NameValue nameValue = getAttribute(); + if (nameValue == null) + return null; + else { + Object value = nameValue.getValueAsObject(); + if (value == null) + return null; + else if (value instanceof String) + return (String) value; + else + return value.toString(); + } + } + + /** Sets the value of this attribute. + * @param value the - attribute value + * @throws SdpException if the value is null. + */ + public void setValue(String value) throws SdpException { + if (value == null) + throw new SdpException("The value is null"); + else { + NameValue nameValue = getAttribute(); + if (nameValue == null) + nameValue = new NameValue(); + nameValue.setValueAsObject(value); + setAttribute(nameValue); + } + } + + /** + * Allow for null value when setting the value. + * + * @param value -- can be null. + */ + + public void setValueAllowNull(String value) { + NameValue nameValue = getAttribute(); + if (nameValue == null) + nameValue = new NameValue(); + nameValue.setValueAsObject(value); + setAttribute(nameValue); + } + + public Object clone() { + AttributeField retval = (AttributeField) super.clone(); + if (this.attribute != null) + retval.attribute = (NameValue) this.attribute.clone(); + return retval; + } + + public boolean equals(Object that ) { + if ( ! (that instanceof AttributeField)) return false; + AttributeField other = (AttributeField) that; + return other.getAttribute().getName().equalsIgnoreCase(this.getAttribute().getName()) && + this.getAttribute().getValueAsObject().equals(other.getAttribute().getValueAsObject()); + } + + @Override + public int hashCode() { + if (getAttribute() == null ) throw new UnsupportedOperationException("Attribute is null cannot compute hashCode "); + return this.encode().hashCode(); + } +} diff --git a/java/gov/nist/javax/sdp/fields/BandwidthField.java b/java/gov/nist/javax/sdp/fields/BandwidthField.java new file mode 100644 index 0000000..a2ac0c8 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/BandwidthField.java @@ -0,0 +1,116 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; +/** +* Bandwidth field of a SDP header. +* +*@version JSR141-PUBLIC-REVIEW (Subject to change) +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ + +public class BandwidthField extends SDPField implements javax.sdp.BandWidth { + protected String bwtype; + protected int bandwidth; + public BandwidthField() { + super(SDPFieldNames.BANDWIDTH_FIELD); + } + public String getBwtype() { + return bwtype; + } + public int getBandwidth() { + return bandwidth; + } + /** + * Set the bwtype member + */ + public void setBwtype(String b) { + bwtype = b; + } + /** + * Set the bandwidth member + */ + public void setBandwidth(int b) { + bandwidth = b; + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String encoded_string = BANDWIDTH_FIELD; + + if (bwtype != null) + encoded_string += bwtype + Separators.COLON; + return encoded_string + bandwidth + Separators.NEWLINE; + } + + /** Returns the bandwidth type. + * @throws SdpParseException + * @return type + */ + public String getType() throws SdpParseException { + return getBwtype(); + } + + /** Sets the bandwidth type. + * @param type to set + * @throws SdpException if the type is null + */ + public void setType(String type) throws SdpException { + if (type == null) + throw new SdpException("The type is null"); + else + setBwtype(type); + } + + /** Returns the bandwidth value measured in kilobits per second. + * @throws SdpParseException + * @return the bandwidth value + */ + public int getValue() throws SdpParseException { + return getBandwidth(); + } + + /** Sets the bandwidth value. + * @param value to set + * @throws SdpException + */ + public void setValue(int value) throws SdpException { + setBandwidth(value); + } + +} diff --git a/java/gov/nist/javax/sdp/fields/ConnectionAddress.java b/java/gov/nist/javax/sdp/fields/ConnectionAddress.java new file mode 100644 index 0000000..e8e3a26 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/ConnectionAddress.java @@ -0,0 +1,111 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +/** +* Connection Address of the SDP header (appears as part of the Connection field) +* +*@version JSR141-PUBLIC-REVIEW (subject to change) +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class ConnectionAddress extends SDPObject { + protected Host address; + protected int ttl; + protected int port; + + public Host getAddress() { + return address; + } + public int getTtl() { + return ttl; + } + public int getPort() { + return port; + } + /** + * Set the address member + */ + public void setAddress(Host a) { + address = a; + } + /** + * Set the ttl member + */ + public void setTtl(int ttl) { + this.ttl = ttl; + } + /** + * Set the port member + */ + public void setPort(int p) { + port = p; + } + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String encoded_string = ""; + + if (address != null){ + encoded_string = address.encode(); + + //it appears that SDP does not allow square brackets + //in the connection address (see RFC4566) so make sure + //we lose them + if(Host.isIPv6Reference(encoded_string)) + { + //the isIPv6Reference == true means we have a minimum + //of 2 symbols, so substring bravely + encoded_string = encoded_string + .substring(1, encoded_string.length()-1); + } + } + if (ttl != 0 && port != 0) { + encoded_string += Separators.SLASH + ttl + Separators.SLASH + port; + } else if (ttl != 0) { + encoded_string += Separators.SLASH + ttl; + } + return encoded_string; + } + + public Object clone() { + ConnectionAddress retval = (ConnectionAddress) super.clone(); + if (this.address != null) + retval.address = (Host) this.address.clone(); + return retval; + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/ConnectionField.java b/java/gov/nist/javax/sdp/fields/ConnectionField.java new file mode 100644 index 0000000..8e0b1f0 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/ConnectionField.java @@ -0,0 +1,180 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; +/** +* Connectin Field of the SDP request. +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class ConnectionField extends SDPField implements javax.sdp.Connection { + protected String nettype; + protected String addrtype; + protected ConnectionAddress address; + + public ConnectionField() { + super(SDPFieldNames.CONNECTION_FIELD); + } + public String getNettype() { + return nettype; + } + public String getAddrtype() { + return addrtype; + } + public ConnectionAddress getConnectionAddress() { + return address; + } + /** + * Set the nettype member + */ + public void setNettype(String n) { + nettype = n; + } + /** + * Set the addrtype member + */ + public void setAddrType(String a) { + addrtype = a; + } + /** + * Set the address member + */ + public void setAddress(ConnectionAddress a) { + address = a; + } + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String encoded_string = CONNECTION_FIELD; + if (nettype != null) + encoded_string += nettype; + if (addrtype != null) + encoded_string += Separators.SP + addrtype; + if (address != null) + encoded_string += Separators.SP + address.encode(); + return encoded_string += Separators.NEWLINE; + } + + public String toString() { + return this.encode(); + } + /** Returns the type of the network for this Connection. + * @throws SdpParseException + * @return the type of the network + */ + public String getAddress() throws SdpParseException { + ConnectionAddress connectionAddress = getConnectionAddress(); + if (connectionAddress == null) + return null; + else { + Host host = connectionAddress.getAddress(); + if (host == null) + return null; + else + return host.getAddress(); + } + } + + /** Returns the type of the address for this Connection. + * @throws SdpParseException + * @return the type of the address + */ + public String getAddressType() throws SdpParseException { + return getAddrtype(); + } + + /** Returns the type of the network for this Connection. + * @throws SdpParseException + * @return the type of the network + */ + public String getNetworkType() throws SdpParseException { + return getNettype(); + } + + /** Sets the type of the address for this Connection. + * @param addr to set + * @throws SdpException if the type is null + */ + public void setAddress(String addr) throws SdpException { + if (addr == null) + throw new SdpException("the addr is null"); + else { + if (address == null) { + address = new ConnectionAddress(); + Host host = new Host(addr); + address.setAddress(host); + } else { + Host host = address.getAddress(); + if (host == null) { + host = new Host(addr); + address.setAddress(host); + } else + host.setAddress(addr); + } + setAddress(address); + } + } + + /** Returns the type of the network for this Connection. + * @param type to set + * @throws SdpException if the type is null + */ + public void setAddressType(String type) throws SdpException { + if (type == null) + throw new SdpException("the type is null"); + this.addrtype = type; + } + + /** Sets the type of the network for this Connection. + * @param type to set + * @throws SdpException if the type is null + */ + public void setNetworkType(String type) throws SdpException { + if (type == null) + throw new SdpException("the type is null"); + else + setNettype(type); + } + public Object clone() { + ConnectionField retval = (ConnectionField) super.clone(); + if (this.address != null) + retval.address = (ConnectionAddress) this.address.clone(); + return retval; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/Email.java b/java/gov/nist/javax/sdp/fields/Email.java new file mode 100644 index 0000000..5e1255a --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/Email.java @@ -0,0 +1,70 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; + +/** Email address record. +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +*/ +public class Email extends SDPObject { + protected String userName; + protected String hostName; + public String getUserName() { + return userName; + } + public String getHostName() { + return hostName; + } + /** + * Set the userName member + */ + public void setUserName(String u) { + userName = u; + } + /** + * Set the hostName member + */ + public void setHostName(String h) { + hostName = h.trim(); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + return userName + Separators.AT + hostName; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/EmailAddress.java b/java/gov/nist/javax/sdp/fields/EmailAddress.java new file mode 100644 index 0000000..ff363bb --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/EmailAddress.java @@ -0,0 +1,89 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +/** +* email address field of the SDP header. +* +*@version JSR141-PUBLIC-REVIEW (subject to change) +* +*@author Oliver Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class EmailAddress extends SDPObject { + protected String displayName; + protected Email email; + + public String getDisplayName() { + return displayName; + } + /** + * Set the displayName member + */ + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + /** + * Set the email member + */ + public void setEmail(Email email) { + this.email = email; + } + + /** + * Get the string encoded version of this object + * @since v1.0 + * Here, we implement only the "displayName <email>" form + * and not the "email (displayName)" form + */ + public String encode() { + String encoded_string; + + if (displayName != null) { + encoded_string = displayName + Separators.LESS_THAN; + } else { + encoded_string = ""; + } + encoded_string += email.encode(); + if (displayName != null) { + encoded_string += Separators.GREATER_THAN; + } + return encoded_string; + } + public Object clone() { + EmailAddress retval = (EmailAddress) super.clone(); + if (this.email != null) + retval.email = (Email) this.email.clone(); + return retval; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/EmailField.java b/java/gov/nist/javax/sdp/fields/EmailField.java new file mode 100644 index 0000000..4594dcd --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/EmailField.java @@ -0,0 +1,105 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; +/** +* email field in the SDP announce. +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +*/ +public class EmailField extends SDPField implements javax.sdp.EMail { + + protected EmailAddress emailAddress; + + public EmailField() { + super(SDPFieldNames.EMAIL_FIELD); + emailAddress = new EmailAddress(); + } + + public EmailAddress getEmailAddress() { + return emailAddress; + } + /** + * Set the emailAddress member + */ + public void setEmailAddress(EmailAddress emailAddress) { + this.emailAddress = emailAddress; + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + return EMAIL_FIELD + emailAddress.encode() + Separators.NEWLINE; + } + + public String toString() { + return this.encode(); + } + + /** Returns the value. + * @throws SdpParseException + * @return the value + */ + public String getValue() throws SdpParseException { + if (emailAddress == null) + return null; + else { + return emailAddress.getDisplayName(); + } + } + + /** Set the value. + * @param value to set + * @throws SdpException if the value is null + */ + public void setValue(String value) throws SdpException { + if (value == null) + throw new SdpException("The value is null"); + else { + + emailAddress.setDisplayName(value); + } + } + + public Object clone() { + EmailField retval = (EmailField) super.clone(); + if (this.emailAddress != null) + retval.emailAddress = (EmailAddress) this.emailAddress.clone(); + return retval; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/Indentation.java b/java/gov/nist/javax/sdp/fields/Indentation.java new file mode 100644 index 0000000..adc7b43 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/Indentation.java @@ -0,0 +1,60 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; + +/** +* Internal utility class for pretty printing and header formatting. +*/ +class Indentation { + private int indentation; + protected Indentation() { + indentation = 0; + } + protected Indentation(int initval) { + indentation = initval; + } + protected void setIndentation(int initval) { + indentation = initval; + } + protected int getCount() { + return indentation; + } + protected void increment() { + indentation++; + } + protected void decrement() { + indentation--; + } + protected String getIndentation() { + char [] chars = new char [indentation]; + java.util.Arrays.fill (chars, ' '); + return new String (chars); + } +} + diff --git a/java/gov/nist/javax/sdp/fields/InformationField.java b/java/gov/nist/javax/sdp/fields/InformationField.java new file mode 100644 index 0000000..6846cc0 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/InformationField.java @@ -0,0 +1,84 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; + +/** Information field implementation +*@version JSR141-PUBLIC-REVIEW (subject to change) +* +*@author Oliver Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +*/ + +public class InformationField extends SDPField implements javax.sdp.Info { + protected String information; + + public InformationField() { + super(INFORMATION_FIELD); + } + + public String getInformation() { + return information; + } + + public void setInformation(String info) { + information = info; + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + return INFORMATION_FIELD + information + Separators.NEWLINE; + } + + /** Returns the value. + * @throws SdpParseException + * @return the value + */ + public String getValue() throws SdpParseException { + return information; + } + + /** Set the value. + * @param value to set + * @throws SdpException if the value is null + */ + public void setValue(String value) throws SdpException { + if (value == null) + throw new SdpException("The value is null"); + else { + setInformation(value); + } + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/KeyField.java b/java/gov/nist/javax/sdp/fields/KeyField.java new file mode 100644 index 0000000..867aa0a --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/KeyField.java @@ -0,0 +1,131 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; + +import gov.nist.core.*; +import javax.sdp.*; + +/** +* Key field part of an SDP header. +* Acknowledgement. Bug fix contributed by espen@java.net +* +*@version JSR141-PUBLIC-REVIEW (subject to change) +* +*@author Oliver Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +*/ +public class KeyField extends SDPField implements javax.sdp.Key { + protected String type; + protected String keyData; + + public KeyField() { + super(KEY_FIELD); + } + + public String getType() { + return type; + } + + public String getKeyData() { + return keyData; + } + + /** + * Set the type member + */ + public void setType(String t) { + type = t; + } + /** + * Set the keyData member + */ + public void setKeyData(String k) { + keyData = k; + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String encoded_string; + encoded_string = KEY_FIELD + type; + if (keyData != null) { + encoded_string += Separators.COLON; + encoded_string += keyData; + } + encoded_string += Separators.NEWLINE; + return encoded_string; + } + + /** Returns the name of this attribute + * @throws SdpParseException + * @return the name of this attribute + */ + public String getMethod() throws SdpParseException { + return this.type; + } + + /** Sets the id of this attribute. + * @param name to set + * @throws SdpException if the name is null + */ + public void setMethod(String name) throws SdpException { + this.type = name; + } + + /** Determines if this attribute has an associated value. + * @throws SdpParseException + * @return if this attribute has an associated value. + */ + public boolean hasKey() throws SdpParseException { + String key = getKeyData(); + return key != null; + } + + /** Returns the value of this attribute. + * @throws SdpParseException + * @return the value of this attribute + */ + public String getKey() throws SdpParseException { + return getKeyData(); + } + + /** Sets the value of this attribute. + * @param key to set + * @throws SdpException if key is null + */ + public void setKey(String key) throws SdpException { + if (key == null) + throw new SdpException("The key is null"); + else + setKeyData(key); + } +} + diff --git a/java/gov/nist/javax/sdp/fields/MediaField.java b/java/gov/nist/javax/sdp/fields/MediaField.java new file mode 100644 index 0000000..a3b3a94 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/MediaField.java @@ -0,0 +1,245 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; +import java.util.*; +/** +* Media field SDP header. +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class MediaField extends SDPField implements Media { + protected String media; + protected int port; + protected int nports; + protected String proto; + protected Vector formats; + + public MediaField() { + super(SDPFieldNames.MEDIA_FIELD); + formats = new Vector(); + } + + public String getMedia() { + return media; + } + public int getPort() { + return port; + } + public int getNports() { + return nports; + } + public String getProto() { + return proto; + } + public Vector getFormats() { + return formats; + } + /** + * Set the media member + */ + public void setMedia(String m) { + media = m; + } + /** + * Set the port member + */ + public void setPort(int p) { + port = p; + } + /** + * Set the nports member + */ + public void setNports(int n) { + nports = n; + } + /** + * Set the proto member + */ + public void setProto(String p) { + proto = p; + } + /** + * Set the fmt member + */ + public void setFormats(Vector formats) { + this.formats = formats; + } + /** Returns the type (audio,video etc) of the + * media defined by this description. + * @throws SdpParseException + * @return the string media type. + */ + public String getMediaType() throws SdpParseException { + return getMedia(); + } + + /** Sets the type (audio,video etc) of the media defined by this description. + * @param mediaType to set + * @throws SdpException if mediaType is null + */ + public void setMediaType(String mediaType) throws SdpException { + if (mediaType == null) + throw new SdpException("The mediaType is null"); + else + setMedia(mediaType); + } + + /** Returns the port of the media defined by this description + * @throws SdpParseException + * @return the integer media port. + */ + public int getMediaPort() throws SdpParseException { + return getPort(); + } + + /** Sets the port of the media defined by this description + * @param port to set + * @throws SdpException + */ + public void setMediaPort(int port) throws SdpException { + if (port < 0) + throw new SdpException("The port is < 0"); + else + setPort(port); + } + + /** Returns the number of ports associated with this media description + * @throws SdpParseException + * @return the integer port count. + */ + public int getPortCount() throws SdpParseException { + return getNports(); + } + + /** Sets the number of ports associated with this media description. + * @param portCount portCount - the integer port count. + * @throws SdpException + */ + public void setPortCount(int portCount) throws SdpException { + if (portCount < 0) + throw new SdpException("The port count is < 0"); + else + setNports(portCount); + } + + /** Returns the protocol over which this media should be transmitted. + * @throws SdpParseException + * @return the String protocol, e.g. RTP/AVP. + */ + public String getProtocol() throws SdpParseException { + return getProto(); + } + + /** Sets the protocol over which this media should be transmitted. + * @param protocol - the String protocol, e.g. RTP/AVP. + * @throws SdpException if the protocol is null + */ + public void setProtocol(String protocol) throws SdpException { + if (protocol == null) + throw new SdpException("The protocol is null"); + else + setProto(protocol); + } + + /** Returns an Vector of the media formats supported by this description. + * Each element in this Vector will be an String value which matches one of + * the a=rtpmap: attribute fields of the media description. + * @param create to set + * @throws SdpException + * @return the Vector. + */ + public Vector getMediaFormats(boolean create) throws SdpParseException { + + if (!create && formats.size() == 0) + return null; + else + return formats; + } + + /** Adds a media format to the media description. + * Each element in this Vector should be an String value which matches one of the + * a=rtpmap: attribute fields of the media description. + * @param mediaFormats the format to add. + * @throws SdpException if the vector is null + */ + public void setMediaFormats(Vector mediaFormats) throws SdpException { + if (mediaFormats == null) + throw new SdpException("The mediaFormats is null"); + this.formats = mediaFormats; + } + + private String encodeFormats() { + StringBuffer retval = new StringBuffer(3 * formats.size ()); + for (int i = 0; i < formats.size(); i++) { + retval.append(formats.elementAt(i)); + if (i < formats.size() - 1) + retval.append(Separators.SP); + } + return retval.toString(); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String encoded_string; + encoded_string = MEDIA_FIELD; + if (media != null) + encoded_string += media.toLowerCase() + Separators.SP + port; + // Workaround for Microsoft Messenger contributed by Emil Ivov + // Leave out the nports parameter as this confuses the messenger. + if (nports > 1) + encoded_string += Separators.SLASH + nports; + + if (proto != null) + encoded_string += Separators.SP + proto; + + if (formats != null) + encoded_string += Separators.SP + encodeFormats(); + + encoded_string += Separators.NEWLINE; + return encoded_string; + } + + public Object clone() { + MediaField retval = (MediaField) super.clone(); + if (this.formats != null) + retval.formats = (Vector) this.formats.clone(); + return retval; + } +} + diff --git a/java/gov/nist/javax/sdp/fields/OriginField.java b/java/gov/nist/javax/sdp/fields/OriginField.java new file mode 100644 index 0000000..46329df --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/OriginField.java @@ -0,0 +1,314 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.Host; +import gov.nist.core.Separators; + +import javax.sdp.SdpException; +import javax.sdp.SdpParseException; +/** +* Origin Field SDP header +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class OriginField extends SDPField implements javax.sdp.Origin { + protected String username; + //protected long sessId; + //protected long sessVersion; + protected String nettype; // IN + protected String addrtype; // IPV4/6 + protected Host address; + private String sessIdString; + private String sessVersionString; + + public OriginField() { + super(ORIGIN_FIELD); + } + + /** Returns the name of the session originator. + * @throws SdpParseException + * @return the string username. + */ + public String getUsername() throws SdpParseException { + return username; + } + /** + * Get the sessionID member. + */ + public long getSessId() { + + return Long.valueOf(this.sessIdString).longValue(); + } + + public String getSessIdAsString() { + return this.sessIdString; + } + /** + * Get the sessionVersion member. + */ + public long getSessVersion() { + + return Long.valueOf(sessVersionString).longValue(); + } + + public String getSessVersionAsString() { + return this.sessVersionString; + } + /** + * Get the netType member. + */ + public String getNettype() { + return nettype; + } + /** + * Get the address type member. + */ + public String getAddrtype() { + return addrtype; + } + /** + * Get the host member. + */ + public Host getHost() { + return address; + } + /** + * Set the sessId member + */ + public void setSessId(long s) { + this.sessIdString = Long.toString(s); + } + + /** + * This is a work around for some implementations that do not set a long + * session id. + */ + public void setSessionId(String sessId) { + this.sessIdString = sessId; + } + /** + * Set the sessVersion member + */ + public void setSessVersion(long s) { + sessVersionString = Long.toString(s); + } + + /** + * Set the session version as a string. + */ + public void setSessVersion(String s) { + this.sessVersionString = s; + } + /** + * Set the nettype member + */ + public void setNettype(String n) { + nettype = n; + } + /** + * Set the addrtype member + */ + public void setAddrtype(String a) { + addrtype = a; + } + /** + * Set the address member + */ + public void setAddress(Host a) { + address = a; + } + + /** Sets the name of the session originator. + * @param user the string username. + * @throws SdpException if the parameter is null + */ + public void setUsername(String user) throws SdpException { + if (user == null) + throw new SdpException("The user parameter is null"); + else { + this.username = user; + } + } + + /** Returns the unique identity of the session. + * @throws SdpParseException + * @return the session id. + */ + public long getSessionId() throws SdpParseException { + return getSessId(); + } + + /** Sets the unique identity of the session. + * @param id the session id. + * @throws SdpException if the id is <0 + */ + public void setSessionId(long id) throws SdpException { + if (id < 0) + throw new SdpException("The is parameter is <0"); + else + setSessId(id); + } + + /** Returns the unique version of the session. + * @throws SdpException + * @return the session version. + */ + public long getSessionVersion() throws SdpParseException { + return getSessVersion(); + } + + /** Sets the unique version of the session. + * @param version the session version. + * @throws SdpException if the version is <0 + */ + public void setSessionVersion(long version) throws SdpException { + if (version < 0) + throw new SdpException("The version parameter is <0"); + else + setSessVersion(version); + } + + /** Returns the type of the network for this Connection. + * @throws SdpParseException + * @return the string network type. + */ + public String getAddress() throws SdpParseException { + Host addr = getHost(); + if (addr == null) + return null; + else + return addr.getAddress(); + } + + /** Returns the type of the address for this Connection. + * @throws SdpParseException + * @return the string address type. + */ + public String getAddressType() throws SdpParseException { + return getAddrtype(); + } + + /** Returns the type of the network for this Connection + * @throws SdpParseException + * @return the string network type. + */ + public String getNetworkType() throws SdpParseException { + return getNettype(); + } + + /** Sets the type of the address for this Connection. + * @param addr string address type. + * @throws SdpException if the addr is null + */ + public void setAddress(String addr) throws SdpException { + if (addr == null) + throw new SdpException("The addr parameter is null"); + else { + Host host = getHost(); + if (host == null) + host = new Host(); + host.setAddress(addr); + setAddress(host); + } + } + + /** Returns the type of the network for this Connection. + * @param type the string network type. + * @throws SdpException if the type is null + */ + public void setAddressType(String type) throws SdpException { + if (type == null) + throw new SdpException("The type parameter is <0"); + else + setAddrtype(type); + } + + /** Sets the type of the network for this Connection. + * @param type the string network type. + * @throws SdpException if the type is null + */ + public void setNetworkType(String type) throws SdpException { + if (type == null) + throw new SdpException("The type parameter is <0"); + else + setNettype(type); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + String addressStr = null; + + if (address != null){ + addressStr = address.encode(); + + //it appears that SDP does not allow square brackets + //in the connection address (see RFC4566) so make sure + //we lose them + if(Host.isIPv6Reference(addressStr)) + { + //the isIPv6Reference == true means we have a minimum + //of 2 symbols, so substring bravely + addressStr = addressStr + .substring(1, addressStr.length()-1); + } + } + + return ORIGIN_FIELD + + username + + Separators.SP + + sessIdString + + Separators.SP + + sessVersionString + + Separators.SP + + nettype + + Separators.SP + + addrtype + + Separators.SP + + addressStr + + Separators.NEWLINE; + } + + public Object clone() { + OriginField retval = (OriginField) super.clone(); + if (this.address != null) + retval.address = (Host) this.address.clone(); + return retval; + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/PhoneField.java b/java/gov/nist/javax/sdp/fields/PhoneField.java new file mode 100644 index 0000000..12641e4 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/PhoneField.java @@ -0,0 +1,113 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; +/** +* Phone Field SDP header +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class PhoneField extends SDPField implements javax.sdp.Phone { + protected String name; + protected String phoneNumber; + + public PhoneField() { + super(PHONE_FIELD); + } + + public String getName() { + return name; + } + public String getPhoneNumber() { + return phoneNumber; + } + /** + * Set the name member + * + *@param name - the name to set. + */ + public void setName(String name) { + this.name = name; + } + /** + * Set the phoneNumber member + *@param phoneNumber - phone number to set. + */ + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + /** Returns the value. + * @throws SdpParseException + * @return the value. + */ + public String getValue() throws SdpParseException { + return getName(); + } + + /** Sets the value. + * @param value the - new information. + * @throws SdpException if the value is null + */ + public void setValue(String value) throws SdpException { + if (value == null) + throw new SdpException("The value parameter is null"); + else + setName(value); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + * Here, we implement only the "name <phoneNumber>" form + * and not the "phoneNumber (name)" form + */ + public String encode() { + String encoded_string; + encoded_string = PHONE_FIELD; + if (name != null) { + encoded_string += name + Separators.LESS_THAN; + } + encoded_string += phoneNumber; + if (name != null) { + encoded_string += Separators.GREATER_THAN; + } + encoded_string += Separators.NEWLINE; + return encoded_string; + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/PreconditionFields.java b/java/gov/nist/javax/sdp/fields/PreconditionFields.java new file mode 100644 index 0000000..3a528a9 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/PreconditionFields.java @@ -0,0 +1,673 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/***************************************************************************** + * PRODUCT OF PT INOVACAO - EST DEPARTMENT and Aveiro University - Portugal) * + *****************************************************************************/ + + +package gov.nist.javax.sdp.fields; + + +import java.util.Vector; +import javax.sdp.SdpException; +import javax.sdp.SdpParseException; +import gov.nist.core.NameValue; + + + + +/** + * Precondition fields (segmented / end-to-end). + * + * <p>For one media description, precondition attributes should + * be only of one type (segmented or end-to-end) </p> + * <p>3GPP TS 24.299, </p> + * IETF RFC3312 + RFC4032 (Precondition Mechanism). + * + * @author Miguel Freitas (IT) PT-Inovacao + */ + + +public class PreconditionFields +{ + + // Media Description attributes for precondition + protected Vector preconditionAttributes; + + + /** + * Constructor + * + */ + public PreconditionFields() + { + preconditionAttributes = new Vector(); + } + + + /** + * Get the number of Precondition attributes + * + * @return int size of segmented precondition vector of attribute fields + */ + public int getPreconditionSize() + { + if (preconditionAttributes != null) + return preconditionAttributes.size(); + + else // TODO treat this exception well + return -1; + } + + /** + * Get Precondition + * + * @return Vector of attribute fields (segmented precondition) + */ + public Vector getPreconditions() + { + return preconditionAttributes; + } + + + /** + * Set Preconditions + * + * @param preconditions - vector with precondition attributes + * @throws SdpException -- if precondition attributes is null + */ + public void setPreconditions(Vector preconditions) throws SdpException + { + if (preconditions == null) + throw new SdpException("Precondition attributes are null"); + else + preconditionAttributes = preconditions; + } + + + + /** + * <p>Set attribute line for current precondition state, given + * a string value encoded like the "curr" attribute value</p> + * + * @param precondCurrValue - a string with the value for a "curr" attribute + * @throws SdpException + */ + public void setPreconditionCurr(String precondCurrValue) throws SdpException + { + if (precondCurrValue == null) + throw new SdpException("The Precondition \"curr\" attribute value is null"); + else if (preconditionAttributes == null) + throw new SdpException("The Precondition Attributes is null"); + else + { + try + { + /* split the "curr" attribute value into words + * attributes[0] = "qos" + * attributes[1] = status-type (e2e/local/remote) + * attributes[2] = direction-tag (none/send/recv/sendrecv) + * + * split() - regular expression: + * \s -> a whitespace character [ \t\n\x0B\f\r] + * \b -> a word boundary + */ + String[] attributes = precondCurrValue.split(" "); + + + // which is this length?! of the string or the []? + /* + if (attributes.length < 3) + { + throw new SdpException + ("The Precondition \"curr\" attribute value mal-formed (<3words)"); + }*/ + + setPreconditionCurr(attributes[1], // status-type + attributes[2] // direction-tag + ); + } + catch (ArrayIndexOutOfBoundsException ex) + { + throw new SdpException + ("Error spliting the \"curr\" attribute into words", ex); + } + } + } + + + + + + /** + * <p>Set the value of the attributes with the name "curr" + * for current precondition.</p> + * <p>- eg: a=curr:qos local none</p> + * + * <p>If there is an attribute "curr" for the same status-type, + * the direction-tag is updated with the one supplied.</p> + * + * @param status - (local, remote, e2e) + * @param directionTag - (none, send, recv, sendrecv) + * @throws SdpParseException + */ + public void setPreconditionCurr(String status, String directionTag) + throws SdpException + { + if (status == null) + throw new SdpException("The status-type is null"); + if (directionTag == null) + throw new SdpException("The direction-tag is null"); + + if (preconditionAttributes == null) + throw new SdpException("Precondition Attributes is null"); + + int i = 0; + // search for attributes "curr" + for (i = 0; i < preconditionAttributes.size(); i++) + { + AttributeField af = + (AttributeField) this.preconditionAttributes.elementAt(i); + + // go to next attribute if this is not "curr" + if (!af.getAttribute().getName().equals("curr")) + continue; + + // if it is "curr" attribute, check the status-type + // if it matches the value supplied, update the direction-tag + // with the value supplied + if (af.getValue().indexOf(status) != -1) + { + if (af.getValue().indexOf(directionTag) == -1) + { + // attribute exists with same status, directionTag updated + af.setValue("qos " + status + " " + directionTag); + preconditionAttributes.setElementAt(af,i); + } + // else, exit and do nothing (attribute already exists) + else + break; + } + } + + // attribute "curr" not found + if (i == preconditionAttributes.size()) + { + // create attribute for the status-type supplied + NameValue nv = new NameValue("curr", "qos " + status + " " + directionTag); + + AttributeField newAF = new AttributeField(); + newAF.setAttribute(nv); + preconditionAttributes.add(newAF); + } + } + + + + + + + + /** + * <p>Set attribute line for desired precondition state, given + * a string value encoded like the "des" attribute value</p> + * + * @param precondDesValue - a string with the value for a "des" attribute + * @throws SdpException + */ + public void setPreconditionDes(String precondDesValue) throws SdpException + { + if (precondDesValue == null) + throw new SdpException("The Precondition \"des\" attribute value is null"); + else if (preconditionAttributes == null) + throw new SdpException("The Precondition Attributes is null"); + else + { + /* split the "des" attribute value into words + * attributes[0] = "qos" + * attributes[1] = strength-tag (unknown/failure/none/optional/mandatory) + * attributes[2] = status-type (e2e/local/remote) + * attributes[3] = direction-tag (none/send/recv/sendrecv) + * + * split() - regular expression: + * \s -> a whitespace character [ \t\n\x0B\f\r] + * \b -> a word boundary + */ + try + { + String[] attributes = precondDesValue.split(" "); + + // which is this length?! of the string or the []? + /* + if (attributes.length < 4) + { + throw new SdpException + ("The Precondition \"des\" attribute value mal-formed (<4words)"); + }*/ + + setPreconditionDes( attributes[1], // strength-tag + attributes[2], // status-type + attributes[3] // direction-tag + ); + } + catch (ArrayIndexOutOfBoundsException ex) + { + throw new SdpException + ("Error spliting the \"des\" attribute into words", ex); + } + } + } + + + + + + + /** + * <p>Set the value of the attributes with the name "des" + * for desired precondition. </p> + * <p>- eg: a=des:qos mandatory remote sendrecv</p> + * + * <p>There can be more than one desired precondition line + * for a status-type, specially if strength-tag is different.</p> + * + * <p>If there is an attribute "des" for the same status-type, + * the strength-tag and direction-tag are updated with the + * ones supplied.<p> + * + * <p>IETF RFC4032: strength should only be downgraded within SDP offers</p> + * + * + * @param strength - (none, optional, + * @param status - (local, remote, e2e) + * @param direction - (none, send, recv, sendrecv) + * @throws SdpParseException + */ + public void setPreconditionDes(String strength, String status, String direction) + throws SdpException + { + if (strength == null) + throw new SdpException("The strength-tag is null"); + if (status == null) + throw new SdpException("The status-type is null"); + if (direction == null) + throw new SdpException("The direction-tag is null"); + + if (preconditionAttributes == null) + throw new SdpException("Precondition Attributes is null"); + + int i = 0; + // search for attributes "des" + for (i = 0; i < preconditionAttributes.size(); i++) + { + AttributeField af = + (AttributeField) this.preconditionAttributes.elementAt(i); + + // go to next attribute if this is not "des" + if (!af.getAttribute().getName().equals("des")) + continue; + + // if it is "des" attribute, check the status-type + // if it match, update the strength-tag and direction-tag + if (af.getValue().indexOf(status) != -1) + { + // attribute exists with same status-type, + // strength-tag and direction-tag updated + af.setValue("qos " + strength + " " + status + " " + direction); + preconditionAttributes.setElementAt(af,i); + + } + } + + // attribute "des" not found + if (i == preconditionAttributes.size()) + { + // create attribute for the status-type supplied + // with the values strength-tag and direction-tag + NameValue nv = + new NameValue("des", "qos " + strength + " " + status + " " + direction); + + AttributeField newAF = new AttributeField(); + newAF.setAttribute(nv); + preconditionAttributes.add(newAF); + } + } + + + + + + + + /** + * <p>Set attribute line for confirmation precondition request, given + * a string value encoded like the "conf" attribute value</p> + * + * @param precondConfValue - a string with the value for a "conf" attribute + * @throws SdpException + */ + public void setPreconditionConfirmStatus(String precondConfValue) + throws SdpException + { + if (precondConfValue == null || precondConfValue.length()==0) + throw new SdpException("The Precondition \"conf\" attribute value is null"); + else if (preconditionAttributes == null) + throw new SdpException("The Precondition Attributes is null"); + else + { + /* split the "conf" attribute value into words + * attributes[0] = "qos" + * attributes[1] = status-type (e2e/local/remote) + * attributes[2] = direction-tag (none/send/recv/sendrecv) + */ + try + { + String[] attributes = precondConfValue.split(" "); + + setPreconditionConfirmStatus( + attributes[1], // status-type + attributes[2] // direction-tag + ); + } + catch (ArrayIndexOutOfBoundsException ex) + { + throw new SdpException + ("Error spliting the \"conf\" attribute into words", ex); + } + } + } + + + + + + /** + * <p>IETF RFC3312</p> + * <p>"The confirmation status attribute carries threshold conditions + * for a media stream. When the status of network resources reach + * these conditions, the peer UA will send an update of the + * session description".</p> + * + * <p>- eg: a=conf:qos remote sendrecv</p> + * + * @param status - (e2e, local, remote) + * @param direction - (none, send, recv, sendrecv) + * @throws SdpException -- if param are null + */ + public void setPreconditionConfirmStatus(String status, String direction) + throws SdpException + { + if (status == null || direction.length()==0) + throw new SdpException("The status-type is null"); + if (direction == null || direction.length()==0) + throw new SdpException("The direction-tag is null"); + + if (preconditionAttributes == null) + throw new SdpException("Precondition Attributes is null"); + + int i = 0; + // search for attributes "conf" + for (i = 0; i < preconditionAttributes.size(); i++) + { + AttributeField af = + (AttributeField) this.preconditionAttributes.elementAt(i); + + + //System.out.println("--> PreconditionField -> (i="+i+") > attribute field: " + af.toString()); + + + // go to next attribute if this is not "conf" + if (!af.getAttribute().getName().equals("conf")) + continue; + + // if it is "conf" attribute, check the status-type + // if it matches, update the direction-tag + // with the value supplied + if (af.getValue().indexOf(status) != -1) + { + if (af.getValue().indexOf(direction) == -1) + { + // attribute exists with same status, directionTag updated + af.setValue("qos " + status + " " + direction); + preconditionAttributes.setElementAt(af,i); + } + // else, exit and do nothing (attribute already exists) + break; + } + } + + // attribute "conf" not found + if (i == preconditionAttributes.size()) + { + // create attribute for the status-type supplied + // with the values strength-tag and direction-tag + NameValue nv = + new NameValue("conf", "qos " + status + " " + direction); + + AttributeField newAF = new AttributeField(); + newAF.setAttribute(nv); + preconditionAttributes.add(newAF); + + + //System.out.println("--> PreconditionField -> new \"conf\" attribute created: " + newAF.toString() ); + } + } + + + + + + + + + + + /** + * <p>Get the attribute fields with the name "curr" + * for current precondition.</p> + * <p>One attribute field per status-type. + * (eg: a=curr:qos local none)</p> + * + * @param status - (local, remote, e2e) + * @return a vector with the attribute field that match status-type + * (with only one element or null if none exists) + * @throws SdpParseException + */ + public Vector getPreconditionCurr(String status) + throws SdpException, SdpParseException + { + if (status == null) + throw new SdpException("The status-type is null"); + + if (preconditionAttributes == null) + return null; + else + { + Vector vCurr = new Vector(); + for (int i=0; i < preconditionAttributes.size(); i++) + { + AttributeField af = + (AttributeField) this.preconditionAttributes.elementAt(i); + + // go to next attribute if this is not "curr" + if (!af.getAttribute().getName().equals("curr")) + continue; + + // if it is "curr" attribute, check the status-type + // and add the attribute value to the vector if it + // matches the status desired + if (af.getValue().indexOf(status) != -1) + vCurr.addElement(af); + } + + // if none "curr" attribute found + if (vCurr.size() == 0) + return null; + else + return vCurr; + } + } + + + + + /** + * <p>Get the attribute fields with the name "des" + * for desired precondition</p> + * + * <p>There can be more than one current precondition line + * for a status-type (with different direction-tag values), + * specially if strength-tag is different</p> + * + * @param status - (local, remote, e2e) + * @return a vector with the attribute fields that match location-tag + * @throws SdpParseException + */ + public Vector getPreconditionDes(String status) + throws SdpException, SdpParseException + { + if (status == null) + throw new SdpException("The status-type is null"); + + if (preconditionAttributes == null) + return null; + else + { + Vector vCurr = new Vector(); + for (int i=0; i < preconditionAttributes.size(); i++) + { + AttributeField af = + (AttributeField) this.preconditionAttributes.elementAt(i); + + // go to next attribute if this is not "des" + if (!af.getAttribute().getName().equals("des")) + continue; + + // if it is "des" attribute, check the status-type + // and add the attribute value to the vector if it + // matches the status desired + if (af.getValue().indexOf(status) != -1) + vCurr.addElement(af); + } + + // if none "des" attribute found + if (vCurr.size() == 0) + return null; + else + return vCurr; + } + } + + + + /** + * <p>Get the attribute fields with the name "conf" + * for confirmation precondition.</p> + * + * <p>IETF RFC3312</p> + * <p>"The confirmation status attribute carries threshold conditions + * for a media stream. When the status of network resources reach + * these conditions, the peer UA will send an update of the + * session description".</p> + * + * <p>(eg: a=conf:qos remote sendrecv)</p> + * + * @return a vector with the "conf" attribute fields + * @throws SdpException + */ + public Vector getPreconditionConfirmStatus() throws SdpException + { + if (preconditionAttributes == null) + return null; // ignore or send SdpException? + else + { + Vector vCurr = new Vector(); + for (int i=0; i < preconditionAttributes.size(); i++) + { + AttributeField af = + (AttributeField) this.preconditionAttributes.elementAt(i); + + // go to next attribute if this is not "conf" + if (!af.getAttribute().getName().equals("conf")) + continue; + else + // add the attribute value to the vector + vCurr.addElement(af); + } + + // if none "conf" attribute found + if (vCurr.size() == 0) + return null; + else + return vCurr; + } + } + + + + /* strength-tag */ + public static final int STRENGTH_UNKNOWN = 0; + public static final int STRENGTH_FAILURE = 1; + public static final int STRENGTH_NONE = 2; + public static final int STRENGTH_OPTIONAL = 3; + public static final int STRENGTH_MANDATORY = 4; + public static final String[] STRENGTH = { "unknown", + "failure", + "none", + "optional", + "mandatory" + }; + /* direction-tag */ + public static final int DIRECTION_NONE = 0; + public static final int DIRECTION_SEND = 1; + public static final int DIRECTION_RECV = 2; + public static final int DIRECTION_SENDRECV = 3; + public static final String[] DIRECTION = { "none", + "send", + "recv", + "sendrecv" + }; + + /* status-tag */ + public static final int STATUS_E2E = 0; + public static final int STATUS_LOCAL = 1; + public static final int STATUS_REMOTE = 2; + public static final String[] STATUS = { "e2e", + "local", + "remote" + }; + + /* precondition type */ + public static final int PRECONDITION_QOS = 0; + public static final String[] PRECONDITION = { "qos" + }; + + + + + + +} diff --git a/java/gov/nist/javax/sdp/fields/ProtoVersionField.java b/java/gov/nist/javax/sdp/fields/ProtoVersionField.java new file mode 100644 index 0000000..615c2a7 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/ProtoVersionField.java @@ -0,0 +1,90 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; + +/** Proto version field of SDP announce. +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +* +*/ +public class ProtoVersionField extends SDPField implements javax.sdp.Version { + protected int protoVersion; + + public ProtoVersionField() { + super(PROTO_VERSION_FIELD); + } + + public int getProtoVersion() { + return protoVersion; + } + + /** + * Set the protoVersion member + */ + public void setProtoVersion(int pv) { + protoVersion = pv; + } + + /** Returns the version number. + * @throws SdpParseException + * @return int + */ + public int getVersion() throws SdpParseException { + return getProtoVersion(); + } + + /** Sets the version. + * @param value the - new version value. + * @throws SdpException if the value is <=0 + */ + public void setVersion(int value) throws SdpException { + if (value < 0) + throw new SdpException("The value is <0"); + else + setProtoVersion(value); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + return PROTO_VERSION_FIELD + protoVersion + Separators.NEWLINE; + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/RepeatField.java b/java/gov/nist/javax/sdp/fields/RepeatField.java new file mode 100644 index 0000000..8c5f1a4 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/RepeatField.java @@ -0,0 +1,217 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import java.util.LinkedList; +import java.util.ListIterator; +import javax.sdp.*; +/** +* Repeat SDP Field (part of the time field). +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ +public class RepeatField extends SDPField implements javax.sdp.RepeatTime { + + private static final long serialVersionUID = -6415338212212641819L; + protected TypedTime repeatInterval; + protected TypedTime activeDuration; + protected SDPObjectList offsets; + + public RepeatField() { + super(REPEAT_FIELD); + offsets = new SDPObjectList(); + } + + public void setRepeatInterval(TypedTime interval) { + repeatInterval = interval; + } + + public void setActiveDuration(TypedTime duration) { + activeDuration = duration; + } + + public void addOffset(TypedTime offset) { + offsets.add(offset); + } + + public LinkedList getOffsets() { + return offsets; + } + + /** Returns the "repeat interval" in seconds. + * @throws SdpParseException + * @return the "repeat interval" in seconds. + */ + public int getRepeatInterval() throws SdpParseException { + if (repeatInterval == null) + return -1; + else { + return repeatInterval.getTime(); + } + } + + /** Set the "repeat interval" in seconds. + * @param repeatInterval the "repeat interval" in seconds. + * @throws SdpException if repeatInterval is <0 + */ + public void setRepeatInterval(int repeatInterval) throws SdpException { + if (repeatInterval < 0) + throw new SdpException("The repeat interval is <0"); + else { + if (this.repeatInterval == null) + this.repeatInterval = new TypedTime(); + this.repeatInterval.setTime(repeatInterval); + } + } + + /** Returns the "active duration" in seconds. + * @throws SdpParseException + * @return the "active duration" in seconds. + */ + public int getActiveDuration() throws SdpParseException { + if (activeDuration == null) + return -1; + else { + return activeDuration.getTime(); + } + } + + /** Sets the "active duration" in seconds. + * @param activeDuration the "active duration" in seconds. + * @throws SdpException if the active duration is <0 + */ + public void setActiveDuration(int activeDuration) throws SdpException { + if (activeDuration < 0) + throw new SdpException("The active Duration is <0"); + else { + if (this.activeDuration == null) + this.activeDuration = new TypedTime(); + this.activeDuration.setTime(activeDuration); + } + } + + /** Returns the list of offsets. These are relative to the start-time given + * in the Time object (t= + * field) with which this RepeatTime is associated. + * @throws SdpParseException + * @return the list of offsets + */ + public int[] getOffsetArray() throws SdpParseException { + LinkedList linkedList = getOffsets(); + int[] result = new int[linkedList.size()]; + for (int i = 0; i < linkedList.size(); i++) { + TypedTime typedTime = (TypedTime) linkedList.get(i); + result[i] = typedTime.getTime(); + } + return result; + } + + /** Set the list of offsets. These are relative to the start-time given in the + * Time object (t= + * field) with which this RepeatTime is associated. + * @param offsets array of repeat time offsets + * @throws SdpException + */ + public void setOffsetArray(int[] offsets) throws SdpException { + for (int i = 0; i < offsets.length; i++) { + TypedTime typedTime = new TypedTime(); + typedTime.setTime(offsets[i]); + addOffset(typedTime); + } + + } + + /** Returns whether the field will be output as a typed time or a integer value. + * + * Typed time is formatted as an integer followed by a unit character. The unit indicates an + * appropriate multiplier for the integer. + * + * The following unit types are allowed. + * d - days (86400 seconds) + * h - hours (3600 seconds) + * m - minutes (60 seconds) + * s - seconds ( 1 seconds) + * @throws SdpParseException + * @return true, if the field will be output as a typed time; false, if as an integer value. + */ + public boolean getTypedTime() throws SdpParseException { + return true; + } + + /** Sets whether the field will be output as a typed time or a integer value. + * + * Typed time is formatted as an integer followed by a unit character. The unit indicates an + * appropriate multiplier for the integer. + * + * The following unit types are allowed. + * d - days (86400 seconds) + * h - hours (3600 seconds) + * m - minutes (60 seconds) + * s - seconds ( 1 seconds) + * @param typedTime typedTime - if set true, the start and stop times will be output in an optimal typed + * time format; if false, the times will be output as integers. + */ + public void setTypedTime(boolean typedTime) { + + } + + public String encode() { + StringBuffer retval = new StringBuffer(); + retval.append(REPEAT_FIELD) + .append(repeatInterval.encode()) + .append(Separators.SP) + .append(activeDuration.encode()); + ListIterator li = offsets.listIterator(); + while (li.hasNext()) { + TypedTime off = (TypedTime) li.next(); + retval.append (Separators.SP).append (off.encode()); + } + retval.append (Separators.NEWLINE); + return retval.toString (); + } + + public Object clone() { + RepeatField retval = (RepeatField) super.clone(); + if (this.repeatInterval != null) + retval.repeatInterval = (TypedTime) this.repeatInterval.clone(); + if (this.activeDuration != null) + retval.activeDuration = (TypedTime) this.activeDuration.clone(); + if (this.offsets != null) + retval.offsets = (SDPObjectList) this.offsets.clone(); + return retval; + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/SDPField.java b/java/gov/nist/javax/sdp/fields/SDPField.java new file mode 100644 index 0000000..ac3cb59 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPField.java @@ -0,0 +1,72 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; + +/** +* Placeholder root class for SDP headers. +* +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +* +*/ + +public abstract class SDPField extends SDPObject { + protected String fieldName; + + public abstract String encode(); + + protected SDPField(String hname) { + fieldName = hname; + } + + public String getFieldName() { + return fieldName; + } + + /** Returns the type character for the field. + * @return the type character for the field. + */ + public char getTypeChar() { + if (fieldName == null) + return '\0'; + else + return fieldName.charAt(0); + } + + public SDPField() { + } + + public String toString() { + return this.encode(); + } + +} diff --git a/java/gov/nist/javax/sdp/fields/SDPFieldList.java b/java/gov/nist/javax/sdp/fields/SDPFieldList.java new file mode 100644 index 0000000..c25e405 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPFieldList.java @@ -0,0 +1,163 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import java.util.ListIterator; + +/** +* A list of SDP Fields. +* +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +* +*/ + +public abstract class SDPFieldList extends SDPField { + protected SDPObjectList sdpFields; + + public SDPFieldList() { + } + + /** Return a list iterator for the embedded field list. + */ + public ListIterator listIterator() { + return sdpFields.listIterator(); + } + + public SDPFieldList(String fieldName) { + super(fieldName); + sdpFields = new SDPObjectList(fieldName); + } + + public SDPFieldList(String fieldName, String classname) { + super(fieldName); + sdpFields = new SDPObjectList(fieldName, classname); + } + + /** + *add a SDP Field to the list of headers that we maintain. + *@param h is the sdp field to add to our list. + */ + public void add(SDPField h) { + sdpFields.add(h); + } + + public SDPObject first() { + return (SDPObject) sdpFields.first(); + } + + public SDPObject next() { + return (SDPObject) sdpFields.next(); + } + + /** + * Encode into a canonical string. + */ + public String encode() { + StringBuffer retval = new StringBuffer(); + ListIterator li = sdpFields.listIterator(); + while (li.hasNext()) { + SDPField sdphdr = (SDPField) li.next(); + retval.append(sdphdr.encode()); + } + return retval.toString(); + } + /** + * convert to a string representation (for printing). + * @param indentation int to set + * @return String string representation of object (for printing). + */ + public String debugDump(int indentation) { + stringRepresentation = ""; + String indent = new Indentation(indentation).getIndentation(); + ; + String className = this.getClass().getName(); + sprint(indent + className); + sprint(indent + "{"); + sprint(indent + sdpFields.debugDump(indentation)); + sprint(indent + "}"); + return stringRepresentation; + } + + /** convert to a string representation + * @return String + */ + public String debugDump() { + return debugDump(0); + } + + /** Return a string representation. + * + *@return String representation. + */ + public String toString() { + return encode(); + } + + /** + * Equality checking predicate. + *@param other is the other object to compare ourselves against. + */ + public boolean equals(Object other) { + if (other == null ) return false; + if (!this.getClass().equals(other.getClass())) + return false; + SDPFieldList that = (SDPFieldList) other; + if (sdpFields == null) + return that.sdpFields == null; + return this.sdpFields.equals(that.sdpFields); + } + + /** + * Do a template match of fields. + *@param template is the template to match against. + */ + public boolean match(Object template) { + if (template == null) + return true; + if (!template.getClass().equals(this.getClass())) + return false; + SDPFieldList other = (SDPFieldList) template; + if (sdpFields == other.sdpFields) + return true; + else if (sdpFields == null) + return false; + return sdpFields.match(other.sdpFields); + } + + public Object clone() { + SDPFieldList retval = (SDPFieldList) super.clone(); + if (this.sdpFields != null) + retval.sdpFields = (SDPObjectList) this.sdpFields.clone(); + return retval; + } +} + diff --git a/java/gov/nist/javax/sdp/fields/SDPFieldNames.java b/java/gov/nist/javax/sdp/fields/SDPFieldNames.java new file mode 100644 index 0000000..a73379c --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPFieldNames.java @@ -0,0 +1,59 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/***************************************************************************** +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +******************************************************************************/ +package gov.nist.javax.sdp.fields; + +/** +*Field names for SDP Fields. +* +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +* +*/ + +public interface SDPFieldNames { + + public static final String SESSION_NAME_FIELD = "s="; + public static final String INFORMATION_FIELD = "i="; + public static final String EMAIL_FIELD = "e="; + public static final String PHONE_FIELD = "p="; + public static final String CONNECTION_FIELD = "c="; + public static final String BANDWIDTH_FIELD = "b="; + public static final String ORIGIN_FIELD = "o="; + public static final String TIME_FIELD = "t="; + public static final String KEY_FIELD = "k="; + public static final String ATTRIBUTE_FIELD = "a="; + public static final String PROTO_VERSION_FIELD = "v="; + public static final String URI_FIELD = "u="; + public static final String MEDIA_FIELD = "m="; + public static final String REPEAT_FIELD = "r="; + public static final String ZONE_FIELD = "z="; +} diff --git a/java/gov/nist/javax/sdp/fields/SDPFormat.java b/java/gov/nist/javax/sdp/fields/SDPFormat.java new file mode 100644 index 0000000..adba422 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPFormat.java @@ -0,0 +1,64 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; + +/** +* Media Description SDP header +* +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +* +*/ +public class SDPFormat extends SDPObject { + protected String format; + + public void setFormat(String fmt) { + format = fmt; + } + + public String getFormat() { + return format; + } + + public SDPFormat(String s) { + format = s; + } + + public SDPFormat() { + } + + public String encode() { + return format; + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/SDPKeywords.java b/java/gov/nist/javax/sdp/fields/SDPKeywords.java new file mode 100644 index 0000000..c2422f2 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPKeywords.java @@ -0,0 +1,42 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; + +/** +* A context sensitive list of keyowrds for SDP Headers. +*/ +public interface SDPKeywords { + public static final String BASE64="base64"; + public static final String PROMPT="prompt"; + public static final String CLEAR = "clear"; + public static final String URI="URI"; + public static final String IPV4="IP4"; + public static final String IPV6="IP6"; + public static final String IN="IN"; +} diff --git a/java/gov/nist/javax/sdp/fields/SDPObject.java b/java/gov/nist/javax/sdp/fields/SDPObject.java new file mode 100644 index 0000000..b4bed6f --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPObject.java @@ -0,0 +1,354 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import java.lang.reflect.*; + +/** +* Root class for everything in this package. +*/ +public abstract class SDPObject + extends GenericObject + implements SDPFieldNames { + + protected static final String SDPFIELDS_PACKAGE = + PackageNames.SDP_PACKAGE + ".fields"; + protected static final String CORE_PACKAGE = PackageNames.CORE_PACKAGE; + + // should make this a property during the compile. + + public abstract String encode(); + + protected void sprint(String s) { + super.sprint(s); + } + + protected void initSprint() { + super.stringRepresentation = ""; + } + + public String toString() { + return encode(); + } + + protected String getStringRepresentation() { + return super.stringRepresentation; + } + + /** + * An introspection based equality predicate for SDPObjects. + *@param that is the other object to test against. + *@return true if the objects are equal. + */ + public boolean equals(Object that) { + if (!this.getClass().equals(that.getClass())) + return false; + Class myclass = this.getClass(); + Field[] fields = myclass.getDeclaredFields(); + Class hisclass = that.getClass(); + Field[] hisfields = hisclass.getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + Field f = fields[i]; + Field g = hisfields[i]; + // Only print protected and public members. + int modifier = f.getModifiers(); + if (modifier == Modifier.PRIVATE) + continue; + Class fieldType = f.getType(); + String fieldName = f.getName(); + if (fieldName.compareTo("stringRepresentation") == 0) { + continue; + } + if (fieldName.compareTo("indentation") == 0) { + continue; + } + try { + // Primitive fields are printed with type: value + if (fieldType.isPrimitive()) { + String fname = fieldType.toString(); + if (fname.compareTo("int") == 0) { + if (f.getInt(this) != g.getInt(that)) + return false; + } else if (fname.compareTo("short") == 0) { + if (f.getShort(this) != g.getShort(that)) + return false; + } else if (fname.compareTo("char") == 0) { + if (f.getChar(this) != g.getChar(that)) + return false; + } else if (fname.compareTo("long") == 0) { + if (f.getLong(this) != g.getLong(that)) + return false; + } else if (fname.compareTo("boolean") == 0) { + if (f.getBoolean(this) != g.getBoolean(that)) + return false; + } else if (fname.compareTo("double") == 0) { + if (f.getDouble(this) != g.getDouble(that)) + return false; + } else if (fname.compareTo("float") == 0) { + if (f.getFloat(this) != g.getFloat(that)) + return false; + } + } else if (g.get(that) == f.get(this)) + continue; + else if (f.get(this) == null && g.get(that) != null) + return false; + else if (g.get(that) == null && f.get(that) != null) + return false; + else if (!f.get(this).equals(g.get(that))) + return false; + } catch (IllegalAccessException ex1) { + InternalErrorHandler.handleException(ex1); + } + } + return true; + } + + /** + * Generic introspection based printing funciton for this package. + * Because we use introspection, this must reside in this package + * and we cannot use the superclass defintion (even though it + * is virtually identical. + */ + public String debugDump() { + stringRepresentation = ""; + Class myclass = getClass(); + sprint(myclass.getName()); + sprint("{"); + Field[] fields = myclass.getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + Field f = fields[i]; + // Only print protected and public members. + int modifier = f.getModifiers(); + if (modifier == Modifier.PRIVATE) + continue; + Class fieldType = f.getType(); + String fieldName = f.getName(); + if (fieldName.compareTo("stringRepresentation") == 0) { + // avoid nasty recursions... + continue; + } + if (fieldName.compareTo("indentation") == 0) { + // formatting stuff - not relevant here. + continue; + } + sprint(fieldName + ":"); + try { + // Primitive fields are printed with type: value + if (fieldType.isPrimitive()) { + String fname = fieldType.toString(); + sprint(fname + ":"); + if (fname.compareTo("int") == 0) { + int intfield = f.getInt(this); + sprint(intfield); + } else if (fname.compareTo("short") == 0) { + short shortField = f.getShort(this); + sprint(shortField); + } else if (fname.compareTo("char") == 0) { + char charField = f.getChar(this); + sprint(charField); + } else if (fname.compareTo("long") == 0) { + long longField = f.getLong(this); + sprint(longField); + } else if (fname.compareTo("boolean") == 0) { + boolean booleanField = f.getBoolean(this); + sprint(booleanField); + } else if (fname.compareTo("double") == 0) { + double doubleField = f.getDouble(this); + sprint(doubleField); + } else if (fname.compareTo("float") == 0) { + float floatField = f.getFloat(this); + sprint(floatField); + } + } else if ( + Class.forName( + CORE_PACKAGE + ".GenericObject").isAssignableFrom( + fieldType)) { + if (f.get(this) != null) { + sprint( + ((GenericObject) f.get(this)).debugDump( + indentation + 1)); + } else { + sprint("<null>"); + } + + } else if ( + Class.forName( + CORE_PACKAGE + ".GenericObjectList").isAssignableFrom( + fieldType)) { + if (f.get(this) != null) { + sprint( + ((GenericObjectList) f.get(this)).debugDump( + indentation + 1)); + } else { + sprint("<null>"); + } + + } else { + // Dont do recursion on things that are not + // of our header type... + if (f.get(this) != null) { + sprint(f.get(this).getClass().getName() + ":"); + } else { + sprint(fieldType.getName() + ":"); + } + + sprint("{"); + if (f.get(this) != null) { + sprint(f.get(this).toString()); + } else { + sprint("<null>"); + } + sprint("}"); + } + } catch (IllegalAccessException ex1) { + continue; // we are accessing a private field... + } catch (ClassNotFoundException ex) { + System.out.println("Cound not find " + ex.getMessage()); + ex.printStackTrace(); + System.exit(0); + } + } + sprint("}"); + return stringRepresentation; + } + + /** An introspection based predicate matching using a template + * object. Allows for partial match of two protocl Objects. + *@param other the match pattern to test against. The match object + * has to be of the same type (class). Primitive types + * and non-sip fields that are non null are matched for equality. + * Null in any field matches anything. Some book-keeping fields + * are ignored when making the comparison. + */ + + public boolean match(Object other) { + if (other == null) + return true; + if (!this.getClass().equals(other.getClass())) + return false; + GenericObject that = (GenericObject) other; + Class myclass = this.getClass(); + Field[] fields = myclass.getDeclaredFields(); + Class hisclass = other.getClass(); + Field[] hisfields = hisclass.getDeclaredFields(); + for (int i = 0; i < fields.length; i++) { + Field f = fields[i]; + Field g = hisfields[i]; + // Only print protected and public members. + int modifier = f.getModifiers(); + if (modifier == Modifier.PRIVATE) + continue; + Class fieldType = f.getType(); + String fieldName = f.getName(); + if (fieldName.compareTo("stringRepresentation") == 0) { + continue; + } + if (fieldName.compareTo("indentation") == 0) { + continue; + } + try { + // Primitive fields are printed with type: value + if (fieldType.isPrimitive()) { + String fname = fieldType.toString(); + if (fname.compareTo("int") == 0) { + if (f.getInt(this) != g.getInt(that)) + return false; + } else if (fname.compareTo("short") == 0) { + if (f.getShort(this) != g.getShort(that)) + return false; + } else if (fname.compareTo("char") == 0) { + if (f.getChar(this) != g.getChar(that)) + return false; + } else if (fname.compareTo("long") == 0) { + if (f.getLong(this) != g.getLong(that)) + return false; + } else if (fname.compareTo("boolean") == 0) { + if (f.getBoolean(this) != g.getBoolean(that)) + return false; + } else if (fname.compareTo("double") == 0) { + if (f.getDouble(this) != g.getDouble(that)) + return false; + } else if (fname.compareTo("float") == 0) { + if (f.getFloat(this) != g.getFloat(that)) + return false; + } + } else { + Object myObj = f.get(this); + Object hisObj = g.get(that); + if (hisObj == myObj) + return true; + else if (hisObj != null && myObj == null) + return false; + else if ( + hisObj instanceof java.lang.String + && myObj instanceof java.lang.String) { + if (((String) myObj) + .compareToIgnoreCase((String) hisObj) + != 0) + return false; + } else if ( + hisObj != null + && GenericObject.isMySubclass(myObj.getClass()) + && GenericObject.isMySubclass(hisObj.getClass()) + && myObj.getClass().equals(hisObj.getClass()) + && ((GenericObject) hisObj).getMatcher() != null) { + String myObjEncoded = ((GenericObject) myObj).encode(); + return ((GenericObject) hisObj).getMatcher().match( + myObjEncoded); + } else if ( + GenericObject.isMySubclass(myObj.getClass()) + && !((GenericObject) myObj).match(hisObj)) + return false; + else if ( + GenericObjectList.isMySubclass(myObj.getClass()) + && !((GenericObjectList) myObj).match(hisObj)) + return false; + } + } catch (IllegalAccessException ex1) { + InternalErrorHandler.handleException(ex1); + } + } + return true; + } + + + /** + * Formatter with a given starting indentation. + */ + public String dbgPrint(int indent) { + int save = indentation; + indentation = indent; + String retval = this.toString(); + indentation = save; + return retval; + } + + +} + diff --git a/java/gov/nist/javax/sdp/fields/SDPObjectList.java b/java/gov/nist/javax/sdp/fields/SDPObjectList.java new file mode 100644 index 0000000..782640c --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SDPObjectList.java @@ -0,0 +1,117 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import java.util.ListIterator; +import java.util.Iterator; +import java.util.LinkedList; +import java.lang.reflect.*; + +public class SDPObjectList extends GenericObjectList { + protected static final String SDPFIELDS_PACKAGE = + PackageNames.SDP_PACKAGE + ".fields"; + + /** + * Do a merge of the GenericObjects contained in this list with the + * GenericObjects in the mergeList. Note that this does an inplace + * modification of the given list. This does an object by object + * merge of the given objects. + * + *@param mergeList is the list of Generic objects that we want to do + * an object by object merge with. Note that no new objects are + * added to this list. + * + */ + + public void mergeObjects(GenericObjectList mergeList) { + + Iterator<GenericObject> it1 = this.listIterator(); + Iterator<GenericObject> it2 = mergeList.listIterator(); + while (it1.hasNext()) { + GenericObject outerObj = (GenericObject) it1.next(); + while (it2.hasNext()) { + Object innerObj = it2.next(); + outerObj.merge(innerObj); + } + } + } + + /** + * Add an sdp object to this list. + */ + public void add(SDPObject s) { + super.add(s); + } + + /** + * Get the input text of the sdp object (from which the object was + * generated). + */ + + public SDPObjectList(String lname, String classname) { + super(lname, classname); + } + + public SDPObjectList() { + super(null, SDPObject.class); + } + + public SDPObjectList(String lname) { + super(lname, SDPFIELDS_PACKAGE + ".SDPObject"); + } + + public GenericObject first() { + return (SDPObject) super.first(); + } + + public GenericObject next() { + return (SDPObject) super.next(); + } + + + + public String encode() { + StringBuffer retval = new StringBuffer(); + SDPObject sdpObject; + for (sdpObject = (SDPObject) this.first(); + sdpObject != null; + sdpObject = (SDPObject) this.next()) { + retval.append (sdpObject.encode()); + } + return retval.toString(); + } + + public String toString() { + return this.encode(); + } + + + +} + diff --git a/java/gov/nist/javax/sdp/fields/SessionNameField.java b/java/gov/nist/javax/sdp/fields/SessionNameField.java new file mode 100644 index 0000000..3eeb88f --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/SessionNameField.java @@ -0,0 +1,77 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; + +public class SessionNameField extends SDPField implements SessionName { + protected String sessionName; + + public SessionNameField() { + super(SDPFieldNames.SESSION_NAME_FIELD); + } + public String getSessionName() { + return sessionName; + } + /** + * Set the sessionName member + */ + public void setSessionName(String s) { + sessionName = s; + } + + /** Returns the value. + * @throws SdpParseException + * @return the value + */ + public String getValue() throws SdpParseException { + return getSessionName(); + } + + /** Sets the value + * @param value the - new information. + * @throws SdpException if the value is null + */ + public void setValue(String value) throws SdpException { + if (value == null) + throw new SdpException("The value is null"); + else { + setSessionName(value); + } + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + return SESSION_NAME_FIELD + sessionName + Separators.NEWLINE; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/TimeField.java b/java/gov/nist/javax/sdp/fields/TimeField.java new file mode 100644 index 0000000..b88cca0 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/TimeField.java @@ -0,0 +1,175 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import javax.sdp.*; +import java.util.*; +/** +* Time Field. +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan +* +*Bug Report contributed by Brian J. Collins. +* +*/ +public class TimeField extends SDPField implements Time { + protected long startTime; + protected long stopTime; + public TimeField() { + super(TIME_FIELD); + } + public long getStartTime() { + return startTime; + } + public long getStopTime() { + return stopTime; + } + /** + * Set the startTime member + */ + public void setStartTime(long startTime) { + this.startTime = startTime; + } + /** + * Set the stopTime member + */ + public void setStopTime(long stopTime) { + this.stopTime = stopTime; + } + + /** Returns the start time of the conference/session. + * @throws SdpParseException + * @return the date + */ + public Date getStart() throws SdpParseException { + return SdpFactory.getDateFromNtp(startTime); + } + + /** Returns the stop time of the session + * @throws SdpParseException + * @return the stop time of the session. + */ + public Date getStop() throws SdpParseException { + return SdpFactory.getDateFromNtp(stopTime); + } + + /** Sets the stop time of the session. + * @param stop start - the start time + * @throws SdpException if the date is null + */ + public void setStop(Date stop) throws SdpException { + if (stop == null) + throw new SdpException("The date is null"); + else { + this.stopTime = SdpFactory.getNtpTime(stop); + } + } + + /** Sets the start time of the conference/session. + * @param start start - the start time for the session. + * @throws SdpException if the date is null + */ + public void setStart(Date start) throws SdpException { + if (start == null) + throw new SdpException("The date is null"); + else { + this.startTime = SdpFactory.getNtpTime(start); + } + } + + /** Returns whether the field will be output as a typed time + * or a integer value. + * + * Typed time is formatted as an integer followed by a unit character. + * The unit indicates an appropriate multiplier for + * the integer. + * + * The following unit types are allowed. + * d - days (86400 seconds) + * h - hours (3600 seconds) + * m - minutes (60 seconds) + * s - seconds ( 1 seconds) + * @return true, if the field will be output as a + * typed time; false, if as an integer value. + */ + public boolean getTypedTime() { + return false; + } + + /** Sets whether the field will be output as a typed time or a integer value. + * + * Typed time is formatted as an integer followed by a unit character. + * The unit indicates an appropriate multiplier for + * the integer. + * + * The following unit types are allowed. + * d - days (86400 seconds) + * h - hours (3600 seconds) + * m - minutes (60 seconds) + * s - seconds ( 1 seconds) + * @param typedTime typedTime - if set true, the start and stop times will + * be output in an optimal typed time format; if false, the + * times will be output as integers. + */ + public void setTypedTime(boolean typedTime) { + + } + + /** Returns whether the start and stop times were set to zero (in NTP). + * @return boolean + */ + public boolean isZero() { + return getStartTime()==0 && getStopTime()==0; + } + + /** Sets the start and stop times to zero (in NTP). + */ + public void setZero() { + setStopTime(0); + setStartTime(0); + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + return new StringBuffer() + .append(TIME_FIELD) + .append(startTime) + .append(Separators.SP) + .append(stopTime) + .append(Separators.NEWLINE) + .toString(); + } + +} + diff --git a/java/gov/nist/javax/sdp/fields/TypedTime.java b/java/gov/nist/javax/sdp/fields/TypedTime.java new file mode 100644 index 0000000..936a582 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/TypedTime.java @@ -0,0 +1,65 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/************************************************************************** +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +***************************************************************************/ +package gov.nist.javax.sdp.fields; + +/** + * Typed time SDP field. + * + * @author M. Ranganathan + * + */ +public class TypedTime extends SDPObject { + String unit; + int time; + + public String encode() { + String retval = ""; + retval += Integer.toString(time); + if (unit != null) + retval += unit; + return retval; + } + + public void setTime(int t) { + time = t; + } + + public int getTime() { + return time; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String u) { + unit = u; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/URIField.java b/java/gov/nist/javax/sdp/fields/URIField.java new file mode 100644 index 0000000..bf2db7e --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/URIField.java @@ -0,0 +1,93 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; + +import gov.nist.core.*; +import java.net.*; + +/** Implementation of URI field. +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +*/ + +public class URIField extends SDPField implements javax.sdp.URI { + + private static final long serialVersionUID = -4322063343955734258L; + protected URL url; + protected String urlString; + + public URIField() { + super(URI_FIELD); + } + + public String getURI() { + return urlString; + } + + public void setURI(String uri) { + this.urlString = uri; + this.url = null; + } + + public URL get() { + if (this.url != null) { + return this.url; + } else { + try { + this.url = new URL(this.urlString); + return this.url; + } catch (Exception ex) { + return null; + } + } + } + + public void set(URL uri) { + this.url = uri; + this.urlString = null; + } + + /** + * Get the string encoded version of this object + * @since v1.0 + */ + public String encode() { + if (urlString != null) { + return URI_FIELD + urlString + Separators.NEWLINE; + } else if (url != null) { + return URI_FIELD + url.toString() + Separators.NEWLINE; + } else + return ""; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/ZoneAdjustment.java b/java/gov/nist/javax/sdp/fields/ZoneAdjustment.java new file mode 100644 index 0000000..3d51283 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/ZoneAdjustment.java @@ -0,0 +1,105 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; + +/** +* Zone adjustment class. +* +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +* +*/ +public class ZoneAdjustment extends SDPObject { + protected long time; + protected String sign; + protected TypedTime offset; + + /** + * Set the time. + *@param t time to set. + */ + public void setTime(long t) { + time = t; + } + + /** + * Get the time. + */ + public long getTime() { + return time; + } + + /** + * get the offset. + */ + public TypedTime getOffset() { + return offset; + } + + /** + * Set the offset. + *@param off typed time offset to set. + */ + public void setOffset(TypedTime off) { + offset = off; + } + + /** + * Set the sign. + *@param s sign for the offset. + */ + public void setSign(String s) { + sign = s; + } + + /** + * Encode this structure into canonical form. + *@return encoded form of the header. + */ + public String encode() { + String retval = Long.toString(time); + retval += Separators.SP; + if (sign != null) + retval += sign; + retval += offset.encode(); + return retval; + } + + public Object clone() { + ZoneAdjustment retval = (ZoneAdjustment) super.clone(); + if (this.offset != null) + retval.offset = (TypedTime) this.offset.clone(); + return retval; + } + +} diff --git a/java/gov/nist/javax/sdp/fields/ZoneField.java b/java/gov/nist/javax/sdp/fields/ZoneField.java new file mode 100644 index 0000000..c67f63e --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/ZoneField.java @@ -0,0 +1,188 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/******************************************************************************* +* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * +*******************************************************************************/ +package gov.nist.javax.sdp.fields; +import gov.nist.core.*; +import java.util.*; +import javax.sdp.*; + +/** +* Z= SDP field. +* +*@version JSR141-PUBLIC-REVIEW (subject to change). +* +*@author Olivier Deruelle <deruelle@antd.nist.gov> +*@author M. Ranganathan <br/> +* +* +* +*/ + +public class ZoneField + extends SDPField + implements javax.sdp.TimeZoneAdjustment { + + protected SDPObjectList zoneAdjustments; + + /** + * Constructor. + */ + public ZoneField() { + super(ZONE_FIELD); + zoneAdjustments = new SDPObjectList(); + } + + /** + * Add an element to the zone adjustment list. + *@param za zone adjustment to add. + */ + public void addZoneAdjustment(ZoneAdjustment za) { + zoneAdjustments.add(za); + } + + /** + * Get the zone adjustment list. + *@return the list of zone adjustments. + */ + + public SDPObjectList getZoneAdjustments() { + return zoneAdjustments; + } + + /** + * Encode this structure into a canonical form. + */ + public String encode() { + StringBuffer retval = new StringBuffer(ZONE_FIELD); + ListIterator li = zoneAdjustments.listIterator(); + int num = 0; + while (li.hasNext()) { + ZoneAdjustment za = (ZoneAdjustment) li.next(); + if (num > 0) + retval.append(Separators.SP); + retval.append(za.encode()); + num++; + } + retval.append(Separators.NEWLINE); + return retval.toString(); + } + + /** Returns a Hashtable of adjustment times, where: + * key = Date. This is the equivalent of the decimal NTP time value. + * value = Int Adjustment. This is a relative time value in seconds. + * @param create to set + * @throws SdpParseException + * @return create - when true, an empty Hashtable is created, if it is null. + */ + public Hashtable getZoneAdjustments(boolean create) + throws SdpParseException { + Hashtable result = new Hashtable(); + SDPObjectList zoneAdjustments = getZoneAdjustments(); + ZoneAdjustment zone; + if (zoneAdjustments == null) + if (create) + return new Hashtable(); + else + return null; + else { + while ((zone = (ZoneAdjustment) zoneAdjustments.next()) != null) { + Long l = Long.valueOf(zone.getTime()); + Integer time = Integer.valueOf(l.toString()); + Date date = new Date(zone.getTime()); + result.put(date, time); + } + return result; + } + } + + /** Sets the Hashtable of adjustment times, where: + * key = Date. This is the equivalent of the decimal NTP time value. + * value = Int Adjustment. This is a relative time value in seconds. + * @param map Hashtable to set + * @throws SdpException if the parameter is null + */ + public void setZoneAdjustments(Hashtable map) throws SdpException { + if (map == null) + throw new SdpException("The map is null"); + else { + for (Enumeration e = map.keys(); e.hasMoreElements();) { + Object o = e.nextElement(); + if (o instanceof Date) { + Date date = (Date) o; + ZoneAdjustment zone = new ZoneAdjustment(); + zone.setTime(date.getTime()); + addZoneAdjustment(zone); + } else + throw new SdpException("The map is not well-formated "); + } + } + } + + /** Sets whether the field will be output as a typed time or a integer value. + * + * Typed time is formatted as an integer followed by a unit character. + * The unit indicates an appropriate multiplier for + * the integer. + * + * The following unit types are allowed. + * d - days (86400 seconds) + * h - hours (3600 seconds) + * m - minutes (60 seconds) + * s - seconds ( 1 seconds) + * @param typedTime typedTime - if set true, the start and stop times will be + * output in an optimal typed time format; if false, the + * times will be output as integers. + */ + public void setTypedTime(boolean typedTime) { + // Dummy -- feature not implemented. + } + + /** Returns whether the field will be output as a typed time or a integer value. + * + * Typed time is formatted as an integer followed by a unit character. + * The unit indicates an appropriate multiplier for + * the integer. + * + * The following unit types are allowed. + * d - days (86400 seconds) + * h - hours (3600 seconds) + * m - minutes (60 seconds) + * s - seconds ( 1 seconds) + * @return true, if the field will be output as a typed time; false, if as an integer value. + */ + public boolean getTypedTime() { + return false; + } + + public Object clone() { + ZoneField retval = (ZoneField) super.clone(); + if (this.zoneAdjustments != null) + retval.zoneAdjustments = (SDPObjectList) this.zoneAdjustments.clone(); + return retval; + } +} diff --git a/java/gov/nist/javax/sdp/fields/package.html b/java/gov/nist/javax/sdp/fields/package.html new file mode 100644 index 0000000..a438088 --- /dev/null +++ b/java/gov/nist/javax/sdp/fields/package.html @@ -0,0 +1,4 @@ + +<body> +Classes for SDP Fields. +</body> diff --git a/java/gov/nist/javax/sdp/package.html b/java/gov/nist/javax/sdp/package.html new file mode 100644 index 0000000..f88067f --- /dev/null +++ b/java/gov/nist/javax/sdp/package.html @@ -0,0 +1,5 @@ + +<body> +Preliminary +implementation of the javax.sdp package (JSR 141 see <a href="http://www.jcp.org/jsr/detail/141.jsp"> JSR 141 </a> ) +</body> diff --git a/java/gov/nist/javax/sdp/parser/AttributeFieldParser.java b/java/gov/nist/javax/sdp/parser/AttributeFieldParser.java new file mode 100644 index 0000000..a99d95d --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/AttributeFieldParser.java @@ -0,0 +1,187 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * AttributeFieldParser.java + * + * Created on February 19, 2002, 10:09 AM + */ + +package gov.nist.javax.sdp.parser; +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.*; + +/** + * @author Olivier Deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.6 $ $Date: 2009/07/17 18:57:15 $ + */ +public class AttributeFieldParser extends SDPParser { + + /** Creates new AttributeFieldParser */ + public AttributeFieldParser(String attributeField) { + + this.lexer = new Lexer("charLexer", attributeField); + } + + public AttributeField attributeField() throws ParseException { + try { + AttributeField attributeField = new AttributeField(); + + this.lexer.match('a'); + + this.lexer.SPorHT(); + this.lexer.match('='); + + this.lexer.SPorHT(); + + NameValue nameValue = new NameValue(); + + int ptr = this.lexer.markInputPosition(); + try { + String name = lexer.getNextToken(':'); + this.lexer.consume(1); + String value = lexer.getRest(); + nameValue = new NameValue(name.trim(), value.trim()); + } catch (ParseException ex) { + this.lexer.rewindInputPosition(ptr); + String rest = this.lexer.getRest(); + if (rest == null) + throw new ParseException( + this.lexer.getBuffer(), + this.lexer.getPtr()); + nameValue = new NameValue(rest.trim(), null); + } + attributeField.setAttribute(nameValue); + + this.lexer.SPorHT(); + + return attributeField; + } catch (Exception e) { + e.printStackTrace(); + throw new ParseException(e.getMessage(), 0); + } + } + + public SDPField parse() throws ParseException { + return this.attributeField(); + } + + /** + public static void main(String[] args) throws ParseException { + String attribute[] = { + "a=rtpmap:0 PCMU/8000\n", + "a=rtpmap:31 LPC\n", + "a=rtpmap:0 PCMU/8000\n", + "a=rtpmap:4 G723/8000\n", + "a=rtpmap:18 G729A/8000\n", + "a=ptime:30\n", + "a=orient:landscape\n", + "a=recvonly\n", + "a=T38FaxVersion:0\n", + "a=T38maxBitRate:14400\n", + "a=T38FaxFillBitRemoval:0\n", + "a=T38FaxTranscodingMMR:0\n", + "a=T38FaxTranscodingJBIG:0\n", + "a=T38FaxRateManagement:transferredTCF\n", + "a=T38FaxMaxBuffer:72\n", + "a=T38FaxMaxDatagram:316\n", + "a=T38FaxUdpEC:t38UDPRedundancy\n" + }; + + for (int i = 0; i < attribute.length; i++) { + AttributeFieldParser attributeFieldParser = new AttributeFieldParser( + attribute[i] ); + AttributeField attributeField= attributeFieldParser.attributeField(); + System.out.println("encoded: " + attributeField.encode()); + } + + } + **/ +} +/* + * $Log: AttributeFieldParser.java,v $ + * Revision 1.6 2009/07/17 18:57:15 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.5 2006/07/13 09:02:35 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/BandwidthFieldParser.java b/java/gov/nist/javax/sdp/parser/BandwidthFieldParser.java new file mode 100644 index 0000000..ef2b4df --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/BandwidthFieldParser.java @@ -0,0 +1,162 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.*; + +/** + * @author deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.6 $ $Date: 2009/07/17 18:57:15 $ + */ +public class BandwidthFieldParser extends SDPParser { + + /** Creates new BandwidthFieldParser */ + public BandwidthFieldParser(String bandwidthField) { + this.lexer = new Lexer("charLexer", bandwidthField); + } + + public BandwidthField bandwidthField() throws ParseException { + try { + this.lexer.match('b'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + BandwidthField bandwidthField = new BandwidthField(); + + NameValue nameValue = nameValue(':'); + String name = nameValue.getName(); + String value = (String) nameValue.getValueAsObject(); + + bandwidthField.setBandwidth(Integer.parseInt(value.trim())); + bandwidthField.setBwtype(name); + + this.lexer.SPorHT(); + return bandwidthField; + } catch (Exception e) { + e.printStackTrace(); + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.bandwidthField(); + } + + /** + public static void main(String[] args) throws ParseException { + String bandwidth[] = { + "b=X-YZ:128\n", + "b=CT: 31\n", + "b=AS:0 \n", + "b= AS:4\n" + }; + + for (int i = 0; i < bandwidth.length; i++) { + BandwidthFieldParser bandwidthFieldParser=new BandwidthFieldParser( + bandwidth[i] ); + System.out.println("toParse: " + bandwidth[i]); + BandwidthField bandwidthField = bandwidthFieldParser.bandwidthField(); + System.out.println("encoded: " + bandwidthField.encode()); + } + + } + **/ +} +/* + * $Log: BandwidthFieldParser.java,v $ + * Revision 1.6 2009/07/17 18:57:15 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.5 2007/10/22 03:38:26 mranga + * Issue number: + * Obtained from: + * Submitted by: mranga + * Reviewed by: mranga + * + * Java 5 porting. + * + * Revision 1.4 2006/07/13 09:02:41 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/ConnectionFieldParser.java b/java/gov/nist/javax/sdp/parser/ConnectionFieldParser.java new file mode 100644 index 0000000..fd3ec31 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/ConnectionFieldParser.java @@ -0,0 +1,194 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; + +import java.text.*; + +/** + * Parser for Connection Field. + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.5 $ $Date: 2009/07/17 18:57:15 $ + * + * @author Olivier Deruelle + * @author M. Ranganathan + * + * + */ +public class ConnectionFieldParser extends SDPParser { + + /** Creates new ConnectionFieldParser */ + public ConnectionFieldParser(String connectionField) { + this.lexer = new Lexer("charLexer", connectionField); + } + + public ConnectionAddress connectionAddress(String address) { + ConnectionAddress connectionAddress = new ConnectionAddress(); + + int begin = address.indexOf("/"); + + if (begin != -1) { + connectionAddress.setAddress(new Host(address.substring(0, begin))); + + int middle = address.indexOf("/", begin + 1); + if (middle != -1) { + String ttl = address.substring(begin + 1, middle); + connectionAddress.setTtl(Integer.parseInt(ttl.trim())); + + String addressNumber = address.substring(middle + 1); + connectionAddress.setPort( + Integer.parseInt(addressNumber.trim())); + } else { + String ttl = address.substring(begin + 1); + connectionAddress.setTtl(Integer.parseInt(ttl.trim())); + } + } else + connectionAddress.setAddress(new Host(address)); + + return connectionAddress; + } + + public ConnectionField connectionField() throws ParseException { + try { + this.lexer.match('c'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + ConnectionField connectionField = new ConnectionField(); + + lexer.match(LexerCore.ID); + this.lexer.SPorHT(); + Token token = lexer.getNextToken(); + connectionField.setNettype(token.getTokenValue()); + + lexer.match(LexerCore.ID); + this.lexer.SPorHT(); + token = lexer.getNextToken(); + connectionField.setAddressType(token.getTokenValue()); + this.lexer.SPorHT(); + String rest = lexer.getRest(); + ConnectionAddress connectionAddress = + connectionAddress(rest.trim()); + + connectionField.setAddress(connectionAddress); + + return connectionField; + } catch (Exception e) { + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.connectionField(); + } + + /** + public static void main(String[] args) throws ParseException { + String connection[] = { + "c=IN IP4 224.2.17.12/127\n", + "c=IN IP4 224.2.1.1/127/3 \n", + "c=IN IP4 135.180.130.88\n" + }; + + for (int i = 0; i < connection.length; i++) { + ConnectionFieldParser connectionFieldParser= + new ConnectionFieldParser( + connection[i] ); + ConnectionField connectionField=connectionFieldParser. + connectionField(); + System.out.println("toParse: " +connection[i]); + System.out.println("encoded: " +connectionField.encode()); + } + + } + **/ +} +/* + * $Log: ConnectionFieldParser.java,v $ + * Revision 1.5 2009/07/17 18:57:15 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:43 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/EmailFieldParser.java b/java/gov/nist/javax/sdp/parser/EmailFieldParser.java new file mode 100644 index 0000000..b12c937 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/EmailFieldParser.java @@ -0,0 +1,248 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import java.text.ParseException; + +/** + * Parser for Email Field + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.6 $ $Date: 2009/07/17 18:57:16 $ + * + * @author Olivier Deruelle + * @author M. Ranganathan + * + * + */ +public class EmailFieldParser extends SDPParser { + + /** Creates new EmailFieldParser */ + public EmailFieldParser(String emailField) { + this.lexer = new Lexer("charLexer", emailField); + } + + public String getDisplayName(String rest) { + String retval = null; + + try { + int begin = rest.indexOf("("); + int end = rest.indexOf(")"); + + if (begin != -1) { + // e=mjh@isi.edu (Mark Handley) + retval = rest.substring(begin + 1, end); + } else { + // The alternative RFC822 name quoting convention + // is also allowed for + // email addresses. ex: e=Mark Handley <mjh@isi.edu> + int ind = rest.indexOf("<"); + if (ind != -1) { + retval = rest.substring(0, ind); + } else { + // There is no display name !!! + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + return retval; + } + + public Email getEmail(String rest) { + Email email = new Email(); + + try { + int begin = rest.indexOf("("); + + if (begin != -1) { + // e=mjh@isi.edu (Mark Handley) + String emailTemp = rest.substring(0, begin); + int i = emailTemp.indexOf("@"); + if (i != -1) { + email.setUserName(emailTemp.substring(0, i)); + email.setHostName(emailTemp.substring(i + 1)); + } else { + // Pb: the email is not well formatted + } + } else { + // The alternative RFC822 name quoting convention is + // also allowed for + // email addresses. ex: e=Mark Handley <mjh@isi.edu> + int ind = rest.indexOf("<"); + int end = rest.indexOf(">"); + + if (ind != -1) { + String emailTemp = rest.substring(ind + 1, end); + int i = emailTemp.indexOf("@"); + if (i != -1) { + email.setUserName(emailTemp.substring(0, i)); + email.setHostName(emailTemp.substring(i + 1)); + } else { + // Pb: the email is not well formatted + } + + } else { + int i = rest.indexOf("@"); + int j = rest.indexOf("\n"); + if (i != -1) { + email.setUserName(rest.substring(0, i)); + email.setHostName(rest.substring(i + 1)); + } else { + // Pb: the email is not well formatted + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + return email; + } + + public EmailField emailField() throws ParseException { + try { + + this.lexer.match('e'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + EmailField emailField = new EmailField(); + EmailAddress emailAddress = new EmailAddress(); + + String rest = lexer.getRest(); + + String displayName = getDisplayName(rest.trim()); + emailAddress.setDisplayName(displayName); + Email email = getEmail(rest); + emailAddress.setEmail(email); + + emailField.setEmailAddress(emailAddress); + return emailField; + } catch (Exception e) { + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.emailField(); + } + + +/* + public static void main(String[] args) throws ParseException { + String email[] = { + "e=mjh@isi.edu (Mark Handley)\n", + "e=Mark Handley <mjh@isi.edu>\n", + "e= <mjh@isi.edu>\n", + "e=mjh@isi.edu\n" + }; + + for (int i = 0; i < email.length; i++) { + EmailFieldParser emailFieldParser=new EmailFieldParser( + email[i] ); + EmailField emailFields=emailFieldParser.emailField(); + System.out.println("toParse: " +email[i]); + System.out.println("encoded: " +emailFields.encode()); + } + + } +*/ + +} +/* + * $Log: EmailFieldParser.java,v $ + * Revision 1.6 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.5 2006/07/13 09:02:36 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.3 2004/12/13 15:01:39 mranga + * Issue number: 47 + * Submitted by: espen@dev.java.net + * Reviewed by: mranga + * + * Bug in parsing email field. + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/InformationFieldParser.java b/java/gov/nist/javax/sdp/parser/InformationFieldParser.java new file mode 100644 index 0000000..f938f15 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/InformationFieldParser.java @@ -0,0 +1,149 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * InformationFieldParser.java + * + * Created on February 19, 2002, 5:28 PM + */ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import java.text.*; + +/** + * @author deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.5 $ $Date: 2009/07/17 18:57:16 $ + */ +public class InformationFieldParser extends SDPParser { + + /** Creates new InformationFieldParser */ + public InformationFieldParser(String informationField) { + this.lexer = new Lexer("charLexer", informationField); + } + + public InformationField informationField() throws ParseException { + try { + this.lexer.match('i'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + InformationField informationField = new InformationField(); + String rest = lexer.getRest(); + informationField.setInformation(rest.trim()); + + return informationField; + } catch (Exception e) { + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.informationField(); + } + + /** + public static void main(String[] args) throws ParseException { + String information[] = { + "i=A Seminar on the session description protocol\n" + }; + + for (int i = 0; i < information.length; i++) { + InformationFieldParser informationFieldParser=new InformationFieldParser( + information[i] ); + InformationField informationField= + informationFieldParser.informationField(); + + System.out.println("encoded: " +informationField.encode()); + } + + } + **/ +} +/* + * $Log: InformationFieldParser.java,v $ + * Revision 1.5 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:34 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/KeyFieldParser.java b/java/gov/nist/javax/sdp/parser/KeyFieldParser.java new file mode 100644 index 0000000..82a75d4 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/KeyFieldParser.java @@ -0,0 +1,176 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.*; + +/** + * Parser for key field. Ack: bug fix contributed by espen@java.net + * + * @author deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.7 $ $Date: 2009/07/17 18:57:16 $ + */ +public class KeyFieldParser extends SDPParser { + + /** Creates new KeyFieldParser */ + public KeyFieldParser(String keyField) { + this.lexer = new Lexer("charLexer", keyField); + } + + public KeyField keyField() throws ParseException { + try { + this.lexer.match('k'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + KeyField keyField = new KeyField(); + //Espen: Stealing the approach from AttributeFieldParser from from here... + NameValue nameValue = new NameValue(); + + int ptr = this.lexer.markInputPosition(); + try { + String name = lexer.getNextToken(':'); + this.lexer.consume(1); + String value = lexer.getRest(); + nameValue = new NameValue(name.trim(), value.trim()); + } catch (ParseException ex) { + this.lexer.rewindInputPosition(ptr); + String rest = this.lexer.getRest(); + if (rest == null) + throw new ParseException( + this.lexer.getBuffer(), + this.lexer.getPtr()); + nameValue = new NameValue(rest.trim(), null); + } + keyField.setType(nameValue.getName()); + keyField.setKeyData((String) nameValue.getValueAsObject()); + this.lexer.SPorHT(); + + return keyField; + } catch (Exception e) { + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.keyField(); + } + + /** + public static void main(String[] args) throws ParseException { + String key[] = { + "k=clear:1234124\n", + "k=base64:12\n", + "k=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\n", + "k=prompt\n" + }; + + for (int i = 0; i < key.length; i++) { + KeyFieldParser keyFieldParser=new KeyFieldParser( + key[i] ); + KeyField keyField=keyFieldParser.keyField(); + System.out.println("toParse: " +key[i]); + System.out.println("encoded: " +keyField.encode()); + } + + } + **/ +} +/* + * $Log: KeyFieldParser.java,v $ + * Revision 1.7 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.6 2007/10/22 03:38:26 mranga + * Issue number: + * Obtained from: + * Submitted by: mranga + * Reviewed by: mranga + * + * Java 5 porting. + * + * Revision 1.5 2006/07/13 09:02:42 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.3 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/Lexer.java b/java/gov/nist/javax/sdp/parser/Lexer.java new file mode 100644 index 0000000..5c68105 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/Lexer.java @@ -0,0 +1,109 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; +import gov.nist.core.*; + +public class Lexer extends LexerCore { + public Lexer(String lexerName, String buffer) { + super(lexerName, buffer); + + } + + public void selectLexer(String lexerName) { + } + + public static String getFieldName(String line) { + int i = line.indexOf("="); + if (i == -1) + return null; + else + return line.substring(0, i); + } +} +/* + * $Log: Lexer.java,v $ + * Revision 1.5 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:41 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/MediaFieldParser.java b/java/gov/nist/javax/sdp/parser/MediaFieldParser.java new file mode 100644 index 0000000..3d35f5b --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/MediaFieldParser.java @@ -0,0 +1,224 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.*; +import java.util.*; + +/** + * Parser for Media field. + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.6 $ $Date: 2009/07/17 18:57:16 $ + * + * @author Olivier Deruelle + * @author M. Ranganathan <br/> + * + * + * + */ +public class MediaFieldParser extends SDPParser { + + /** Creates new MediaFieldParser */ + public MediaFieldParser(String mediaField) { + lexer = new Lexer("charLexer", mediaField); + } + + public MediaField mediaField() throws ParseException { + if (Debug.parserDebug) + dbg_enter("mediaField"); + try { + MediaField mediaField = new MediaField(); + + lexer.match('m'); + lexer.SPorHT(); + lexer.match('='); + lexer.SPorHT(); + + lexer.match(Lexer.ID); + Token media = lexer.getNextToken(); + mediaField.setMedia(media.getTokenValue()); + this.lexer.SPorHT(); + + lexer.match(Lexer.ID); + Token port = lexer.getNextToken(); + mediaField.setPort(Integer.parseInt(port.getTokenValue())); + + this.lexer.SPorHT(); + + // Some strange media formatting from Sun Ray systems with media + // reported by Emil Ivov and Iain Macdonnell at Sun + if (lexer.hasMoreChars() && lexer.lookAhead(1) == '\n') + return mediaField; + + if (lexer.lookAhead(0) == '/') { + // The number of ports is present: + lexer.consume(1); + lexer.match(Lexer.ID); + Token portsNumber = lexer.getNextToken(); + mediaField.setNports( + Integer.parseInt(portsNumber.getTokenValue())); + this.lexer.SPorHT(); + } + + lexer.match(Lexer.ID); + Token token = lexer.getNextToken(); + this.lexer.SPorHT(); + String transport = token.getTokenValue(); + if (lexer.lookAhead(0) == '/') { + lexer.consume(1); + lexer.match(Lexer.ID); + Token transportTemp = lexer.getNextToken(); + transport = transport + "/" + transportTemp.getTokenValue(); + this.lexer.SPorHT(); + } + + mediaField.setProto(transport); + + // The formats list: + Vector formatList = new Vector(); + while (lexer.hasMoreChars()) { + char la = lexer.lookAhead(0); + if (la == '\n' || la == '\r') + break; + this.lexer.SPorHT(); + //while(lexer.lookAhead(0) == ' ') lexer.consume(1); + lexer.match(Lexer.ID); + Token tok = lexer.getNextToken(); + this.lexer.SPorHT(); + String format = tok.getTokenValue().trim(); + if (!format.equals("")) + formatList.add(format); + } + mediaField.setFormats(formatList); + + return mediaField; + } catch (Exception e) { + e.printStackTrace(); + //System.out.println(lexer.getPtr()); + //System.out.println("char = [" + lexer.lookAhead(0) +"]"); + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } finally { + dbg_leave("mediaField"); + } + } + + public SDPField parse() throws ParseException { + return this.mediaField(); + } + + /** + public static void main(String[] args) throws ParseException { + String media[] = { + "m=video 0\r\n", + "m=audio 50006 RTP/AVP 0 8 4 18\r\n", + "m=video 49170/2 RTP/AVP 31\n", + "m=video 49232 RTP/AVP 0\n", + "m=audio 49230 RTP/AVP 96 97 98\n", + "m=application 32416 udp wb\n", + "m=control 49234 H323 mc\n", + "m=audio 50012 RTP/AVP 0 8 4 18\n", + "m=image 49172 udptl t38\n" + }; + + for (int i = 0; i < media.length; i++) { + MediaFieldParser mediaFieldParser=new MediaFieldParser( + media[i] ); + System.out.println("toParse: " + media[i]); + MediaField mediaField=mediaFieldParser.mediaField(); + System.out.println("encoded: " +mediaField.encode()); + } + + } + **/ +} +/* + * $Log: MediaFieldParser.java,v $ + * Revision 1.6 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.5 2007/02/06 16:40:00 belangery + * Introduced simple code optimizations. + * + * Revision 1.4 2006/07/13 09:02:42 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/OriginFieldParser.java b/java/gov/nist/javax/sdp/parser/OriginFieldParser.java new file mode 100644 index 0000000..9b40e00 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/OriginFieldParser.java @@ -0,0 +1,225 @@ +/* + * Conditions Of Use + * + * This software was developed by employees of the National Institute of + * Standards and Technology (NIST), an agency of the Federal Government. + * Pursuant to title 15 Untied States Code Section 105, works of NIST + * employees are not subject to copyright protection in the United States + * and are considered to be in the public domain. As a result, a formal + * license is not needed to use the software. + * + * This software is provided by NIST as a service and is expressly + * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT + * AND DATA ACCURACY. NIST does not warrant or make any representations + * regarding the use of the software or the results thereof, including but + * not limited to the correctness, accuracy, reliability or usefulness of + * the software. + * + * Permission to use this software is contingent upon your acceptance + * of the terms of this agreement + * + * . + * + */ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.*; + +/** + * @author deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.8 $ $Date: 2009/07/17 18:57:16 $ + */ +public class OriginFieldParser extends SDPParser { + + /** Creates new OriginFieldParser */ + public OriginFieldParser(String originField) { + lexer = new Lexer("charLexer", originField); + } + + public OriginField originField() throws ParseException { + try { + OriginField originField = new OriginField(); + + lexer.match('o'); + lexer.SPorHT(); + lexer.match('='); + lexer.SPorHT(); + + lexer.match(LexerCore.SAFE); + Token userName = lexer.getNextToken(); + originField.setUsername(userName.getTokenValue()); + this.lexer.SPorHT(); + + lexer.match(LexerCore.ID); + //lexer.ttokenSafe(); + Token sessionId = lexer.getNextToken(); + // guard against very long session IDs + String sessId = sessionId.getTokenValue(); + if (sessId.length() > 18) + sessId = sessId.substring(sessId.length() - 18); + try { + originField.setSessId(Long.parseLong(sessId)); + } catch (NumberFormatException ex) { + originField.setSessionId(sessId); + } + this.lexer.SPorHT(); + + lexer.match(LexerCore.ID); + Token sessionVersion = lexer.getNextToken(); + // guard against very long session Verion + String sessVer = sessionVersion.getTokenValue(); + if (sessVer.length() > 18) + sessVer = sessVer.substring(sessVer.length() - 18); + try { + originField.setSessVersion(Long.parseLong(sessVer)); + } catch (NumberFormatException ex) { + originField.setSessVersion(sessVer); + + } + this.lexer.SPorHT(); + + lexer.match(LexerCore.ID); + Token networkType = lexer.getNextToken(); + originField.setNettype(networkType.getTokenValue()); + this.lexer.SPorHT(); + + lexer.match(LexerCore.ID); + Token addressType = lexer.getNextToken(); + originField.setAddrtype(addressType.getTokenValue()); + this.lexer.SPorHT(); + + String host = lexer.getRest(); + HostNameParser hostNameParser = new HostNameParser(host); + Host h = hostNameParser.host(); + originField.setAddress(h); + + return originField; + } catch (Exception e) { + e.printStackTrace(); + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.originField(); + } + + public static void main(String[] args) throws ParseException { + String origin[] = { + "o=- 45ec4ba1.1 45ec4ba1 in ip4 10.1.80.200\r\n", + "o=- 4322650003578 0 IN IP4 192.53.18.122\r\n", + "o=4855 12345678901234567890 12345678901234567890 IN IP4 166.35.224.216\n", + "o=mh/andley 2890844526 2890842807 IN IP4 126.16.64.4\n", + "o=UserB 2890844527 2890844527 IN IP4 everywhere.com\n", + "o=UserA 2890844526 2890844526 IN IP4 here.com\n", + "o=IFAXTERMINAL01 2890844527 2890844527 IN IP4 ift.here.com\n", + "o=GATEWAY1 2890844527 2890844527 IN IP4 gatewayone.wcom.com\n", + "o=- 2890844527 2890844527 IN IP4 gatewayone.wcom.com\n" }; + + for (int i = 0; i < origin.length; i++) { + OriginFieldParser originFieldParser = new OriginFieldParser( + origin[i]); + OriginField originField = originFieldParser.originField(); + System.out.println("toParse :" + origin[i]); + System.out.println("encoded: " + originField.encode()); + } + + } +} +/* + * $Log: OriginFieldParser.java,v $ + * Revision 1.8 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.7 2007/03/08 05:20:20 mranga + * Issue number: + * Obtained from: + * Submitted by: + * Reviewed by: mranga + * Fix logging code. Losen up on Sdp parsing (allow for extra long origin fields) + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * Revision 1.6 2006/11/16 19:05:44 pmusgrave + * Issue number: 82 - SDP with Origin/Time or Zone creater than 18 digits causes + * parse exception Obtained from: Submitted by: pmusgrave@newheights.com + * Reviewed by: CVS: + * ---------------------------------------------------------------------- CVS: + * Issue number: CVS: If this change addresses one or more issues, CVS: then + * enter the issue number(s) here. CVS: Obtained from: CVS: If this change has + * been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + * Revision 1.5 2006/07/13 09:02:36 mranga Issue number: Obtained from: + * Submitted by: jeroen van bemmel Reviewed by: mranga Moved some changes from + * jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: CVS: If this change addresses one or more issues, CVS: + * then enter the issue number(s) here. CVS: Obtained from: CVS: If this change + * has been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + * Revision 1.4 2006/06/19 06:47:26 mranga javadoc fixups + * + * Revision 1.3 2006/06/16 15:26:28 mranga Added NIST disclaimer to all public + * domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.2 2006/04/01 04:52:22 mranga *** empty log message *** + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.3 2004/10/21 14:57:17 mranga Reviewed by: mranga + * + * Fixed origin field parser for sdp. + * + * Revision 1.2 2004/01/22 13:26:28 sverker Issue number: Obtained from: + * Submitted by: sverker Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and + * javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: CVS: If this change addresses one or more issues, CVS: + * then enter the issue number(s) here. CVS: Obtained from: CVS: If this change + * has been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/ParserFactory.java b/java/gov/nist/javax/sdp/parser/ParserFactory.java new file mode 100644 index 0000000..2f28604 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/ParserFactory.java @@ -0,0 +1,170 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; +import java.util.*; +import gov.nist.core.*; +import java.text.ParseException; +import java.lang.reflect.*; + +/** Factory for creating parsers for the SDP stuff. +* +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +*/ +public class ParserFactory { + private static Hashtable parserTable; + private static Class[] constructorArgs; + private static final String packageName = + PackageNames.SDP_PACKAGE + ".parser"; + + private static Class getParser(String parserClass) { + try { + return Class.forName(packageName + "." + parserClass); + } catch (ClassNotFoundException ex) { + System.out.println("Could not find class"); + ex.printStackTrace(); + System.exit(0); + return null; // dummy + } + } + + static { + constructorArgs = new Class[1]; + constructorArgs[0] = String.class; + parserTable = new Hashtable(); + parserTable.put("a", getParser("AttributeFieldParser")); + parserTable.put("b", getParser("BandwidthFieldParser")); + parserTable.put("c", getParser("ConnectionFieldParser")); + parserTable.put("e", getParser("EmailFieldParser")); + parserTable.put("i", getParser("InformationFieldParser")); + parserTable.put("k", getParser("KeyFieldParser")); + parserTable.put("m", getParser("MediaFieldParser")); + parserTable.put("o", getParser("OriginFieldParser")); + parserTable.put("p", getParser("PhoneFieldParser")); + parserTable.put("v", getParser("ProtoVersionFieldParser")); + parserTable.put("r", getParser("RepeatFieldParser")); + parserTable.put("s", getParser("SessionNameFieldParser")); + parserTable.put("t", getParser("TimeFieldParser")); + parserTable.put("u", getParser("URIFieldParser")); + parserTable.put("z", getParser("ZoneFieldParser")); + } + + public static SDPParser createParser(String field) throws ParseException { + String fieldName = Lexer.getFieldName(field); + if (fieldName == null) + return null; + Class parserClass = (Class) parserTable.get(fieldName.toLowerCase()); + + if (parserClass != null) { + try { + + Constructor cons = parserClass.getConstructor(constructorArgs); + Object[] args = new Object[1]; + args[0] = field; + SDPParser retval = (SDPParser) cons.newInstance(args); + return retval; + + } catch (Exception ex) { + InternalErrorHandler.handleException(ex); + return null; // to placate the compiler. + } + } else + throw new ParseException( + "Could not find parser for " + fieldName, + 0); + } + +} +/* + * $Log: ParserFactory.java,v $ + * Revision 1.6 2009/07/17 18:57:16 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.5 2006/07/13 09:02:33 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.3 2005/04/04 09:29:02 dmuresan + * Replaced new String().getClass() with String.class. + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/PhoneFieldParser.java b/java/gov/nist/javax/sdp/parser/PhoneFieldParser.java new file mode 100644 index 0000000..e85547f --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/PhoneFieldParser.java @@ -0,0 +1,216 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import java.text.ParseException; + +/** + * Parser for the Phone field. + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.5 $ $Date: 2009/07/17 18:57:17 $ + * + * @author Olivier Deruelle + * @author M. Ranganathan + * + * + * + */ +public class PhoneFieldParser extends SDPParser { + + /** Creates new PhoneFieldParser */ + public PhoneFieldParser(String phoneField) { + lexer = new Lexer("charLexer", phoneField); + } + + public String getDisplayName(String rest) { + String retval = null; + + try { + int begin = rest.indexOf("("); + int end = rest.indexOf(")"); + + if (begin != -1) { + // p=+44-171-380-7777 (Mark Handley) + retval = rest.substring(begin + 1, end); + } else { + // The alternative RFC822 name quoting convention is + // also allowed for + // email addresses. ex: p=Mark Handley <+44-171-380-7777> + int ind = rest.indexOf("<"); + if (ind != -1) { + retval = rest.substring(0, ind); + } else { + // There is no display name !!! + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + return retval; + } + + public String getPhoneNumber(String rest) throws ParseException { + String phoneNumber = null; + + try { + int begin = rest.indexOf("("); + + if (begin != -1) { + // p=+44-171-380-7777 (Mark Handley) + phoneNumber = rest.substring(0, begin).trim(); + } else { + // The alternative RFC822 name quoting convention is also allowed for + // email addresses. ex: p=Mark Handley <+44-171-380-7777> + int ind = rest.indexOf("<"); + int end = rest.indexOf(">"); + + if (ind != -1) { + phoneNumber = rest.substring(ind + 1, end); + } else { + // p=+44-171-380-7777 + phoneNumber = rest.trim(); + } + } + } catch (Exception e) { + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + return phoneNumber; + } + + public PhoneField phoneField() throws ParseException { + try { + + this.lexer.match('p'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + PhoneField phoneField = new PhoneField(); + String rest = lexer.getRest(); + + String displayName = getDisplayName(rest.trim()); + phoneField.setName(displayName); + String phoneNumber = getPhoneNumber(rest); + phoneField.setPhoneNumber(phoneNumber); + + return phoneField; + } catch (Exception e) { + throw new ParseException(lexer.getBuffer(), lexer.getPtr()); + } + } + + public SDPField parse() throws ParseException { + return this.phoneField(); + } + + /** + + public static void main(String[] args) throws ParseException { + String phone[] = { + "p=+44-171-380-7777 (Mark Handley)\n", + "p=Mark Handley <+1 617 253 6011>\n", + "p= <+44-171-380-7777>\n", + "p=+44-171-380-7777\n" + }; + + for (int i = 0; i < phone.length; i++) { + PhoneFieldParser phoneFieldParser=new PhoneFieldParser( + phone[i] ); + PhoneField phoneFields=phoneFieldParser.phoneField(); + System.out.println("toParse: " + phone[i]); + System.out.println("encoded: " +phoneFields.encode()); + } + + } + + **/ +} +/* + * $Log: PhoneFieldParser.java,v $ + * Revision 1.5 2009/07/17 18:57:17 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:34 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/ProtoVersionFieldParser.java b/java/gov/nist/javax/sdp/parser/ProtoVersionFieldParser.java new file mode 100644 index 0000000..90d25b7 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/ProtoVersionFieldParser.java @@ -0,0 +1,157 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.*; + +/** + * Parser for Proto Version. + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.5 $ $Date: 2009/07/17 18:57:17 $ + * + * @author Olivier Deruelle <deruelle@antd.nist.gov> + * @author M. Ranganathan + * + * + * + */ +public class ProtoVersionFieldParser extends SDPParser { + + /** Creates new ProtoVersionFieldParser */ + public ProtoVersionFieldParser(String protoVersionField) { + this.lexer = new Lexer("charLexer", protoVersionField); + } + + public ProtoVersionField protoVersionField() throws ParseException { + try { + this.lexer.match('v'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + ProtoVersionField protoVersionField = new ProtoVersionField(); + lexer.match(Lexer.ID); + Token version = lexer.getNextToken(); + protoVersionField.setProtoVersion( + Integer.parseInt(version.getTokenValue())); + this.lexer.SPorHT(); + + return protoVersionField; + } catch (Exception e) { + throw lexer.createParseException(); + } + } + + public SDPField parse() throws ParseException { + return this.protoVersionField(); + } + + /** + public static void main(String[] args) throws ParseException { + String protoVersion[] = { + "v=0\n" + }; + + for (int i = 0; i < protoVersion.length; i++) { + ProtoVersionFieldParser protoVersionFieldParser= + new ProtoVersionFieldParser( + protoVersion[i] ); + ProtoVersionField protoVersionField = + protoVersionFieldParser.protoVersionField(); + System.out.println + ("encoded: " +protoVersionField.encode()); + } + + } + **/ + +} +/* + * $Log: ProtoVersionFieldParser.java,v $ + * Revision 1.5 2009/07/17 18:57:17 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:39 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/RepeatFieldParser.java b/java/gov/nist/javax/sdp/parser/RepeatFieldParser.java new file mode 100644 index 0000000..1f2ad07 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/RepeatFieldParser.java @@ -0,0 +1,242 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.ParseException; + +/** Parser for Repeat field. +* +*@version 1.2 +* +*@author Olivier Deruelle +*@author M. Ranganathan <br/> +* +* +* + */ +public class RepeatFieldParser extends SDPParser { + + /** Creates new RepeatFieldsParser */ + public RepeatFieldParser(String repeatField) { + lexer = new Lexer("charLexer", repeatField); + } + + /** Get the typed time. + * + * @param tokenValue to convert into a typed time. + * @return the typed time + */ + public TypedTime getTypedTime(String tokenValue) { + TypedTime typedTime = new TypedTime(); + + if (tokenValue.endsWith("d")) { + typedTime.setUnit("d"); + String t = tokenValue.replace('d', ' '); + + typedTime.setTime(Integer.parseInt(t.trim())); + } else if (tokenValue.endsWith("h")) { + typedTime.setUnit("h"); + String t = tokenValue.replace('h', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else if (tokenValue.endsWith("m")) { + typedTime.setUnit("m"); + String t = tokenValue.replace('m', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else { + typedTime.setUnit("s"); + if (tokenValue.endsWith("s")) { + String t = tokenValue.replace('s', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else + typedTime.setTime(Integer.parseInt(tokenValue.trim())); + } + return typedTime; + } + + /** parse the field string + * @return RepeatFields + */ + public RepeatField repeatField() throws ParseException { + try { + + this.lexer.match('r'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + RepeatField repeatField = new RepeatField(); + + lexer.match(LexerCore.ID); + Token repeatInterval = lexer.getNextToken(); + this.lexer.SPorHT(); + TypedTime typedTime = getTypedTime(repeatInterval.getTokenValue()); + repeatField.setRepeatInterval(typedTime); + + lexer.match(LexerCore.ID); + Token activeDuration = lexer.getNextToken(); + this.lexer.SPorHT(); + typedTime = getTypedTime(activeDuration.getTokenValue()); + repeatField.setActiveDuration(typedTime); + + // The offsets list: + /*Patch 117 */ + while (lexer.hasMoreChars()) { + char la = lexer.lookAhead(0); + if (la == '\n' || la == '\r') + break; + lexer.match(LexerCore.ID); + Token offsets = lexer.getNextToken(); + this.lexer.SPorHT(); + typedTime = getTypedTime(offsets.getTokenValue()); + repeatField.addOffset(typedTime); + } + + return repeatField; + } catch (Exception e) { + throw lexer.createParseException(); + } + } + + public SDPField parse() throws ParseException { + return this.repeatField(); + } + + /** + + public static void main(String[] args) throws ParseException { + String repeat[] = { + "r=604800s 3600s 0s 90000s\n", + "r=7d 1h 0 25h\n", + "r=7 6 5 4 3 2 1 0 \n" + }; + + for (int i = 0; i < repeat.length; i++) { + RepeatFieldParser repeatFieldParser=new RepeatFieldParser( + repeat[i] ); + RepeatField repeatFields=repeatFieldParser.repeatField(); + System.out.println("toParse: " +repeat[i]); + System.out.println("encoded: " +repeatFields.encode()); + } + + } + **/ +} +/* + * $Log: RepeatFieldParser.java,v $ + * Revision 1.7 2009/07/17 18:57:17 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.6 2007/07/12 15:39:53 mranga + * Issue number: 117 + * Obtained from: + * Submitted by: patrick_poglitsch (patrick_poglitsch) + * Reviewed by: mranga + * + * Revision 1.5 2006/08/23 00:00:22 mranga + * Issue number: + * Obtained from: + * Submitted by: + * Reviewed by: mranga + * + * javadoc fixups. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.4 2006/07/13 09:02:39 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/SDPAnnounceParser.java b/java/gov/nist/javax/sdp/parser/SDPAnnounceParser.java new file mode 100644 index 0000000..83576e4 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/SDPAnnounceParser.java @@ -0,0 +1,212 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; +import java.util.*; +import gov.nist.core.*; +import gov.nist.javax.sdp.fields.*; +import gov.nist.javax.sdp.*; +import java.text.ParseException; +// Acknowledgement: this includes a bug fix submitted by +// Rafael Barriuso rbarriuso@dit.upm.es + +/** Parser for SDP Announce messages. + */ +public class SDPAnnounceParser extends ParserCore { + + protected Lexer lexer; + protected Vector sdpMessage; + + /** Creates new SDPAnnounceParser + * @param sdpMessage Vector of messages to parse. + */ + public SDPAnnounceParser(Vector sdpMessage) { + this.sdpMessage = sdpMessage; + } + + /** Create a new SDPAnnounceParser. + *@param message string containing the sdp announce message. + * + */ + public SDPAnnounceParser(String message) { + int start = 0; + String line = null; + // Return trivially if there is no sdp announce message + // to be parsed. Bruno Konik noticed this bug. + if (message == null) return; + sdpMessage = new Vector(); + // Strip off leading and trailing junk. + String sdpAnnounce = message.trim() + "\r\n"; + // Bug fix by Andreas Bystrom. + while (start < sdpAnnounce.length()) { + // Major re-write by Ricardo Borba. + int lfPos = sdpAnnounce.indexOf("\n", start); + int crPos = sdpAnnounce.indexOf("\r", start); + + if (lfPos > 0 && crPos < 0) { + // there are only "\n" separators + line = sdpAnnounce.substring(start, lfPos); + start = lfPos + 1; + } else if (lfPos < 0 && crPos > 0) { + //bug fix: there are only "\r" separators + line = sdpAnnounce.substring(start, crPos); + start = crPos + 1; + } else if (lfPos > 0 && crPos > 0) { + // there are "\r\n" or "\n\r" (if exists) separators + if (lfPos > crPos) { + // assume "\r\n" for now + line = sdpAnnounce.substring(start, crPos); + // Check if the "\r" and "\n" are close together + if (lfPos == crPos + 1) { + start = lfPos + 1; // "\r\n" + } else { + start = crPos + 1; // "\r" followed by the next record and a "\n" further away + } + } else { + // assume "\n\r" for now + line = sdpAnnounce.substring(start, lfPos); + // Check if the "\n" and "\r" are close together + if (crPos == lfPos + 1) { + start = crPos + 1; // "\n\r" + } else { + start = lfPos + 1; // "\n" followed by the next record and a "\r" further away + } + } + } else if (lfPos < 0 && crPos < 0) { // end + break; + } + sdpMessage.addElement(line); + } + } + + public SessionDescriptionImpl parse() throws ParseException { + SessionDescriptionImpl retval = new SessionDescriptionImpl(); + for (int i = 0; i < sdpMessage.size(); i++) { + String field = (String) sdpMessage.elementAt(i); + SDPParser sdpParser = ParserFactory.createParser(field); + SDPField sdpField = null; + if (sdpParser != null) + { + sdpField = sdpParser.parse(); + } + retval.addField(sdpField); + } + return retval; + + } + + + +} +/* + * $Log: SDPAnnounceParser.java,v $ + * Revision 1.11 2009/10/16 19:27:56 mranga + * Issue number: 128 + * Reviewed by: mranga + * This would only work for SDP. + * + * Revision 1.10 2009/07/17 18:57:17 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.9 2008/01/18 02:18:24 mranga + * Issue number: + * Obtained from: + * Submitted by: + * Reviewed by: mranga + * Moved out some test code. + * + * Revision 1.8 2006/11/22 04:08:57 rborba + * Fixed a null pointer exception when an SDP is received with an empty session name ("s="). + * + * Revision 1.7 2006/07/13 09:02:37 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.5 2005/01/21 21:19:24 mranga + * Reviewed by: mranga + * Strip leading whitespace while parsing Sdp Announce messages. + * + * Revision 1.4 2004/02/18 14:33:02 mranga + * Submitted by: Bruno Konik + * Reviewed by: mranga + * Remove extraneous newline in encoding messages. Test for empty sdp announce + * rather than die with null when null is passed to sdp announce parser. + * Fixed bug in checking for \n\n when looking for message end. + * + * Revision 1.3 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/SDPParser.java b/java/gov/nist/javax/sdp/parser/SDPParser.java new file mode 100644 index 0000000..0484636 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/SDPParser.java @@ -0,0 +1,107 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +package gov.nist.javax.sdp.parser; +import gov.nist.core.*; +import java.text.ParseException; +import gov.nist.javax.sdp.fields.*; + +/** +*@version 1.2 +* +*@author M. Ranganathan <br/> +* +* +* +*/ +public abstract class SDPParser extends ParserCore { + + public abstract SDPField parse() throws ParseException; + +} +/* + * $Log: SDPParser.java,v $ + * Revision 1.5 2009/07/17 18:57:17 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:39 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/SessionNameFieldParser.java b/java/gov/nist/javax/sdp/parser/SessionNameFieldParser.java new file mode 100644 index 0000000..775cc88 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/SessionNameFieldParser.java @@ -0,0 +1,151 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * SessionNameFieldParser.java + * + * Created on February 25, 2002, 10:26 AM + */ + +package gov.nist.javax.sdp.parser; +import gov.nist.javax.sdp.fields.*; +import java.text.*; + +/** + * @author deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.6 $ $Date: 2009/07/17 18:57:17 $ + */ +public class SessionNameFieldParser extends SDPParser { + + /** Creates new SessionNameFieldParser */ + public SessionNameFieldParser(String sessionNameField) { + this.lexer = new Lexer("charLexer", sessionNameField); + } + + /** Get the SessionNameField + * @return SessionNameField + */ + public SessionNameField sessionNameField() throws ParseException { + try { + this.lexer.match('s'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + SessionNameField sessionNameField = new SessionNameField(); + String rest = lexer.getRest(); + // Some endpoints may send us a blank session name ("s=") -- [rborba] + sessionNameField.setSessionName(rest == null ? "" : rest.trim()); + + return sessionNameField; + } catch (Exception e) { + throw lexer.createParseException(); + } + + } + + public SDPField parse() throws ParseException { + return this.sessionNameField(); + } + + public static void main(String[] args) throws ParseException { + String session[] = { "s=SDP Seminar \n", "s= Session SDP\n" }; + + for (int i = 0; i < session.length; i++) { + SessionNameFieldParser sessionNameFieldParser = + new SessionNameFieldParser(session[i]); + SessionNameField sessionNameField = + sessionNameFieldParser.sessionNameField(); + System.out.println("encoded: " + sessionNameField.encode()); + } + } +} +/* + * $Log: SessionNameFieldParser.java,v $ + * Revision 1.6 2009/07/17 18:57:17 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.5 2006/11/22 04:22:01 rborba + * Made the SDPAnnounceParser constructor a little more robust in order to handle SDPs with mixed CR, LF, CR/LF anf LF/CR lines. + * + * Revision 1.4 2006/07/13 09:02:38 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/TimeFieldParser.java b/java/gov/nist/javax/sdp/parser/TimeFieldParser.java new file mode 100644 index 0000000..429aa4d --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/TimeFieldParser.java @@ -0,0 +1,248 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * TimeFieldParser.java + * + * Created on February 25, 2002, 9:58 AM + */ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import java.text.*; + +/** + * @author deruelle + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.7 $ $Date: 2009/07/17 18:57:18 $ + */ +public class TimeFieldParser extends SDPParser { + + /** Creates new TimeFieldParser */ + public TimeFieldParser(String timeField) { + lexer = new Lexer("charLexer", timeField); + } + + /** Get the typed time. + * + * @param tokenValue to convert to typedTime. + * @return TypedTime + */ + public TypedTime getTypedTime(String tokenValue) { + TypedTime typedTime = new TypedTime(); + + if (tokenValue.endsWith("d")) { + typedTime.setUnit("d"); + String t = tokenValue.replace('d', ' '); + + typedTime.setTime(Integer.parseInt(t.trim())); + } else if (tokenValue.endsWith("h")) { + typedTime.setUnit("h"); + String t = tokenValue.replace('h', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else if (tokenValue.endsWith("m")) { + typedTime.setUnit("m"); + String t = tokenValue.replace('m', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else { + typedTime.setUnit("s"); + if (tokenValue.endsWith("s")) { + String t = tokenValue.replace('s', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else + typedTime.setTime(Integer.parseInt(tokenValue.trim())); + } + return typedTime; + } + + private long getTime() throws ParseException { + try { + String startTime = this.lexer.number(); + if ( startTime.length() > 18) + startTime = startTime.substring( startTime.length() - 18); + return Long.parseLong(startTime); + } catch (NumberFormatException ex) { + throw lexer.createParseException(); + } + + } + + /** parse the field string + * @return TimeField + */ + public TimeField timeField() throws ParseException { + try { + this.lexer.match('t'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + TimeField timeField = new TimeField(); + + long st = this.getTime(); + timeField.setStartTime(st); + this.lexer.SPorHT(); + + st = this.getTime(); + timeField.setStopTime(st); + + return timeField; + } catch (Exception e) { + throw lexer.createParseException(); + } + } + + public SDPField parse() throws ParseException { + return this.timeField(); + } + + /** + public static void main(String[] args) throws ParseException { + String time[] = { + "t=3033434331 3042462419\n", + "t=7d 1h \n", + "t=3149328700 0 \n", + "t=0 0\n" + }; + + + for (int i = 0; i < time.length; i++) { + TimeFieldParser timeFieldParser=new TimeFieldParser( + time[i] ); + TimeField timeField=timeFieldParser.timeField(); + System.out.println("encoded: " +timeField.encode()); + } + + } + **/ +} +/* + * $Log: TimeFieldParser.java,v $ + * Revision 1.7 2009/07/17 18:57:18 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.6 2006/11/16 19:05:44 pmusgrave + * Issue number: 82 - SDP with Origin/Time or Zone creater than 18 digits causes parse exception + * Obtained from: + * Submitted by: pmusgrave@newheights.com + * Reviewed by: + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.5 2006/08/23 00:00:23 mranga + * Issue number: + * Obtained from: + * Submitted by: + * Reviewed by: mranga + * + * javadoc fixups. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.4 2006/07/13 09:02:38 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/URIFieldParser.java b/java/gov/nist/javax/sdp/parser/URIFieldParser.java new file mode 100644 index 0000000..d1a08d3 --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/URIFieldParser.java @@ -0,0 +1,162 @@ +/* +* Conditions Of Use +* +* This software was developed by employees of the National Institute of +* Standards and Technology (NIST), an agency of the Federal Government. +* Pursuant to title 15 Untied States Code Section 105, works of NIST +* employees are not subject to copyright protection in the United States +* and are considered to be in the public domain. As a result, a formal +* license is not needed to use the software. +* +* This software is provided by NIST as a service and is expressly +* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED +* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT +* AND DATA ACCURACY. NIST does not warrant or make any representations +* regarding the use of the software or the results thereof, including but +* not limited to the correctness, accuracy, reliability or usefulness of +* the software. +* +* Permission to use this software is contingent upon your acceptance +* of the terms of this agreement +* +* . +* +*/ +/* + * URIFieldParser.java + * + * Created on February 25, 2002, 11:10 AM + */ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import java.text.ParseException; + +/** + * URI Field Parser. + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.5 $ $Date: 2009/07/17 18:57:18 $ + * + * @author Olivier Deruelle + * @author M. Ranganathan <br/> + * + * + * + */ +public class URIFieldParser extends SDPParser { + + /** Creates new URIFieldParser */ + public URIFieldParser(String uriField) { + this.lexer = new Lexer("charLexer", uriField); + } + + /** Get the URI field + * @return URIField + */ + public URIField uriField() throws ParseException { + try { + this.lexer.match('u'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + URIField uriField = new URIField(); + String rest = lexer.getRest().trim(); + uriField.setURI(rest); + return uriField; + } catch (Exception e) { + throw lexer.createParseException(); + } + } + + public SDPField parse() throws ParseException { + return this.uriField(); + } + + /** + + public static void main(String[] args) throws ParseException { + String uri[] = { + "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\n", + "u=sip:j.doe@big.com\n", + "u=sip:j.doe:secret@big.com;transport=tcp\n", + "u=sip:j.doe@big.com?subject=project\n", + "u=sip:+1-212-555-1212:1234@gateway.com;user=phone\n" + }; + + for (int i = 0; i < uri.length; i++) { + URIFieldParser uriFieldParser=new URIFieldParser( + uri[i] ); + URIField uriField=uriFieldParser.uriField(); + System.out.println("toParse: " +uri[i]); + System.out.println("encoded: " +uriField.encode()); + } + + } + **/ +} +/* + * $Log: URIFieldParser.java,v $ + * Revision 1.5 2009/07/17 18:57:18 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.4 2006/07/13 09:02:41 mranga + * Issue number: + * Obtained from: + * Submitted by: jeroen van bemmel + * Reviewed by: mranga + * Moved some changes from jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga + * javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga + * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker + * Issue number: + * Obtained from: + * Submitted by: sverker + * Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: + * CVS: If this change addresses one or more issues, + * CVS: then enter the issue number(s) here. + * CVS: Obtained from: + * CVS: If this change has been taken from another system, + * CVS: then name the system in this line, otherwise delete it. + * CVS: Submitted by: + * CVS: If this code has been contributed to the project by someone else; i.e., + * CVS: they sent us a patch or a set of diffs, then include their name/email + * CVS: address here. If this is your work then delete this line. + * CVS: Reviewed by: + * CVS: If we are doing pre-commit code reviews and someone else has + * CVS: reviewed your changes, include their name(s) here. + * CVS: If you have not had it reviewed then delete this line. + * + */ diff --git a/java/gov/nist/javax/sdp/parser/ZoneFieldParser.java b/java/gov/nist/javax/sdp/parser/ZoneFieldParser.java new file mode 100644 index 0000000..8eacdda --- /dev/null +++ b/java/gov/nist/javax/sdp/parser/ZoneFieldParser.java @@ -0,0 +1,257 @@ +/* + * Conditions Of Use + * + * This software was developed by employees of the National Institute of + * Standards and Technology (NIST), an agency of the Federal Government. + * Pursuant to title 15 Untied States Code Section 105, works of NIST + * employees are not subject to copyright protection in the United States + * and are considered to be in the public domain. As a result, a formal + * license is not needed to use the software. + * + * This software is provided by NIST as a service and is expressly + * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT + * AND DATA ACCURACY. NIST does not warrant or make any representations + * regarding the use of the software or the results thereof, including but + * not limited to the correctness, accuracy, reliability or usefulness of + * the software. + * + * Permission to use this software is contingent upon your acceptance + * of the terms of this agreement + * + * . + * + */ +package gov.nist.javax.sdp.parser; + +import gov.nist.javax.sdp.fields.*; +import gov.nist.core.*; +import java.text.ParseException; + +/** + * Parser For the Zone field. + * + * @version JAIN-SDP-PUBLIC-RELEASE $Revision: 1.8 $ $Date: 2009/07/17 18:57:18 $ + * + * @author Olivier Deruelle <deruelle@antd.nist.gov> + * @author M. Ranganathan <mranga@antd.nist.gov> <br/> + * + * + * + */ +public class ZoneFieldParser extends SDPParser { + + /** Creates new ZoneFieldParser */ + public ZoneFieldParser(String zoneField) { + lexer = new Lexer("charLexer", zoneField); + } + + /** + * Get the sign of the offset. + * + * @param tokenValue + * to examine. + * @return the sign. + */ + public String getSign(String tokenValue) { + if (tokenValue.startsWith("-")) + return "-"; + else + return "+"; + } + + /** + * Get the typed time. + * + * @param tokenValue -- + * token value to convert to typed time. + * @return TypedTime -- the converted typed time value. + */ + public TypedTime getTypedTime(String tokenValue) { + TypedTime typedTime = new TypedTime(); + String offset = null; + if (tokenValue.startsWith("-")) + offset = tokenValue.replace('-', ' '); + else if (tokenValue.startsWith("+")) + offset = tokenValue.replace('+', ' '); + else + offset = tokenValue; + + if (offset.endsWith("d")) { + typedTime.setUnit("d"); + String t = offset.replace('d', ' '); + + typedTime.setTime(Integer.parseInt(t.trim())); + } else if (offset.endsWith("h")) { + typedTime.setUnit("h"); + String t = offset.replace('h', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else if (offset.endsWith("m")) { + typedTime.setUnit("m"); + String t = offset.replace('m', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else { + typedTime.setUnit("s"); + if (offset.endsWith("s")) { + String t = offset.replace('s', ' '); + typedTime.setTime(Integer.parseInt(t.trim())); + } else + typedTime.setTime(Integer.parseInt(offset.trim())); + } + return typedTime; + } + + /** + * parse the Zone field string + * + * @return ZoneField + */ + public ZoneField zoneField() throws ParseException { + try { + ZoneField zoneField = new ZoneField(); + + this.lexer.match('z'); + this.lexer.SPorHT(); + this.lexer.match('='); + this.lexer.SPorHT(); + + // The zoneAdjustment list: + // Patch 117 + while (lexer.hasMoreChars()) { + char la = lexer.lookAhead(0); + if (la == '\n' || la == '\r') + break; + ZoneAdjustment zoneAdjustment = new ZoneAdjustment(); + + lexer.match(LexerCore.ID); + Token time = lexer.getNextToken(); + this.lexer.SPorHT(); + String timeValue = time.getTokenValue(); + if (timeValue.length() > 18) + timeValue = timeValue.substring(timeValue.length() - 18); + + zoneAdjustment.setTime(Long.parseLong(timeValue)); + + lexer.match(LexerCore.ID); + Token offset = lexer.getNextToken(); + this.lexer.SPorHT(); + String sign = getSign(offset.getTokenValue()); + TypedTime typedTime = getTypedTime(offset.getTokenValue()); + zoneAdjustment.setSign(sign); + zoneAdjustment.setOffset(typedTime); + + zoneField.addZoneAdjustment(zoneAdjustment); + } + + return zoneField; + } catch (Exception e) { + throw lexer.createParseException(); + } + } + + public SDPField parse() throws ParseException { + return this.zoneField(); + } + + /** + * public static void main(String[] args) throws ParseException { String + * zone[] = { "z=2882844526 -1h 2898848070 0\n", "z=2886 +1h 2898848070 10 + * 23423 -6s \n" }; + * + * for (int i = 0; i <zone.length; i++) { ZoneFieldParser + * zoneFieldParser=new ZoneFieldParser( zone[i] ); ZoneField + * zoneField=zoneFieldParser.zoneField(); System.out.println("encoded: " + * +zoneField.encode()); } + * } + */ + +} +/* + * $Log: ZoneFieldParser.java,v $ + * Revision 1.8 2009/07/17 18:57:18 emcho + * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. + * + * Revision 1.7 2007/07/12 15:39:52 mranga + * Issue number: 117 + * Obtained from: + * Submitted by: patrick_poglitsch (patrick_poglitsch) + * Reviewed by: mranga + * Revision 1.6 2006/11/16 19:05:44 pmusgrave + * Issue number: 82 - SDP with Origin/Time or Zone creater than 18 digits causes + * parse exception Obtained from: Submitted by: pmusgrave@newheights.com + * Reviewed by: CVS: + * ---------------------------------------------------------------------- CVS: + * Issue number: CVS: If this change addresses one or more issues, CVS: then + * enter the issue number(s) here. CVS: Obtained from: CVS: If this change has + * been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + * Revision 1.5 2006/08/23 00:00:22 mranga Issue number: Obtained from: + * Submitted by: Reviewed by: mranga + * + * javadoc fixups. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: CVS: If this change addresses one or more issues, CVS: + * then enter the issue number(s) here. CVS: Obtained from: CVS: If this change + * has been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + * Revision 1.4 2006/07/13 09:02:37 mranga Issue number: Obtained from: + * Submitted by: jeroen van bemmel Reviewed by: mranga Moved some changes from + * jain-sip-1.2 to java.net + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: CVS: If this change addresses one or more issues, CVS: + * then enter the issue number(s) here. CVS: Obtained from: CVS: If this change + * has been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + * Revision 1.3 2006/06/19 06:47:26 mranga javadoc fixups + * + * Revision 1.2 2006/06/16 15:26:28 mranga Added NIST disclaimer to all public + * domain files. Clean up some javadoc. Fixed a leak + * + * Revision 1.1.1.1 2005/10/04 17:12:34 mranga + * + * Import + * + * + * Revision 1.2 2004/01/22 13:26:28 sverker Issue number: Obtained from: + * Submitted by: sverker Reviewed by: mranga + * + * Major reformat of code to conform with style guide. Resolved compiler and + * javadoc warnings. Added CVS tags. + * + * CVS: ---------------------------------------------------------------------- + * CVS: Issue number: CVS: If this change addresses one or more issues, CVS: + * then enter the issue number(s) here. CVS: Obtained from: CVS: If this change + * has been taken from another system, CVS: then name the system in this line, + * otherwise delete it. CVS: Submitted by: CVS: If this code has been + * contributed to the project by someone else; i.e., CVS: they sent us a patch + * or a set of diffs, then include their name/email CVS: address here. If this + * is your work then delete this line. CVS: Reviewed by: CVS: If we are doing + * pre-commit code reviews and someone else has CVS: reviewed your changes, + * include their name(s) here. CVS: If you have not had it reviewed then delete + * this line. + * + */ |