Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Parses href and obtains plugin id
     * 
     * @param href
     *            String in format /string1[/string2]
     * @return plugin ID, or null
     */
    public static String getPluginIDFromHref(String href) {
        if (href == null || href.length() < 2 || href.charAt(0) != '/')
            return null;
        int secondSlashIx = href.indexOf("/", 1); //$NON-NLS-1$
        if (secondSlashIx < 0) // href is /pluginID
            return href.substring(1);
        // href is /pluginID/path[#anchorID]
        return href.substring(1, secondSlashIx);
    }
}