- ResourceRepository improved

- action-config.xml & menu-config.xml moved into ResourceRepository
This commit is contained in:
Konstantin Krivopustov 2008-12-25 11:29:08 +00:00
parent e64d86b99c
commit a095a26d73
11 changed files with 69 additions and 43 deletions

View File

@ -6,7 +6,8 @@
<property name="root.dir" location="${project.dir}/.."/>
<property name="src-serv.dir" location="src-serv"/>
<property name="src-conf.dir" location="src-conf"/>
<property name="module.name" value="core"/>
<property name="module.jar" value="20cuba-core.jar"/>
<property name="module.global.jar" value="cuba-core-global.jar"/>
@ -58,6 +59,7 @@
<target name="build-module" depends="compile-module">
<echo>==> building ${project.dir} ${module.name}</echo>
<mkdir dir="${build.dir}"/>
<jar basedir="${prod.out.dir}/${module.name}" destfile="${build.dir}/${module.jar}">
<exclude name="**/entity/*"/>
@ -70,14 +72,23 @@
<jar basedir="${test.out.dir}/${module.name}" destfile="${build.dir}/${module.test.jar}">
<include name="**/*"/>
</jar>
<copy file="src-serv/${module.service.xml}" todir="${build.dir}"/>
<copy file="src-serv/${module.ds.xml}" todir="${build.dir}"/>
<mkdir dir="${build.dir}/conf"/>
<copy todir="${build.dir}/conf">
<fileset dir="src-conf" includes="**/*"/>
</copy>
</target>
<target name="deploy-module" depends="base-mod.deploy-module">
<copy file="${build.dir}/${module.global.jar}" todir="${jboss.dir}/server/default/deploy"/>
<copy file="${build.dir}/${module.service.xml}" todir="${jboss.deploy.dir}"/>
<copy file="${src-serv.dir}/${module.ds.xml}" todir="${jboss.deploy.dir}"/>
<copy todir="${jboss.dir}/server/default/conf">
<fileset dir="${build.dir}/conf" includes="**/*"/>
</copy>
</target>
<target name="undeploy-module" depends="base-mod.undeploy-module">

View File

@ -0,0 +1,11 @@
<permission-config>
<specific>
<category name="sampleCategory" description="Sample Category">
<permission name="samplePermission" description="Sample Permission"/>
</category>
</specific>
</permission-config>

View File

View File

@ -18,6 +18,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import com.haulmont.cuba.core.Locator;
@ -38,7 +41,7 @@ public class ResourceRepository implements ResourceRepositoryMBean
public void create() {
String confUrl = System.getProperty("jboss.server.config.url");
if (confUrl == null)
throw new IllegalStateException("Evnironment variable jboss.server.config.url is not set");
throw new IllegalStateException("Environment variable jboss.server.config.url is not set");
rootPath = URI.create(confUrl).getPath() + "/";
}
@ -46,6 +49,20 @@ public class ResourceRepository implements ResourceRepositoryMBean
return this;
}
public String getContent() {
List<String> list = new ArrayList<String>(repository.keySet());
Collections.sort(list);
StringBuilder sb = new StringBuilder();
for (String s : list) {
sb.append(s).append("<br>");
}
return sb.toString();
}
public void evict(String name) {
repository.remove(name);
}
public void evictAll() {
repository.clear();
}

View File

@ -10,8 +10,6 @@
*/
package com.haulmont.cuba.core.app;
import java.io.InputStream;
public interface ResourceRepositoryMBean
{
String OBJECT_NAME = "haulmont.cuba:service=ResourceRepository";
@ -20,19 +18,11 @@ public interface ResourceRepositoryMBean
ResourceRepository getImplementation();
String getContent();
void evict(String name);
void evictAll();
/**
* Loads resource into cache as byte array and returns it
* @param name resource file name relative to resources root (jboss/server/default/conf)
* @return resource as stream
*/
InputStream getResAsStream(String name);
/**
* Loads resource into cache as String and returns it
* @param name resource file name relative to resources root (jboss/server/default/conf)
* @return String resource
*/
String getResAsString(String name);
}

View File

