mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
added repository browser client api
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* 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.client;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.8
|
||||
*/
|
||||
public interface ClientRepositoryBrowser
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getContent(String revision, String path)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
* @param path
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<FileObjectWrapper> getFiles(String revision, String path);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param revision
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<FileObjectWrapper> getFiles(String revision);
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* 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.client;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.FileObject;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.8
|
||||
*/
|
||||
public class FileObjectWrapper
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param repositoryBrowser
|
||||
* @param revision
|
||||
* @param file
|
||||
*/
|
||||
public FileObjectWrapper(ClientRepositoryBrowser repositoryBrowser,
|
||||
String revision, FileObject file)
|
||||
{
|
||||
this.repositoryBrowser = repositoryBrowser;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<FileObjectWrapper> getChildren()
|
||||
{
|
||||
List<FileObjectWrapper> children = null;
|
||||
|
||||
if (isDirectory())
|
||||
{
|
||||
children = repositoryBrowser.getFiles(revision, getPath());
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getContent() throws IOException
|
||||
{
|
||||
return repositoryBrowser.getContent(revision, getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return file.getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Long getLastModified()
|
||||
{
|
||||
return file.getLastModified();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getLength()
|
||||
{
|
||||
return file.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isDirectory()
|
||||
{
|
||||
return file.isDirectory();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private FileObject file;
|
||||
|
||||
/** Field description */
|
||||
private ClientRepositoryBrowser repositoryBrowser;
|
||||
|
||||
/** Field description */
|
||||
private String revision;
|
||||
}
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.client;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.NotSupportedFeatuerException;
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
@@ -49,6 +50,20 @@ import java.util.Collection;
|
||||
public interface RepositoryClientHandler extends ClientHandler<Repository>
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repository
|
||||
*
|
||||
* @return
|
||||
* @since 1.8
|
||||
*
|
||||
* @throws NotSupportedFeatuerException
|
||||
*/
|
||||
public ClientRepositoryBrowser getRepositoryBrowser(Repository repository)
|
||||
throws NotSupportedFeatuerException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -38,6 +38,12 @@ package sonia.scm.client;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -73,6 +79,12 @@ public class ScmUrlProvider
|
||||
/** Field description */
|
||||
public static final String URLPART_USERS = "users";
|
||||
|
||||
/** Field description */
|
||||
public static final String URLPATTERN_BROWSE = "repositories/{0}/browse";
|
||||
|
||||
/** Field description */
|
||||
public static final String URLPATTERN_CONTENT = "repositories/{0}/content";
|
||||
|
||||
/** the logger for classVar */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(ScmUrlProvider.class);
|
||||
@@ -183,6 +195,65 @@ public class ScmUrlProvider
|
||||
return getResourceUrl(URLPART_REPOSITORIES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param revision
|
||||
* @param path
|
||||
* @since 1.8
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getRepositoryBrowseUrl(String repositoryId, String path,
|
||||
String revision)
|
||||
{
|
||||
String url = MessageFormat.format(getResourceUrl(URLPATTERN_BROWSE),
|
||||
repositoryId);
|
||||
String s = "?";
|
||||
|
||||
if (Util.isNotEmpty(path))
|
||||
{
|
||||
url = url.concat(s).concat("path=").concat(path);
|
||||
s = "&";
|
||||
}
|
||||
|
||||
if (Util.isNotEmpty(revision))
|
||||
{
|
||||
url = url.concat(s).concat("revision=").concat(revision);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
* @param path
|
||||
* @param revision
|
||||
* @since 1.8
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getRepositoryContentUrl(String repositoryId, String path,
|
||||
String revision)
|
||||
{
|
||||
String url = MessageFormat.format(getResourceUrl(URLPATTERN_CONTENT,
|
||||
false), repositoryId);
|
||||
|
||||
url = url.concat("?path=").concat(path);
|
||||
|
||||
if (Util.isNotEmpty(revision))
|
||||
{
|
||||
url = url.concat("&revision=").concat(revision);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -206,7 +277,27 @@ public class ScmUrlProvider
|
||||
*/
|
||||
public String getResourceUrl(String urlPart)
|
||||
{
|
||||
String resourceUrl = baseUrl.concat(urlPart).concat(extension);
|
||||
return getResourceUrl(urlPart, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param urlPart
|
||||
* @param appendExtension
|
||||
* @since 1.8
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getResourceUrl(String urlPart, boolean appendExtension)
|
||||
{
|
||||
String resourceUrl = baseUrl.concat(urlPart);
|
||||
|
||||
if (appendExtension)
|
||||
{
|
||||
resourceUrl = resourceUrl.concat(extension);
|
||||
}
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user