PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Java|javax|print|MimeType.java =

page 6 of 7



	    }
	    result.append (c);
	}
	result.append ('\"');
	return result.toString();
    }

    /**
     * Parses the given string into canonical pieces and stores the pieces in
     * {@link #myPieces <CODE>myPieces</CODE>}.
     * <P>
     * Special rules applied:
     * <UL>
     * <LI> If the media type is text, the value of a charset parameter is
     *      converted to lowercase.
     * </UL>
     *
     * @param  s  MIME media type string.
     *
     * @exception  NullPointerException
     *     (unchecked exception) Thrown if <CODE>s</CODE> is null. 
     * @exception  IllegalArgumentException
     *     (unchecked exception) Thrown if <CODE>s</CODE> does not obey the 
     *     syntax for a MIME media type string. 
     */
    private void parse(String s) {
	// Initialize.
	if (s == null) {
	    throw new NullPointerException();
	}
	LexicalAnalyzer theLexer = new LexicalAnalyzer (s);
	int theLexemeType;
	Vector thePieces = new Vector();
	boolean mediaTypeIsText = false;
	boolean parameterNameIsCharset = false;

	// Parse media type.
	if (theLexer.getLexemeType() == TOKEN_LEXEME) {
	    String mt = toUnicodeLowerCase (theLexer.getLexeme());
	    thePieces.add (mt);
	    theLexer.nextLexeme();
	    mediaTypeIsText = mt.equals ("text");
	} else {
	    throw new IllegalArgumentException();
	}
	// Parse slash.
	if (theLexer.getLexemeType() == TSPECIAL_LEXEME &&
	      theLexer.getLexemeFirstCharacter() == '/') {
	    theLexer.nextLexeme();
	} else {
	    throw new IllegalArgumentException();
	}
	if (theLexer.getLexemeType() == TOKEN_LEXEME) {
	    thePieces.add (toUnicodeLowerCase (theLexer.getLexeme()));
	    theLexer.nextLexeme();
	} else {
	    throw new IllegalArgumentException();
	}
	// Parse zero or more parameters.
	while (theLexer.getLexemeType() == TSPECIAL_LEXEME &&
	       theLexer.getLexemeFirstCharacter() == ';') {
	    // Parse semicolon.
	    theLexer.nextLexeme();

	    // Parse parameter name.
	    if (theLexer.getLexemeType() == TOKEN_LEXEME) {
		String pn = toUnicodeLowerCase (theLexer.getLexeme());
		thePieces.add (pn);
		theLexer.nextLexeme();
		parameterNameIsCharset = pn.equals ("charset");
	    } else {
		throw new IllegalArgumentException();
	    }
	    
	    // Parse equals.
	    if (theLexer.getLexemeType() == TSPECIAL_LEXEME &&
		theLexer.getLexemeFirstCharacter() == '=') {
		theLexer.nextLexeme();
	    } else {
		throw new IllegalArgumentException();
	    }

	    // Parse parameter value.
	    if (theLexer.getLexemeType() == TOKEN_LEXEME) {
		String pv = theLexer.getLexeme();
		thePieces.add(mediaTypeIsText && parameterNameIsCharset ?
			      toUnicodeLowerCase (pv) :
			      pv);
		theLexer.nextLexeme();
	    } else if (theLexer.getLexemeType() == QUOTED_STRING_LEXEME) {
		String pv = removeBackslashes (theLexer.getLexeme());
		thePieces.add(mediaTypeIsText && parameterNameIsCharset ?
			      toUnicodeLowerCase (pv) :
			      pv);
		theLexer.nextLexeme();
	    } else {
		throw new IllegalArgumentException();
	    }
	}

=6=

1|2|3|4|5| < PREV = PAGE 6 = NEXT > |7

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.0109711 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)