marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sschaff...@apache.org
Subject [16/50] [abbrv] git commit: refactored admin templating (for MARMOTTA-228)
Date Mon, 30 Sep 2013 16:44:53 GMT
refactored admin templating (for MARMOTTA-228)


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/4e767a74
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/4e767a74
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/4e767a74

Branch: refs/heads/master
Commit: 4e767a740abf395f826c133548b6e6dd744a3f48
Parents: 0c21ac9
Author: tkurz <tkurz@apache.org>
Authored: Wed Sep 11 17:00:00 2013 +0200
Committer: tkurz <tkurz@apache.org>
Committed: Wed Sep 11 17:00:00 2013 +0200

----------------------------------------------------------------------
 .../core/api/modules/ModuleService.java         |  29 +++
 .../core/api/templating/TemplatingService.java  |   8 +
 .../platform/core/model/template/MenuItem.java  |  75 ++++++-
 .../core/model/template/MenuItemType.java       |  12 ++
 .../services/modules/ModuleServiceImpl.java     | 160 ++++++++++++--
 .../templating/AdminTemplatingServiceImpl.java  | 210 +++++--------------
 .../src/main/resources/kiwi-module.properties   |   5 +-
 .../src/main/resources/templates/admin.ftl      |  80 +++++--
 8 files changed, 382 insertions(+), 197 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
index 0739abe..173c34f 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/modules/ModuleService.java
@@ -17,11 +17,13 @@
  */
 package org.apache.marmotta.platform.core.api.modules;
 
