集册 Java实例教程 遍历给定的acceptedContentTypes,查找以下值之一:text / html application / xhtml + xml application / xml

遍历给定的acceptedContentTypes,查找以下值之一:text / html application / xhtml + xml application / xml

欢马劈雪     最近更新时间:2020-01-02 10:19:05

703
遍历给定的acceptedContentTypes,查找以下值之一:text / html application / xhtml + xml application / xml

/******************************************************************************* 

 * Copyright (c) 2008 Red Hat, Inc. 

 * Distributed under license by Red Hat, Inc. All rights reserved. 

 * This program is made available under the terms of the 

 * Eclipse Public License v1.0 which accompanies this distribution, 

 * and is available at http://www.eclipse.org/legal/epl-v10.html 

 * 

 * Contributors: 

 * Xavier Coulon - Initial API and implementation 

 ******************************************************************************/
 /*
 n o w j a v a . c o m 提 供
 */

//package com.nowjava;


import java.util.StringTokenizer;


public class Main {

    /**

     * <p>

     * Iterates over the given acceptedContentTypes, looking for one of those

     * values:

     * <ul>

     * <li>text/html</li>

     * <li>application/xhtml+xml</li>

     * <li>application/xml</li>

     * </ul>

     * </p>

     * 

     * @param acceptedContentTypes

     * @return true if one of the values above was found, false otherwise

     */

    public static boolean isHtmlContentType(

            final String acceptedContentTypes) {

        if (acceptedContentTypes == null) {

            return false;

        }

        // first, let's remove everything behind the comma character

        int location = acceptedContentTypes.indexOf(";");

        final String contentTypes = (location != -1) ? acceptedContentTypes

                .substring(0, location) : acceptedContentTypes;

        // now, let's analyze each type/*来 自 NowJava.com*/

        final StringTokenizer tokenizer = new StringTokenizer(contentTypes,

                ",");

        while (tokenizer.hasMoreElements()) {

            final String acceptedContentType = tokenizer.nextToken();
展开阅读全文