Given a uri that represents a XML qualified name, tries to determine the index of the split point between the namespace and the local name. - Android XML

Android examples for XML:QName

Description

Given a uri that represents a XML qualified name, tries to determine the index of the split point between the namespace and the local name.

Demo Code

/***************************************
 *            ViPER                    *
 *  The Video Processing               *
 *         Evaluation Resource         *
 *                                     *
 *  Distributed under the GPL license  *
 *        Terms available at gnu.org.  *
 *                                     *
 *  Copyright University of Maryland,  *
 *                      College Park.  *
 ***************************************/
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String uri = "java2s.com";
        System.out.println(getQNameSplitPoint(uri));
    }/* w  w  w  .  j a  v a 2 s  . co  m*/

    /**
     * Given a uri that represents a qualified name, tries to 
     * determine the index of the split point between the namespace
     * and the local name. Returns the last index of #, /, or :,
     * checking for each. If the string contains no :, it doesn't count 
     * as a uri and nothing is returned.
     * @param uri the uri
     * @return the split point, or -1 if not found
     */
    public static int getQNameSplitPoint(String uri) {
        int col = uri.indexOf(":");
        if (col < 0) {
            return -1;
        } else {
            int hash = uri.indexOf("#");
            if (hash < 0) {
                int slash = Math.max(uri.lastIndexOf("/"),
                        uri.lastIndexOf("\\"));
                if (slash > 0) {
                    return slash;
                } else {
                    return col;
                }
            } else {
                return hash;
            }
        }
    }
}

Related Tutorials