Java Json String Create toJsonUrl(String pUrl)

Here you can find the source of toJsonUrl(String pUrl)

Description

to Json Url

License

Open Source License

Declaration

private static String toJsonUrl(String pUrl) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2009, 2010, Hoccer GmbH Berlin, Germany <www.hoccer.com>
 * //from   ww w  .  j  a  v a 2  s.  c  o  m
 * These coded instructions, statements, and computer programs contain
 * proprietary information of Hoccer GmbH Berlin, and are copy protected
 * by law. They may be used, modified and redistributed under the terms
 * of GNU General Public License referenced below. 
 *    
 * Alternative licensing without the obligations of the GPL is
 * available upon request.
 * 
 * GPL v3 Licensing:
 * 
 * This file is part of the "Linccer Java-API".
 * 
 * Linccer Java-API is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Linccer Java-API is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Linccer Java-API. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

public class Main {
    private static String toJsonUrl(String pUrl) {

        if (pUrl.endsWith(".xml")) {
            // an xml uri means that someone is using this method in a wrong way
            // --> fail fast
            throw new IllegalArgumentException("HttpHelper was passed a Uri which explicitly "
                    + "asked for a different format: '" + pUrl + "'!");
        }

        // remove trailing slashes
        if (pUrl.endsWith("/")) {

            pUrl = pUrl.substring(0, pUrl.length() - 1);
        }

        // gracefully accept format-agnostic Uris
        if (!pUrl.endsWith(".json")) {
            pUrl = pUrl + ".json";
        }

        return pUrl;
    }
}

Related

  1. toJson(String str)
  2. toJSON(String string)
  3. toJsonArrays(String... strings)
  4. toJsonField(String name, String value)
  5. toJsonName(String name, int prefixLen)
  6. toJSONValue(Enum e)
  7. write2Json(String json, String path, String name)