From d202d2c0924a337df9042167d09c3d5260a3b680 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 11:51:50 +0100 Subject: [PATCH] added UrlProvider api --- .../java/sonia/scm/url/ModelUrlProvider.java | 58 +++++ .../sonia/scm/url/RepositoryUrlProvider.java | 117 ++++++++++ .../sonia/scm/url/RestModelUrlProvider.java | 97 ++++++++ .../scm/url/RestRepositoryUrlProvider.java | 209 ++++++++++++++++++ .../java/sonia/scm/url/RestUrlProvider.java | 149 +++++++++++++ .../main/java/sonia/scm/url/UrlProvider.java | 82 +++++++ .../sonia/scm/url/UrlProviderFactory.java | 89 ++++++++ 7 files changed, 801 insertions(+) create mode 100644 scm-core/src/main/java/sonia/scm/url/ModelUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/RepositoryUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/RestModelUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/UrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java diff --git a/scm-core/src/main/java/sonia/scm/url/ModelUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/ModelUrlProvider.java new file mode 100644 index 0000000000..ea60645d00 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/ModelUrlProvider.java @@ -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(); + +} diff --git a/scm-core/src/main/java/sonia/scm/url/RepositoryUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RepositoryUrlProvider.java new file mode 100644 index 0000000000..cb34869b96 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/RepositoryUrlProvider.java @@ -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); +} diff --git a/scm-core/src/main/java/sonia/scm/url/RestModelUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RestModelUrlProvider.java new file mode 100644 index 0000000000..3974135a53 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/RestModelUrlProvider.java @@ -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; +} diff --git a/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java new file mode 100644 index 0000000000..d0b2715ab9 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java @@ -0,0 +1,209 @@ +/** + * 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).append(extension).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).append(extension).appendParameter( + PARAMETER_REVISION, revision).toString(); + } +} diff --git a/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java new file mode 100644 index 0000000000..2fa008bea6 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java @@ -0,0 +1,149 @@ +/** + * 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_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); + } + + /** + * 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); + } + + /** + * 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; +} diff --git a/scm-core/src/main/java/sonia/scm/url/UrlProvider.java b/scm-core/src/main/java/sonia/scm/url/UrlProvider.java new file mode 100644 index 0000000000..ea8ad19c0f --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/UrlProvider.java @@ -0,0 +1,82 @@ +/** + * 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 ModelUrlProvider getGroupUrlProvider(); + + /** + * Method description + * + * + * @return + */ + public RepositoryUrlProvider getRepositoryUrlProvider(); + + /** + * Method description + * + * + * @return + */ + public String getStateUrl(); + + /** + * Method description + * + * + * @return + */ + public ModelUrlProvider getUserUrlProvider(); +} diff --git a/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java b/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java new file mode 100644 index 0000000000..fa45d6703e --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java @@ -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 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)) + { + throw new UnsupportedOperationException("not yet implemented"); + } + + return provider; + } +}