+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config;\r
-\r
-import java.io.IOException;\r
-import java.io.StringReader;\r
-import java.io.StringWriter;\r
-import java.util.HashMap;\r
-\r
-/**\r
- * ExpressionParser.\r
- * \r
- * Object to parse preference declaration expression\r
- * \r
- * Variable notation is like ${blahblah}\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- */\r
-public class\r
-ExpressionParser\r
-{\r
- /**\r
- * Parser status in parsing\r
- */\r
- protected static enum Status{ ST_EXP, ST_ESCAPE, ST_VAR };\r
- \r
- /**\r
- * Variable start token\r
- */\r
- protected static final char CH_VAR = '$';\r
- /**\r
- * Variable open token\r
- */\r
- protected static final char CH_VAR_OPEN = '{';\r
- /**\r
- * Variable close token\r
- */\r
- protected static final char CH_VAR_CLOSE = '}';\r
- /**\r
- * Escaper character\r
- */\r
- protected static final char CH_ESCAPE = '^';\r
-\r
- /**\r
- * Parse <code>exp</code> and return its value\r
- * \r
- * @param exp Config definition to parse\r
- * \r
- * @return Config value to be parsed\r
- */\r
- protected static\r
- String\r
- parse(\r
- final String exp\r
- )\r
- {\r
- Status status = Status.ST_EXP;\r
- if ( null == exp )\r
- {\r
- return null;\r
- }\r
- \r
- final StringReader reader = new StringReader( exp );\r
- final StringWriter writer = new StringWriter();\r
- int ch = 0;\r
- \r
- StringWriter variableWriter = new StringWriter();\r
- try\r
- {\r
- final HashMap<String, String> var2val = new HashMap<String, String>();\r
- while ( 0 <= ( ch = reader.read() ) )\r
- {\r
- switch ( status ) { \r
- case ST_EXP:\r
- if ( CH_VAR == ch )\r
- {\r
- ch = reader.read();\r
- if ( CH_VAR_OPEN == ch )\r
- {\r
- status = Status.ST_VAR;\r
- variableWriter = new StringWriter();\r
- break;\r
- }\r
- else\r
- {\r
- writer.write( CH_VAR );\r
- }\r
- }\r
- else if ( CH_ESCAPE == ch )\r
- {\r
- status = Status.ST_ESCAPE;\r
- break;\r
- }\r
- \r
- case ST_ESCAPE:\r
- writer.write( (char) ch );\r
- status = Status.ST_EXP;\r
- break;\r
- \r
- case ST_VAR:\r
- if ( CH_VAR_CLOSE == ch )\r
- {\r
- final String variable = variableWriter.toString();\r
- final String cached = var2val.get( variable );\r
- final String subVal =\r
- ( null == cached )?Preference.getValue( variable, null ):cached;\r
- \r
- if ( null == subVal )\r
- {\r
- writer.write( CH_VAR );\r
- writer.write( CH_VAR_OPEN );\r
- writer.write( variable );\r
- writer.write( CH_VAR_CLOSE );\r
- }\r
- else\r
- {\r
- var2val.put( variable, subVal );\r
- writer.write( subVal );\r
- }\r
- status = Status.ST_EXP;\r
- break;\r
- }\r
- variableWriter.write( (char) ch );\r
- }\r
- }\r
- \r
- if ( Status.ST_VAR == status )\r
- {\r
- writer.write( CH_VAR );\r
- writer.write( CH_VAR_OPEN );\r
- writer.write( variableWriter.toString() );\r
- }\r
- }\r
- catch ( final IOException e )\r
- {\r
- throw new IllegalStateException( "StringReader#read throw IOException", e );\r
- }\r
- \r
- \r
- return writer.toString();\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config;\r
-\r
-import java.io.IOException;\r
-\r
-/**\r
- * Loader.\r
- * \r
- * Object to load preference from media resource\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- */\r
-public interface\r
-Loader\r
-{\r
- /**\r
- * Load and register preference with namespace <code>ns</code>\r
- * \r
- * @param ns Namespace name\r
- * \r
- * @throws IOException If preference can't be loaded\r
- */\r
- void load( final String ns ) throws IOException;\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config;\r
-\r
-import java.util.LinkedHashMap;\r
-import java.util.Map;\r
-\r
-/**\r
- * Namespace.\r
- * \r
- * Object to indicate preference inner region to be separated\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- */\r
-public class\r
-Namespace\r
-{\r
-\r
- /**\r
- * regsion name\r
- */\r
- protected final String name;\r
-\r
- // Prefernece ( key/definition )\r
- protected final Map<String, String> key2value =\r
- new LinkedHashMap<String, String>();\r
-\r
- /**\r
- * Consructor with name\r
- * \r
- * @param name namespace name\r
- */\r
- public Namespace(\r
- final String name\r
- )\r
- {\r
- this.name = name;\r
- }\r
-\r
- /**\r
- * Remove all preference in this namespace\r
- */\r
- public\r
- void\r
- clear()\r
- {\r
- key2value.clear();\r
- }\r
-\r
- /**\r
- * Register prefernece in this namespace\r
- * \r
- * @param key key of preference\r
- * @param definition definition of preference\r
- */\r
- public\r
- void\r
- put(\r
- final String key,\r
- final String definition\r
- )\r
- {\r
- key2value.put( key, definition );\r
- }\r
-\r
- /**\r
- * Return value having <code>key</code> as key\r
- * \r
- * @param key Key of preference\r
- * \r
- * @return preference definition\r
- */\r
- public\r
- String\r
- get(\r
- final String key\r
- )\r
- {\r
- return key2value.get( key );\r
- }\r
- \r
- /**\r
- * Remove preference having <code>key</code> as key\r
- * \r
- * @param key Key of preference\r
- * \r
- * @return preference definition\r
- */\r
- public\r
- String\r
- remove(\r
- final String key\r
- )\r
- {\r
- return key2value.remove( key );\r
- }\r
- \r
- /**\r
- * Return if no preference exists\r
- * \r
- * @return flag if no prefernece exists\r
- */\r
- public\r
- boolean\r
- isEmpty()\r
- {\r
- return key2value.isEmpty();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#toString()\r
- */\r
- public\r
- String\r
- toString()\r
- {\r
- return "Namespace[" + ((null == name)?"DEFAULT":name) + "]";\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.LinkedHashSet;\r
-import java.util.TreeMap;\r
-\r
-import org.tizen.common.config.loader.PropertiesLoader;\r
-import org.tizen.common.util.ArrayUtil;\r
-import org.tizen.common.util.ParsingUtil;\r
-import org.tizen.common.util.StringUtil;\r
-\r
-/**\r
- * Preference.\r
- * \r
- * Object to manage preferences\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- */\r
-public class\r
-Preference\r
-{\r
- /**\r
- * Default namespace that non-specified preference have\r
- */\r
- protected static Namespace DEFAULT_NAMESPACE = new Namespace( null );\r
-\r
- /**\r
- * name-namespace map\r
- */\r
- protected static final TreeMap<String, Namespace> name2ns = \r
- new TreeMap<String, Namespace>();\r
-\r
- /**\r
- * {@link Rule}s to apply\r
- */\r
- protected static final LinkedHashSet<Rule> rules =\r
- new LinkedHashSet<Rule>();\r
-\r
- static {\r
- init();\r
- }\r
-\r
- protected Preference() {}\r
-\r
- /**\r
- * Initialize preference from os environment and jvm properties\r
- */\r
- public static\r
- void\r
- init()\r
- {\r
- // From OS environment variables\r
- new PropertiesLoader( System.getenv() ).load( null );\r
-\r
- // From JVM properties. Overwrite if preference is duplicated\r
- new PropertiesLoader( System.getProperties() ).load( null );\r
- }\r
-\r
- /**\r
- * Remove all preference\r
- */\r
- public static\r
- void\r
- clear()\r
- {\r
- DEFAULT_NAMESPACE.clear();\r
- name2ns.clear();\r
- }\r
-\r
- /**\r
- * Check <code>name</code> is valid\r
- * \r
- * Key must contain only alphabet, unicode, '_', and '.'\r
- * \r
- * @param name string to check\r
- * \r
- * @return Flag if <code>name</code> is valid\r
- */\r
- protected static\r
- final\r
- boolean\r
- checkName(\r
- final String name\r
- )\r
- {\r
- final char[] chars = name.toCharArray();\r
- for ( int i=0, n=chars.length ; i<n ; ++i ) {\r
- if ( Character.isJavaIdentifierPart( chars[i] ) ) continue;\r
- if ( '.' == chars[i] ) continue;\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * Register prefernece( key-value pair ) in namespace <code>name</code>\r
- * \r
- * Ignore if invalid preference\r
- * \r
- * @param name namespace name\r
- * @param key prefernece key\r
- * @param exp prefernece expression\r
- */\r
- public static\r
- void\r
- register(\r
- final String name,\r
- final String key,\r
- final String exp\r
- )\r
- {\r
- // check namespace\r
- if ( null != name && !checkName( name ) )\r
- {\r
- return ;\r
- }\r
-\r
- // check key\r
- if ( !checkName( key ) )\r
- {\r
- return ;\r
- }\r
- if ( StringUtil.isEmpty( key ) )\r
- {\r
- return ;\r
- }\r
-\r
- // specify namespace\r
- Namespace namespace =\r
- ( null==name )?DEFAULT_NAMESPACE:name2ns.get( name );\r
- if ( null == namespace )\r
- {\r
- // create new namespace\r
- namespace = new Namespace( name );\r
- name2ns.put( name, namespace );\r
- }\r
-\r
- if ( null == exp )\r
- {\r
- // remove preference\r
- namespace.remove( key );\r
- }\r
- else\r
- {\r
- // add preference\r
- namespace.put( key, exp );\r
- }\r
- \r
- if ( null != name && namespace.isEmpty() )\r
- {\r
- // remove namespace if it is empty\r
- name2ns.remove( name );\r
- }\r
- \r
- }\r
-\r
- /**\r
- * Clear namespace naming <code>name</code>\r
- * @param name\r
- */\r
- public static\r
- void\r
- clear(\r
- final String name\r
- )\r
- {\r
- // check namespace\r
- if ( null != name && !checkName( name ) )\r
- {\r
- return ;\r
- }\r
-\r
- if ( null == name )\r
- {\r
- DEFAULT_NAMESPACE.clear();\r
- }\r
- else\r
- {\r
- name2ns.remove( name );\r
- }\r
- }\r
-\r
- /**\r
- * \r
- * Add namespace rule\r
- * \r
- * @param rule {@link Rule} to add\r
- * \r
- * @see Rule\r
- */\r
- public static\r
- void\r
- addRule(\r
- final Rule rule\r
- )\r
- {\r
- rules.add( rule );\r
- }\r
-\r
- /**\r
- * Remove namespace rule\r
- * \r
- * @param rule {@link Rule} to remove\r
- */\r
- public static\r
- void\r
- removeRule(\r
- final Rule rule\r
- )\r
- {\r
- rules.remove( rule );\r
- }\r
-\r
- /**\r
- * Remove all rules\r
- */\r
- public static\r
- void\r
- clearRule()\r
- {\r
- rules.clear();\r
- }\r
-\r
- /**\r
- * Return preference expression\r
- * \r
- * @param name namespace name\r
- * @param key preference key\r
- * \r
- * @return preference expression\r
- */\r
- public static\r
- String\r
- get(\r
- final String name,\r
- final String key\r
- )\r
- {\r
- final Namespace ns =\r
- (null==name)?DEFAULT_NAMESPACE:name2ns.get( name );\r
- if ( null == ns ) return null;\r
-\r
- return ns.get( key );\r
- }\r
- /**\r
- * Find preference expression for <code>key</code>\r
- * \r
- * Return <code>null</code> if it is not found\r
- * \r
- * @param key preference key\r
- * \r
- * @return preference expression\r
- */\r
- protected static\r
- String\r
- find(\r
- final String key\r
- )\r
- {\r
- // callstack\r
- final StackTraceElement[] stacks =\r
- Thread.currentThread().getStackTrace();\r
-\r
- // iterate callstack\r
- for ( int i=0, n=ArrayUtil.size( stacks ) ; i<n ; ++i )\r
- {\r
- final StackTraceElement e = stacks[i];\r
- \r
- // check active namespace and validation\r
- for ( final Rule rule : rules )\r
- {\r
- final String name = rule.accept( e );\r
-\r
- if ( null == name )\r
- {\r
- // check next rule\r
- continue;\r
- }\r
-\r
- // get expression\r
- final String exp = get( name, key );\r
-\r
- if ( null == exp ) \r
- {\r
- continue;\r
- }\r
-\r
- // Return found expression\r
- return exp;\r
- }\r
- }\r
-\r
- // Find default namespace\r
- return get( null, key );\r
- }\r
-\r
- /* List */\r
- /**\r
- * Return all registered {@link Namespace}s\r
- * \r
- * @return registered namespaces\r
- */\r
- public static\r
- Collection<Namespace>\r
- getNamespaces()\r
- {\r
- final HashSet<Namespace> namespaces = new HashSet<Namespace>();\r
-\r
- namespaces.add( DEFAULT_NAMESPACE );\r
- namespaces.addAll( name2ns.values() );\r
-\r
- return namespaces;\r
- }\r
- /**\r
- * Return preference keys in namespace <code>name</code>\r
- * \r
- * @param name namespace name\r
- * \r
- * @return preference keys\r
- */\r
- public static \r
- Collection<String>\r
- list(\r
- final String name\r
- )\r
- {\r
- final Namespace ns =\r
- ( null == name ) ? DEFAULT_NAMESPACE : name2ns.get( name ); \r
-\r
- if ( null == ns )\r
- {\r
- return Collections.emptySet();\r
- }\r
-\r
- return Collections.unmodifiableCollection( ns.key2value.keySet() );\r
-\r
- }\r
- /* Value */\r
- /**\r
- * Return <b>value</b> for <code>key</code>\r
- * \r
- * @param key preference key\r
- * @param defaultValue default value if value doesn't exist\r
- * \r
- * @return calculated value\r
- */\r
- public static \r
- String\r
- getValue(\r
- final String key,\r
- final String defaultValue\r
- )\r
- {\r
- // get definition\r
- final String exp = find( key );\r
- if ( null == exp )\r
- {\r
- // return default value if definition doesn't exist\r
- if ( null == defaultValue )\r
- {\r
- return null;\r
- }\r
- return ExpressionParser.parse( defaultValue );\r
- }\r
- return ExpressionParser.parse( exp );\r
- }\r
-\r
-\r
- /**\r
- * Return <b>value</b> for <code>key</code> as <code>int</code>\r
- * \r
- * @param key preference key\r
- * @param defaultValue default value if value doesn't exist\r
- * \r
- * @return calculated value\r
- */\r
- public static\r
- int\r
- getInteger(\r
- final String key,\r
- final int defaultValue\r
- )\r
- {\r
- // get value\r
- final String value = getValue( key, null );\r
-\r
- // convert to integer\r
- return ParsingUtil.parseInt( value, defaultValue );\r
- }\r
-\r
- /**\r
- * Return <b>value</b> for <code>key</code> as <code>boolean</code>\r
- * \r
- * @param key preference key\r
- * @param defaultValue default value if value doesn't exist\r
- * \r
- * @return calculated value\r
- */\r
- public static\r
- boolean\r
- getBoolean(\r
- final String key,\r
- final boolean defaultValue\r
- )\r
- {\r
- // get value\r
- final String value = getValue( key, null );\r
-\r
- // convert to boolean\r
- return ParsingUtil.parseBoolean( value, defaultValue );\r
-\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config;\r
-\r
-import org.tizen.common.util.Assert;\r
-\r
-/**\r
- * Rule.\r
- * \r
- * Object to justify that target is valid\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- */\r
-public interface\r
-Rule\r
-{\r
- /**\r
- * Return namespace name for <code>arg</code>\r
- * \r
- * Return <code>null</code> if rule is invalid for <code>arg</code>\r
- * \r
- * @param arg target name\r
- * \r
- * @return namespace name\r
- */\r
- String accept( final Object arg );\r
-\r
- /**\r
- * {@link Rule} using pattern and call stack\r
- */\r
- public static class\r
- PatternRule\r
- implements Rule\r
- {\r
- /**\r
- * Separator between class name and method name\r
- */\r
- protected static final String SEP_METHOD = "#";\r
-\r
- /**\r
- * Wildcard matching any character\r
- */\r
- protected static final String ANY = "*";\r
-\r
- /**\r
- * Class qualified name pattern to apply\r
- */\r
- protected final String qnPattern;\r
-\r
- /**\r
- * Method name pattern to apply\r
- */\r
- protected final String methodNamePattern;\r
-\r
- /**\r
- * Namespace name\r
- */\r
- protected final String name;\r
-\r
- /**\r
- * Constructor with pattern and namespace name\r
- * \r
- * Example is following.\r
- * <ul>\r
- * <li>{QualifiedNamePattern}</li>\r
- * <li>{QualifiedNamePattern}#{MethodNamePattern}\r
- * </ul>\r
- * \r
- * @param pattern pattern string to apply\r
- * @param name namespace name to return if rule is valid\r
- */\r
- public\r
- PatternRule(\r
- final String pattern,\r
- final String name\r
- )\r
- {\r
- final int index = pattern.indexOf( SEP_METHOD );\r
- if ( index < 0 )\r
- {\r
- // qualified name if no separator exists\r
- qnPattern = pattern;\r
- methodNamePattern = "*";\r
- }\r
- else\r
- {\r
- // qualfied name and method name if separator exists\r
- qnPattern = pattern.substring( 0, index );\r
- methodNamePattern = pattern.substring( index + 1 );\r
- }\r
-\r
- this.name = name;\r
- }\r
-\r
- /**\r
- * Check <code>str</code> is matching with pattern <code>p</code>\r
- * \r
- * @param p pattern to check\r
- * @param str string to check\r
- * \r
- * @return Flag if <code>str</code> is matching with <code>p</code>\r
- */\r
- protected\r
- boolean\r
- check(\r
- final String p,\r
- final String str\r
- )\r
- {\r
- if ( ANY.equals( p ) ) {\r
- // Any string is ok\r
- return true;\r
- } else if ( !p.contains( ANY ) ) {\r
- // Pattern contains no wildcard;exact matching\r
- return p.equals( str );\r
- } else {\r
- final boolean bStart = p.startsWith( ANY );\r
- final boolean bEnd = p.endsWith( ANY );\r
-\r
- final String keyword =\r
- p.substring( 0, p.length() - (bEnd?1:0) ).\r
- substring( bStart?1:0 );\r
-\r
- if ( !bStart && !bEnd ) {\r
- // in case that strings exist leading and trailing \r
- int index = keyword.indexOf( ANY );\r
-\r
- // Dose NOT permit more than one wildcard\r
- Assert.isFalse(\r
- 0 <= keyword.indexOf( ANY, index ),\r
- "Invalid Pattern[" + p + "]"\r
- );\r
-\r
- return (\r
- str.startsWith( keyword.substring( 0, index ) ) &&\r
- str.endsWith( keyword.substring( index + 1 ) )\r
- );\r
- }\r
-\r
- Assert.isFalse(\r
- keyword.contains( ANY ),\r
- "Invalid Pattern[" + p + "]"\r
- );\r
- if ( bStart && bEnd )\r
- {\r
- // In case that target pattern exists in middle of string\r
- return str.contains( keyword );\r
- }\r
- else if ( bStart )\r
- {\r
- // In case of suffix\r
- return str.endsWith( keyword );\r
- }\r
- else if ( bEnd )\r
- {\r
- // In case of prefix\r
- return str.startsWith( keyword );\r
- }\r
- throw new IllegalStateException();\r
- }\r
- } // END of method 'check'\r
-\r
-\r
- /* (non-Javadoc)\r
- * @see com.parthenon.config.Rule#accept(java.lang.Object)\r
- */\r
- public\r
- String\r
- accept(\r
- final Object arg\r
- )\r
- {\r
- if ( arg instanceof StackTraceElement )\r
- {\r
- final StackTraceElement e = (StackTraceElement) arg;\r
-\r
- // Check classname in call stack\r
- if ( !check( qnPattern, e.getClassName() ) )\r
- {\r
- return null;\r
- }\r
-\r
- // Check method in call stack\r
- if ( !check( methodNamePattern, e.getMethodName() ) )\r
- {\r
- return null;\r
- }\r
-\r
- return name;\r
- }\r
- return null;\r
- } // END of method 'accept'\r
-\r
- /* (non-Javadoc)\r
- * @see java.lang.Object#toString()\r
- */\r
- public\r
- String\r
- toString()\r
- {\r
- return "Rule[" + qnPattern + "->" + name + "]";\r
- }\r
-\r
- } // END of class 'PatternRule'\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config.loader;\r
-\r
-import org.tizen.common.config.Loader;\r
-\r
-/**\r
- * AbstractLoader.\r
- * \r
- * Abstract class to load preference\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- */\r
-abstract public class\r
-AbstractLoader\r
-implements Loader\r
-{\r
- /**\r
- * {@link Source} for preference\r
- */\r
- protected final Source src;\r
- \r
- /**\r
- * Constructor with preference source\r
- * \r
- * @param src {@link Source} for preference\r
- */\r
- public\r
- AbstractLoader(\r
- final Source src\r
- )\r
- {\r
- this.src = src;\r
- if ( null == src ) \r
- {\r
- throw new NullPointerException();\r
- }\r
- }\r
- \r
- /**\r
- * @return {@link Source} to load preference \r
- */\r
- protected\r
- Source\r
- getSource()\r
- {\r
- return src;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config.loader;\r
-\r
-import java.util.Map;\r
-import java.util.Properties;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.tizen.common.config.Preference;\r
-\r
-/**\r
- * PropertiesLoader.\r
- * \r
- * Object to load preference from *.properties file \r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- */\r
-public class\r
-PropertiesLoader\r
-{\r
- protected final Logger logger = LoggerFactory.getLogger( getClass() );\r
- \r
- protected final Map<String, String> props;\r
-\r
- /**\r
- * Constructor with {@link Properties}\r
- * \r
- * @param props {@link Properties} to clone from\r
- */\r
- @SuppressWarnings("unchecked")\r
- public\r
- PropertiesLoader(\r
- final Properties props\r
- )\r
- {\r
- this( (Map<String, String>) (Object) props );\r
- }\r
-\r
- /**\r
- * Constructor with {@link Map}\r
- * \r
- * @param props {@link Map} to clone from\r
- */\r
- public\r
- PropertiesLoader(\r
- final Map<String, String> props\r
- )\r
- {\r
- this.props = props;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.parthenon.config.Loader#load(java.lang.String)\r
- */\r
- public\r
- void\r
- load(\r
- final String name\r
- )\r
- {\r
- // 읽어들일 key/definition을 설정에 등록한다.\r
- for( final String key : props.keySet() )\r
- {\r
- try\r
- {\r
- Preference.register( name, key, props.get( key ) );\r
- }\r
- catch ( final IllegalArgumentException e )\r
- {\r
- logger.error( "Error occurred in loading.", e );\r
- }\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config.loader;\r
-\r
-import java.io.IOException;\r
-import java.net.URL;\r
-import java.util.Collections;\r
-import java.util.Enumeration;\r
-import java.util.Iterator;\r
-\r
-import org.apache.commons.collections.iterators.EnumerationIterator;\r
-\r
-/**\r
- * ResourceSource.\r
- * \r
- * {@link Source} to provide resource from classpath \r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- */\r
-public class\r
-ResourceSource\r
-implements Source\r
-{\r
- \r
- protected final String resourceName;\r
- \r
- /**\r
- * Constructor with resource name\r
- * \r
- * @param resourceName name of resource\r
- */\r
- public\r
- ResourceSource(\r
- final String resourceName\r
- )\r
- {\r
- this.resourceName = resourceName;\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see java.lang.Iterable#iterator()\r
- */\r
- @SuppressWarnings("unchecked")\r
- public\r
- Iterator<URL>\r
- iterator()\r
- {\r
- try {\r
- final ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
- final Enumeration<URL> urls = cl.getResources( resourceName );\r
- return new EnumerationIterator( urls );\r
- } catch ( final IOException e ) {\r
- e.printStackTrace();\r
- }\r
- \r
- return Collections.<URL>emptySet().iterator();\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config.loader;\r
-\r
-import java.net.URL;\r
-\r
-/**\r
- * Source.\r
- * \r
- * Object to provide {@link URL}s of resource\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- * @see Iterable\r
- */\r
-public interface\r
-Source\r
-extends Iterable<URL>\r
-{\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config.loader;\r
-\r
-import static org.tizen.common.util.IOUtil.tryClose;\r
-import static org.tizen.common.util.StringUtil.EMPTY_STRING;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.ByteArrayInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.io.StringReader;\r
-import java.net.URL;\r
-import java.text.ParseException;\r
-import java.util.Iterator;\r
-import java.util.Stack;\r
-\r
-import org.apache.log4j.lf5.util.StreamUtils;\r
-import org.tizen.common.config.Preference;\r
-import org.tizen.common.util.CollectionUtil;\r
-import org.tizen.common.util.StringUtil;\r
-\r
-/**\r
- * StructuredResourceLoader.\r
- * \r
- * Object to load preference from *.ini file\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- */\r
-public class\r
-StructuredResourceLoader\r
-extends AbstractLoader\r
-{\r
-\r
- \r
- /**\r
- * Section start token\r
- */\r
- protected static final String SEC_OPEN ="[";\r
- \r
- /**\r
- * Section end token\r
- */\r
- protected static final String SEC_CLOSE = "]";\r
- \r
- /**\r
- * Line comment token\r
- */\r
- protected static final String PREFIX_COMMENT = "#";\r
-\r
- /**\r
- * Separator of preference\r
- */\r
- protected static final char CH_ATTR_VAL = '=';\r
- /**\r
- * Escaper\r
- */\r
- protected static final char CH_ESCAPE = '\\';\r
-\r
- /**\r
- * Status of parser in syntax\r
- */\r
- protected enum Status{ ST_INDENT, ST_ATTR, ST_VAL };\r
-\r
- /**\r
- * current name space\r
- */\r
- protected String ns = EMPTY_STRING;\r
- \r
- /**\r
- * current title in parsing\r
- */\r
- protected String title = null;\r
- \r
- /**\r
- * Constructor with source\r
- * \r
- * @param src {@link Source}\r
- */\r
- public\r
- StructuredResourceLoader(\r
- final Source src\r
- )\r
- {\r
- super( src );\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see org.tizen.common.config.Loader#load(java.lang.String)\r
- */\r
- public\r
- void\r
- load(\r
- final String ns\r
- ) throws IOException {\r
- final Iterator<URL> iter = src.iterator();\r
- this.ns = StringUtil.nvl( ns );\r
- while ( iter.hasNext() )\r
- {\r
- \r
- final URL url = iter.next();\r
- final InputStream in = url.openStream();\r
- try\r
- {\r
- ByteArrayInputStream byteIn = new ByteArrayInputStream( StreamUtils.getBytes( in ) );\r
- read( byteIn );\r
- }\r
- finally\r
- {\r
- tryClose( in );\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * Composite sentence from <code>in</code> line-by-line\r
- * \r
- * @param in {@link InputStream} to read preference from\r
- * \r
- * @throws IOException If prefernece can't be read\r
- */\r
- protected\r
- void\r
- read(\r
- final InputStream in\r
- ) throws IOException {\r
- final BufferedReader reader =\r
- new BufferedReader( new InputStreamReader( in ) );\r
-\r
- String line = null;\r
- String meaning = "";\r
-\r
- final Stack<String> names = new Stack<String>();\r
-\r
- try\r
- {\r
- while ( null != ( line = reader.readLine() ) )\r
- {\r
- meaning += line;\r
- meaning = processLine( meaning, names );\r
- }\r
- }\r
- catch ( final ParseException e )\r
- {\r
- throw new IOException( e );\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Process preference sentence\r
- * \r
- * @param line preference sentence\r
- * @param names name stack\r
- * \r
- * @throws ParseException If <code>line</code> is invalid\r
- */\r
- protected\r
- String \r
- processLine(\r
- final String line,\r
- final Stack<String> names\r
- )\r
- throws ParseException\r
- {\r
- // Ignore line comment\r
- if ( line.startsWith( PREFIX_COMMENT ) ) return EMPTY_STRING;\r
-\r
- // If next line exists\r
- int cnt = 0;\r
- for ( int i=line.length()-1 ; 0<=i ; --i )\r
- {\r
- if ( CH_ESCAPE == line.charAt( i ) )\r
- {\r
- ++cnt;\r
- }\r
- }\r
-\r
- if ( 1 == ( cnt % 2 ) )\r
- {\r
- return line.substring( 0, line.length() - 1 );\r
- }\r
-\r
- // Process meaningful sentence\r
- if ( line.startsWith( SEC_OPEN ) && line.endsWith( SEC_CLOSE ) )\r
- {\r
- // In case of title\r
- title = ns + line.substring( 1, line.length() - 1 ).trim();\r
- return EMPTY_STRING;\r
- }\r
- \r
- // Process preference\r
- try {\r
- final StringReader reader = new StringReader( line );\r
-\r
- // character index\r
- int ch = 0;\r
-\r
- // parsing state\r
- Status status = Status.ST_INDENT;\r
-\r
- // the number of indent\r
- int nTab = 0;\r
-\r
- // buffer for name\r
- final StringBuilder nameBuffer = new StringBuilder();\r
-\r
- // buffer for value \r
- final StringBuilder valBuffer = new StringBuilder();\r
-\r
- // flat that previous character is escape\r
- boolean bEscape = false;\r
-\r
- int nRead = 0;\r
- while ( 0 <= ( ch = reader.read() ) )\r
- {\r
- ++nRead;\r
- switch ( status )\r
- {\r
- case ST_INDENT:\r
- if ( '\t' == ch )\r
- {\r
- ++nTab;\r
- continue;\r
- }\r
-\r
- while ( nTab < names.size() )\r
- {\r
- names.pop();\r
- }\r
- status = Status.ST_ATTR;\r
- case ST_ATTR:\r
- if ( '.' == ch )\r
- {\r
- throw new ParseException( "It containers '.' which is NOT permitted in " + line, nRead );\r
- }\r
- else if ( bEscape )\r
- {\r
- nameBuffer.append( (char) ch );\r
- bEscape = false;\r
- }\r
- else if ( CH_ESCAPE == ch )\r
- {\r
- bEscape = true;\r
- }\r
- else if ( '=' == ch )\r
- {\r
- status = Status.ST_VAL;\r
- }\r
- else\r
- {\r
- nameBuffer.append( (char) ch );\r
- }\r
- break;\r
- case ST_VAL:\r
- valBuffer.append( (char) ch );\r
- break;\r
- }\r
- }\r
- \r
- if ( status == Status.ST_INDENT )\r
- {\r
- return EMPTY_STRING;\r
- }\r
- \r
- // Create qualified name\r
- final StringBuilder qn = new StringBuilder();\r
- for ( int i=0, n=CollectionUtil.size( names ) ; i<n ; ++i )\r
- {\r
- qn.append( names.get( i ) );\r
- qn.append( '.' );\r
- }\r
- qn.append( StringUtil.trim( nameBuffer.toString() ) );\r
- names.push( StringUtil.trim( nameBuffer.toString() ) );\r
- Preference.register( title, qn.toString(), valBuffer.toString() );\r
- }\r
- catch ( final IOException e )\r
- {\r
- e.printStackTrace();\r
- }\r
-\r
-\r
- return EMPTY_STRING;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact:\r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config.loader;\r
-\r
-import java.net.URL;\r
-import java.util.Iterator;\r
-\r
-/**\r
- * URLSource.\r
- * \r
- * Object to provide {@link URL}s of resource using {@link URL}\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- * @see Source\r
- */\r
-public class\r
-URLSource\r
-implements Source\r
-{\r
- /**\r
- * {@link URL} for resource\r
- */\r
- protected final URL url;\r
- \r
- /**\r
- * Constructor with url\r
- * \r
- * @param url {@link URL} for resource\r
- */\r
- public\r
- URLSource(\r
- final URL url\r
- )\r
- {\r
- this.url = url;\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see java.lang.Iterable#iterator()\r
- */\r
- public\r
- Iterator<URL>\r
- iterator()\r
- {\r
- return null;\r
- }\r
-\r
-}\r
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.Map;
/**
/**
* Map to manage key-values
*/
- protected final Map<K, Collection<V>> map;
-
- /**
- * Default constructor
- */
- public
- CollectionMap() {
- this( new LinkedHashMap<K, Collection<V>>() );
- }
-
- /**
- * Constructor with map
- *
- * @param map key-value container
- */
- public
- CollectionMap(
- final Map<K, Collection<V>> map
- )
- {
- this.map = map;
- }
+ protected final HashMap<K, Collection<V>> map = new LinkedHashMap<K, Collection<V>>();
/**
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
-import java.net.URLDecoder;
-
-import javax.xml.crypto.URIDereferencer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
{
final String path = url.getPath();
logger.trace( "Path :{}", path );
- return vfHandler.read( URLDecoder.decode( path ) );
+ return vfHandler.read( path );
}
}
*/
package org.tizen.common;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
(String) doNotCare()
);
}
- verify( preferenceStore ).setDefault( TizenBasePreferencePage.KEY_SDKUPDATE, false );
+ verify( preferenceStore ).setDefault( TizenBasePreferencePage.KEY_SDKUPDATE, true );
}
}
+++ /dev/null
-K 25
-svn:wc:ra_dav:version-url
-V 68
-/svn/!svn/ver/3135/product/common/escode.util/test/src/escode/config
-END
-PreferenceTest.java
-K 25
-svn:wc:ra_dav:version-url
-V 88
-/svn/!svn/ver/3123/product/common/escode.util/test/src/escode/config/PreferenceTest.java
-END
-ExpressionParserTest.java
-K 25
-svn:wc:ra_dav:version-url
-V 94
-/svn/!svn/ver/1885/product/common/escode.util/test/src/escode/config/ExpressionParserTest.java
-END
+++ /dev/null
-10
-
-dir
-3304
-http://bravo/svn/product/common/escode.util/test/src/escode/config
-http://bravo/svn
-
-
-
-2012-02-07T00:29:23.967704Z
-3135
-bylee
-
-
-svn:special svn:externals svn:needs-lock
-
-
-
-
-
-
-
-
-
-
-
-deffe9a1-5acb-4285-bb96-7fb302350b82
-\f
-ExpressionParserTest.java
-file
-
-
-
-
-2012-07-22T09:20:35.000000Z
-405bee8a1d862887cd44cd4b77ca02d0
-2011-09-15T23:44:14.853268Z
-1885
-bylee
-has-props
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-1611
-\f
-PreferenceTest.java
-file
-
-
-
-
-2012-07-22T09:20:35.000000Z
-2fda4d6c8d0b3ac0b89256dc275319e9
-2012-02-03T06:01:04.868665Z
-3123
-bylee
-has-props
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2560
-\f
-loader
-dir
-\f
+++ /dev/null
-K 13
-svn:mime-type
-V 10
-text/plain
-END
+++ /dev/null
-K 13
-svn:mime-type
-V 10
-text/plain
-END
+++ /dev/null
-package escode.config;
-
-import escode.config.ExpressionParser;
-import escode.config.Preference;
-import escode.util.AbstractTestCase;
-
-
-
-public class
-ExpressionParserTest
-extends AbstractTestCase {
- /* 테스트 환경 초기화 */
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected
- void
- setUp()
- throws Exception {
- final String[][] CONFIGS = new String[][] {
- new String[] { "msg1", "hello" },
- new String[] { "msg2", "${msg3}, ${msg4}!!" },
- new String[] { "msg5", "${msg6}, ${msg7}!!" },
- new String[] { "msg6", "hello" },
- new String[] { "msg7", "world" },
- new String[] { "msg8", "${msg9" },
- new String[] { "msg9", "$abcd" },
- new String[] { "msg10", "^${abc}" }
- };
-
- for ( final String[] CONFIG : CONFIGS )
- {
- final String key = CONFIG[0];
- final String exp = CONFIG[1];
-
- Preference.register( null, key, exp );
- }
- }
-
- protected
- void
- tearDown()
- throws Exception {
- Preference.clear();
-
- super.tearDown();
- }
-
- /**
- * @throws Exception
- *
- * @see {@link ExpressionParser#parse(String)}
- */
- public
- void
- test_parse()
- throws Exception {
- final String[][] TEST_CASES = new String[][] {
- new String[] { "msg1", "hello" },
- new String[] { "msg2", "${msg3}, ${msg4}!!" },
- new String[] { "msg5", "hello, world!!" },
- new String[] { "msg8", "${msg9" },
- new String[] { "msg9", "$abcd" },
- new String[] { "msg10", "${abc}" }
- };
-
-
- for ( final String[] TEST_CASE : TEST_CASES )
- {
- final String key = TEST_CASE[0];
- final String value = TEST_CASE[1];
-
- assertEquals( value, Preference.getValue( key, null ) );
- }
- }
-
-
-}
+++ /dev/null
-package escode.config;\r
-\r
-import java.io.InputStream;\r
-import java.util.Properties;\r
-\r
-import escode.config.Preference;\r
-import escode.config.Rule;\r
-import escode.config.loader.PropertiesLoader;\r
-import escode.util.AbstractTestCase;\r
-import escode.util.StreamUtils;\r
-\r
-\r
-\r
-\r
-public class\r
-PreferenceTest\r
-extends AbstractTestCase\r
-{\r
- /**\r
- * @throws Exception\r
- * \r
- * @see Preference#checkName(String)\r
- */\r
- public void \r
- test_checkName()\r
- throws Exception {\r
- assertTrue( Preference.checkName( "ajfdkfj" ) );\r
- assertTrue( Preference.checkName( "344223" ) );\r
- assertTrue( Preference.checkName( "한글" ) );\r
-\r
- assertFalse( Preference.checkName( "344 223" ) );\r
- }\r
-\r
- /**\r
- * @throws Exception\r
- * \r
- * @see {@link Preference#find(String)}\r
- */\r
- public void\r
- test_find()\r
- throws Exception {\r
- final ClassLoader cl =\r
- Thread.currentThread().getContextClassLoader();\r
-\r
- final InputStream in =\r
- cl.getResourceAsStream( "test.properties" );\r
-\r
- try\r
- {\r
- final Properties props = new Properties();\r
- props.load( in ); \r
-\r
- final PropertiesLoader loader = new PropertiesLoader( props );\r
- loader.load( "test" );\r
-\r
- assertEquals( null, Preference.getValue( "hello", null ) );\r
-\r
- Preference.addRule( new Rule.PatternRule( "*Test", "test" ) );\r
-\r
- assertEquals( "world", Preference.find( "hello" ) );\r
- assertEquals( "${b}", Preference.find( "a" ) );\r
- assertEquals( null, Preference.find( "hello1" ) );\r
-\r
-\r
- }\r
- finally\r
- {\r
- StreamUtils.tryClose( in );\r
- Preference.clear();\r
- Preference.clearRule();\r
- }\r
- }\r
-\r
- /**\r
- * @throws Exception\r
- * \r
- * @see {@link Preference#find(String)}\r
- */\r
- public\r
- void\r
- test_getValue()\r
- throws Exception\r
- {\r
- final ClassLoader cl =\r
- Thread.currentThread().getContextClassLoader();\r
-\r
- final InputStream in =\r
- cl.getResourceAsStream( "test.properties" );\r
-\r
- try\r
- {\r
- final Properties props = new Properties();\r
- props.load( in ); \r
-\r
- final PropertiesLoader loader = new PropertiesLoader( props );\r
- loader.load( "test" );\r
-\r
- assertEquals( null, Preference.getValue( "hello", null ) );\r
-\r
- Preference.addRule( new Rule.PatternRule( "*Test", "test" ) );\r
-\r
- assertEquals( "world", Preference.getValue( "hello", null ) );\r
- assertEquals( "c", Preference.getValue( "a", null ) );\r
- assertEquals( null, Preference.getValue( "hello1", null ) );\r
- assertEquals( "e", Preference.getValue( "hello1", "${d}" ) );\r
- }\r
- finally\r
- {\r
- StreamUtils.tryClose( in );\r
- Preference.clear();\r
- Preference.clearRule();\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Common
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * BonYong Lee <bonyong.lee@samsung.com>
- *
- * Licensed 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.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-package org.tizen.common.config;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * ExpressionParserTest
- *
- * Test case for {@link ExpressionParser}
- *
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
- *
- * @see ExpressionParser
- */
-public class
-ExpressionParserTest
-{
- /**
- * Prepare test
- *
- * @throws Exception in case of failure in preparation
- */
- @Before
- protected
- void
- setUp()
- throws Exception {
- final String[][] CONFIGS = new String[][] {
- new String[] { "msg1", "hello" },
- new String[] { "msg2", "${msg3}, ${msg4}!!" },
- new String[] { "msg5", "${msg6}, ${msg7}!!" },
- new String[] { "msg6", "hello" },
- new String[] { "msg7", "world" },
- new String[] { "msg8", "${msg9" },
- new String[] { "msg9", "$abcd" },
- new String[] { "msg10", "^${abc}" }
- };
-
- for ( final String[] CONFIG : CONFIGS )
- {
- final String key = CONFIG[0];
- final String exp = CONFIG[1];
-
- Preference.register( null, key, exp );
- }
- }
-
- @After
- protected
- void
- tearDown()
- throws Exception {
- Preference.clear();
- }
-
- /**
- * Test {@link ExpressionParser#parse(String)}
- *
- * @throws Exception in case of failure in test
- *
- * @see {@link ExpressionParser#parse(String)}
- */
- @Test
- public
- void
- test_parse()
- throws Exception {
- final String[][] TEST_CASES = new String[][] {
- new String[] { "msg1", "hello" },
- new String[] { "msg2", "${msg3}, ${msg4}!!" },
- new String[] { "msg5", "hello, world!!" },
- new String[] { "msg8", "${msg9" },
- new String[] { "msg9", "$abcd" },
- new String[] { "msg10", "${abc}" }
- };
-
-
- for ( final String[] TEST_CASE : TEST_CASES )
- {
- final String key = TEST_CASE[0];
- final String value = TEST_CASE[1];
-
- assertEquals( value, Preference.getValue( key, null ) );
- }
- }
-
-
-}
+++ /dev/null
-/*\r
- * Common\r
- *\r
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: \r
- * BonYong Lee <bonyong.lee@samsung.com>\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- * Contributors:\r
- * - S-Core Co., Ltd\r
- *\r
- */\r
-package org.tizen.common.config;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertFalse;\r
-import static org.junit.Assert.assertTrue;\r
-import static org.tizen.common.util.IOUtil.tryClose;\r
-\r
-import java.io.InputStream;\r
-import java.util.Properties;\r
-\r
-import org.junit.Test;\r
-import org.tizen.common.config.loader.PropertiesLoader;\r
-\r
-\r
-/**\r
- * PreferenceTest\r
- *\r
- * Test case for {@link Preference}\r
- * \r
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
- * \r
- * @see Preference\r
- */\r
-public class\r
-PreferenceTest\r
-{\r
- /**\r
- * Test {@link Preference#checkName(String)}\r
- * \r
- * @throws Exception in case of failure in test\r
- * \r
- * @see {@link Preference#checkName(String)}\r
- */\r
- public void \r
- test_checkName()\r
- throws Exception {\r
- assertTrue( Preference.checkName( "ajfdkfj" ) );\r
- assertTrue( Preference.checkName( "344223" ) );\r
- assertTrue( Preference.checkName( "한글" ) );\r
-\r
- assertFalse( Preference.checkName( "344 223" ) );\r
- }\r
-\r
- /**\r
- * Test {@link Preference#find(String)}\r
- * \r
- * @throws Exception in case of failure in test\r
- * \r
- * @see {@link Preference#find(String)}\r
- */\r
- public void\r
- test_find()\r
- throws Exception {\r
- final ClassLoader cl =\r
- Thread.currentThread().getContextClassLoader();\r
-\r
- final InputStream in =\r
- cl.getResourceAsStream( "test.properties" );\r
-\r
- try\r
- {\r
- final Properties props = new Properties();\r
- props.load( in ); \r
-\r
- final PropertiesLoader loader = new PropertiesLoader( props );\r
- loader.load( "test" );\r
-\r
- assertEquals( null, Preference.getValue( "hello", null ) );\r
-\r
- Preference.addRule( new Rule.PatternRule( "*Test", "test" ) );\r
-\r
- assertEquals( "world", Preference.find( "hello" ) );\r
- assertEquals( "${b}", Preference.find( "a" ) );\r
- assertEquals( null, Preference.find( "hello1" ) );\r
-\r
-\r
- }\r
- finally\r
- {\r
- tryClose( in );\r
- Preference.clear();\r
- Preference.clearRule();\r
- }\r
- }\r
-\r
- /**\r
- * Test {@link Preference#getValue(String, String)}\r
- * \r
- * @throws Exception in case of failure in test\r
- * \r
- * @see {@link Preference#getValue(String, String)}\r
- */\r
- @Test\r
- public\r
- void\r
- test_getValue()\r
- throws Exception\r
- {\r
- final ClassLoader cl =\r
- Thread.currentThread().getContextClassLoader();\r
-\r
- final InputStream in =\r
- cl.getResourceAsStream( "test.properties" );\r
-\r
- try\r
- {\r
- final Properties props = new Properties();\r
- props.load( in ); \r
-\r
- final PropertiesLoader loader = new PropertiesLoader( props );\r
- loader.load( "test" );\r
-\r
- assertEquals( null, Preference.getValue( "hello", null ) );\r
-\r
- Preference.addRule( new Rule.PatternRule( "*Test", "test" ) );\r
-\r
- assertEquals( "world", Preference.getValue( "hello", null ) );\r
- assertEquals( "c", Preference.getValue( "a", null ) );\r
- assertEquals( null, Preference.getValue( "hello1", null ) );\r
- assertEquals( "e", Preference.getValue( "hello1", "${d}" ) );\r
- }\r
- finally\r
- {\r
- tryClose( in );\r
- Preference.clear();\r
- Preference.clearRule();\r
- }\r
- }\r
-\r
-}\r
+++ /dev/null
-K 25
-svn:wc:ra_dav:version-url
-V 75
-/svn/!svn/ver/3135/product/common/escode.util/test/src/escode/config/loader
-END
-StructuredResourceReaderTest.java
-K 25
-svn:wc:ra_dav:version-url
-V 109
-/svn/!svn/ver/3135/product/common/escode.util/test/src/escode/config/loader/StructuredResourceReaderTest.java
-END
+++ /dev/null
-10
-
-dir
-3304
-http://bravo/svn/product/common/escode.util/test/src/escode/config/loader
-http://bravo/svn
-
-
-
-2012-02-07T00:29:23.967704Z
-3135
-bylee
-
-
-svn:special svn:externals svn:needs-lock
-
-
-
-
-
-
-
-
-
-
-
-deffe9a1-5acb-4285-bb96-7fb302350b82
-\f
-StructuredResourceReaderTest.java
-file
-
-
-
-
-2012-07-22T09:20:35.000000Z
-ec0fc2c324dfb74801d1f833df7287cb
-2012-02-07T00:29:23.967704Z
-3135
-bylee
-has-props
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-824
-\f
+++ /dev/null
-K 13
-svn:mime-type
-V 10
-text/plain
-END
+++ /dev/null
-package escode.config.loader;
-
-import escode.config.Loader;
-import escode.config.Preference;
-import escode.util.AbstractTestCase;
-
-
-
-
-public class
-StructuredResourceReaderTest
-extends AbstractTestCase
-{
- public
- void
- test_load()
- throws Exception {
- final Source src = new ResourceSource( "logging.ini" );
- final Loader reader = new StructuredResourceReader( src );
- try
- {
-
- reader.load( "escode.logging." );
-
- assertNotNull( Preference.getNamespaces() );
-
- assertEquals( 4, Preference.getNamespaces().size() );
-
- assertEquals( 3, Preference.list( "escode.logging.layout" ).size() );
- assertEquals( 6, Preference.list( "escode.logging.appender" ).size() );
- assertEquals( 8, Preference.list( "escode.logging.logger" ).size() );
- }
- finally
- {
- Preference.clear();
- Preference.clearRule();
- }
- }
-
-}
+++ /dev/null
-/*
- * Common
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * BonYong Lee <bonyong.lee@samsung.com>
- *
- * Licensed 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.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-package org.tizen.common.config.loader;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.tizen.common.config.Loader;
-import org.tizen.common.config.Preference;
-
-/**
- * StructuredResourceLoaderTest
- *
- * Test case for {@link StructuredResourceLoader}
- *
- * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
- *
- * @see StructuredResourceLoader
- */
-public class
-StructuredResourceLoaderTest
-{
- /**
- * Test {@link StructuredResourceLoader#load(String)}
- *
- * @throws Exception in case of failure in test
- *
- * @see {@link StructuredResourceLoader#load(String)}
- */
- @Test
- public
- void
- test_load()
- throws Exception {
- final Source src = new ResourceSource( "logging.ini" );
- final Loader reader = new StructuredResourceLoader( src );
- try
- {
-
- reader.load( "escode.logging." );
-
- assertNotNull( Preference.getNamespaces() );
-
- assertEquals( 4, Preference.getNamespaces().size() );
-
- assertEquals( 3, Preference.list( "escode.logging.layout" ).size() );
- assertEquals( 6, Preference.list( "escode.logging.appender" ).size() );
- assertEquals( 8, Preference.list( "escode.logging.logger" ).size() );
- }
- finally
- {
- Preference.clear();
- Preference.clearRule();
- }
- }
-
-}
/*
- * Common
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * BonYong Lee <bonyong.lee@samsung.com>
- *
- * Licensed 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.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* BonYong Lee <bonyong.lee@samsung.com>
+*
+* Licensed 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
package org.tizen.common.util;
import static org.junit.Assert.assertEquals;