@ -18,27 +18,24 @@ import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.io.StringReader;
public class ActionsConfig
{
private Log LOG = LogFactory.getLog(ActionsConfig.class);
private Map<String, Map<String, Action>> actions = new HashMap<String, Map<String, Action>>();
public void loadConfig(String moduleName, ResourceBundle resourceBundle, InputStream stream) {
if (stream == null)
throw new NullPointerException("Null actions config");
public void loadConfig(String moduleName, ResourceBundle resourceBundle, String xml) {
Map<String, Action> actions = new HashMap<String, Action>();
SAXReader reader = new SAXReader();
Document doc;
try {
doc = reader.read(stream);
doc = reader.read(new StringReader(xml));
} catch (DocumentException e) {
throw new RuntimeException(e);
}

View File

@ -19,6 +19,7 @@ import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import java.io.StringReader;
import java.util.*;
import com.haulmont.cuba.core.global.ClientType;
@ -51,11 +52,7 @@ public class MenuConfig
return res;
}
public void loadConfig(String moduleName, ActionsConfig actionsConfig, ResourceBundle resourceBundle, InputStream stream) {
if (stream == null) {
throw new NullPointerException("Null menu config");
}
public void loadConfig(String moduleName, ActionsConfig actionsConfig, ResourceBundle resourceBundle, String xml) {
rootItems.clear();
this.actionsConfig = actionsConfig;
@ -64,7 +61,7 @@ public class MenuConfig
SAXReader reader = new SAXReader();
Document doc;
try {
doc = reader.read(stream);
doc = reader.read(new StringReader(xml));
} catch (DocumentException e) {
throw new RuntimeException(e);
}

View File

@ -23,17 +23,17 @@
<fileset refid="server-lib-fs"/>
</path>
<!--<target name="build-module" depends="base-mod.build-module">-->
<!--<mkdir dir="${build.dir}/conf"/>-->
<!--<copy todir="${build.dir}/conf">-->
<!--<fileset dir="src-conf" includes="**/*"/>-->
<!--</copy>-->
<!--</target>-->
<target name="build-module" depends="base-mod.build-module">
<mkdir dir="${build.dir}/conf"/>
<copy todir="${build.dir}/conf">
<fileset dir="src-conf" includes="**/*"/>
</copy>
</target>
<!--<target name="deploy-module" depends="base-mod.deploy-module">-->
<!--<copy todir="${jboss.dir}/server/default/conf">-->
<!--<fileset dir="${build.dir}/conf" includes="**/*"/>-->
<!--</copy>-->
<!--</target>-->
<target name="deploy-module" depends="base-mod.deploy-module">
<copy todir="${jboss.dir}/server/default/conf">
<fileset dir="${build.dir}/conf" includes="**/*"/>
</copy>
</target>
</project>

View File

@ -16,6 +16,7 @@ import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.web.log.AppLog;
import com.haulmont.cuba.web.resource.Messages;
import com.haulmont.cuba.core.global.ClientType;
import com.haulmont.cuba.core.app.ResourceRepositoryService;
import com.itmill.toolkit.Application;
import com.itmill.toolkit.service.ApplicationContext;
import com.itmill.toolkit.terminal.Terminal;
@ -102,12 +103,14 @@ public class App extends Application implements ConnectionListener
return actionConfig;
}
protected InputStream getActionsConfigXml() {
return getClass().getResourceAsStream("/com/haulmont/cuba/web/app/config/action-config.xml");
protected String getActionsConfigXml() {
ResourceRepositoryService rrs = ServiceLocator.lookup(ResourceRepositoryService.JNDI_NAME);
return rrs.getResAsString("cuba/client/web/action-config.xml");
}
protected InputStream getMenuConfigXml() {
return getClass().getResourceAsStream("/com/haulmont/cuba/web/app/config/menu-config.xml");
protected String getMenuConfigXml() {
ResourceRepositoryService rrs = ServiceLocator.lookup(ResourceRepositoryService.JNDI_NAME);
return rrs.getResAsString("cuba/client/web/menu-config.xml");
}
protected ResourceBundle getResourceBundle() {