+import org.apache.commons.configuration.Configuration;
 import org.apache.marmotta.platform.core.model.module.ModuleConfiguration;
 
 import javax.enterprise.inject.spi.InjectionPoint;
 import java.net.URL;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -129,4 +131,31 @@ public interface ModuleService {
      */
     public int getWeight(String moduleName);
 
+    /**
+     * returns  more complex admin page description
+     * @param moduleName
+     * @return
+     */
+    public List<HashMap<String,String>> getAdminPageObjects(String moduleName);
+
+    /**
+     * returns the icon (if set), null otherwise
+     * @param moduleName
+     * @return
+     */
+    public String getIcon(String moduleName);
+
+    /**
+     * list modules for container sorted on weight
+     * @param container
+     * @return
+     */
+    public List<String> listSortedModules(String container);
+
+    /**
+     * list containers sorted on weight
+     * @return
+     */
+    public List<String> listSortedContainers();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/templating/TemplatingService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/templating/TemplatingService.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/templating/TemplatingService.java
index 2e6c770..7a17f87 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/templating/TemplatingService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/templating/TemplatingService.java
@@ -33,10 +33,18 @@ import freemarker.template.TemplateException;
 public interface TemplatingService {
     
     final static String PATH = "/templates/";
+
+    public final static String DEFAULT_REST_PATH = "/doc/rest/";
+
+    public final static String DEFAULT_REST_FILE = "overview-index.html";
     
     static final String DEFAULT_PROJECT = "marmotta";
     
     static final String DEFAULT_STYLE = "blue";
+
+    static final String ADMIN_TPL = "admin.ftl";
+
+    public final static String DEFAULT_WEBSERVICE_TITLE = "Webservice";
     
     void initDataModel();
     

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItem.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItem.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItem.java
index 883d01e..1e04adf 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItem.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItem.java
@@ -17,6 +17,8 @@
  */
 package org.apache.marmotta.platform.core.model.template;
 
+import org.apache.marmotta.platform.core.api.templating.TemplatingService;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -31,19 +33,76 @@ import java.util.Map;
  */
 public class MenuItem {
 
-    private Map<String,Object> properties;
-    private List<MenuItem> submenu;
+    private boolean initialized = false;
+    public final static String DEFAULT_MENU_ICON = "icon-asterisk";
+
+    private HashMap<String,Object> properties;
+    private List<MenuItem> items;
+    private MenuItemType type;
+
+    public MenuItem(String label, MenuItemType type) {
+        this.properties = new HashMap<String, Object>();
+        this.type = type;
+        this.items = new ArrayList<MenuItem>();
 
-    public MenuItem() {
-        properties = new HashMap<String, Object>();
-        submenu = new ArrayList<MenuItem>();
+        properties.put("items",items);
+        properties.put("label",label);
+        properties.put("isActive",false);
+        properties.put("icon",DEFAULT_MENU_ICON);
     }
 
-    public Map<String, Object> getProperties() {
+    public HashMap<String,Object> getProperties() {
+        if(properties.get("items") != null) {
+            List<Object> os = new ArrayList<Object>();
+            for(MenuItem item : items) {
+                os.add(item.getProperties());
+            }
+            properties.put("items",os);
+        }
         return properties;
     }
 
-    public List<MenuItem> getSubmenu() {
-        return submenu;
+    public void set(String name, Object value) {
+        properties.put(name,value);
+    }
+
+    public Object get(String name) {
+        return properties.get(name);
+    }
+
+    public void addItem(MenuItem item) {
+        items.add(item);
+    }
+
+    public boolean setActive(String path) {
+        boolean isActive = false;
+        switch(type) {
+            case ROOT:
+            case CONTAINER:
+            case MODULE:
+                for(MenuItem item : items) {
+                    if(item.setActive(path)) {
+                        isActive = true;
+                    }
+                }
+                break;
+            case PAGE:
+                isActive  = get("path").equals(path);
+                break;
+            case WEBSERVICE:
+                String s = (String)properties.get("path");
+                isActive = (
+                        path.startsWith(s.substring(0,s.lastIndexOf("/"))) &&
+                                path.contains(TemplatingService.DEFAULT_REST_PATH));
+                break;
+            default:
+                isActive = false;
+        }
+        set("isActive",isActive);
+        return isActive;
+    }
+
+    public boolean isEmpty() {
+        return items.isEmpty();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItemType.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItemType.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItemType.java
new file mode 100644
index 0000000..524db52
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/model/template/MenuItemType.java
@@ -0,0 +1,12 @@
+package org.apache.marmotta.platform.core.model.template;
+
+/**
+ * ...
+ * <p/>
+ * Author: Thomas Kurz (tkurz@apache.org)
+ */
+public enum MenuItemType {
+
+    ROOT,CONTAINER,MODULE,PAGE,WEBSERVICE
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
index b7e4d63..c54ffa1 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/modules/ModuleServiceImpl.java
@@ -37,13 +37,7 @@ import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Add file description here!
@@ -53,16 +47,29 @@ import java.util.Set;
 @ApplicationScoped
 public class ModuleServiceImpl implements ModuleService {
 
+    private String default_container_name = "Others";
+
     private Logger log = LoggerFactory.getLogger(ModuleServiceImpl.class);
 
     private Set<String> modules;
 
+    private HashMap<String,ArrayList<String>> containers;
+
+    private HashMap<String,Integer> container_weight;
+
     private Map<String,Configuration> configurationMap;
     private Map<String, Configuration> jarURLs;
 
     @PostConstruct
     public void initialize() {
+
+        //default_container_name = configurationService.getStringConfiguration("kiwi.pages.default_container.name",default_container_name);
+        //default_container_number = configurationService.getIntConfiguration("kiwi.pages.default_container.number",default_container_number);
+
         modules = new HashSet<String>();
+        containers = new HashMap<String,ArrayList<String>>();
+        container_weight = new HashMap<String, Integer>();
+
         configurationMap = new HashMap<String, Configuration>();
         jarURLs = new HashMap<String, Configuration>();
 
@@ -83,6 +90,20 @@ public class ModuleServiceImpl implements ModuleService {
                     String moduleName = moduleProperties.getString("name");
                     modules.add(moduleName);
 
+                    String c_name = moduleProperties.getString("container") != null ? moduleProperties.getString("container")
: default_container_name;
+
+                    if(containers.get(c_name) == null) {
+                        containers.put(c_name, new ArrayList<String>());
+                    }
+                    containers.get(c_name).add(moduleName);
+
+                    if(container_weight.get(c_name) == null ) {
+                        container_weight.put(c_name,-1);
+                    }
+
+                    if(moduleProperties.getString("container.weight") != null) {
+                        container_weight.put(c_name,Math.max(container_weight.get(c_name),moduleProperties.getInt("container.weight",-1)));
+                    }
 
                     URLConnection urlConnection = moduleUrl.openConnection();
                     URL jarUrl;
@@ -112,8 +133,6 @@ public class ModuleServiceImpl implements ModuleService {
                     } catch(ConfigurationException ex) {
                     }
 
-
-
                     // create runtime configuration
                     MapConfiguration runtimeConfiguration = new MapConfiguration(new HashMap<String,
Object>());
                     runtimeConfiguration.setProperty("runtime.jarfile", jarUrl.toString());
@@ -130,6 +149,7 @@ public class ModuleServiceImpl implements ModuleService {
 
 
             }
+            //TODO container should be sortable
         } catch (IOException ex) {
             log.error("I/O error while trying to retrieve kiwi-module.properties file",ex);
         }
@@ -173,6 +193,7 @@ public class ModuleServiceImpl implements ModuleService {
      * @param moduleName
      * @return
      */
+    @Deprecated
     @Override
     public Collection<String> getEntities(String moduleName) {
         Configuration config = getModuleConfiguration(moduleName).getConfiguration();
@@ -191,6 +212,64 @@ public class ModuleServiceImpl implements ModuleService {
         return modules;
     }
 
+    public List<String> listSortedModules() {
+        return sortModules(modules);
+    }
+
+    /**
+     * returns all modules within a container
+     * @param container
+     * @return
+     */
+    public Collection<String> listModules(String container) {
+        if(containers.containsKey(container)) {
+            return containers.get(container);
+        } else return null;
+    }
+
+    @Override
+    public List<String> listSortedModules(String container) {
+        if(containers.containsKey(container)) {
+            return sortModules(containers.get(container));
+        } else return null;
+    }
+
+    /**
+     * sort modules
+     * @param m
+     * @return
+     */
+    private List<String> sortModules(Collection<String> m) {
+        List<String> sorted = new ArrayList<String>(m);
+        Collections.sort(sorted,new Comparator<String>() {
+            @Override
+            public int compare(String o, String o2) {
+                return ((Integer) getWeight(o)).compareTo(getWeight(o2));
+            }
+        });
+        return sorted;
+    }
+
+    /**
+     * Lists containers and underlying modules
+     * @return
+     */
+    public Collection<String> listContainers() {
+        return containers.keySet();
+    }
+
+    @Override
+    public List<String> listSortedContainers() {
+        List sorted = new ArrayList(containers.keySet());
+        Collections.sort(sorted,new Comparator<String>() {
+            @Override
+            public int compare(String o, String o2) {
+                return container_weight.get(o2).compareTo(container_weight.get(o));
+            }
+        });
+        return sorted;
+    }
+
     /**
      * Return the configuration for the module identified by the name given as argument.
Returns an
      * immutable Apache Commons Configuration object, or null if the module is not found.
@@ -269,18 +348,73 @@ public class ModuleServiceImpl implements ModuleService {
     }
 
     /**
-     * Return a list of admin pages (paths)
+     * returns the icon (if set), null otherwise
      * @param moduleName
      * @return
      */
     @Override
-    public List<String> getAdminPages(String moduleName) {
+    public String getIcon(String moduleName) {
         Configuration config = getModuleConfiguration(moduleName).getConfiguration();
-        if(config != null) return ImmutableList.copyOf(config.getStringArray("adminpages"));
+        if(config != null) return config.getString("icon");
         else
             return null;
     }
 
+    /**
+     * Return a list of admin pages (links)
+     * @param moduleName
+     * @return
+     */
+    @Override
+    public List<String> getAdminPages(String moduleName) {
+        Configuration config = getModuleConfiguration(moduleName).getConfiguration();
+        if(config != null) {
+            if(!config.subset("adminpage.").isEmpty()) {
+                ArrayList<String> l = new ArrayList<String>();
+                while(config.getString("adminpage."+l.size()+".link") != null) {
+                    l.add(config.getString("adminpage."+l.size()+".link"));
+                }
+                return l;
+            } else return ImmutableList.copyOf(config.getStringArray("adminpages"));
+        } else
+            return null;
+    }
+
+    /**
+     * returns  more complex admin page description
+     * @param moduleName
+     * @return
+     */
+    @Override
+    public List<HashMap<String,String>> getAdminPageObjects(String moduleName)
{
+        Configuration config = getModuleConfiguration(moduleName).getConfiguration();
+        if(config != null) {
+            ArrayList<HashMap<String,String>> l = new ArrayList<HashMap<String,String>>();
+            if(!config.subset("adminpage").isEmpty()) {
+                while(config.getString("adminpage."+l.size()+".link") != null) {
+                    HashMap<String,String> map = new HashMap<String, String>();
+                    map.put("link",config.getString("baseurl")+config.getString("adminpage."+l.size()+".link"));
+                    map.put("title",config.getString("adminpage."+l.size()+".title"));
+                    l.add(map);
+                }
+            } else {
+                for(String path : config.getStringArray("adminpages")) {
+                    HashMap<String,String> map = new HashMap<String, String>();
+                    map.put("link",config.getString("baseurl")+path);
+                    String title;
+                    if(path.lastIndexOf(".") > path.lastIndexOf("/")+1)
+                        title = path.substring(path.lastIndexOf("/")+1,path.lastIndexOf(".")).replaceAll("_","
");
+                    else
+                        title = path.substring(path.lastIndexOf("/")+1);
+                    map.put("title",title);
+                    l.add(map);
+                }
+            }
+            return l;
+        } else
+            return null;
+    }
+
     @Override
     public int getWeight(String moduleName) {
         Configuration config = getModuleConfiguration(moduleName).getConfiguration();
@@ -290,4 +424,4 @@ public class ModuleServiceImpl implements ModuleService {
             return 50;
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/AdminTemplatingServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/AdminTemplatingServiceImpl.java
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/AdminTemplatingServiceImpl.java
index 293b1e6..86c3d4e 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/AdminTemplatingServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/AdminTemplatingServiceImpl.java
@@ -38,6 +38,7 @@ import org.apache.marmotta.platform.core.api.templating.AdminInterfaceService;
 import org.apache.marmotta.platform.core.api.templating.TemplatingService;
 import org.apache.marmotta.platform.core.exception.TemplatingException;
 import org.apache.marmotta.platform.core.model.template.MenuItem;
+import org.apache.marmotta.platform.core.model.template.MenuItemType;
 
 /**
  * User: Thomas Kurz
@@ -53,7 +54,7 @@ public class AdminTemplatingServiceImpl implements AdminInterfaceService
{
 
     @Inject
     private ModuleService moduleService;
-    
+
     @Inject
     private TemplatingService templatingService;
 
@@ -61,15 +62,11 @@ public class AdminTemplatingServiceImpl implements AdminInterfaceService
{
     private ConfigurationService configurationService;
 
     //some statics
-    private static final String TEMPLATE_STRING = "admin.ftl";
-    private static final String DEFAULT_REST_PATH = "/doc/rest/";
-    private static final String DEFAULT_REST_FILE = "overview-summary.html";
-    private static final String DEFAULT_TITLE_FOR_WEBSERVICES = "webservices";
-
+    private static final String DEFAULT_ICON = "icon-beaker";
 
     //pattern to filter comments content
     private static final Pattern PATTERN = Pattern.compile("\\<!--###BEGIN_([^#]+)###--\\>(.+)\\<!--###END_\\1###--\\>",Pattern.DOTALL);
-    private Menu menu;
+    private MenuItem menu;
 
     /**
      * inits a freemarker template service with a servlet context
@@ -77,32 +74,17 @@ public class AdminTemplatingServiceImpl implements AdminInterfaceService
{
      */
     @Override
     public void init(ServletContext context) throws TemplatingException {
-    	menu = new Menu();
+        menu = buildMenu();
         this.context = context;
         try {
-        	 //try-run to check it from the very beginning
-            // sschaffert: disabled the call because it requires the host name
-            //templatingService.getTemplate(TEMPLATE_STRING);
+            //try-run to check it from the very beginning
+            templatingService.getTemplate(TemplatingService.ADMIN_TPL);
         } catch (Exception e) {
             throw new TemplatingException("Severe Error: admin template cannot be found:
" + e.getMessage());
         }
     }
 
     /**
-     * Check whether the templating service considers the resource passed in the path as
a menu entry it is
-     * responsible for.
-     *
-     * @param path a url path
-     * @return if the give path points to an admin page
-     */
-    @Override
-    public boolean isMenuEntry(String path) {
-        if(menu.path_titles.keySet().contains(configurationService.getPath()+path)) return
true;
-        if(path.contains(DEFAULT_REST_PATH)) return true;
-        else return false;
-    }
-
-    /**
      * this method wraps a file with a specified admin template. If the file is not a admin
page,
      * the bytes are returned unprocessed
      * @param bytes content represented in a byte array
@@ -114,21 +96,21 @@ public class AdminTemplatingServiceImpl implements AdminInterfaceService
{
         if(!configurationService.getBooleanConfiguration("templating.cache.enabled",true)
&& context!=null) {
             init(context);
         }
-        //apply template
-        if(!isMenuEntry(path)) return bytes;
-        //activate
-        String module = menu.getCurrentModule(configurationService.getPath() + path);
+
+        //set active
+        menu.setActive(path);
+
         //fill data model
         Map<String, Object> datamodel = new HashMap<String,Object>();
-    	for(Properties p : Properties.values()) {
-    		datamodel.put(p.name(),"<!-- "+p.name()+" not defined -->");
-    	}
+        for(Properties p : Properties.values()) {
+            datamodel.put(p.name(),"<!-- "+p.name()+" not defined -->");
+        }
         //begin hack!!!
         datamodel.put("USER_MODULE_IS_ACTIVE", moduleService.listModules().contains("Users"));
         //end hack!!!
-        datamodel.put("MODULE_MENU",menu.menuItems);
-        datamodel.put("CURRENT_TITLE", getNameFromPath(path));
-        datamodel.put("CURRENT_MODULE", module);
+
+        //add menu
+        datamodel.put("MENU",menu.getProperties());
         try {
             String s = new String(bytes);
             Matcher m = PATTERN.matcher(s);
@@ -142,7 +124,7 @@ public class AdminTemplatingServiceImpl implements AdminInterfaceService
{
         //make magic happen
         try {
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        	templatingService.process(TEMPLATE_STRING, datamodel, new OutputStreamWriter(bos));
+            templatingService.process(TemplatingService.ADMIN_TPL, datamodel, new OutputStreamWriter(bos));
             bytes = bos.toByteArray();
             bos.flush();
             bos.close();
@@ -152,133 +134,49 @@ public class AdminTemplatingServiceImpl implements AdminInterfaceService
{
         return bytes;
     }
 
+    @Override
+    public boolean isMenuEntry(String path) {
+        return menu.setActive(path);
+    }
+
     /**
-     * This object represents a menu for the admin interface. It is build using the ModuleService.
+     * build menu
+     * @return
      */
-    class Menu {
-
-        public List<MenuItem> menuItems;
-        public Map<String,String> path_titles;
-
-        public Menu() {
-            //instantiate
-            menuItems = new ArrayList<MenuItem>();
-            path_titles = new HashMap<String, String>();
-            //sort menu
-            ArrayList<String> menuSorted = new ArrayList<String>(moduleService.listModules());
-            if(configurationService.getBooleanConfiguration("templating.sort_by_weight",
true)) {
-                Collections.sort(menuSorted, new Comparator<String>() {
-                    @Override
-                    public int compare(String o1, String o2) {
-                        final int w1 = moduleService.getWeight(o1), w2 = moduleService.getWeight(o2);
-                        if (w1 == w2) return o1.compareTo(o2);
-                        return w1 - w2;
-                    }
-                });
-            } else {
-                Collections.sort(menuSorted);
-            }
-
-            //build structure
-            for(String module : menuSorted) {
-                String path = configurationService.getPath() + moduleService.getModuleWeb(module);
-                if(moduleHasAdminPages(module)) {
-                    MenuItem menu_item = new MenuItem();
-                    menu_item.getProperties().put("title",module);
-                    menu_item.getProperties().put("baseurl",moduleService.getModuleConfiguration(module).getConfiguration().getString("baseurl","/"+module));
-                    for(String page : moduleService.getAdminPages(module)) {
-                        if(page.equals("")) {
-                            continue;
-                        }
-                        MenuItem submenu = new MenuItem();
-                        submenu.getProperties().put("title",getNameFromPath(page));
-                        submenu.getProperties().put("path",path+page);
-                        //test if it is active
-                        menu_item.getSubmenu().add(submenu);
-                        path_titles.put(path+page,page);
-                    }
-                    if(moduleService.getWebservices(module)!=null &&
-                            !moduleService.getWebservices(module).isEmpty() &&
-                            !moduleService.getWebservices(module).iterator().next().equals(""))
{
-                        MenuItem submenu = new MenuItem();
-                        submenu.getProperties().put("title",DEFAULT_TITLE_FOR_WEBSERVICES);
-                        submenu.getProperties().put("path",path+DEFAULT_REST_PATH+DEFAULT_REST_FILE);
-                        //test if it is active
-                        menu_item.getSubmenu().add(submenu);
-                        path_titles.put(path+DEFAULT_REST_PATH+DEFAULT_REST_FILE,DEFAULT_TITLE_FOR_WEBSERVICES);
-                    }
-                    menuItems.add(menu_item);
+    private MenuItem buildMenu() {
+        MenuItem menu = new MenuItem("MENU", MenuItemType.ROOT);
+
+        for(String container_string : moduleService.listSortedContainers()) {
+            MenuItem container = new MenuItem(container_string, MenuItemType.CONTAINER);
+
+            //add modules
+            for(String module_string : moduleService.listSortedModules(container_string))
{
+                MenuItem module = new MenuItem(module_string, MenuItemType.MODULE);
+                module.set("path",moduleService.getModuleWeb(module_string));
+                if(moduleService.getIcon(module_string) != null)
+                    module.set("icon",moduleService.getIcon(module_string));
+
+                //add pages
+                for(HashMap<String,String> page_object : moduleService.getAdminPageObjects(module_string))
{
+                    MenuItem page = new MenuItem(page_object.get("title"), MenuItemType.PAGE);
+                    page.set("path",page_object.get("link"));
+                    module.addItem(page);
                 }
-            }
-        }
 
-        /**
-         * get current module and set submenu to active
-         * @param path the current system path
-         * @return current module name
-         */
-        public String getCurrentModule(String path) {
-            String module = "";
-            boolean active = false;
-            //test with module and submenu must be active
-            for(MenuItem menuItem : menuItems) {
-                if(path.startsWith((String)menuItem.getProperties().get("baseurl"))) {
-                    module = (String)menuItem.getProperties().get("title");
-                }
-                menuItem.getProperties().put("active",false);
-                for(MenuItem submenu : menuItem.getSubmenu()) {
-                    if(submenu.getProperties().get("path").equals(path)) {
-                        submenu.getProperties().put("active",true);
-                        menuItem.getProperties().put("active",true);
-                        module = (String)menuItem.getProperties().get("title");
-                        active = true;
-                    } else {
-                        submenu.getProperties().put("active",false);
-                    }
-                }
-            }
-            //workaround for webservices (autogenerated pages that are nit fix stored in
the menu structure)
-            if(!active) {
-                for(MenuItem menuItem : menuItems) {
-                    if(module.equals(menuItem.getProperties().get("title"))) {
-                        for(MenuItem submenu : menuItem.getSubmenu()) {
-                            if(submenu.getProperties().get("title").equals(DEFAULT_TITLE_FOR_WEBSERVICES))
{
-                                submenu.getProperties().put("active",true);
-                                menuItem.getProperties().put("active",true);
-                            }
-                        }
-                    }
+                //add webservice
+                if(!moduleService.getWebservices(module_string).isEmpty()) {
+                    MenuItem page = new MenuItem(TemplatingService.DEFAULT_WEBSERVICE_TITLE,
MenuItemType.WEBSERVICE);
+                    page.set("path",module.get("path")+TemplatingService.DEFAULT_REST_PATH+TemplatingService.DEFAULT_REST_FILE);
+                    module.addItem(page);
                 }
-            }
-            return module;
-        }
 
-        /**
-         * Tests if a module should appear in the menu
-         * @param module a module name
-         * @return true is module should appear, false if not
-         */
-        private boolean moduleHasAdminPages(String module) {
-            if(moduleService.getAdminPages(module)!=null &&
-                    !moduleService.getAdminPages(module).isEmpty() &&
-                    !moduleService.getAdminPages(module).get(0).equals(""))
-                return true;
-            else if(moduleService.getWebservices(module)!=null &&
-                    !moduleService.getWebservices(module).isEmpty() &&
-                    !moduleService.getWebservices(module).iterator().next().equals("")) return
true;
-            return false;
+                //add if there are pages to display
+                if(!module.isEmpty()) container.addItem(module);
+            }
+            menu.addItem(container);
         }
 
+        return menu;
     }
 
-    /**
-     * returns a proper name for a path by using the filename.
-     * @param path
-     * @return
-     */
-    private String getNameFromPath(String path) {
-        if(path.contains(DEFAULT_REST_PATH)) return DEFAULT_TITLE_FOR_WEBSERVICES;
-        return path.substring(path.lastIndexOf("/")).replaceAll("/"," ").replaceAll("_","
").replaceAll(".html","").replaceAll(".jsp","");
-    }
-
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/resources/kiwi-module.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/kiwi-module.properties b/platform/marmotta-core/src/main/resources/kiwi-module.properties
index 30703e7..c3e2c28 100644
--- a/platform/marmotta-core/src/main/resources/kiwi-module.properties
+++ b/platform/marmotta-core/src/main/resources/kiwi-module.properties
@@ -18,6 +18,9 @@
 
 name=Core Services
 
+container=Admin
+container.weight = 10
+
 subtitle = Configure LMF Core
 weight = 10
 
@@ -35,7 +38,7 @@ adminpages=/admin/about.html,\
   /admin/contexts.html,\
   /admin/prefixes.html,\
   /admin/system.html,\
-  /admin/database.html,
+  /admin/database.html
 
 webservices=org.apache.marmotta.platform.core.webservices.config.ConfigurationWebService,\
   org.apache.marmotta.platform.core.webservices.config.DependenciesWebService,\

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4e767a74/platform/marmotta-core/src/main/resources/templates/admin.ftl
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/templates/admin.ftl b/platform/marmotta-core/src/main/resources/templates/admin.ftl
index 7d8d7a1..3352942 100644
--- a/platform/marmotta-core/src/main/resources/templates/admin.ftl
+++ b/platform/marmotta-core/src/main/resources/templates/admin.ftl
@@ -47,7 +47,31 @@
     </#if>
 
     ${HEAD}
-
+    <style type="text/css">
+        div.menu_heading {
+            color: white;
+            font-weight: bold;
+        }
+        ul.center_submenu {
+            margin:0;
+            padding:0;
+        }
+        ul.center_submenu li {
+            list-style: none;
+            display: inline;
+            margin-bottom: -1px;
+            padding: 5px 0 0;
+            margin-bottom: 10px;
+            background-color: white;
+            border: 1px solid black;
+        }
+        ul.center_submenu li.active {
+            margin-bottom:-1px;
+        }
+        ul.center_submenu a {
+            padding:10px;
+        }
+    </style>
 </head>
 
 <body>
@@ -57,7 +81,6 @@
         <a id="logo" href="${SERVER_URL}" title="${PROJECT}">
             <img src="${SERVER_URL}${LOGO}" alt="${PROJECT} logo" />
         </a>
-        <h1>${CURRENT_MODULE} - ${CURRENT_TITLE}</h1>
         <#if USER_MODULE_IS_ACTIVE>
             <div id="login_logout"></div>
         </#if>
@@ -65,29 +88,48 @@
     <div class="clear"></div>
     <div id="left">
         <ul id="menu">
-            <#list MODULE_MENU as menu>
-            <li
-                <#if menu.properties["active"]>
-                        class="menu_item active"
-                <#else>
-                        class="menu_item"
-                </#if>
-            >
-                <div class="menu_heading"><a href="${menu.submenu[0].properties["path"]}">${menu.properties["title"]}</a></div>
+        <#list MENU["items"] as menu>
+            <li class="menu_item">
+                <div class="menu_heading">${menu.label}</div>
                 <ul class="submenu">
-                <#list menu.submenu as submenu>
-                    <li
-                        <#if submenu.properties["active"]> class="active" </#if>
-                    >
-                    <a href="${submenu.properties["path"]}">${submenu.properties["title"]}</a>
-                    </li>
-                </#list>
+                    <#list menu["items"] as submenu>
+                        <li
+                            <#if submenu["isActive"]> class="menu_item active" </#if>
+                                >
+                            <#if submenu["items"]?has_content>
+                            <a href="${SERVER_URL}${submenu["items"][0]["path"]?substring(1)}">
+                            <#else>
+                            <a href="${SERVER_URL}doc/rest/index.html">
+                            </#if>
+                            <!-- <i class="${submenu["icon"]}"></i>  <!--
TODO icon -->
+                            <span>${submenu["label"]}</span>
+                        </a>
+                        </li>
+                    </#list>
                 </ul>
             </li>
-            </#list>
+        </#list>
+
         </ul>
     </div>
     <div id="center">
+        <ul class="center_submenu">
+        <#list MENU["items"] as menu>
+            <#if menu["isActive"]>
+                <#list menu["items"] as submenu>
+                    <#if submenu["isActive"]>
+                        <#list submenu["items"] as pages>
+                            <li
+                                <#if pages["isActive"]> class="active" </#if>
+                                    >
+                                <a href="${SERVER_URL}${pages["path"]?substring(1)}">${pages["label"]}</a>
+                            </li>
+                        </#list>
+                    </#if>
+                </#list>
+            </#if>
+        </#list>
+        </ul>
         <div id="content">
         ${CONTENT}
         </div>


Mime
View raw message