Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;
import java.util.Map;

import java.util.StringTokenizer;

public class Main {
    /**
     * Build schema location map of schemas used in given
     * <code>schemaLocationAttribute</code>.
     * 
     * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema
     *      Part 0: Primer Second Edition | 5.6 schemaLocation</a>
     * 
     * @param schemaLocation
     *          attribute value to build schema location map from.
     * @return {@link Map} of schema namespace URIs to location URLs.
     * @since 8.1
     */
    public static final Map<String, List<String>> buildSchemaLocationMap(final String schemaLocation) {
        return buildSchemaLocationMap(new HashMap<String, List<String>>(), schemaLocation);
    }

    /**
     * Build schema location map of schemas used in given
     * <code>schemaLocationAttribute</code> and adds them to the given
     * <code>schemaLocationMap</code>.
     * 
     * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema
     *      Part 0: Primer Second Edition | 5.6 schemaLocation</a>
     * 
     * @param schemaLocationMap
     *          {@link Map} to add schema locations to.
     * @param schemaLocation
     *          attribute value to build schema location map from.
     * @return {@link Map} of schema namespace URIs to location URLs.
     * @since 8.1
     */
    static final Map<String, List<String>> buildSchemaLocationMap(Map<String, List<String>> schemaLocationMap,
            final String schemaLocation) {
        if (null == schemaLocation) {
            return schemaLocationMap;
        }

        if (null == schemaLocation || schemaLocation.isEmpty()) {
            // should really ever be null but being safe.
            return schemaLocationMap;
        }

        final StringTokenizer st = new StringTokenizer(schemaLocation, " \n\t\r");
        while (st.hasMoreElements()) {
            final String ns = st.nextToken();
            final String loc = st.nextToken();
            List<String> locs = schemaLocationMap.get(ns);
            if (null == locs) {
                locs = new ArrayList<>();
                schemaLocationMap.put(ns, locs);
            }
            if (!locs.contains(loc)) {
                locs.add(loc);
            }
        }

        return schemaLocationMap;
    }
}