From 6af47415f58dcbb8c7f17c96d47a7bbbc2e7cbb3 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 12:19:59 +0100 Subject: [PATCH] implement url provider for web user interface --- .../sonia/scm/url/UrlProviderFactory.java | 2 +- .../sonia/scm/url/WUIModelUrlProvider.java | 91 ++++++++ .../scm/url/WUIRepositoryUrlProvider.java | 196 ++++++++++++++++++ .../java/sonia/scm/url/WUIUrlBuilder.java | 118 +++++++++++ .../java/sonia/scm/url/WUIUrlProvider.java | 142 +++++++++++++ 5 files changed, 548 insertions(+), 1 deletion(-) create mode 100644 scm-core/src/main/java/sonia/scm/url/WUIModelUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/WUIRepositoryUrlProvider.java create mode 100644 scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java create mode 100644 scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java diff --git a/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java b/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java index fa45d6703e..4f245718b2 100644 --- a/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java +++ b/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java @@ -81,7 +81,7 @@ public class UrlProviderFactory } else if (TYPE_WUI.equals(type)) { - throw new UnsupportedOperationException("not yet implemented"); + provider = new WUIUrlProvider(baseUrl); } return provider; diff --git a/scm-core/src/main/java/sonia/scm/url/WUIModelUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/WUIModelUrlProvider.java new file mode 100644 index 0000000000..bef0ef3b68 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/WUIModelUrlProvider.java @@ -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; +} diff --git a/scm-core/src/main/java/sonia/scm/url/WUIRepositoryUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/WUIRepositoryUrlProvider.java new file mode 100644 index 0000000000..136d160186 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/WUIRepositoryUrlProvider.java @@ -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; +} diff --git a/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java b/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java new file mode 100644 index 0000000000..1fefbac529 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java @@ -0,0 +1,118 @@ +/** + * 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; + } + + 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; +} diff --git a/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java new file mode 100644 index 0000000000..06a44abc17 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java @@ -0,0 +1,142 @@ +/** + * 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_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 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; +}