Skip to content
Browse files

updated i18n, config and expression projects

  • Loading branch information...
1 parent faf8b6f commit 9076a0f194480da4622b56318d07469368f13788 @alvinrdeleon alvinrdeleon committed
Showing with 305 additions and 124 deletions.
  1. +1 −1 jspringbot-config/src/main/java/org/jspringbot/keyword/config/ConfigDomainObject.java
  2. +83 −12 jspringbot-config/src/main/java/org/jspringbot/keyword/config/ConfigHelper.java
  3. +1 −1 jspringbot-config/src/main/resources/desc/CreateConfigDomainObject.txt
  4. +1 −1 jspringbot-config/src/main/resources/desc/GetConfigBooleanProperty.txt
  5. +1 −1 jspringbot-config/src/main/resources/desc/GetConfigDoubleProperty.txt
  6. +1 −1 jspringbot-config/src/main/resources/desc/GetConfigIntegerProperty.txt
  7. +1 −1 jspringbot-config/src/main/resources/desc/GetConfigLongProperty.txt
  8. +1 −1 jspringbot-config/src/main/resources/desc/GetConfigProperty.txt
  9. +2 −2 jspringbot-config/src/main/resources/desc/SelectConfigDomain.txt
  10. +21 −27 jspringbot-config/src/main/resources/libdoc.intro
  11. +2 −18 jspringbot-config/src/main/resources/spring-libdoc.xml
  12. +1 −10 jspringbot-config/src/{test/resources/sample-config.xml → main/resources/spring/spring-config.xml}
  13. +9 −1 jspringbot-config/src/test/java/org/jspringbot/keyword/config/ConfigHelperTest.java
  14. +2 −0 jspringbot-config/src/test/resources/config.properties
  15. +1 −0 jspringbot-config/src/test/resources/config/a.properties
  16. +1 −0 jspringbot-config/src/test/resources/config/b.properties
  17. +28 −0 jspringbot-config/src/test/resources/spring-test.xml
  18. +2 −2 jspringbot-expression/src/main/java/org/jspringbot/keyword/expression/ELRunKeywordForEach.java
  19. +30 −1 ...ion/src/main/java/org/jspringbot/keyword/expression/{EvaluateExpressionUtils.java → ELUtils.java}
  20. +14 −0 jspringbot-expression/src/main/resources/desc/ELRunKeywordForEach.txt
  21. +17 −0 jspringbot-expression/src/main/resources/desc/ELShouldBeFalse.txt
  22. +14 −0 jspringbot-expression/src/main/resources/desc/ELShouldBeNull.txt
  23. +9 −7 jspringbot-expression/src/main/resources/desc/ELShouldBeTrue.txt
  24. +12 −0 jspringbot-expression/src/main/resources/desc/ELShouldNotBeNull.txt
  25. +10 −5 jspringbot-expression/src/main/resources/functions/expression-functions.xml
  26. +2 −2 jspringbot-i18n/src/main/resources/desc/CreateI18nObject.txt
  27. +2 −2 jspringbot-i18n/src/main/resources/desc/GetI18nMessage.txt
  28. +2 −2 jspringbot-i18n/src/main/resources/desc/SetI18nLocale.txt
  29. +16 −14 jspringbot-i18n/src/main/resources/libdoc.intro
  30. +1 −1 jspringbot-json/src/main/java/org/jspringbot/keyword/json/JSONUtils.java
  31. +17 −11 jspringbot-pretty-logger/src/main/java/org/jspringbot/syntax/HighlighterUtils.java
