/* * This file was derived from libdissipate, an open source SIP library. The original file * was modified on 1/23/2001. Please see * http://www.div8.net/dissipate for more information. * * Copyright (c) 2000 Billy Biggs * * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public * License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * */ /** * class MimeContentType * * This code has been generated using C2J++ * C2J++ is based on Chris Laffra's C2J (laffra@watson.ibm.com) * Read general disclaimer distributed with C2J++ before using this code * For information about C2J++, send mail to Ilya_Tilevich@ibi.com */ package org.mitre.jsip; import java.util.Hashtable; import java.util.Enumeration; public class MimeContentType { /** * MimeContentType */ public MimeContentType() { } /** * MimeContentType * @param initialtype * @param initialsubtype */ public MimeContentType(String initialtype, String initialsubtype) { m_type = initialtype; m_subtype = initialsubtype; } /** * MimeContentType * @param parseinput */ public MimeContentType(String parseinput) { parseContentType( parseinput ); } /** * getType * @return QString */ public String getType() { return m_type; } /** * getSubType * @return QString */ public String getSubType() { return m_subtype; } /** * setType * @param newtype */ public void setType(String newtype) { m_type = newtype.toLowerCase(); } /** * setSubType * @param newsubtype */ public void setSubType(String newsubtype) { m_subtype = newsubtype.toLowerCase(); } /** * setParameter * @param param * @param value */ public void setParameter(String param, String value) { parameters.put( param, value ); } /** * queryParameter * @param param * @return QString */ public String queryParameter(String param) { return (String)parameters.get(param); } /** * parseContentType * @param parseinput */ public void parseContentType(String parseinput) { String inputline; String curparam; String attr; String val; inputline = parseinput.trim(); setType( inputline.substring( 0, inputline.indexOf( "/" ) ).trim().toLowerCase() ); inputline = inputline.substring( inputline.indexOf( "/" ) + 1 ); if ( inputline.indexOf( ";" ) >= 0 ) { setSubType( inputline.substring( 0, inputline.indexOf( ";" ) ).trim().toLowerCase() ); inputline = inputline.substring( inputline.indexOf( ";" ) + 1 ); } else { setSubType( inputline.trim() ); inputline = ""; // *** LOOK AT *** } while ( inputline.startsWith(";") ) { curparam = inputline.substring( 1, inputline.indexOf( ";", 1 ) ).trim(); inputline = inputline.substring( inputline.indexOf( ";", 1 ) ); if ( curparam.indexOf( "=" ) > 0 ) { attr = curparam.substring( 0, curparam.indexOf( "=" ) ).trim(); val = curparam.substring( curparam.indexOf( "=" ) + 1 ).trim(); parameters.put( attr, val ); } else { parameters.put( curparam.trim(), null ); } } } /** * type * @return QString */ public String type() { String ctype; ctype = getType() + "/" + getSubType(); for (Enumeration e = parameters.keys(); e.hasMoreElements();) { String keyval = (String)e.nextElement(); ctype += ";" + keyval + (String)parameters.get(keyval); } return ctype; } /** * test method */ public static void main(String[] args) { // takes a mime-type as the argument MimeContentType mct = new MimeContentType(args[0]); System.out.println("the type is " + mct.getType()); System.out.println("the subtype is " + mct.getSubType()); System.out.println("together they make " + mct.type()); System.out.println("if I were to replace the subtype with steveapp, I get:"); mct.setSubType("steveapp"); System.out.println(mct.type()); System.exit(0); } // class variables private String m_type; private String m_subtype; private Hashtable parameters = new Hashtable(); }