Make it possible for the user to specify the document name of the SSK.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 19 Oct 2010 06:34:08 +0000 (08:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 19 Oct 2010 06:34:08 +0000 (08:34 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/web/CreateSonePage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/createSone.html
src/main/resources/templates/login.html

index 4197067..a6cbc82 100644 (file)
@@ -274,7 +274,7 @@ public class Core extends AbstractService {
         *             if a Sone error occurs
         */
        public Sone createSone(String name) throws SoneException {
-               return createSone(name, null, null);
+               return createSone(name, "Sone-" + name, null, null);
        }
 
        /**
@@ -284,6 +284,8 @@ public class Core extends AbstractService {
         *
         * @param name
         *            The name of the Sone
+        * @param documentName
+        *            The document name in the SSK
         * @param requestUri
         *            The request URI of the Sone, or {@link NullPointerException}
         *            to create a Sone at a random location
@@ -294,7 +296,7 @@ public class Core extends AbstractService {
         * @throws SoneException
         *             if a Sone error occurs
         */
-       public Sone createSone(String name, String requestUri, String insertUri) throws SoneException {
+       public Sone createSone(String name, String documentName, String requestUri, String insertUri) throws SoneException {
                if ((name == null) || (name.trim().length() == 0)) {
                        throw new SoneException(Type.INVALID_SONE_NAME);
                }
@@ -311,7 +313,7 @@ public class Core extends AbstractService {
                Sone sone;
                try {
                        logger.log(Level.FINEST, "Creating new Sone “%s” at %s (%s)…", new Object[] { name, finalRequestUri, finalInsertUri });
-                       sone = getSone(UUID.randomUUID().toString()).setName(name).setRequestUri(new FreenetURI(finalRequestUri).setKeyType("USK").setDocName("Sone-" + name)).setInsertUri(new FreenetURI(finalInsertUri).setKeyType("USK").setDocName("Sone-" + name));
+                       sone = getSone(UUID.randomUUID().toString()).setName(name).setRequestUri(new FreenetURI(finalRequestUri).setKeyType("USK").setDocName(documentName)).setInsertUri(new FreenetURI(finalInsertUri).setKeyType("USK").setDocName(documentName));
                        sone.setProfile(new Profile());
                        /* set modification counter to 1 so it is inserted immediately. */
                        sone.setModificationCounter(1);
index 0174b76..901874c 100644 (file)
@@ -61,17 +61,22 @@ public class CreateSonePage extends SoneTemplatePage {
        protected void processTemplate(Request request, Template template) throws RedirectException {
                super.processTemplate(request, template);
                String name = "";
+               String documentName = null;
                String requestUri = null;
                String insertUri = null;
                if (request.getMethod() == Method.POST) {
                        name = request.getHttpRequest().getPartAsStringFailsafe("name", 100);
+                       documentName = request.getHttpRequest().getPartAsStringFailsafe("document-name", 96);
+                       if (documentName.trim().length() == 0) {
+                               documentName = "Sone-" + name;
+                       }
                        if (request.getHttpRequest().getParam("create-from-uri").length() > 0) {
                                requestUri = request.getHttpRequest().getPartAsStringFailsafe("request-uri", 256);
                                insertUri = request.getHttpRequest().getPartAsStringFailsafe("insert-uri", 256);
                        }
                        try {
                                /* create Sone. */
-                               Sone sone = webInterface.core().createSone(name, requestUri, insertUri);
+                               Sone sone = webInterface.core().createSone(name, documentName, requestUri, insertUri);
 
                                /* log in the new Sone. */
                                setCurrentSone(request.getToadletContext(), sone);
index 76d0a06..06ad735 100644 (file)
@@ -33,6 +33,7 @@ Page.Login.CreateSone.Description=Use this function if you want to create a comp
 Page.Login.CreateSone.Label.RequestURI=Sone Request URI:
 Page.Login.CreateSone.Label.InsertURI=Sone Insert URI:
 Page.Login.CreateSone.Label.Name=Sone name:
+Page.Login.CreateSone.Label.DocumentName=Name in key:
 Page.Login.CreateSone.Button.CreateFromURI=Create at given URI
 Page.Login.CreateSone.Button.CreateRandom=Create new Sone
 
index d95415f..71d7366 100644 (file)
@@ -9,6 +9,10 @@
                        <label for="name"><%= Page.Login.CreateSone.Label.Name|l10n|html></label>
                        <input type="text" name="name" value="<% name|html>"/>
                </div>
+               <div>
+                       <label for="document-name"><%= Page.Login.CreateSone.Label.DocumentName|l10n|html></label>
+                       <input type="text" name="document-name" value="<% documentName|html>" />
+               </div>
                <div<%if errorUri> class="error"<%/if>>
                        <label for="insert-uri"><%= Page.Login.CreateSone.Label.RequestURI|l10n|html></label>
                        <input type="text" name="insert-uri" value="<% insertUri|html>" />
index 7356fbb..3bb860f 100644 (file)
                        <input type="text" name="name" />
                </div>
                <div>
+                       <label for="document-name"><%= Page.Login.CreateSone.Label.DocumentName|l10n|html></label>
+                       <input type="text" name="document-name" value="<% documentName|html>" />
+               </div>
+               <div>
                        <label for="insert-uri"><%= Page.Login.CreateSone.Label.RequestURI|l10n|html></label>
                        <input type="text" name="insert-uri" value="" />
                </div>