View
2 jspringbot-config/src/main/java/org/jspringbot/keyword/config/ConfigDomainObject.java
@@ -32,7 +32,7 @@ public String get(String code) {
LOG.keywordAppender()
.appendProperty("Config String Value", properties.getProperty(code));
- return properties.getProperty(code);
+ return ConfigHelper.evaluate(properties.getProperty(code));
}
public Boolean getBoolean(String code) {
View
95 jspringbot-config/src/main/java/org/jspringbot/keyword/config/ConfigHelper.java
@@ -18,10 +18,15 @@
package org.jspringbot.keyword.config;
+import org.apache.commons.lang.StringUtils;
+import org.jspringbot.keyword.expression.ELUtils;
+import org.jspringbot.keyword.expression.ExpressionHelper;
+import org.jspringbot.spring.ApplicationContextHolder;
import org.jspringbot.syntax.HighlightRobotLogger;
import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceEditor;
-import java.io.IOException;
+import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -29,9 +34,7 @@
public class ConfigHelper {
public static final HighlightRobotLogger LOG = HighlightRobotLogger.getLogger(ConfigHelper.class);
- protected Map<String, Resource> domains;
-
- protected Map<String, Properties> domainProperties;
+ private Map<String, Properties> domainProperties = new HashMap<String, Properties>();
private String selectedDomain;
@@ -43,18 +46,75 @@ public String getSelectedDomain() {
return selectedDomain;
}
- public void setDomains(Map<String, Resource> domains) {
- this.domains = domains;
+ private void addProperties(String domain, File file) throws IOException {
+ String filename = file.getName();
+
+ Properties properties = new Properties();
+
+ if(StringUtils.endsWith(filename, ".properties")) {
+ properties.load(new FileReader(file));
+ } else if(StringUtils.endsWith(filename, ".xml")) {
+ properties.loadFromXML(new FileInputStream(file));
+ }
+
+ domainProperties.put(domain, properties);
}
public void init() throws IOException {
- domainProperties = new HashMap<String, Properties>(domains.size());
+ ResourceEditor editor = new ResourceEditor();
+ editor.setAsText("classpath:config/");
+ Resource configDirResource = (Resource) editor.getValue();
+
+ if(configDirResource != null) {
+ try {
+ File configDir = configDirResource.getFile();
+
+ if(configDir.isDirectory()) {
+ File[] propertiesFiles = configDir.listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File file) {
+ return StringUtils.endsWith(file.getName(), ".properties") || StringUtils.endsWith(file.getName(), ".xml");
+ }
+ });
+
+ for(File propFile : propertiesFiles) {
+ String filename = propFile.getName();
+ String name = StringUtils.substring(filename, 0, StringUtils.indexOf(filename, "."));
+
+ addProperties(name, propFile);
+ }
+ }
+ } catch(IOException ignore) {
+ }
+ }
+
+ editor.setAsText("classpath:config.properties");
+ Resource configPropertiesResource = (Resource) editor.getValue();
+
- for (Map.Entry<String, Resource> entry : domains.entrySet()) {
- Properties properties = new Properties();
- properties.load(entry.getValue().getInputStream());
+ if(configPropertiesResource != null) {
+ try {
+ File configPropertiesFile = configPropertiesResource.getFile();
- domainProperties.put(entry.getKey(), properties);
+ if(configPropertiesFile.isFile()) {
+ Properties configs = new Properties();
+
+ configs.load(new FileReader(configPropertiesFile));
+
+ for(Map.Entry entry : configs.entrySet()) {
+ String name = (String) entry.getKey();
+ editor.setAsText(String.valueOf(entry.getValue()));
+
+ try {
+ Resource resource = (Resource) editor.getValue();
+ addProperties(name, resource.getFile());
+ } catch(Exception e) {
+ throw new IOException(String.format("Unable to load config '%s'.", name), e);
+ }
+ }
+ }
+ } catch(IOException ignore) {
+ }
}
}
@@ -118,6 +178,17 @@ public Double getDoubleProperty(String key) {
return value;
}
+ public static String evaluate(String value) {
+ try {
+ // ensure that expression is enabled
+ ApplicationContextHolder.get().getBean(ExpressionHelper.class);
+
+ return ELUtils.replaceVars(value);
+ } catch (Exception e) {
+ return value;
+ }
+ }
+
public String getProperty(String key) {
LOG.keywordAppender()
.appendProperty("Current Selected Domain", selectedDomain)
@@ -135,6 +206,6 @@ public String getProperty(String key) {
LOG.keywordAppender().appendProperty("Property String Value", properties.getProperty(key));
- return properties.getProperty(key);
+ return evaluate(properties.getProperty(key));
}
}
View
2 jspringbot-config/src/main/resources/desc/CreateConfigDomainObject.txt
@@ -10,7 +10,7 @@ Create and return a configuration domain object. With this object, you can retri
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| stringProperty=string value
| integerProperty=100
View
2 jspringbot-config/src/main/resources/desc/GetConfigBooleanProperty.txt
@@ -2,7 +2,7 @@ Retrieves the boolean property from the selected configuration domain.
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| stringProperty=string value
| integerProperty=100
View
2 jspringbot-config/src/main/resources/desc/GetConfigDoubleProperty.txt
@@ -2,7 +2,7 @@ Retrieves the double property from the selected configuration domain.
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| stringProperty=string value
| integerProperty=100
View
2 jspringbot-config/src/main/resources/desc/GetConfigIntegerProperty.txt
@@ -2,7 +2,7 @@ Retrieves the integer property from the selected configuration domain.
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| stringProperty=string value
| integerProperty=100
View
2 jspringbot-config/src/main/resources/desc/GetConfigLongProperty.txt
@@ -2,7 +2,7 @@ Retrieves the long property from the selected configuration domain.
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| stringProperty=string value
| integerProperty=100
View
2 jspringbot-config/src/main/resources/desc/GetConfigProperty.txt
@@ -2,7 +2,7 @@ Retrieves the string property from the selected configuration domain.
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| stringProperty=string value
| integerProperty=100
View
4 jspringbot-config/src/main/resources/desc/SelectConfigDomain.txt
@@ -2,11 +2,11 @@ Switch the selected domain configuration to the given domain argument.
Example:
-{{classpath:domain1.properties}}
+{{classpath:config/domain1.properties}}
| property1=domain1 property1 value
-{{classpath:domain2.properties}}
+{{classpath:config/domain2.properties}}
| property1=domain2 property1 value
View
48 jspringbot-config/src/main/resources/libdoc.intro
@@ -6,16 +6,33 @@ Please see the example {{Config Library}} project.
{{jspringbot-github:sample-config|Sample Project}}
+== Configuration Files ==
+
+The configuration files are properties file with name and value pair. The configuration files are auto detected using two ways.
+
+*1. Using {{classpath:config.properties}}*
+
+| domain_name=resource
+
+where:
+
+- {{domain_name}} = is the domain name
+- {{resource}} = the domain configuration file resource
+
+*2. Using the {{classpath:config/}} directory*
+
+All configuration files in this directory will be auto detected where the filename without the extension is the domain.
+
== Examples ==
*Assume we have the following properties:*
-{{classpath:variables.properties}}
+{{classpath:config/variables.properties}}
| url=http://localhost:8080/
| property1=property1 value
-{{classpath:sample.properties}}
+{{classpath:config/sample.properties}}
| property1=sample property 1 value
| property2=sample property 2 value
@@ -23,17 +40,6 @@ Please see the example {{Config Library}} project.
| amount=5.35
| is.enable.config=true
-*Spring configuration code snippet ({{spring-config.xml}}):*
-
-| <bean name="configHelper" class="org.jspringbot.keyword.config.ConfigHelper" init-method="init">
-| <property name="domains">
-| <map>
-| <entry key="variables" value="classpath:variables.properties"/>
-| <entry key="sample" value="classpath:sample.properties"/>
-| </map>
-| </property>
-| </bean>
-
*Sample Test Usage:*
| `Select Config Domain` | variable | |
@@ -84,22 +90,10 @@ Where:
{{html:<div class="alert alert-danger">}} {{html:<strong>}}Important!{{html:</strong>}} The config expression is only available for jSpringBot Library keywords. {{html:</div>}}
-*To enable add the following to {{spring-config.xml}}:*
-
-| <bean name="configExpressionHandlerRegistryBean"
-| class="org.jspringbot.keyword.expression.plugin.ExpressionHandlerRegistryBean">
-| <constructor-arg>
-| <bean class="org.jspringbot.keyword.config.ConfigExpressionHandler">
-| <constructor-arg ref="configHelper"/>
-| </bean>
-| </constructor-arg>
-| </bean>
-
-
*Sample Test Usage:*
-| `Select Config Domain` | variable | |
-| `Evaluate Expression` | $[config:url] | # output the result to log |
+| `Select Config Domain` | variable | |
+| `Evaluate Expression` | $[config:url] | # output the result to log |
=>
View
20 jspringbot-config/src/main/resources/spring-libdoc.xml
@@ -19,25 +19,9 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd">
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
- <description>jSpringBot Config Keywords</description>
-
- <bean name="configHelper" class="org.jspringbot.keyword.config.ConfigHelper" init-method="init">
- <property name="domains">
- <map>
- <entry key="robot-variables" value="classpath:variables.properties"/>
- <entry key="sample" value="classpath:sample.properties"/>
- </map>
- </property>
- </bean>
-
- <!-- Scan components -->
- <ctx:component-scan base-package="org.jspringbot.keyword.config"/>
- <ctx:annotation-config/>
+ <import resource="spring/spring-config.xml"/>
</beans>
View
11 ...nfig/src/test/resources/sample-config.xml → ...c/main/resources/spring/spring-config.xml
@@ -28,16 +28,7 @@
<description>jSpringBot Config Keywords</description>
- <import resource="classpath:spring/spring-expression.xml"/>
-
- <bean name="configHelper" class="org.jspringbot.keyword.config.ConfigHelper" init-method="init">
- <property name="domains">
- <map>
- <entry key="robot-variables" value="classpath:variables.properties"/>
- <entry key="sample" value="classpath:sample.properties"/>
- </map>
- </property>
- </bean>
+ <bean name="configHelper" class="org.jspringbot.keyword.config.ConfigHelper" init-method="init"/>
<bean name="configExpressionHandlerRegistryBean"
class="org.jspringbot.keyword.expression.plugin.ExpressionHandlerRegistryBean">
View
10 jspringbot-config/src/test/java/org/jspringbot/keyword/config/ConfigHelperTest.java
@@ -32,7 +32,7 @@
* Test for {@link org.jspringbot.keyword.config.ConfigHelper} class.
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations={"classpath:sample-config.xml"})
+@ContextConfiguration(locations={"classpath:spring-test.xml"})
public class ConfigHelperTest {
@Autowired
@@ -42,6 +42,14 @@
protected ExpressionHelper expressionHelper;
@Test
+ public void testConfigDir() throws Exception {
+ configHelper.selectDomain("a");
+ assertEquals("a value", configHelper.getProperty("a"));
+ configHelper.selectDomain("b");
+ assertEquals("b value", configHelper.getProperty("b"));
+ }
+
+ @Test
public void testSample() throws Exception {
configHelper.selectDomain("sample");
View
2 jspringbot-config/src/test/resources/config.properties
@@ -0,0 +1,2 @@
+sample=classpath:sample.properties
+robot-variables=classpath:variables.properties
View
1 jspringbot-config/src/test/resources/config/a.properties
@@ -0,0 +1 @@
+a=a value
View
1 jspringbot-config/src/test/resources/config/b.properties
@@ -0,0 +1 @@
+b=b value
View
28 jspringbot-config/src/test/resources/spring-test.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ Copyright (c) 2012. JSpringBot. All Rights Reserved.
+ ~
+ ~ See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The JSpringBot licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <import resource="classpath:spring/spring-expression.xml"/>
+ <import resource="classpath:spring/spring-config.xml"/>
+</beans>
View
4 ...ngbot-expression/src/main/java/org/jspringbot/keyword/expression/ELRunKeywordForEach.java
@@ -27,8 +27,8 @@
@Component
@KeywordInfo(
name = "EL Run Keyword For Each",
- parameters = {"keyword", "name", "list"},
- description = "classpath:desc/ELForEachRunKeyword.txt"
+ parameters = {"keyword", "itemName", "itemList"},
+ description = "classpath:desc/ELRunKeywordForEach.txt"
)
public class ELRunKeywordForEach extends AbstractExpressionKeyword {
public static final HighlightRobotLogger LOG = HighlightRobotLogger.getLogger(ExpressionHelper.class);
View
31 ...d/expression/EvaluateExpressionUtils.java → ...springbot/keyword/expression/ELUtils.java
@@ -3,21 +3,50 @@
import org.apache.commons.lang.StringUtils;
import org.jspringbot.MainContextHolder;
import org.jspringbot.PythonUtils;
+import org.jspringbot.keyword.expression.plugin.DefaultVariableProviderImpl;
import org.jspringbot.spring.ApplicationContextHolder;
import org.jspringbot.syntax.HighlightRobotLogger;
import org.python.util.PythonInterpreter;
import java.util.Arrays;
import java.util.concurrent.Callable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-public class EvaluateExpressionUtils {
+public class ELUtils {
public static final HighlightRobotLogger LOG = HighlightRobotLogger.getLogger(ExpressionHelper.class);
+ public static final Pattern PATTERN = Pattern.compile("\\$\\{[^\\}]+\\}", Pattern.CASE_INSENSITIVE);
+
private static ExpressionHelper getHelper() {
return ApplicationContextHolder.get().getBean(ExpressionHelper.class);
}
+ private static DefaultVariableProviderImpl getVariables() {
+ return (DefaultVariableProviderImpl) ApplicationContextHolder.get().getBean("defaultVariableProvider");
+ }
+
+ public static String replaceVars(String string) throws Exception {
+ StringBuilder buf = new StringBuilder(string);
+ Matcher matcher = PATTERN.matcher(buf);
+
+ int startIndex = 0;
+ while(matcher.find(startIndex)) {
+ String name = matcher.group(1);
+
+ String value = String.valueOf(getVariables().getVariables().get(name));
+ if(value == null) {
+ value = String.valueOf(robotVar(name));
+ }
+
+ buf.replace(matcher.start(), matcher.end(), value);
+ startIndex = matcher.end();
+ }
+
+ return buf.toString();
+ }
+
public static Object eval(final String expression, Object... args) throws Exception {
if(args == null || args.length == 0) {
return getHelper().evaluate(expression);
View
14 jspringbot-expression/src/main/resources/desc/ELRunKeywordForEach.txt
@@ -0,0 +1,14 @@
+This will `Run Keyword` for each items in the given list.
+
+Example:
+
+| ${items}= | `Create List` | item1 | item2 | item3 |
+| `EL Run Keyword For Each` | Process Item | item | ${items} |
+| |
+| *** Keywords *** |
+| Process Item |
+| ${item}= | `EL Evaluate` | $[item] |
+| Log | ${item} |
+
+This will loop the {{items}} and call {{Process Item}} keyword for each items.
+Each call will have an EL variable named {{item}}.
View
17 jspringbot-expression/src/main/resources/desc/ELShouldBeFalse.txt
@@ -0,0 +1,17 @@
+Evaluates the given EL {{expression}} with {{*variables}}, and this fails if the evaluation is not {{false}}.
+
+The variable identifiers are {{$1}}, {{$2}}, {{$3}} ... and so on depending on the number.
+
+*Note:* The {{*variables}} can be an EL expression as well.
+
+Example:
+
+| `EL Add Variable` | var1 | hello |
+| `EL Add Variable` | var2 | world |
+| `EL Should Be True` | $[contains(var1, 'lo')] | |
+| `EL Should Be True` | $[1+1 eq 2] | |
+| `EL Should Be True` | $[$1 eq true] | $[b:'true'] |
+| `EL Should Be True` | $[empty ''] | |
+| `EL Should Be True` | $[not empty var1] | |
+
+See also `EL Should Be True`.
View
14 jspringbot-expression/src/main/resources/desc/ELShouldBeNull.txt
@@ -0,0 +1,14 @@
+Evaluates the given EL {{expression}} with {{*variables}}, and this fails if the evaluation is not {{null}}.
+
+The variable identifiers are {{$1}}, {{$2}}, {{$3}} ... and so on depending on the number.
+
+*Note:* The {{*variables}} can be an EL expression as well.
+
+Example:
+
+| `EL Add Variable` | nullVar | $[null] |
+| `EL Should Be Null` | $[null] |
+| `EL Should Be Null` | $[$1] | $[null] |
+| `EL Should Be Null` | $[nullVar] |
+
+See also `EL Should Not Be Null`.
View
16 jspringbot-expression/src/main/resources/desc/ELShouldBeTrue.txt
@@ -6,10 +6,12 @@ The variable identifiers are {{$1}}, {{$2}}, {{$3}} ... and so on depending on t
Example:
-| `EL Add Variable` | var1 | hello |
-| `EL Add Variable` | var2 | world |
-| `EL Should Be True` | $[contains(var1, 'lo')] | |
-| `EL Should Be True` | $[1+1 eq 2] | |
-| `EL Should Be True` | $[$1 eq true] | $[b:'true'] |
-| `EL Should Be True` | $[empty ''] | |
-| `EL Should Be True` | $[not empty var1] | |
+| `EL Add Variable` | var1 | hello |
+| `EL Add Variable` | var2 | world |
+| `EL Should Be False` | $[contains(var1, 'alvin')] | |
+| `EL Should Be False` | $[1+1 ne 2] | |
+| `EL Should Be False` | $[$1 eq false] | $[b:'true'] |
+| `EL Should Be False` | $[not empty ''] | |
+| `EL Should Be False` | $[empty var1] | |
+
+See also `EL Should Be True`.
View
12 jspringbot-expression/src/main/resources/desc/ELShouldNotBeNull.txt
@@ -0,0 +1,12 @@
+Evaluates the given EL {{expression}} with {{*variables}}, and this fails if the evaluation is {{null}}.
+
+The variable identifiers are {{$1}}, {{$2}}, {{$3}} ... and so on depending on the number.
+
+*Note:* The {{*variables}} can be an EL expression as well.
+
+Example:
+
+| `EL Add Variable` | notNullVar | test |
+| `EL Should Be Not Null` | $[notNullVar] |
+
+See also `EL Should Not Be Null`.
View
15 jspringbot-expression/src/main/resources/functions/expression-functions.xml
@@ -3,27 +3,32 @@
<functions>
<function>
<name>eval</name>
- <function-class>org.jspringbot.keyword.expression.EvaluateExpressionUtils</function-class>
+ <function-class>org.jspringbot.keyword.expression.ELUtils</function-class>
<function-signature>Object eval(java.lang.String,java.lang.Object[])</function-signature>
</function>
<function>
<name>var</name>
- <function-class>org.jspringbot.keyword.expression.EvaluateExpressionUtils</function-class>
+ <function-class>org.jspringbot.keyword.expression.ELUtils</function-class>
<function-signature>Object robotVar(java.lang.String)</function-signature>
</function>
<function>
+ <name>replaceVars</name>
+ <function-class>org.jspringbot.keyword.expression.ELUtils</function-class>
+ <function-signature>java.lang.String replaceVars(java.lang.String)</function-signature>
+ </function>
+ <function>
<name>concat</name>
- <function-class>org.jspringbot.keyword.expression.EvaluateExpressionUtils</function-class>
+ <function-class>org.jspringbot.keyword.expression.ELUtils</function-class>
<function-signature>java.lang.String concat(java.lang.Object[])</function-signature>
</function>
<function>
<name>join</name>
- <function-class>org.jspringbot.keyword.expression.EvaluateExpressionUtils</function-class>
+ <function-class>org.jspringbot.keyword.expression.ELUtils</function-class>
<function-signature>java.lang.String join(java.lang.String, java.lang.Object[])</function-signature>
</function>
<function>
<name>substring</name>
- <function-class>org.jspringbot.keyword.expression.EvaluateExpressionUtils</function-class>
+ <function-class>org.jspringbot.keyword.expression.ELUtils</function-class>
<function-signature>java.lang.String substring(java.lang.String,java.lang.Integer[])</function-signature>
</function>
</functions>
View
4 jspringbot-i18n/src/main/resources/desc/CreateI18nObject.txt
@@ -13,11 +13,11 @@ When no locale was set using the `Set i18n Locale` keyword, this will use the ma
Example:
-{{classpath:Messages_en.properties}} - English language messages.
+{{Messages_en.properties}} - English language messages.
| login.page.title=Login Page
-{{classpath:Messages_ja.properties}} - Japanese language messages.
+{{Messages_ja.properties}} - Japanese language messages.
| login.page.title=\u30ED\u30B0\u30A4\u30F3\u30DA\u30FC\u30B8
View
4 jspringbot-i18n/src/main/resources/desc/GetI18nMessage.txt
@@ -6,13 +6,13 @@ Please see the {{jspringbot-doc:i18n|#introduction}} introduction section for th
Example:
-{{classpath:Messages_en.properties}} - English language messages.
+{{Messages_en.properties}} - English language messages.
| login.field.username=User Name
| login.field.password=Password
| login.page.title=Login Page
-{{classpath:Messages_ja.properties}} - Japanese language messages.
+{{Messages_ja.properties}} - Japanese language messages.
| login.field.username=\u30E6\u30FC\u30B6\u30FC\u540D
View
4 jspringbot-i18n/src/main/resources/desc/SetI18nLocale.txt
@@ -4,11 +4,11 @@ Please see the {{jspringbot-doc:i18n|#introduction}} introduction section for th
Example:
-{{classpath:Messages_en.properties}} - English language messages.
+{{Messages_en.properties}} - English language messages.
| login.page.title=Login Page
-{{classpath:Messages_ja.properties}} - Japanese language messages.
+{{Messages_ja.properties}} - Japanese language messages.
| login.page.title=\u30ED\u30B0\u30A4\u30F3\u30DA\u30FC\u30B8
View
30 jspringbot-i18n/src/main/resources/libdoc.intro
@@ -164,23 +164,36 @@ The {{Locale ID}} has the following format {{language_country_variant}}.
| da_DK | Danish | Denmark |
| es_HN | Spanish | Honduras |
+== Messages Files ==
+
+All resources with format {{Messages_[localeID].properties}} will be loaded as messages i18n file.
+
+Example:
+
+| src/
+| test/
+| resources/
+| Messages_en.properties
+| Messages_ja.properties
+| Messages_es_PR.properties
+
== Examples ==
Assume we have these multilingual messages resources.
-{{classpath:Messages_en.properties}} - English language messages.
+{{Messages_en.properties}} - English language messages.
| login.field.username=User Name
| login.field.password=Password
| login.page.title=Login Page
-{{classpath:Messages_ja.properties}} - Japanese language messages.
+{{Messages_ja.properties}} - Japanese language messages.
| login.field.username=\u30E6\u30FC\u30B6\u30FC\u540D
| login.field.password=\u30D1\u30B9\u30EF\u30FC\u30C9
| login.page.title=\u30ED\u30B0\u30A4\u30F3\u30DA\u30FC\u30B8
-{{classpath:Messages_es.properties}} - Spanish language messages.
+{{Messages_es_PR.properties}} - Spanish language messages.
| login.field.username=Nombre de usuario
| login.field.password=Contrase\u00F1a
@@ -252,17 +265,6 @@ Where:
{{html:<div class="alert alert-danger">}} {{html:<strong>}}Important!{{html:</strong>}} The i18n expression is only available for jSpringBot Library keywords. {{html:</div>}}
-*The following code snippet enables the expression support {{classpath:spring/spring-i18n.xml}}:*
-
-| <bean name="i18nExpressionHandlerRegistryBean"
-| class="org.jspringbot.keyword.expression.plugin.ExpressionHandlerRegistryBean">
-| <constructor-arg>
-| <bean class="org.jspringbot.keyword.i18n.I18nExpressionHandler">
-| <constructor-arg ref="i18nHelper"/>
-| </bean>
-| </constructor-arg>
-| </bean>
-
*Sample Test Usage:*
| `Set i18n Locale` | en | |
View
2 jspringbot-json/src/main/java/org/jspringbot/keyword/json/JSONUtils.java
@@ -30,7 +30,7 @@ public static Object singleProperty(JSONObject obj, String propertyName) {
}
public static Object property(Object... args) throws TransformerException {
- if(args[0] == null && args.length == 2 && String.class.isInstance(args[0])) {
+ if(args[0] == null && args.length == 2 && String.class.isInstance(args[1])) {
return property(args[1]);
} else if(JSONObject.class.isInstance(args[0]) && args.length == 2) {
JSONObject obj = (JSONObject) args[0];
View
28 jspringbot-pretty-logger/src/main/java/org/jspringbot/syntax/HighlighterUtils.java
@@ -18,6 +18,7 @@
package org.jspringbot.syntax;
+import org.apache.commons.lang.StringEscapeUtils;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;
@@ -35,7 +36,10 @@
private PythonInterpreter interpreter;
private HighlighterUtils() {
- interpreter = new PythonInterpreter(null, new PySystemState());
+ PySystemState sys = new PySystemState();
+ sys.setrecursionlimit(1500);
+
+ interpreter = new PythonInterpreter(null, sys);
}
public String highlightProperties(Properties properties, String comment) {
@@ -81,15 +85,17 @@ public String highlight(String code, String type) {
}
public String highlight(String code, String type, boolean linenumber) {
- interpreter.set("code", code);
- interpreter.set("type", type);
-
- interpreter.exec("from pygments import highlight\n" +
- "from pygments.lexers import get_lexer_by_name\n" +
- "from pygments.formatters import HtmlFormatter\n" +
- "formatter = HtmlFormatter(cssclass=\"syntax\"" + (linenumber ? ",linenos=\"table\"" : "") + ")\n" +
- "result = highlight(code, get_lexer_by_name(type), formatter)\n");
-
- return String.valueOf(interpreter.get("result")) + "<link rel='stylesheet' href='highlight.css'>";
+ return StringEscapeUtils.escapeHtml(code);
+
+// interpreter.set("code", code);
+// interpreter.set("type", type);
+//
+// interpreter.exec("from pygments import highlight\n" +
+// "from pygments.lexers import get_lexer_by_name\n" +
+// "from pygments.formatters import HtmlFormatter\n" +
+// "formatter = HtmlFormatter(cssclass=\"syntax\"" + (linenumber ? ",linenos=\"table\"" : "") + ")\n" +
+// "result = highlight(code, get_lexer_by_name(type), formatter)\n");
+//
+// return String.valueOf(interpreter.get("result")) + "<link rel='stylesheet' href='highlight.css'>";
}
}

0 comments on commit 9076a0f

Please sign in to comment.
Something went wrong with that request. Please try again.