mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
merge with default branch
This commit is contained in:
@@ -59,6 +59,19 @@ public interface HttpClient
|
||||
*/
|
||||
public HttpResponse post(String url) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse post(HttpRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -87,6 +100,19 @@ public interface HttpClient
|
||||
*/
|
||||
public HttpResponse get(String url) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponse get(HttpRequest request) throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
264
scm-core/src/main/java/sonia/scm/net/HttpRequest.java
Normal file
264
scm-core/src/main/java/sonia/scm/net/HttpRequest.java
Normal file
@@ -0,0 +1,264 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.net;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.AssertUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.9
|
||||
*/
|
||||
public class HttpRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*/
|
||||
public HttpRequest(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param values
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HttpRequest addHeader(String name, String... values)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(name);
|
||||
|
||||
if (headers == null)
|
||||
{
|
||||
headers = new HashMap<String, List<String>>();
|
||||
}
|
||||
|
||||
appendValues(headers, name, values);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param values
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HttpRequest addParameters(String name, String... values)
|
||||
{
|
||||
AssertUtil.assertIsNotNull(name);
|
||||
|
||||
if (parameters == null)
|
||||
{
|
||||
parameters = new HashMap<String, List<String>>();
|
||||
}
|
||||
|
||||
appendValues(parameters, name, values);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, List<String>> getHeaders()
|
||||
{
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, List<String>> getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HttpRequest setBasicAuthentication(String username, String password)
|
||||
{
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param headers
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HttpRequest setHeaders(Map<String, List<String>> headers)
|
||||
{
|
||||
this.headers = headers;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param parameters
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HttpRequest setParameters(Map<String, List<String>> parameters)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param map
|
||||
* @param name
|
||||
* @param values
|
||||
*/
|
||||
private void appendValues(Map<String, List<String>> map, String name,
|
||||
String[] values)
|
||||
{
|
||||
List<String> valueList = map.get(name);
|
||||
|
||||
if (valueList == null)
|
||||
{
|
||||
valueList = new ArrayList<String>();
|
||||
map.put(name, valueList);
|
||||
}
|
||||
|
||||
if (values != null)
|
||||
{
|
||||
valueList.addAll(Arrays.asList(values));
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Map<String, List<String>> headers;
|
||||
|
||||
/** Field description */
|
||||
private Map<String, List<String>> parameters;
|
||||
|
||||
/** Field description */
|
||||
private String password;
|
||||
|
||||
/** Field description */
|
||||
private String url;
|
||||
|
||||
/** Field description */
|
||||
private String username;
|
||||
}
|
||||
58
scm-core/src/main/java/sonia/scm/url/ModelUrlProvider.java
Normal file
58
scm-core/src/main/java/sonia/scm/url/ModelUrlProvider.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
package sonia.scm.url;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface ModelUrlProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDetailUrl(String name);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAllUrl();
|
||||
|
||||
}
|
||||
117
scm-core/src/main/java/sonia/scm/url/RepositoryUrlProvider.java
Normal file
117
scm-core/src/main/java/sonia/scm/url/RepositoryUrlProvider.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface RepositoryUrlProvider extends ModelUrlProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getBlameUrl(String repositoryId, String path, String revision);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getBrowseUrl(String repositoryId, String path, String revision);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getChangesetUrl(String repositoryId, String path,
|
||||
String revision, int start, int limit);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getChangesetUrl(String repositoryId, int start, int limit);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getContentUrl(String repositoryId, String path,
|
||||
String revision);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDiffUrl(String repositoryId, String revision);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RestModelUrlProvider implements ModelUrlProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param modelSuffix
|
||||
* @param extension
|
||||
*/
|
||||
public RestModelUrlProvider(String baseUrl, String modelSuffix,
|
||||
String extension)
|
||||
{
|
||||
this.base = HttpUtil.append(baseUrl, modelSuffix);
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getAllUrl()
|
||||
{
|
||||
return base.concat(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getDetailUrl(String name)
|
||||
{
|
||||
return HttpUtil.append(base, name).concat(extension);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected String base;
|
||||
|
||||
/** Field description */
|
||||
protected String extension;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.UrlBuilder;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RestRepositoryUrlProvider extends RestModelUrlProvider
|
||||
implements RepositoryUrlProvider
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PARAMETER_LIMIT = "limit";
|
||||
|
||||
/** Field description */
|
||||
public static final String PARAMETER_PATH = "path";
|
||||
|
||||
/** Field description */
|
||||
public static final String PARAMETER_REVISION = "revision";
|
||||
|
||||
/** Field description */
|
||||
public static final String PARAMETER_START = "start";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_BLAME = "blame";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_BROWSE = "browse";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_CHANGESETS = "changesets";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_CONTENT = "content";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_DIFF = "diff";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param modelSuffix
|
||||
* @param extension
|
||||
*/
|
||||
public RestRepositoryUrlProvider(String baseUrl, String modelSuffix,
|
||||
String extension)
|
||||
{
|
||||
super(baseUrl, modelSuffix, extension);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getBlameUrl(String repositoryId, String path, String revision)
|
||||
{
|
||||
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
|
||||
PART_BLAME).append(extension).appendParameter(
|
||||
PARAMETER_PATH, path).appendParameter(
|
||||
PARAMETER_REVISION, revision).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getBrowseUrl(String repositoryId, String path, String revision)
|
||||
{
|
||||
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
|
||||
PART_BROWSE).append(extension).appendParameter(
|
||||
PARAMETER_PATH, path).appendParameter(
|
||||
PARAMETER_REVISION, revision).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getChangesetUrl(String repositoryId, String path,
|
||||
String revision, int start, int limit)
|
||||
{
|
||||
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
|
||||
PART_CHANGESETS).append(extension).appendParameter(
|
||||
PARAMETER_PATH, path).appendParameter(
|
||||
PARAMETER_REVISION, revision).appendParameter(
|
||||
PARAMETER_START, start).appendParameter(
|
||||
PARAMETER_LIMIT, limit).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getChangesetUrl(String repositoryId, int start, int limit)
|
||||
{
|
||||
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
|
||||
PART_CHANGESETS).append(extension).appendParameter(
|
||||
PARAMETER_START, start).appendParameter(
|
||||
PARAMETER_LIMIT, limit).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getContentUrl(String repositoryId, String path, String revision)
|
||||
{
|
||||
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
|
||||
PART_CONTENT).appendParameter(PARAMETER_PATH, path).appendParameter(
|
||||
PARAMETER_REVISION, revision).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getDiffUrl(String repositoryId, String revision)
|
||||
{
|
||||
return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart(
|
||||
PART_DIFF).appendParameter(PARAMETER_REVISION, revision).toString();
|
||||
}
|
||||
}
|
||||
164
scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java
Normal file
164
scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class RestUrlProvider implements UrlProvider
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_API = "api/rest/";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_AUTHENTICATION = "authentication/login";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_CONFIG = "config";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_GROUP = "groups";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_REPOSITORIES = "repositories";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_STATE = "authentication";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_USER = "users";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param extension
|
||||
*/
|
||||
public RestUrlProvider(String baseUrl, String extension)
|
||||
{
|
||||
this.baseUrl = HttpUtil.append(baseUrl, PART_API);
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getAuthenticationUrl()
|
||||
{
|
||||
return HttpUtil.append(baseUrl, PART_AUTHENTICATION).concat(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getConfigUrl()
|
||||
{
|
||||
return HttpUtil.append(baseUrl, PART_CONFIG).concat(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ModelUrlProvider getGroupUrlProvider()
|
||||
{
|
||||
return new RestModelUrlProvider(baseUrl, PART_GROUP, extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public RepositoryUrlProvider getRepositoryUrlProvider()
|
||||
{
|
||||
return new RestRepositoryUrlProvider(baseUrl, PART_REPOSITORIES, extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getStateUrl()
|
||||
{
|
||||
return HttpUtil.append(baseUrl, PART_STATE).concat(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ModelUrlProvider getUserUrlProvider()
|
||||
{
|
||||
return new RestModelUrlProvider(baseUrl, PART_USER, extension);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected String baseUrl;
|
||||
|
||||
/** Field description */
|
||||
protected String extension;
|
||||
}
|
||||
90
scm-core/src/main/java/sonia/scm/url/UrlProvider.java
Normal file
90
scm-core/src/main/java/sonia/scm/url/UrlProvider.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface UrlProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAuthenticationUrl();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getConfigUrl();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ModelUrlProvider getGroupUrlProvider();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public RepositoryUrlProvider getRepositoryUrlProvider();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getStateUrl();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ModelUrlProvider getUserUrlProvider();
|
||||
}
|
||||
89
scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java
Normal file
89
scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class UrlProviderFactory
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_RESTAPI_JSON = "json-rest-api";
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_RESTAPI_XML = "xml-rest-api";
|
||||
|
||||
/** Field description */
|
||||
public static final String TYPE_WUI = "wui";
|
||||
|
||||
/** Field description */
|
||||
private static final String EXTENSION_JSON = ".json";
|
||||
|
||||
/** Field description */
|
||||
private static final String EXTENSION_XML = ".xml";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param type
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static UrlProvider createUrlProvider(String baseUrl, String type)
|
||||
{
|
||||
UrlProvider provider = null;
|
||||
|
||||
if (TYPE_RESTAPI_JSON.equals(type))
|
||||
{
|
||||
provider = new RestUrlProvider(baseUrl, EXTENSION_JSON);
|
||||
}
|
||||
else if (TYPE_RESTAPI_XML.equals(type))
|
||||
{
|
||||
provider = new RestUrlProvider(baseUrl, EXTENSION_XML);
|
||||
}
|
||||
else if (TYPE_WUI.equals(type))
|
||||
{
|
||||
provider = new WUIUrlProvider(baseUrl);
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class WUIModelUrlProvider implements ModelUrlProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param component
|
||||
*/
|
||||
public WUIModelUrlProvider(String baseUrl, String component)
|
||||
{
|
||||
this.url = HttpUtil.appendHash(baseUrl, component);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getAllUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getDetailUrl(String name)
|
||||
{
|
||||
return url.concat(WUIUrlBuilder.SEPARATOR).concat(name);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String url;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class WUIRepositoryUrlProvider extends WUIModelUrlProvider
|
||||
implements RepositoryUrlProvider
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_BROWSER = "repositoryBrowser";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_CHANGESETS =
|
||||
"repositoryChangesetViewerPanel";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_CONTENT = "contentPanel";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_DIFF = "diffPanel";
|
||||
|
||||
/** Field description */
|
||||
public static final String VIEW_BLAME = "blame";
|
||||
|
||||
/** Field description */
|
||||
public static final String VIEW_CONTENT = "content";
|
||||
|
||||
/** Field description */
|
||||
public static final String VIEW_HISTORY = "history";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param component
|
||||
*/
|
||||
public WUIRepositoryUrlProvider(String baseUrl, String component)
|
||||
{
|
||||
super(baseUrl, component);
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getBlameUrl(String repositoryId, String path, String revision)
|
||||
{
|
||||
return new WUIUrlBuilder(baseUrl, COMPONENT_CONTENT).append(
|
||||
repositoryId).append(revision).append(path).append(
|
||||
VIEW_BLAME).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getBrowseUrl(String repositoryId, String path, String revision)
|
||||
{
|
||||
return new WUIUrlBuilder(baseUrl, COMPONENT_BROWSER).append(
|
||||
repositoryId).append(revision).append(path).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getChangesetUrl(String repositoryId, String path,
|
||||
String revision, int start, int limit)
|
||||
{
|
||||
|
||||
// TODO handle start and limit
|
||||
return new WUIUrlBuilder(baseUrl, COMPONENT_CONTENT).append(
|
||||
repositoryId).append(revision).append(path).append(
|
||||
VIEW_HISTORY).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param start
|
||||
* @param limit
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getChangesetUrl(String repositoryId, int start, int limit)
|
||||
{
|
||||
return new WUIUrlBuilder(baseUrl, COMPONENT_CHANGESETS).append(
|
||||
repositoryId).append(start).append(limit).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getContentUrl(String repositoryId, String path, String revision)
|
||||
{
|
||||
return new WUIUrlBuilder(baseUrl, COMPONENT_CONTENT).append(
|
||||
repositoryId).append(revision).append(path).append(
|
||||
VIEW_HISTORY).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getDiffUrl(String repositoryId, String revision)
|
||||
{
|
||||
return new WUIUrlBuilder(baseUrl, COMPONENT_DIFF).append(
|
||||
repositoryId).append(revision).toString();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String baseUrl;
|
||||
}
|
||||
123
scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java
Normal file
123
scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class WUIUrlBuilder
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String NULL = "null";
|
||||
|
||||
/** Field description */
|
||||
public static final String SEPARATOR = ";";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
* @param component
|
||||
*/
|
||||
public WUIUrlBuilder(String baseUrl, String component)
|
||||
{
|
||||
this.url = HttpUtil.appendHash(baseUrl, component);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WUIUrlBuilder append(String value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
if (!this.url.endsWith(SEPARATOR))
|
||||
{
|
||||
this.url = this.url.concat(SEPARATOR);
|
||||
}
|
||||
|
||||
this.url = this.url.concat(value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WUIUrlBuilder append(int value)
|
||||
{
|
||||
return append(String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String url;
|
||||
}
|
||||
157
scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java
Normal file
157
scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.url;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class WUIUrlProvider implements UrlProvider
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_CONFIG = "scmConfig";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_GROUP = "groupPanel";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_REPOSITORY = "repositoryPanel";
|
||||
|
||||
/** Field description */
|
||||
public static final String COMPONENT_USER = "userPanel";
|
||||
|
||||
/** Field description */
|
||||
public static final String PART_INDEX = "index.html";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
*/
|
||||
public WUIUrlProvider(String baseUrl)
|
||||
{
|
||||
this.baseUrl = HttpUtil.append(baseUrl, PART_INDEX);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getAuthenticationUrl()
|
||||
{
|
||||
|
||||
// ???
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getConfigUrl()
|
||||
{
|
||||
return HttpUtil.appendHash(baseUrl, COMPONENT_CONFIG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ModelUrlProvider getGroupUrlProvider()
|
||||
{
|
||||
return new WUIModelUrlProvider(baseUrl, COMPONENT_GROUP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public RepositoryUrlProvider getRepositoryUrlProvider()
|
||||
{
|
||||
return new WUIRepositoryUrlProvider(baseUrl, COMPONENT_REPOSITORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getStateUrl()
|
||||
{
|
||||
|
||||
// ???
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ModelUrlProvider getUserUrlProvider()
|
||||
{
|
||||
return new WUIModelUrlProvider(baseUrl, COMPONENT_USER);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String baseUrl;
|
||||
}
|
||||
@@ -92,6 +92,30 @@ public class HttpUtil
|
||||
*/
|
||||
public static final String SCHEME_HTTPS = "https";
|
||||
|
||||
/**
|
||||
* Url hash separator
|
||||
* @since 1.9
|
||||
*/
|
||||
public static final String SEPARATOR_HASH = "#";
|
||||
|
||||
/**
|
||||
* Url parameter separator
|
||||
* @since 1.9
|
||||
*/
|
||||
public static final String SEPARATOR_PARAMETER = "&";
|
||||
|
||||
/**
|
||||
* Url parameters separator
|
||||
* @since 1.9
|
||||
*/
|
||||
public static final String SEPARATOR_PARAMETERS = "?";
|
||||
|
||||
/**
|
||||
* Url parameter value separator
|
||||
* @since 1.9
|
||||
*/
|
||||
public static final String SEPARATOR_PARAMETER_VALUE = "=";
|
||||
|
||||
/**
|
||||
* Url folder separator
|
||||
* @since 1.5
|
||||
@@ -119,6 +143,69 @@ public class HttpUtil
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param uri
|
||||
* @param suffix
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
public static String append(String uri, String suffix)
|
||||
{
|
||||
if (!uri.endsWith(SEPARATOR_PATH))
|
||||
{
|
||||
uri = uri.concat(SEPARATOR_PATH);
|
||||
}
|
||||
|
||||
return uri.concat(suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param uri
|
||||
* @param hash
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
public static String appendHash(String uri, String hash)
|
||||
{
|
||||
return uri.concat(SEPARATOR_HASH).concat(hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param uri
|
||||
* @param name
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
* @since 1.9
|
||||
*/
|
||||
public static String appendParameter(String uri, String name, String value)
|
||||
{
|
||||
String s = null;
|
||||
|
||||
if (uri.contains(SEPARATOR_PARAMETERS))
|
||||
{
|
||||
s = SEPARATOR_PARAMETERS;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SEPARATOR_PARAMETER;
|
||||
}
|
||||
|
||||
return new StringBuilder(uri).append(s).append(name).append(
|
||||
SEPARATOR_PARAMETER_VALUE).append(value).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
208
scm-core/src/main/java/sonia/scm/util/UrlBuilder.java
Normal file
208
scm-core/src/main/java/sonia/scm/util/UrlBuilder.java
Normal file
@@ -0,0 +1,208 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @since 1.9
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class UrlBuilder
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param baseUrl
|
||||
*/
|
||||
public UrlBuilder(String baseUrl)
|
||||
{
|
||||
this.url = baseUrl;
|
||||
|
||||
if (baseUrl.contains(HttpUtil.SEPARATOR_PARAMETERS))
|
||||
{
|
||||
separator = HttpUtil.SEPARATOR_PARAMETER;
|
||||
}
|
||||
else
|
||||
{
|
||||
separator = HttpUtil.SEPARATOR_PARAMETERS;
|
||||
}
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param part
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UrlBuilder append(String part)
|
||||
{
|
||||
url = url.concat(part);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UrlBuilder appendParameter(String name, boolean value)
|
||||
{
|
||||
return appendParameter(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UrlBuilder appendParameter(String name, int value)
|
||||
{
|
||||
return appendParameter(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UrlBuilder appendParameter(String name, long value)
|
||||
{
|
||||
return appendParameter(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UrlBuilder appendParameter(String name, String value)
|
||||
{
|
||||
if (Util.isNotEmpty(name) && Util.isNotEmpty(value))
|
||||
{
|
||||
url = new StringBuilder(url).append(separator).append(name).append(
|
||||
HttpUtil.SEPARATOR_PARAMETER_VALUE).append(value).toString();
|
||||
parameterAdded = true;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param part
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public UrlBuilder appendUrlPart(String part)
|
||||
{
|
||||
if (parameterAdded)
|
||||
{
|
||||
throw new IllegalStateException("parameter added");
|
||||
}
|
||||
|
||||
url = HttpUtil.append(url, part);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public URL toURL()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new URL(url);
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private boolean parameterAdded = false;
|
||||
|
||||
/** Field description */
|
||||
private String separator;
|
||||
|
||||
/** Field description */
|
||||
private String url;
|
||||
}
|
||||
Reference in New Issue
Block a user