From 23c1760105986cd53d78535010fe2a5c979f0c85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 14 Oct 2013 06:45:31 +0200 Subject: [PATCH] Factor out some methods. --- .../net/pterodactylus/sone/web/CreateAlbumPage.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java index 8473eb0..4f268ec 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.java @@ -62,15 +62,23 @@ public class CreateAlbumPage extends SoneTemplatePage { templateContext.set("nameMissing", true); return; } - String description = request.getHttpRequest().getPartAsStringFailsafe("description", 256).trim(); - Sone currentSone = getCurrentSone(request.getToadletContext()); - String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36); - AlbumBuilderFactory parent = parentId.equals("") ? currentSone : webInterface.getCore().getAlbum(parentId).get(); - Album album = parent.newAlbumBuilder().randomId().build(); - album.modify().setTitle(name).setDescription(filter(request.getHttpRequest().getHeader("host"), description)).update(); + Album album = createAlbum(request, name); webInterface.getCore().touchConfiguration(); throw new RedirectException("imageBrowser.html?album=" + album.getId()); } } + private Album createAlbum(FreenetRequest request, String name) { + Sone currentSone = getCurrentSone(request.getToadletContext()); + String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36); + AlbumBuilderFactory parent = parentId.equals("") ? currentSone : webInterface.getCore().getAlbum(parentId).get(); + Album album = parent.newAlbumBuilder().randomId().build(); + return setTitleAndDescription(request, name, album); + } + + private Album setTitleAndDescription(FreenetRequest request, String name, Album album) { + String description = request.getHttpRequest().getPartAsStringFailsafe("description", 256).trim(); + return album.modify().setTitle(name).setDescription(filter(request.getHttpRequest().getHeader("host"), description)).update(); + } + } -- 2.7.4