From adc047692123f24d9928bcd7bf1370ffe8eea791 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 16:31:36 +0100 Subject: [PATCH 01/36] fix history panel selection --- .../src/main/webapp/resources/js/group/sonia.group.panel.js | 2 ++ .../webapp/resources/js/repository/sonia.repository.panel.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js index a3e840db3c..2370956fc5 100644 --- a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js @@ -186,6 +186,8 @@ Sonia.History.register('groupPanel', { if ( ! panel ){ main.addGroupsTabPanel(); panel = Ext.getCmp('groups'); + } else { + main.addTab(panel); } if (repoId){ panel.getGrid().selectById(repoId); diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index 28be95d035..ddd0bd9c46 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -295,6 +295,8 @@ Sonia.History.register('repositoryPanel', { if ( ! panel ){ main.addRepositoriesTabPanel(); panel = Ext.getCmp('repositories'); + } else { + main.addTab(panel); } if (repoId){ panel.getGrid().selectById(repoId); From 1ec8771064e01b22db52c5017871d05d0f695a9d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 16:39:10 +0100 Subject: [PATCH 02/36] added history functions for user panel --- .../resources/js/user/sonia.user.grid.js | 7 +++ .../resources/js/user/sonia.user.panel.js | 47 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js index 69f78adb84..506d0d60a7 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js @@ -40,6 +40,9 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { colCreationDateText: 'Creation Date', colLastModifiedText: 'Last modified', colTypeText: 'Type', + + // parent for history + parentPanel: null, initComponent: function(){ @@ -85,6 +88,10 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.user.Grid.superclass.initComponent.apply(this, arguments); + + if (this.parentPanel){ + this.parentPanel.userGrid = this; + } }, onFallBelowMinHeight: function(height, minHeight){ diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js index 5716792c32..3af0e05f57 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js @@ -37,6 +37,9 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { removeMsgText: 'Remove User "{0}"?', errorTitleText: 'Error', errorMsgText: 'User deletion failed', + + // userGrid for history + userGrid: null, initComponent: function(){ @@ -51,7 +54,8 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { items: [{ id: 'userGrid', xtype: 'userGrid', - region: 'center' + region: 'center', + parentPanel: this },{ id: 'userEditPanel', layout: 'fit', @@ -72,6 +76,16 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.user.Panel.superclass.initComponent.apply(this, arguments); }, + + getGrid: function(){ + if (!this.userGrid){ + if (debug){ + console.debug('userGrid not found retrvie by id'); + } + this.userGrid = Ext.getCmp('userGrid'); + } + return this.userGrid; + }, showAddPanel: function(){ var editPanel = Ext.getCmp('userEditPanel'); @@ -99,7 +113,7 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { removeUser: function(){ - var grid = Ext.getCmp('userGrid'); + var grid = this.getGrid(); var selected = grid.getSelectionModel().getSelected(); if ( selected ){ var item = selected.data; @@ -153,3 +167,32 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { // register xtype Ext.reg('userPanel', Sonia.user.Panel); + + +// register history handler +Sonia.History.register('userPanel', { + + onActivate: function(panel){ + var token = null; + var rec = panel.getGrid().getSelectionModel().getSelected(); + if (rec){ + token = Sonia.History.createToken('userPanel', rec.get('name')); + } else { + token = Sonia.History.createToken('userPanel'); + } + return token; + }, + + onChange: function(userId){ + var panel = Ext.getCmp('users'); + if ( ! panel ){ + main.addUsersTabPanel(); + panel = Ext.getCmp('users'); + } else { + main.addTab(panel); + } + if (userId){ + panel.getGrid().selectById(userId); + } + } +}); \ No newline at end of file From 8962797bc027c136a9869924f25279f34b9c4b3b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 16:49:08 +0100 Subject: [PATCH 03/36] fix wrong id property --- .../src/main/webapp/resources/js/group/sonia.group.grid.js | 2 +- .../webapp/resources/js/repository/sonia.repository.grid.js | 2 +- .../src/main/webapp/resources/js/rest/sonia.rest.grid.js | 3 +++ .../src/main/webapp/resources/js/user/sonia.user.grid.js | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js index 7ed4599e6b..17e2f90d9a 100644 --- a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js @@ -48,7 +48,7 @@ Sonia.group.Grid = Ext.extend(Sonia.rest.Grid, { url: restUrl + 'groups.json', disableCaching: false }), - id: 'name', + idProperty: 'name', fields: [ 'name', 'members', 'description', 'creationDate', 'type', 'properties'], sortInfo: { field: 'name' diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js index 02a2829f39..d23f576795 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js @@ -52,7 +52,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { url: restUrl + 'repositories.json', disableCaching: false }), - id: 'id', + idProperty: 'id', fields: [ 'id', 'name', 'type', 'contact', 'description', 'creationDate', 'url', 'public', 'permissions', 'properties' ], sortInfo: { field: 'name' diff --git a/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js b/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js index 08f06bc7e0..2c4e1a684a 100644 --- a/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js @@ -134,6 +134,9 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { }, selectById: function(id){ + if (debug){ + console.debug( 'select by id ' + id ); + } var index = this.getStore().indexOfId(id); if ( index >= 0 ){ this.getSelectionModel().selectRow(index); diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js index 506d0d60a7..fa0b998d6f 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js @@ -51,7 +51,7 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { url: restUrl + 'users.json', disableCaching: false }), - id: 'name', + idProperty: 'name', fields: [ 'name', 'displayName', 'mail', 'admin', 'creationDate', 'lastModified', 'type', 'properties'], sortInfo: { field: 'name' From 26b4382b5e0b1edaf7238e0b6f115b58a0460be6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:00:36 +0100 Subject: [PATCH 04/36] fix onChange method with closed user panel --- .../webapp/resources/js/user/sonia.user.panel.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js index 3af0e05f57..a7a13f1800 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js @@ -188,11 +188,20 @@ Sonia.History.register('userPanel', { if ( ! panel ){ main.addUsersTabPanel(); panel = Ext.getCmp('users'); + if ( userId ){ + var selected = false; + panel.getGrid().getStore().addListener('load', function(store){ + if (!selected){ + panel.getGrid().selectById(userId); + selected = true; + } + }); + } } else { main.addTab(panel); - } - if (userId){ - panel.getGrid().selectById(userId); + if (userId){ + panel.getGrid().selectById(userId); + } } } }); \ No newline at end of file From 209ceec023769eb61daa690c538ae2361a593ebd Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:01:20 +0100 Subject: [PATCH 05/36] user getGrid instead on Ext.getCmp --- .../src/main/webapp/resources/js/user/sonia.user.panel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js index a7a13f1800..8801343be3 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js @@ -160,7 +160,7 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { }, reload: function(){ - Ext.getCmp('userGrid').reload(); + this.getGrid().reload(); } }); @@ -190,7 +190,7 @@ Sonia.History.register('userPanel', { panel = Ext.getCmp('users'); if ( userId ){ var selected = false; - panel.getGrid().getStore().addListener('load', function(store){ + panel.getGrid().getStore().addListener('load', function(){ if (!selected){ panel.getGrid().selectById(userId); selected = true; From 00aac3fd4ac7394a7be7d231061373460562cab6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:03:54 +0100 Subject: [PATCH 06/36] fix onChange method with closed group panel --- .../resources/js/group/sonia.group.panel.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js index 2370956fc5..f2971d16a8 100644 --- a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js @@ -181,16 +181,25 @@ Sonia.History.register('groupPanel', { return token; }, - onChange: function(repoId){ + onChange: function(groupId){ var panel = Ext.getCmp('groups'); if ( ! panel ){ main.addGroupsTabPanel(); panel = Ext.getCmp('groups'); + if (groupId){ + var selected = false; + panel.getGrid().getStore().addListener('load', function(){ + if (!selected){ + panel.getGrid().selectById(groupId); + selected = true; + } + }); + } } else { main.addTab(panel); - } - if (repoId){ - panel.getGrid().selectById(repoId); + if (groupId){ + panel.getGrid().selectById(groupId); + } } } }); \ No newline at end of file From fb9f2c269ceb2e1c4f608c3cfc2003a1e1d15b7d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:05:53 +0100 Subject: [PATCH 07/36] fix onChange method with closed repository panel --- .../js/repository/sonia.repository.panel.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index ddd0bd9c46..6a76207fea 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -295,11 +295,20 @@ Sonia.History.register('repositoryPanel', { if ( ! panel ){ main.addRepositoriesTabPanel(); panel = Ext.getCmp('repositories'); + if ( repoId ){ + var selected = false; + panel.getGrid().getStore().addListener('load', function(){ + if (!selected){ + panel.getGrid().selectedById(repoId); + selected = true; + } + }); + } } else { main.addTab(panel); - } - if (repoId){ - panel.getGrid().selectById(repoId); + if (repoId){ + panel.getGrid().selectById(repoId); + } } } }); \ No newline at end of file From fa537ea5cb0ec607f91c81179edae74e9328beeb Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:16:57 +0100 Subject: [PATCH 08/36] added a webservice method to fetch a single repository by its name and type --- .../rest/resources/RepositoryResource.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 15ea897589..2b4c02603a 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -410,6 +410,47 @@ public class RepositoryResource return response; } + /** + * Returns a repository.
+ *
+ * Status codes: + *
    + *
  • 200 get successful
  • + *
  • 404 not found, + * no repository with the specified type and name available
  • + *
  • 500 internal server error
  • + *
+ * + * @param request the current request + * @param type the type of the repository + * @param name the name of the repository + * + * @return the {@link Repository} with the specified type and name + */ + @GET + @Path("{type}/{name}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @TypeHint(Repository.class) + public Response getByTypeAndName(@Context Request request, + @PathParam("type") String type, + @PathParam("name") String name) + { + Response response = null; + Repository repository = repositoryManager.get(type, name); + + if (repository != null) + { + prepareForReturn(repository); + response = Response.ok(repository).build(); + } + else + { + response = Response.status(Response.Status.NOT_FOUND).build(); + } + + return response; + } + /** * Returns a list of {@link Changeset} for the given repository.
*
From 54abbfb3557c0bd128e8820fc19abfbe7712ca47 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:22:40 +0100 Subject: [PATCH 09/36] fix bug in get method of repository resource --- .../scm/api/rest/resources/RepositoryResource.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 2b4c02603a..0c7b5b4ebe 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -244,18 +244,7 @@ public class RepositoryResource @Override public Response get(@Context Request request, @PathParam("id") String id) { - Response response = null; - - if (SecurityUtil.isAdmin(securityContextProvider)) - { - response = super.get(request, id); - } - else - { - response = Response.status(Response.Status.FORBIDDEN).build(); - } - - return response; + return super.get(request, id); } /** From 1201161a5512a527887246217e3efe8def4b9d9d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:33:58 +0100 Subject: [PATCH 10/36] allow selection of repositories by type and name --- .../resources/js/repository/sonia.repository.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js index f29668c29b..227bc0df1d 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.js @@ -107,7 +107,20 @@ Sonia.repository.get = function(id, callback){ if ( grid ){ var store = grid.getStore(); if (store){ - var rec = store.getById(id); + var rec = null; + var index = id.indexOf('/'); + if ( index > 0 ){ + var type = id.substring(0, index); + var name = id.substring(index); + index = store.findBy(function(rec){ + return rec.get('name') == name && rec.get('type') == type; + }); + if ( index >= 0 ){ + rec = store.getAt(index); + } + } else { + rec = store.getById(id); + } if (rec){ repository = rec.data; } From fa460a6549bb2f3928c42a4ea0a60666f4fe9ae0 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 17:38:49 +0100 Subject: [PATCH 11/36] fix missing title on history change events --- .../webapp/resources/js/config/sonia.config.repositoryconfig.js | 1 + .../webapp/resources/js/config/sonia.config.scmconfigpanel.js | 1 + .../src/main/webapp/resources/js/plugin/sonia.plugin.grid.js | 1 + 3 files changed, 3 insertions(+) diff --git a/scm-webapp/src/main/webapp/resources/js/config/sonia.config.repositoryconfig.js b/scm-webapp/src/main/webapp/resources/js/config/sonia.config.repositoryconfig.js index 6ca37afda3..68f5a1dda7 100644 --- a/scm-webapp/src/main/webapp/resources/js/config/sonia.config.repositoryconfig.js +++ b/scm-webapp/src/main/webapp/resources/js/config/sonia.config.repositoryconfig.js @@ -34,6 +34,7 @@ Sonia.config.RepositoryConfig = Ext.extend(Sonia.config.ConfigPanel,{ initComponent: function(){ var config = { + title: main.tabRepositoryTypesText, panels: repositoryConfigPanels } diff --git a/scm-webapp/src/main/webapp/resources/js/config/sonia.config.scmconfigpanel.js b/scm-webapp/src/main/webapp/resources/js/config/sonia.config.scmconfigpanel.js index 579d05f13e..aa3e9fa6e8 100644 --- a/scm-webapp/src/main/webapp/resources/js/config/sonia.config.scmconfigpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/config/sonia.config.scmconfigpanel.js @@ -84,6 +84,7 @@ Sonia.config.ScmConfigPanel = Ext.extend(Sonia.config.ConfigPanel,{ initComponent: function(){ var config = { + title: main.navGeneralConfigText, panels: [{ xtype: 'configForm', title: this.titleText, diff --git a/scm-webapp/src/main/webapp/resources/js/plugin/sonia.plugin.grid.js b/scm-webapp/src/main/webapp/resources/js/plugin/sonia.plugin.grid.js index a73dde78c4..62f47ec849 100644 --- a/scm-webapp/src/main/webapp/resources/js/plugin/sonia.plugin.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/plugin/sonia.plugin.grid.js @@ -65,6 +65,7 @@ Sonia.plugin.Grid = Ext.extend(Sonia.rest.Grid, { }); var config = { + title: main.tabPluginsText, autoExpandColumn: 'description', store: new Sonia.plugin.Store({ url: restUrl + 'plugins/overview.json' From d9422d2e50e675090447e028688c74f21eb6324c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 18:02:22 +0100 Subject: [PATCH 12/36] call history init after login to get bookmarkable pages for installations without public access --- .../src/main/webapp/resources/js/sonia.global.js | 2 +- .../src/main/webapp/resources/js/sonia.history.js | 15 ++------------- .../src/main/webapp/resources/js/sonia.scm.js | 4 ++++ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.global.js b/scm-webapp/src/main/webapp/resources/js/sonia.global.js index 5fa51f6b48..e6eb8413ff 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.global.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.global.js @@ -112,4 +112,4 @@ var main = null; Ext.QuickTips.init(); // enable history -Ext.History.init(); \ No newline at end of file +// Ext.History.init(); \ No newline at end of file diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.history.js b/scm-webapp/src/main/webapp/resources/js/sonia.history.js index a7b7dc1cd6..d37c534619 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.history.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.history.js @@ -32,7 +32,6 @@ Ext.ns('Sonia'); Sonia.History = { - initialized: false, historyElements: [], recentlyAdded: [], recentlyChanged: [], @@ -133,9 +132,6 @@ Sonia.History = { }, onChange: function(token){ - if (!this.initialized){ - this.initialized = true; - } if(token){ if (this.isInvokeable(this.recentlyAdded, token)){ var parts = token.split('|'); @@ -173,15 +169,8 @@ Sonia.History = { Ext.History.on('ready', function(history){ var token = history.getToken(); - if (!token || token == 'null'){ - Sonia.History.initialized = true; - } else { - setTimeout(function(){ - if (debug){ - console.debug('history ready, handle history token ' + token); - } - Sonia.History.onChange(token); - }, 750); + if (token && token != 'null'){ + Sonia.History.onChange(token); } }); diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js index b8cf1aa8f6..3c9e9b7aa8 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.scm.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.scm.js @@ -528,6 +528,10 @@ Ext.onReady(function(){ main.addListeners('login', loginCallbacks); main.addListeners('logout', logoutCallbacks); + main.addListeners('login', function(){ + Ext.History.init(); + }); + main.init(); main.checkLogin(); }); \ No newline at end of file From 743ee48fc352100a1ada4e9fc64a008dd49a8186 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 18:24:49 +0100 Subject: [PATCH 13/36] fix closure compiler error --- scm-webapp/src/main/webapp/resources/js/sonia.global.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.global.js b/scm-webapp/src/main/webapp/resources/js/sonia.global.js index e6eb8413ff..e0a331ca4f 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.global.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.global.js @@ -110,6 +110,3 @@ var main = null; // enable extjs quicktips Ext.QuickTips.init(); - -// enable history -// Ext.History.init(); \ No newline at end of file From c28390c91f61559d083a789cc3e59f7bc9e77bcb Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 11:40:07 +0100 Subject: [PATCH 14/36] added UrlBuilder --- .../main/java/sonia/scm/util/HttpUtil.java | 66 +++++++ .../main/java/sonia/scm/util/UrlBuilder.java | 184 ++++++++++++++++++ 2 files changed, 250 insertions(+) create mode 100644 scm-core/src/main/java/sonia/scm/util/UrlBuilder.java diff --git a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java index 819efb509c..4aebfbdfd4 100644 --- a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java @@ -92,6 +92,24 @@ public class HttpUtil */ public static final String SCHEME_HTTPS = "https"; + /** + * 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 +137,54 @@ 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 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 * diff --git a/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java b/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java new file mode 100644 index 0000000000..2d9605a2bc --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java @@ -0,0 +1,184 @@ +/** + * 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 = HttpUtil.append(url, 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(); + } + + 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 String separator; + + /** Field description */ + private String url; +} From bd9efdbafc9a9da9c204d0447cfa34c710bcce15 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 11:50:32 +0100 Subject: [PATCH 15/36] improve UrlBuilder --- .../main/java/sonia/scm/util/UrlBuilder.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java b/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java index 2d9605a2bc..e8ba4dfcf3 100644 --- a/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java +++ b/scm-core/src/main/java/sonia/scm/util/UrlBuilder.java @@ -77,7 +77,7 @@ public class UrlBuilder */ public UrlBuilder append(String part) { - url = HttpUtil.append(url, part); + url = url.concat(part); return this; } @@ -139,11 +139,32 @@ public class UrlBuilder { 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 * @@ -176,6 +197,9 @@ public class UrlBuilder //~--- fields --------------------------------------------------------------- + /** Field description */ + private boolean parameterAdded = false; + /** Field description */ private String separator; From d202d2c0924a337df9042167d09c3d5260a3b680 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 11:51:50 +0100 Subject: [PATCH 16/36] 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; + } +} From 6af47415f58dcbb8c7f17c96d47a7bbbc2e7cbb3 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 12:19:59 +0100 Subject: [PATCH 17/36] 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; +} From 329d0b8af357040dc825c691b887be626849cad9 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 12:26:23 +0100 Subject: [PATCH 18/36] added appendHash method to HttpUtil --- .../main/java/sonia/scm/util/HttpUtil.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java index 4aebfbdfd4..c5ab47b8e2 100644 --- a/scm-core/src/main/java/sonia/scm/util/HttpUtil.java +++ b/scm-core/src/main/java/sonia/scm/util/HttpUtil.java @@ -92,20 +92,26 @@ public class HttpUtil */ public static final String SCHEME_HTTPS = "https"; - /** - * Url parameter separator + /** + * 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 + /** + * Url parameters separator * @since 1.9 */ public static final String SEPARATOR_PARAMETERS = "?"; - /** - * Url parameter value separator + /** + * Url parameter value separator * @since 1.9 */ public static final String SEPARATOR_PARAMETER_VALUE = "="; @@ -157,6 +163,21 @@ public class HttpUtil 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 * From cc5b4ace0a89dbddabb77e8d2163ddbe5f6205be Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 13:43:55 +0100 Subject: [PATCH 19/36] mark ScmUrlProvider as deprecated --- .../main/java/sonia/scm/client/ScmUrlProvider.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmUrlProvider.java b/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmUrlProvider.java index 11b226f11e..a7033913db 100644 --- a/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmUrlProvider.java +++ b/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmUrlProvider.java @@ -38,6 +38,7 @@ package sonia.scm.client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import sonia.scm.url.UrlProvider; import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ @@ -47,6 +48,16 @@ import java.text.MessageFormat; /** * * @author Sebastian Sdorra + * @deprecated use {@link UrlProvider} instead. For example: + *
+ * {@code
+ * URLProvider provider = URLProviderFactory.createUrlProvider(
+ *                          baseUrl,
+ *                          UrlProviderFactory.TYPE_RESTAPI_XML
+ * );
+ * String authUrl = provider.getAuthenticationUrl();
+ * }
+ * 
*/ public class ScmUrlProvider { From b5f004c7a8fc73204eeee6f413c59e127b89a984 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 13:44:56 +0100 Subject: [PATCH 20/36] remove unused import --- .../src/main/java/sonia/scm/client/ScmClientSession.java | 1 - 1 file changed, 1 deletion(-) diff --git a/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmClientSession.java b/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmClientSession.java index 7523460478..7e39258390 100644 --- a/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmClientSession.java +++ b/scm-clients/scm-client-api/src/main/java/sonia/scm/client/ScmClientSession.java @@ -36,7 +36,6 @@ package sonia.scm.client; //~--- non-JDK imports -------------------------------------------------------- import sonia.scm.ScmState; -import sonia.scm.user.User; //~--- JDK imports ------------------------------------------------------------ From c8138d23eebef423a01bf59480f00402b3740d5c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 13:46:56 +0100 Subject: [PATCH 21/36] use static method for createUrlProvider of UrlProviderFactory --- scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4f245718b2..71de584c06 100644 --- a/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java +++ b/scm-core/src/main/java/sonia/scm/url/UrlProviderFactory.java @@ -67,7 +67,7 @@ public class UrlProviderFactory * * @return */ - public UrlProvider createUrlProvider(String baseUrl, String type) + public static UrlProvider createUrlProvider(String baseUrl, String type) { UrlProvider provider = null; From a0a9e2a303f83e15556fa70deba9f76e962a631c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 13:55:33 +0100 Subject: [PATCH 22/36] added missing config resource to UrlProvider --- .../java/sonia/scm/url/RestUrlProvider.java | 19 +++++++++++++++++-- .../main/java/sonia/scm/url/UrlProvider.java | 8 ++++++++ .../java/sonia/scm/url/WUIUrlProvider.java | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java index 2fa008bea6..6f2446fec1 100644 --- a/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java +++ b/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java @@ -50,6 +50,9 @@ public class RestUrlProvider implements UrlProvider /** 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"; @@ -88,7 +91,19 @@ public class RestUrlProvider implements UrlProvider @Override public String getAuthenticationUrl() { - return HttpUtil.append(baseUrl, PART_AUTHENTICATION); + return HttpUtil.append(baseUrl, PART_AUTHENTICATION).concat(extension); + } + + /** + * Method description + * + * + * @return + */ + @Override + public String getConfigUrl() + { + return HttpUtil.append(baseUrl, PART_CONFIG).concat(extension); } /** @@ -124,7 +139,7 @@ public class RestUrlProvider implements UrlProvider @Override public String getStateUrl() { - return HttpUtil.append(baseUrl, PART_STATE); + return HttpUtil.append(baseUrl, PART_STATE).concat(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 index ea8ad19c0f..694ea1b698 100644 --- a/scm-core/src/main/java/sonia/scm/url/UrlProvider.java +++ b/scm-core/src/main/java/sonia/scm/url/UrlProvider.java @@ -48,6 +48,14 @@ public interface UrlProvider */ public String getAuthenticationUrl(); + /** + * Method description + * + * + * @return + */ + public String getConfigUrl(); + /** * Method description * diff --git a/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java index 06a44abc17..f022e3ca0d 100644 --- a/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java +++ b/scm-core/src/main/java/sonia/scm/url/WUIUrlProvider.java @@ -44,6 +44,9 @@ import sonia.scm.util.HttpUtil; public class WUIUrlProvider implements UrlProvider { + /** Field description */ + public static final String COMPONENT_CONFIG = "scmConfig"; + /** Field description */ public static final String COMPONENT_GROUP = "groupPanel"; @@ -85,6 +88,18 @@ public class WUIUrlProvider implements UrlProvider return null; } + /** + * Method description + * + * + * @return + */ + @Override + public String getConfigUrl() + { + return HttpUtil.appendHash(baseUrl, COMPONENT_CONFIG); + } + /** * Method description * From b8599e22388acd52d7d50c85a819685563d989c4 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 13:57:58 +0100 Subject: [PATCH 23/36] use UrlProvider instead of deprecated ScmUrlProvider --- .../sonia/scm/client/AbstractClientHandler.java | 3 ++- .../scm/client/JerseyClientChangesetHandler.java | 8 ++++---- .../sonia/scm/client/JerseyClientProvider.java | 8 +++++--- .../scm/client/JerseyClientRepositoryBrowser.java | 14 +++++++------- .../java/sonia/scm/client/JerseyClientSession.java | 7 ++++--- .../sonia/scm/client/JerseyGroupClientHandler.java | 4 ++-- .../scm/client/JerseyRepositoryClientHandler.java | 4 ++-- .../sonia/scm/client/JerseyUserClientHandler.java | 4 ++-- .../java/sonia/scm/client/it/ClientTestUtil.java | 7 ++++--- 9 files changed, 32 insertions(+), 27 deletions(-) diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java index eb4d8a9f15..6deabafb18 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java @@ -46,6 +46,7 @@ import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.WebResource; import java.util.List; +import sonia.scm.url.UrlProvider; /** * @@ -316,7 +317,7 @@ public abstract class AbstractClientHandler protected JerseyClientSession session; /** Field description */ - protected ScmUrlProvider urlProvider; + protected UrlProvider urlProvider; /** Field description */ private Class itemClass; diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientChangesetHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientChangesetHandler.java index f9f7e8beaa..2fffb5afe3 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientChangesetHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientChangesetHandler.java @@ -80,8 +80,8 @@ public class JerseyClientChangesetHandler implements ClientChangesetHandler { ChangesetPagingResult result = null; String url = - session.getUrlProvider().getRepositoryChangesetUrl(repository.getId(), - start, limit); + session.getUrlProvider().getRepositoryUrlProvider().getChangesetUrl( + repository.getId(), start, limit); WebResource resource = session.getClient().resource(url); ClientResponse response = null; @@ -121,8 +121,8 @@ public class JerseyClientChangesetHandler implements ClientChangesetHandler { ChangesetPagingResult result = null; String url = - session.getUrlProvider().getRepositoryChangesetUrl(repository.getId(), - path, revision, start, limit); + session.getUrlProvider().getRepositoryUrlProvider().getChangesetUrl( + repository.getId(), path, revision, start, limit); WebResource resource = session.getClient().resource(url); ClientResponse response = null; diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java index 0b99b03edf..14c8e6f3e5 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java @@ -52,6 +52,8 @@ import com.sun.jersey.api.client.WebResource; import com.sun.jersey.core.util.MultivaluedMapImpl; import javax.ws.rs.core.MultivaluedMap; +import sonia.scm.url.UrlProvider; +import sonia.scm.url.UrlProviderFactory; /** * @@ -114,7 +116,7 @@ public class JerseyClientProvider implements ScmClientProvider logger.info("create new session for {} with username {}", url, user); } - ScmUrlProvider urlProvider = new ScmUrlProvider(url); + UrlProvider urlProvider = UrlProviderFactory.createUrlProvider(url, UrlProviderFactory.TYPE_RESTAPI_XML); DefaultAhcConfig config = new DefaultAhcConfig(); AhcHttpClient client = AhcHttpClient.create(config); ClientResponse response = null; @@ -122,7 +124,7 @@ public class JerseyClientProvider implements ScmClientProvider if (Util.isNotEmpty(username) && Util.isNotEmpty(password)) { WebResource resource = ClientUtil.createResource(client, - urlProvider.getAuthenticationLoginUrl(), + urlProvider.getAuthenticationUrl(), enableLogging); if (logger.isDebugEnabled()) @@ -140,7 +142,7 @@ public class JerseyClientProvider implements ScmClientProvider else { WebResource resource = ClientUtil.createResource(client, - urlProvider.getAuthenticationUrl(), + urlProvider.getStateUrl(), enableLogging); if (logger.isDebugEnabled()) diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientRepositoryBrowser.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientRepositoryBrowser.java index 985748f0ab..571c30f7db 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientRepositoryBrowser.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientRepositoryBrowser.java @@ -91,8 +91,8 @@ public class JerseyClientRepositoryBrowser implements ClientRepositoryBrowser { List blameLines = null; String url = - session.getUrlProvider().getBlameUrl(repository.getId(), path, - revision); + session.getUrlProvider().getRepositoryUrlProvider().getBlameUrl( + repository.getId(), path, revision); WebResource resource = session.getClient().resource(url); ClientResponse response = null; @@ -134,8 +134,8 @@ public class JerseyClientRepositoryBrowser implements ClientRepositoryBrowser { InputStream input = null; String url = - session.getUrlProvider().getRepositoryContentUrl(repository.getId(), - path, revision); + session.getUrlProvider().getRepositoryUrlProvider().getContentUrl( + repository.getId(), path, revision); WebResource resource = session.getClient().resource(url); ClientResponse response = null; @@ -171,8 +171,8 @@ public class JerseyClientRepositoryBrowser implements ClientRepositoryBrowser { List files = null; String url = - session.getUrlProvider().getRepositoryBrowseUrl(repository.getId(), path, - revision); + session.getUrlProvider().getRepositoryUrlProvider().getBrowseUrl( + repository.getId(), path, revision); WebResource resource = session.getClient().resource(url); ClientResponse response = null; @@ -219,7 +219,7 @@ public class JerseyClientRepositoryBrowser implements ClientRepositoryBrowser @Override public List getFiles(String revision) { - return getFiles(revision, ""); + return getFiles(revision, Util.EMPTY_STRING); } //~--- fields --------------------------------------------------------------- diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientSession.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientSession.java index c9ea432b31..7e662bc938 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientSession.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientSession.java @@ -39,6 +39,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sonia.scm.ScmState; +import sonia.scm.url.UrlProvider; //~--- JDK imports ------------------------------------------------------------ @@ -65,7 +66,7 @@ public class JerseyClientSession implements ScmClientSession * @param urlProvider * @param state */ - public JerseyClientSession(Client client, ScmUrlProvider urlProvider, + public JerseyClientSession(Client client, UrlProvider urlProvider, ScmState state) { this.client = client; @@ -146,7 +147,7 @@ public class JerseyClientSession implements ScmClientSession * * @return */ - public ScmUrlProvider getUrlProvider() + public UrlProvider getUrlProvider() { return urlProvider; } @@ -172,5 +173,5 @@ public class JerseyClientSession implements ScmClientSession private ScmState state; /** Field description */ - private ScmUrlProvider urlProvider; + private UrlProvider urlProvider; } diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java index 5f3969ffc7..0c22798279 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyGroupClientHandler.java @@ -105,7 +105,7 @@ public class JerseyGroupClientHandler extends AbstractClientHandler @Override protected String getItemUrl(String itemId) { - return urlProvider.getGroupUrl(itemId); + return urlProvider.getGroupUrlProvider().getDetailUrl(itemId); } /** @@ -117,6 +117,6 @@ public class JerseyGroupClientHandler extends AbstractClientHandler @Override protected String getItemsUrl() { - return urlProvider.getGroupsUrl(); + return urlProvider.getGroupUrlProvider().getAllUrl(); } } diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java index 6309a5b245..4d0efd2869 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyRepositoryClientHandler.java @@ -160,7 +160,7 @@ public class JerseyRepositoryClientHandler @Override protected String getItemUrl(String itemId) { - return urlProvider.getRepositoryUrl(itemId); + return urlProvider.getRepositoryUrlProvider().getDetailUrl(itemId); } /** @@ -172,6 +172,6 @@ public class JerseyRepositoryClientHandler @Override protected String getItemsUrl() { - return urlProvider.getRepositoriesUrl(); + return urlProvider.getRepositoryUrlProvider().getAllUrl(); } } diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java index c28d3eda70..a353434379 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyUserClientHandler.java @@ -105,7 +105,7 @@ public class JerseyUserClientHandler extends AbstractClientHandler @Override protected String getItemUrl(String itemId) { - return urlProvider.getUserUrl(itemId); + return urlProvider.getUserUrlProvider().getDetailUrl(itemId); } /** @@ -117,6 +117,6 @@ public class JerseyUserClientHandler extends AbstractClientHandler @Override protected String getItemsUrl() { - return urlProvider.getUsersUrl(); + return urlProvider.getUserUrlProvider().getAllUrl(); } } diff --git a/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/ClientTestUtil.java b/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/ClientTestUtil.java index fc0e47805e..b2efca3439 100644 --- a/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/ClientTestUtil.java +++ b/scm-clients/scm-client-impl/src/test/java/sonia/scm/client/it/ClientTestUtil.java @@ -40,6 +40,7 @@ import sonia.scm.client.JerseyClientProvider; import sonia.scm.client.JerseyClientSession; import sonia.scm.client.ScmUrlProvider; import sonia.scm.config.ScmConfiguration; +import sonia.scm.url.UrlProvider; //~--- JDK imports ------------------------------------------------------------ @@ -124,10 +125,10 @@ public class ClientTestUtil public static void setAnonymousAccess(boolean access) { JerseyClientSession adminSession = createAdminSession(); - ScmUrlProvider up = adminSession.getUrlProvider(); + UrlProvider up = adminSession.getUrlProvider(); Client client = adminSession.getClient(); - WebResource resource = ClientUtil.createResource(client, - up.getResourceUrl("config"), REQUEST_LOGGING); + WebResource resource = ClientUtil.createResource(client, up.getConfigUrl(), + REQUEST_LOGGING); ScmConfiguration config = resource.get(ScmConfiguration.class); config.setAnonymousAccessEnabled(access); From 4027a824c8177f1e6af4aa19314e12f5034bfee8 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 13:59:59 +0100 Subject: [PATCH 24/36] indent --- .../java/sonia/scm/client/AbstractClientHandler.java | 3 +-- .../java/sonia/scm/client/JerseyClientProvider.java | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java index 6deabafb18..963c3cdbda 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java @@ -36,6 +36,7 @@ package sonia.scm.client; //~--- non-JDK imports -------------------------------------------------------- import sonia.scm.ModelObject; +import sonia.scm.url.UrlProvider; import sonia.scm.util.AssertUtil; //~--- JDK imports ------------------------------------------------------------ @@ -46,7 +47,6 @@ import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.WebResource; import java.util.List; -import sonia.scm.url.UrlProvider; /** * @@ -321,6 +321,5 @@ public abstract class AbstractClientHandler /** Field description */ private Class itemClass; - ; } diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java index 14c8e6f3e5..cbe5627f90 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java @@ -42,6 +42,8 @@ import org.sonatype.spice.jersey.client.ahc.AhcHttpClient; import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig; import sonia.scm.ScmState; +import sonia.scm.url.UrlProvider; +import sonia.scm.url.UrlProviderFactory; import sonia.scm.util.AssertUtil; import sonia.scm.util.Util; @@ -52,8 +54,6 @@ import com.sun.jersey.api.client.WebResource; import com.sun.jersey.core.util.MultivaluedMapImpl; import javax.ws.rs.core.MultivaluedMap; -import sonia.scm.url.UrlProvider; -import sonia.scm.url.UrlProviderFactory; /** * @@ -116,7 +116,8 @@ public class JerseyClientProvider implements ScmClientProvider logger.info("create new session for {} with username {}", url, user); } - UrlProvider urlProvider = UrlProviderFactory.createUrlProvider(url, UrlProviderFactory.TYPE_RESTAPI_XML); + UrlProvider urlProvider = UrlProviderFactory.createUrlProvider(url, + UrlProviderFactory.TYPE_RESTAPI_XML); DefaultAhcConfig config = new DefaultAhcConfig(); AhcHttpClient client = AhcHttpClient.create(config); ClientResponse response = null; @@ -142,8 +143,7 @@ public class JerseyClientProvider implements ScmClientProvider else { WebResource resource = ClientUtil.createResource(client, - urlProvider.getStateUrl(), - enableLogging); + urlProvider.getStateUrl(), enableLogging); if (logger.isDebugEnabled()) { From d2b2d188e6a473419deecf4e029ac0afc0bcc09f Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:05:19 +0100 Subject: [PATCH 25/36] improve logging --- .../scm/client/AbstractClientHandler.java | 25 +++++++++++++++++-- .../scm/client/JerseyClientProvider.java | 21 +++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java index 963c3cdbda..0e29456adc 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/AbstractClientHandler.java @@ -35,6 +35,9 @@ package sonia.scm.client; //~--- non-JDK imports -------------------------------------------------------- +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import sonia.scm.ModelObject; import sonia.scm.url.UrlProvider; import sonia.scm.util.AssertUtil; @@ -58,6 +61,12 @@ public abstract class AbstractClientHandler implements ClientHandler { + /** the logger for AbstractClientHandler */ + private static final Logger logger = + LoggerFactory.getLogger(AbstractClientHandler.class); + + //~--- constructors --------------------------------------------------------- + /** * Constructs ... * @@ -234,7 +243,15 @@ public abstract class AbstractClientHandler public List getAll() { List items = null; - WebResource resource = client.resource(getItemsUrl()); + String url = getItemsUrl(); + + if (logger.isDebugEnabled()) + { + logger.debug("fetch all items of {} from url", itemClass.getSimpleName(), + url); + } + + WebResource resource = client.resource(url); ClientResponse response = null; try @@ -284,6 +301,11 @@ public abstract class AbstractClientHandler */ protected T getItemByUrl(String url) { + if (logger.isDebugEnabled()) + { + logger.debug("fetch item {} from url {}", itemClass.getSimpleName(), url); + } + T item = null; WebResource resource = client.resource(url); ClientResponse response = null; @@ -321,5 +343,4 @@ public abstract class AbstractClientHandler /** Field description */ private Class itemClass; - ; } diff --git a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java index cbe5627f90..8c38f83eb1 100644 --- a/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java +++ b/scm-clients/scm-client-impl/src/main/java/sonia/scm/client/JerseyClientProvider.java @@ -124,8 +124,14 @@ public class JerseyClientProvider implements ScmClientProvider if (Util.isNotEmpty(username) && Util.isNotEmpty(password)) { - WebResource resource = ClientUtil.createResource(client, - urlProvider.getAuthenticationUrl(), + String authUrl = urlProvider.getAuthenticationUrl(); + + if (logger.isDebugEnabled()) + { + logger.debug("try login at {}", authUrl); + } + + WebResource resource = ClientUtil.createResource(client, authUrl, enableLogging); if (logger.isDebugEnabled()) @@ -142,8 +148,15 @@ public class JerseyClientProvider implements ScmClientProvider } else { - WebResource resource = ClientUtil.createResource(client, - urlProvider.getStateUrl(), enableLogging); + String stateUrl = urlProvider.getStateUrl(); + + if (logger.isDebugEnabled()) + { + logger.debug("retrive state from {}", stateUrl); + } + + WebResource resource = ClientUtil.createResource(client, stateUrl, + enableLogging); if (logger.isDebugEnabled()) { From 85cf5cc3195594a14b0f82335793d8f889038b87 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:05:53 +0100 Subject: [PATCH 26/36] fix wrong base url --- scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java index 6f2446fec1..1d60f2a91b 100644 --- a/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java +++ b/scm-core/src/main/java/sonia/scm/url/RestUrlProvider.java @@ -45,7 +45,7 @@ public class RestUrlProvider implements UrlProvider { /** Field description */ - public static final String PART_API = "/api/rest/"; + public static final String PART_API = "api/rest/"; /** Field description */ public static final String PART_AUTHENTICATION = "authentication/login"; From cd09b6f5062f4b914f9719917390c87533311b05 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:13:46 +0100 Subject: [PATCH 27/36] fix license check of scm-plugin-backend --- scm-plugin-backend/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/scm-plugin-backend/pom.xml b/scm-plugin-backend/pom.xml index 9da97a4fa8..4e0686e1c7 100644 --- a/scm-plugin-backend/pom.xml +++ b/scm-plugin-backend/pom.xml @@ -96,6 +96,7 @@ .hg/** **/html5.js **/*.html + **/fancybox/** true From 5d3c0d012e7ad0c32ab7cae858fcf9e0d6896af9 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:30:59 +0100 Subject: [PATCH 28/36] remove unused import --- .../java/sonia/scm/api/rest/resources/RepositoryResource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 0c7b5b4ebe..2b13e2a03d 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -66,7 +66,6 @@ import sonia.scm.repository.RepositoryManager; import sonia.scm.repository.RepositoryNotFoundException; import sonia.scm.util.AssertUtil; import sonia.scm.util.HttpUtil; -import sonia.scm.util.SecurityUtil; import sonia.scm.util.Util; import sonia.scm.web.security.WebSecurityContext; From 9d396589fbc50e7252e08b95f9a62714b07879df Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:32:32 +0100 Subject: [PATCH 29/36] fix wrong content type --- .../java/sonia/scm/api/rest/resources/RepositoryResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 2b13e2a03d..72a9746e77 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -599,7 +599,7 @@ public class RepositoryResource @GET @Path("{id}/diff") @TypeHint(DiffStreamingOutput.class) - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response getDiff(@PathParam("id") String id, @QueryParam("revision") String revision, @QueryParam("path") String path) From 0573192dfe7821adf9c559b643be93730054ddaf Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:33:09 +0100 Subject: [PATCH 30/36] enable injection for url providers --- .../main/java/sonia/scm/ScmServletModule.java | 16 ++++ .../sonia/scm/url/RestJsonUrlProvider.java | 81 +++++++++++++++++++ .../sonia/scm/url/RestXmlUrlProvider.java | 81 +++++++++++++++++++ .../java/sonia/scm/url/WebUIUrlProvider.java | 81 +++++++++++++++++++ 4 files changed, 259 insertions(+) create mode 100644 scm-webapp/src/main/java/sonia/scm/url/RestJsonUrlProvider.java create mode 100644 scm-webapp/src/main/java/sonia/scm/url/RestXmlUrlProvider.java create mode 100644 scm-webapp/src/main/java/sonia/scm/url/WebUIUrlProvider.java diff --git a/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java b/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java index e2c8c3d276..550858ca48 100644 --- a/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java +++ b/scm-webapp/src/main/java/sonia/scm/ScmServletModule.java @@ -75,6 +75,11 @@ import sonia.scm.store.StoreFactory; import sonia.scm.template.FreemarkerTemplateHandler; import sonia.scm.template.TemplateHandler; import sonia.scm.template.TemplateServlet; +import sonia.scm.url.RestJsonUrlProvider; +import sonia.scm.url.RestXmlUrlProvider; +import sonia.scm.url.UrlProvider; +import sonia.scm.url.UrlProviderFactory; +import sonia.scm.url.WebUIUrlProvider; import sonia.scm.user.UserManager; import sonia.scm.user.xml.XmlUserManager; import sonia.scm.util.DebugServlet; @@ -241,6 +246,17 @@ public class ScmServletModule extends ServletModule // bind httpclient bind(HttpClient.class).to(URLHttpClient.class); + // bind url provider staff + bind(UrlProvider.class).annotatedWith( + Names.named(UrlProviderFactory.TYPE_RESTAPI_JSON)).toProvider( + RestJsonUrlProvider.class); + bind(UrlProvider.class).annotatedWith( + Names.named(UrlProviderFactory.TYPE_RESTAPI_XML)).toProvider( + RestXmlUrlProvider.class); + bind(UrlProvider.class).annotatedWith( + Names.named(UrlProviderFactory.TYPE_WUI)).toProvider( + WebUIUrlProvider.class); + /* * filter(PATTERN_PAGE, * PATTERN_STATIC_RESOURCES).through(StaticResourceFilter.class); diff --git a/scm-webapp/src/main/java/sonia/scm/url/RestJsonUrlProvider.java b/scm-webapp/src/main/java/sonia/scm/url/RestJsonUrlProvider.java new file mode 100644 index 0000000000..7be05d9f39 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/url/RestJsonUrlProvider.java @@ -0,0 +1,81 @@ +/** + * 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 com.google.inject.Inject; +import com.google.inject.Provider; + +import sonia.scm.config.ScmConfiguration; + +/** + * + * @author Sebastian Sdorra + */ +public class RestJsonUrlProvider implements Provider +{ + + /** + * Constructs ... + * + * + * @param configuration + */ + @Inject + public RestJsonUrlProvider(ScmConfiguration configuration) + { + this.configuration = configuration; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + public UrlProvider get() + { + return UrlProviderFactory.createUrlProvider(configuration.getBaseUrl(), + UrlProviderFactory.TYPE_RESTAPI_JSON); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private ScmConfiguration configuration; +} diff --git a/scm-webapp/src/main/java/sonia/scm/url/RestXmlUrlProvider.java b/scm-webapp/src/main/java/sonia/scm/url/RestXmlUrlProvider.java new file mode 100644 index 0000000000..a4e8d8f1f2 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/url/RestXmlUrlProvider.java @@ -0,0 +1,81 @@ +/** + * 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 com.google.inject.Inject; +import com.google.inject.Provider; + +import sonia.scm.config.ScmConfiguration; + +/** + * + * @author Sebastian Sdorra + */ +public class RestXmlUrlProvider implements Provider +{ + + /** + * Constructs ... + * + * + * @param configuration + */ + @Inject + public RestXmlUrlProvider(ScmConfiguration configuration) + { + this.configuration = configuration; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + public UrlProvider get() + { + return UrlProviderFactory.createUrlProvider(configuration.getBaseUrl(), + UrlProviderFactory.TYPE_RESTAPI_XML); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private ScmConfiguration configuration; +} diff --git a/scm-webapp/src/main/java/sonia/scm/url/WebUIUrlProvider.java b/scm-webapp/src/main/java/sonia/scm/url/WebUIUrlProvider.java new file mode 100644 index 0000000000..a71b3cd6d7 --- /dev/null +++ b/scm-webapp/src/main/java/sonia/scm/url/WebUIUrlProvider.java @@ -0,0 +1,81 @@ +/** + * 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 com.google.inject.Inject; +import com.google.inject.Provider; + +import sonia.scm.config.ScmConfiguration; + +/** + * + * @author Sebastian Sdorra + */ +public class WebUIUrlProvider implements Provider +{ + + /** + * Constructs ... + * + * + * @param configuration + */ + @Inject + public WebUIUrlProvider(ScmConfiguration configuration) + { + this.configuration = configuration; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + public UrlProvider get() + { + return UrlProviderFactory.createUrlProvider(configuration.getBaseUrl(), + UrlProviderFactory.TYPE_WUI); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private ScmConfiguration configuration; +} From fc543d5d93d84447ef964bb0d0bbcd287aaaa0d6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 14:35:03 +0100 Subject: [PATCH 31/36] don't append xml or json extension at content or diff url --- .../main/java/sonia/scm/url/RestRepositoryUrlProvider.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java b/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java index d0b2715ab9..e75dd5fd14 100644 --- a/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java +++ b/scm-core/src/main/java/sonia/scm/url/RestRepositoryUrlProvider.java @@ -185,8 +185,7 @@ public class RestRepositoryUrlProvider extends RestModelUrlProvider 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( + PART_CONTENT).appendParameter(PARAMETER_PATH, path).appendParameter( PARAMETER_REVISION, revision).toString(); } @@ -203,7 +202,6 @@ public class RestRepositoryUrlProvider extends RestModelUrlProvider public String getDiffUrl(String repositoryId, String revision) { return new UrlBuilder(base).appendUrlPart(repositoryId).appendUrlPart( - PART_DIFF).append(extension).appendParameter( - PARAMETER_REVISION, revision).toString(); + PART_DIFF).appendParameter(PARAMETER_REVISION, revision).toString(); } } From f007bb14160d594e33a62aa83a21dae391996f7c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sun, 20 Nov 2011 18:41:58 +0100 Subject: [PATCH 32/36] added missing separator --- scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java b/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java index 1fefbac529..a34d2e6177 100644 --- a/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java +++ b/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java @@ -81,6 +81,11 @@ public class WUIUrlBuilder value = NULL; } + if (!this.url.endsWith(SEPARATOR)) + { + this.url = this.url.concat(SEPARATOR); + } + this.url = this.url.concat(value); return this; From 5fa2bf38be15865515740075ac4df579a6343f7e Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 22 Nov 2011 19:41:00 +0100 Subject: [PATCH 33/36] use ; as url separator --- .../src/main/java/sonia/scm/url/WUIUrlBuilder.java | 2 +- .../repository/sonia.repository.changesetviewergrid.js | 4 ++-- .../sonia.repository.changesetviewerpanel.js | 2 +- .../js/repository/sonia.repository.contentpanel.js | 2 +- .../js/repository/sonia.repository.diffpanel.js | 2 +- .../repository/sonia.repository.extendedinfopanel.js | 2 +- .../js/repository/sonia.repository.infopanel.js | 2 +- .../repository/sonia.repository.repositorybrowser.js | 2 +- .../src/main/webapp/resources/js/sonia.global.js | 4 ++-- .../src/main/webapp/resources/js/sonia.history.js | 10 +++++----- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java b/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java index a34d2e6177..c9744effe3 100644 --- a/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java +++ b/scm-core/src/main/java/sonia/scm/url/WUIUrlBuilder.java @@ -48,7 +48,7 @@ public class WUIUrlBuilder public static final String NULL = "null"; /** Field description */ - public static final String SEPARATOR = "|"; + public static final String SEPARATOR = ";"; //~--- constructors --------------------------------------------------------- diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewergrid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewergrid.js index 75604d0f93..a1ee25e495 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewergrid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewergrid.js @@ -140,7 +140,7 @@ Sonia.repository.ChangesetViewerGrid = Ext.extend(Ext.grid.GridPanel, { openDiffViewer: function(revision){ main.addTab({ - id: 'diffPanel|' + this.repository.id + '|' + revision, + id: 'diffPanel;' + this.repository.id + ';' + revision, xtype: 'diffPanel', repository: this.repository, revision: revision, @@ -150,7 +150,7 @@ Sonia.repository.ChangesetViewerGrid = Ext.extend(Ext.grid.GridPanel, { openRepositoryBrowser: function(revision){ main.addTab({ - id: 'repositoryBrowser|' + this.repository.id + '|' + revision, + id: 'repositoryBrowser;' + this.repository.id + ';' + revision, xtype: 'repositoryBrowser', repository: this.repository, revision: revision, diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js index 8469c89451..4a1995809b 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js @@ -154,7 +154,7 @@ Sonia.History.register('repositoryChangesetViewerPanel', { if (limit){ limit = parseInt(limit); } - var id = 'repositoryChangesetViewerPanel|' + repoId; + var id = 'repositoryChangesetViewerPanel;' + repoId; Sonia.repository.get(repoId, function(repository){ var panel = Ext.getCmp(id); if (! panel){ diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js index 50bbcd8473..de8706da37 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.contentpanel.js @@ -210,7 +210,7 @@ Sonia.History.register('contentPanel', { if (!view || view == 'null'){ view = 'content'; } - var id = 'contentPanel|' + repoId + '|' + revision + '|' + path; + var id = 'contentPanel;' + repoId + ';' + revision + ';' + path; Sonia.repository.get(repoId, function(repository){ var panel = Ext.getCmp(id); if (! panel){ diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.diffpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.diffpanel.js index 3393e43fa3..c5abf52472 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.diffpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.diffpanel.js @@ -81,7 +81,7 @@ Sonia.History.register('diffPanel', { }, onChange: function(repoId, revision){ - var id = 'diffPanel|' + repoId + '|' + revision; + var id = 'diffPanel;' + repoId + ';' + revision; Sonia.repository.get(repoId, function(repository){ var panel = Ext.getCmp(id); if (! panel){ diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.extendedinfopanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.extendedinfopanel.js index 0edbd171e2..c27034865b 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.extendedinfopanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.extendedinfopanel.js @@ -95,7 +95,7 @@ Sonia.repository.ExtendedInfoPanel = Ext.extend(Sonia.repository.InfoPanel,{ createRepositoryBrowser: function(){ return { - id: 'repositoryBrowser|' + this.item.id + '|null', + id: 'repositoryBrowser;' + this.item.id + ';null', xtype: 'repositoryBrowser', repository: this.item, closable: true diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.infopanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.infopanel.js index f0d0024da8..20c40c62a7 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.infopanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.infopanel.js @@ -148,7 +148,7 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, { createChangesetViewer: function(){ return { - id: 'repositoryChangesetViewerPanel|' + this.item.id, + id: 'repositoryChangesetViewerPanel;' + this.item.id, repository: this.item, xtype: 'repositoryChangesetViewerPanel', closable: true, diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js index 91a099d1b4..4b181c8d9c 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.repositorybrowser.js @@ -329,7 +329,7 @@ Sonia.History.register('repositoryBrowser', { if (path == 'null'){ path = ''; } - var id = 'repositoryBrowser|' + repoId + "|" + revision; + var id = 'repositoryBrowser;' + repoId + ';' + revision; Sonia.repository.get(repoId, function(repository){ var panel = Ext.getCmp(id); if (! panel){ diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.global.js b/scm-webapp/src/main/webapp/resources/js/sonia.global.js index e0a331ca4f..6d23c35b92 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.global.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.global.js @@ -85,7 +85,7 @@ var groupSearchStore = new Ext.data.JsonStore({ Sonia = { - idSeparator: '|', + idSeparator: ';', idNoneObject: '-', id: function(){ @@ -93,7 +93,7 @@ Sonia = { for ( var i=0; i Date: Tue, 22 Nov 2011 19:42:26 +0100 Subject: [PATCH 34/36] fix non working history --- .../src/main/webapp/resources/js/sonia.history.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.history.js b/scm-webapp/src/main/webapp/resources/js/sonia.history.js index c3bd2e52d6..b9781c4794 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.history.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.history.js @@ -37,15 +37,13 @@ Sonia.History = { recentlyChanged: [], add: function(token){ - if (this.initialized){ - if (token != Ext.History.getToken()){ - if (this.isInvokeable(this.recentlyChanged, token)){ - if ( debug ){ - console.debug('add history element ' + token); - } - this.recentlyAdded.push(token); - Ext.History.add(token, true); + if (token != Ext.History.getToken()){ + if (this.isInvokeable(this.recentlyChanged, token)){ + if ( debug ){ + console.debug('add history element ' + token); } + this.recentlyAdded.push(token); + Ext.History.add(token, true); } } }, From 0183f277ddb031b358d772c699d4920b89a137aa Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 22 Nov 2011 19:46:16 +0100 Subject: [PATCH 35/36] append new history tokens after login --- .../main/webapp/resources/js/sonia.history.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.history.js b/scm-webapp/src/main/webapp/resources/js/sonia.history.js index b9781c4794..895c89df39 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.history.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.history.js @@ -32,18 +32,22 @@ Ext.ns('Sonia'); Sonia.History = { + initialized: false, + historyElements: [], recentlyAdded: [], recentlyChanged: [], add: function(token){ - if (token != Ext.History.getToken()){ - if (this.isInvokeable(this.recentlyChanged, token)){ - if ( debug ){ - console.debug('add history element ' + token); + if (this.initialized){ + if (token != Ext.History.getToken()){ + if (this.isInvokeable(this.recentlyChanged, token)){ + if ( debug ){ + console.debug('add history element ' + token); + } + this.recentlyAdded.push(token); + Ext.History.add(token, true); } - this.recentlyAdded.push(token); - Ext.History.add(token, true); } } }, @@ -170,6 +174,7 @@ Ext.History.on('ready', function(history){ if (token && token != 'null'){ Sonia.History.onChange(token); } + Sonia.History.initialized = true; }); Ext.History.on('change', function(token){ From 4a9489bd5c29e5434e2eb8c5a0188a2d571c989b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 24 Nov 2011 17:58:54 +0100 Subject: [PATCH 36/36] improve httpclient to handle headers and authentication --- .../main/java/sonia/scm/net/HttpClient.java | 26 ++ .../main/java/sonia/scm/net/HttpRequest.java | 264 ++++++++++++++++++ scm-server/pom.xml | 3 +- .../java/sonia/scm/net/URLHttpClient.java | 259 +++++++++++++---- 4 files changed, 500 insertions(+), 52 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/net/HttpRequest.java diff --git a/scm-core/src/main/java/sonia/scm/net/HttpClient.java b/scm-core/src/main/java/sonia/scm/net/HttpClient.java index 5878df1e1c..590f682e14 100644 --- a/scm-core/src/main/java/sonia/scm/net/HttpClient.java +++ b/scm-core/src/main/java/sonia/scm/net/HttpClient.java @@ -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 * diff --git a/scm-core/src/main/java/sonia/scm/net/HttpRequest.java b/scm-core/src/main/java/sonia/scm/net/HttpRequest.java new file mode 100644 index 0000000000..7bd99abc9c --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/net/HttpRequest.java @@ -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>(); + } + + 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>(); + } + + appendValues(parameters, name, values); + + return this; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public Map> getHeaders() + { + return headers; + } + + /** + * Method description + * + * + * @return + */ + public Map> 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> headers) + { + this.headers = headers; + + return this; + } + + /** + * Method description + * + * + * @param parameters + * + * @return + */ + public HttpRequest setParameters(Map> parameters) + { + this.parameters = parameters; + + return this; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param map + * @param name + * @param values + */ + private void appendValues(Map> map, String name, + String[] values) + { + List valueList = map.get(name); + + if (valueList == null) + { + valueList = new ArrayList(); + map.put(name, valueList); + } + + if (values != null) + { + valueList.addAll(Arrays.asList(values)); + } + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private Map> headers; + + /** Field description */ + private Map> parameters; + + /** Field description */ + private String password; + + /** Field description */ + private String url; + + /** Field description */ + private String username; +} diff --git a/scm-server/pom.xml b/scm-server/pom.xml index 3fad0c31dc..5d8010314a 100644 --- a/scm-server/pom.xml +++ b/scm-server/pom.xml @@ -20,7 +20,7 @@ commons-daemon commons-daemon - 1.0.5 + 1.0.8 @@ -75,6 +75,7 @@ scm-server + 1.0.8 sonia.scm.server.ScmServerDaemon commons-daemon diff --git a/scm-webapp/src/main/java/sonia/scm/net/URLHttpClient.java b/scm-webapp/src/main/java/sonia/scm/net/URLHttpClient.java index 3f298fe6cc..0c91afac1f 100644 --- a/scm-webapp/src/main/java/sonia/scm/net/URLHttpClient.java +++ b/scm-webapp/src/main/java/sonia/scm/net/URLHttpClient.java @@ -83,6 +83,9 @@ public class URLHttpClient implements HttpClient /** Field description */ public static final String HEADER_ACCEPT_ENCODING_VALUE = "gzip"; + /** Field description */ + public static final String HEADER_AUTHORIZATION = "Authorization"; + /** Field description */ public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization"; @@ -141,7 +144,8 @@ public class URLHttpClient implements HttpClient @Override public HttpResponse post(String url) throws IOException { - HttpURLConnection connection = (HttpURLConnection) openConnection(url); + HttpURLConnection connection = (HttpURLConnection) openConnection(null, + url); connection.setRequestMethod(METHOD_POST); @@ -163,10 +167,180 @@ public class URLHttpClient implements HttpClient public HttpResponse post(String url, Map> parameters) throws IOException { - HttpURLConnection connection = (HttpURLConnection) openConnection(url); + HttpURLConnection connection = (HttpURLConnection) openConnection(null, + url); connection.setRequestMethod(METHOD_POST); + appendPostParameter(connection, parameters); + return new URLHttpResponse(connection); + } + + /** + * Method description + * + * + * @param request + * + * @return + * + * @throws IOException + */ + @Override + public HttpResponse post(HttpRequest request) throws IOException + { + HttpURLConnection connection = (HttpURLConnection) openConnection(request, + request.getUrl()); + + connection.setRequestMethod(METHOD_POST); + appendPostParameter(connection, request.getParameters()); + + return new URLHttpResponse(connection); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param spec + * + * @return + * + * @throws IOException + */ + @Override + public HttpResponse get(String spec) throws IOException + { + return new URLHttpResponse(openConnection(null, spec)); + } + + /** + * Method description + * + * + * @param url + * @param parameters + * + * @return + * + * @throws IOException + */ + @Override + public HttpResponse get(String url, Map> parameters) + throws IOException + { + url = createGetUrl(url, parameters); + + return new URLHttpResponse(openConnection(null, url)); + } + + /** + * Method description + * + * + * @param request + * + * @return + * + * @throws IOException + */ + @Override + public HttpResponse get(HttpRequest request) throws IOException + { + String url = createGetUrl(request.getUrl(), request.getParameters()); + + return new URLHttpResponse(openConnection(request, url)); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param connection + * @param header + * @param username + * @param password + */ + private void appendBasicAuthHeader(HttpURLConnection connection, + String header, String username, + String password) + { + if (Util.isNotEmpty(username) || Util.isNotEmpty(password)) + { + username = Util.nonNull(username); + password = Util.nonNull(password); + + if (logger.isDebugEnabled()) + { + logger.debug("append {} header for user {}", header, username); + } + + String auth = username.concat(CREDENTIAL_SEPARATOR).concat(password); + + auth = new String(Base64.encode(auth.getBytes())); + connection.addRequestProperty(header, + PREFIX_BASIC_AUTHENTICATION.concat(auth)); + } + } + + /** + * Method description + * + * + * @param headers + * @param connection + */ + private void appendHeaders(Map> headers, + URLConnection connection) + { + if (Util.isNotEmpty(headers)) + { + for (Map.Entry> e : headers.entrySet()) + { + String name = e.getKey(); + List values = e.getValue(); + + if (Util.isNotEmpty(name) && Util.isNotEmpty(values)) + { + for (String value : values) + { + if (logger.isTraceEnabled()) + { + logger.trace("append header {}:{}", name, value); + } + + connection.setRequestProperty(name, value); + } + } + else if (logger.isWarnEnabled()) + { + logger.warn("value of {} header is empty", name); + } + } + } + else if (logger.isTraceEnabled()) + { + logger.trace("header map is emtpy"); + } + } + + /** + * Method description + * + * + * @param connection + * @param parameters + * + * @throws IOException + */ + private void appendPostParameter(HttpURLConnection connection, + Map> parameters) + throws IOException + { if (Util.isNotEmpty(parameters)) { connection.setDoOutput(true); @@ -206,26 +380,6 @@ public class URLHttpClient implements HttpClient IOUtil.close(writer); } } - - return new URLHttpResponse(connection); - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param spec - * - * @return - * - * @throws IOException - */ - @Override - public HttpResponse get(String spec) throws IOException - { - return new URLHttpResponse(openConnection(spec)); } /** @@ -236,12 +390,8 @@ public class URLHttpClient implements HttpClient * @param parameters * * @return - * - * @throws IOException */ - @Override - public HttpResponse get(String url, Map> parameters) - throws IOException + private String createGetUrl(String url, Map> parameters) { if (Util.isNotEmpty(parameters)) { @@ -275,11 +425,9 @@ public class URLHttpClient implements HttpClient url = ub.toString(); } - return new URLHttpResponse(openConnection(url)); + return url; } - //~--- methods -------------------------------------------------------------- - /** * Method description * @@ -306,30 +454,36 @@ public class URLHttpClient implements HttpClient * Method description * * + * + * @param request * @param spec * * @return * * @throws IOException */ - private URLConnection openConnection(String spec) throws IOException + private HttpURLConnection openConnection(HttpRequest request, String spec) + throws IOException { - return openConnection(new URL(spec)); + return openConnection(request, new URL(spec)); } /** * Method description * * + * + * @param request * @param url * * @return * * @throws IOException */ - private URLConnection openConnection(URL url) throws IOException + private HttpURLConnection openConnection(HttpRequest request, URL url) + throws IOException { - URLConnection connection = null; + HttpURLConnection connection = null; if (configuration.isEnableProxy()) { @@ -345,7 +499,9 @@ public class URLHttpClient implements HttpClient new InetSocketAddress(configuration.getProxyServer(), configuration.getProxyPort()); - connection = url.openConnection(new Proxy(Proxy.Type.HTTP, address)); + connection = + (HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, + address)); } else { @@ -354,11 +510,25 @@ public class URLHttpClient implements HttpClient logger.debug("fetch '{}'", url.toExternalForm()); } - connection = url.openConnection(); + connection = (HttpURLConnection) url.openConnection(); } connection.setReadTimeout(TIMEOUT_RAED); connection.setConnectTimeout(TIMEOUT_CONNECTION); + + if (request != null) + { + Map> headers = request.getHeaders(); + + appendHeaders(headers, connection); + + String username = request.getUsername(); + String password = request.getPassword(); + + appendBasicAuthHeader(connection, HEADER_AUTHORIZATION, username, + password); + } + connection.setRequestProperty(HEADER_ACCEPT_ENCODING, HEADER_ACCEPT_ENCODING_VALUE); connection.setRequestProperty( @@ -367,21 +537,8 @@ public class URLHttpClient implements HttpClient String username = configuration.getProxyUser(); String password = configuration.getProxyPassword(); - if (Util.isNotEmpty(username) || Util.isNotEmpty(password)) - { - if (logger.isDebugEnabled()) - { - logger.debug("enable proxy authentication for user '{}'", - Util.nonNull(username)); - } - - String auth = Util.nonNull(username).concat(CREDENTIAL_SEPARATOR).concat( - Util.nonNull(password)); - - auth = PREFIX_BASIC_AUTHENTICATION.concat( - new String(Base64.encode(auth.getBytes()))); - connection.setRequestProperty(HEADER_PROXY_AUTHORIZATION, auth); - } + appendBasicAuthHeader(connection, HEADER_PROXY_AUTHORIZATION, username, + password); return connection; }