From: ho.namkoong Date: Wed, 5 Dec 2012 09:48:43 +0000 (+0900) Subject: [Title] Implement CLI wizard X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d21e038e607138e0531f24c76c81c82de069311f;p=sdk%2Fide%2Fcommon-eplugin.git [Title] Implement CLI wizard [Type] [Module] [Priority] [Jira#] [Redmine#] 7053 [Problem] [Cause] [Solution] [TestCase] Change-Id: Iae8758d6279070a830a52f4f1ef8d4cb1bdb0e2e --- diff --git a/org.tizen.common.sign/src/org/tizen/common/sign/util/XMLUtil.java b/org.tizen.common.sign/src/org/tizen/common/sign/util/XMLUtil.java index 1b61bab..a1c01da 100644 --- a/org.tizen.common.sign/src/org/tizen/common/sign/util/XMLUtil.java +++ b/org.tizen.common.sign/src/org/tizen/common/sign/util/XMLUtil.java @@ -25,8 +25,12 @@ package org.tizen.common.sign.util; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -38,9 +42,11 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.tizen.common.util.Assert; +import org.tizen.common.util.FileUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** @@ -55,52 +61,55 @@ import org.xml.sax.SAXException; */ public class XMLUtil { - /** - * Create {@link Document} - * - * @param in {@link InputStream} to provide xml contents - * - * @return {@link Document} to be created - * - * @throws ParserConfigurationException When {@link DocumentBuilder} can't be created - * @throws SAXException When xml can't be parsed - * @throws IOException When in throw {@link IOException} - */ - public static - Document - create( - final InputStream in - ) - throws ParserConfigurationException, SAXException, IOException - { - final DocumentBuilderFactory factory = - DocumentBuilderFactory.newInstance(); - - final DocumentBuilder builder = factory.newDocumentBuilder(); - - return builder.parse( in ); - } + + public static final String FILE_EXT_XML = "xml"; + + /** + * Create {@link Document} + * + * @param in {@link InputStream} to provide xml contents + * + * @return {@link Document} to be created + * + * @throws ParserConfigurationException When {@link DocumentBuilder} can't be created + * @throws SAXException When xml can't be parsed + * @throws IOException When in throw {@link IOException} + */ + public static + Document + create( + final InputStream in + ) + throws ParserConfigurationException, SAXException, IOException + { + final DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance(); + + final DocumentBuilder builder = factory.newDocumentBuilder(); + + return builder.parse( in ); + } - /** - * Create empty {@link Document} - * - * @return {@link Document} to be created - * - * @throws ParserConfigurationException When {@link DocumentBuilder} can't be created - */ - public static - Document - create() - throws ParserConfigurationException - { - final DocumentBuilderFactory factory = - DocumentBuilderFactory.newInstance(); - - final DocumentBuilder builder = factory.newDocumentBuilder(); - - return builder.newDocument(); - } + /** + * Create empty {@link Document} + * + * @return {@link Document} to be created + * + * @throws ParserConfigurationException When {@link DocumentBuilder} can't be created + */ + public static + Document + create() + throws ParserConfigurationException + { + final DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance(); + + final DocumentBuilder builder = factory.newDocumentBuilder(); + + return builder.newDocument(); + } /** * All of the child nodes are removed. @@ -152,4 +161,68 @@ public class XMLUtil return outStream; } + + + /** + * + * Get document root from file. return null if file is not xml. + * + * @param file XML file. + * @return root element of the file + * @throws Exception + * @author ho.namkoong{@literal } + */ + public static Element getDocumentRootFromFile(File file) throws Exception { + Assert.notNull(file); + + if(!file.isFile() || !FileUtil.getFileExtension(file.getName()).equals(FILE_EXT_XML)) { + return null; + } + URL fileUrl = file.toURI().toURL(); + InputStream in = fileUrl.openStream(); + Document fileDoc = create(in); + return fileDoc.getDocumentElement(); + } + + /** + * + * Get child elements whose name is tag from the parent element. + * + * @param parent parent element + * @param tag name of the child elements. + * @return + */ + public static List getElementsByTag(Element parent, String tag) { + Assert.notNull(parent); + Assert.notNull(tag); + + List result = new ArrayList(); + NodeList nodeList = parent.getElementsByTagName(tag); + for(int i=0; i getChildrenOfElement(Element element) { + List list = new ArrayList(); + NodeList children = element.getChildNodes(); + for (int i = 0, l = children.getLength(); i < l; i++) { + Node child = children.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE) { + list.add((Element) child); + } + } + return list; + } } diff --git a/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java b/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java old mode 100755 new mode 100644 index fde2ed3..c8b980a --- a/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java @@ -59,1442 +59,1508 @@ import org.tizen.common.util.ArrayUtil.ArrayIterator; */ public class CollectionUtil { - - /** - * Empty bytes - */ - protected static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; - protected static final byte[] EMPTY_BYTES = EMPTY_BYTE_ARRAY; - - private static final String ARRAY_START = "{"; - - private static final String ARRAY_END = "}"; - - private static final String EMPTY_ARRAY = ARRAY_START + ARRAY_END; - - private static final String ARRAY_ELEMENT_SEPARATOR = ", "; + + /** + * Empty bytes + */ + protected static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + protected static final byte[] EMPTY_BYTES = EMPTY_BYTE_ARRAY; + + private static final String ARRAY_START = "{"; + + private static final String ARRAY_END = "}"; + + private static final String EMPTY_ARRAY = ARRAY_START + ARRAY_END; + + private static final String ARRAY_ELEMENT_SEPARATOR = ", "; - private static final Set> APPROXIMABLE_COLLECTION_TYPES = - Collections.unmodifiableSet( new HashSet>( Arrays.asList( new Class[] { - Collection.class, - Set.class, HashSet.class, SortedSet.class, LinkedHashSet.class, TreeSet.class, - List.class, LinkedList.class, ArrayList.class - } ) ) ); + private static final Set> APPROXIMABLE_COLLECTION_TYPES = + Collections.unmodifiableSet( new HashSet>( Arrays.asList( new Class[] { + Collection.class, + Set.class, HashSet.class, SortedSet.class, LinkedHashSet.class, TreeSet.class, + List.class, LinkedList.class, ArrayList.class + } ) ) ); - private static final Set> APPROXIMABLE_MAP_TYPES = - Collections.unmodifiableSet( new HashSet>( Arrays.asList( new Class[] { - Map.class, SortedMap.class, HashMap.class, LinkedHashMap.class, TreeMap.class - } ) ) ); - + private static final Set> APPROXIMABLE_MAP_TYPES = + Collections.unmodifiableSet( new HashSet>( Arrays.asList( new Class[] { + Map.class, SortedMap.class, HashMap.class, LinkedHashMap.class, TreeMap.class + } ) ) ); + - /* Object */ - /** - * Empty Collection - */ - public static final Collection EMPTY_COLLECTION = - Collections.unmodifiableCollection( new ArrayList() ); + /* Object */ + /** + * Empty Collection + */ + public static final Collection EMPTY_COLLECTION = + Collections.unmodifiableCollection( new ArrayList() ); - /** - * protected constructor - */ - protected CollectionUtil() {} + /** + * protected constructor + */ + protected CollectionUtil() {} - /** - *

- * check collection has no element. - * - * use without null check. - * - * Old style - * - * - * List list = null; - * ... - * if ( null != list && !list.isEmpty() ) { - * ... - * } - * - * - * Usage : - *

- * - * - * List list = null; - * ... - * if ( !CollectionUtil.isEmpty( list ) ) { - * ... - * } - * - * - * or "import static" style if you use JDK6 - * - * - * import static org.tizen.common.util.CollectionUtil.isEmpty; - * - * ... - * List list = null; - * ... - * if ( !isEmpty( list ) ) { - * ... - * } - * - * - * @param collection {@link Collection} to check - * - * @return value if collection is empty - */ - public static - boolean - isEmpty( - final Collection collection - ) - { - if ( null == collection ) - { - return true; - } - - return collection.isEmpty(); - } - - /** - *

- * Return collection's size. - * - * use without null check. - * - * Return 0 if collection is null - * - *

- * - * Old style - * - * if ( null != list ) { - * for ( int i = 0, n = list.size() ; i < n ; ++i ) { - * ... - * } - * } - * - * - * - * - * for ( int i = 0, n = CollectionUtil.size( list ) ; i < n ; ++i ) { - * ... - * } - * - * - * or "import static" style if you use JDK6 - * - * - * import static org.tizen.common.util.CollectionUtil.isEmpty; - * ... - * - * for ( int i = 0, n = size( list ) ; i < n ; ++i ) { - * ... - * } - * - * - * - * @param collection {@link Collection} to check - * - * @return size of collection - * - * @see Collection#size() - */ - public static - int - size( - final Collection collection - ) - { - if ( null == collection ) - { - return 0; - } - - return collection.size(); - } + /** + *

+ * check collection has no element. + * + * use without null check. + * + * Old style + * + * + * List list = null; + * ... + * if ( null != list && !list.isEmpty() ) { + * ... + * } + * + * + * Usage : + *

+ * + * + * List list = null; + * ... + * if ( !CollectionUtil.isEmpty( list ) ) { + * ... + * } + * + * + * or "import static" style if you use JDK6 + * + * + * import static org.tizen.common.util.CollectionUtil.isEmpty; + * + * ... + * List list = null; + * ... + * if ( !isEmpty( list ) ) { + * ... + * } + * + * + * @param collection {@link Collection} to check + * + * @return value if collection is empty + */ + public static + boolean + isEmpty( + final Collection collection + ) + { + if ( null == collection ) + { + return true; + } + + return collection.isEmpty(); + } + + /** + *

+ * Return collection's size. + * + * use without null check. + * + * Return 0 if collection is null + * + *

+ * + * Old style + * + * if ( null != list ) { + * for ( int i = 0, n = list.size() ; i < n ; ++i ) { + * ... + * } + * } + * + * + * + * + * for ( int i = 0, n = CollectionUtil.size( list ) ; i < n ; ++i ) { + * ... + * } + * + * + * or "import static" style if you use JDK6 + * + * + * import static org.tizen.common.util.CollectionUtil.isEmpty; + * ... + * + * for ( int i = 0, n = size( list ) ; i < n ; ++i ) { + * ... + * } + * + * + * + * @param collection {@link Collection} to check + * + * @return size of collection + * + * @see Collection#size() + */ + public static + int + size( + final Collection collection + ) + { + if ( null == collection ) + { + return 0; + } + + return collection.size(); + } - /** - *

- * run runner iterateing element of collection. - * - * use without null-check for collection - * - * delegate error handling to runner - *

- * - * - * - * CollectionUtil.iterate( - * new ArrayList( Arrays.asList( "hello", "Hello", "World", null, "Test" ) ), - * new IteratingRunner() { - * public void run( String arg ) { - * ... - * } - * } - * ); - * - * - * - * @param type of element in collection - * @param collection {@link Collection} containing element - * @param runner {@link Runnable} to execute - * - * @throws InvocationTargetException when runner's {@link Runnable#run()} throws exception - * - * @see {@link #iterate(Collection, IteratingRunner, boolean)} - * @see FilterIterator - */ - public static - void - iterate( - final Collection collection, - final IteratingRunner runner - ) - throws InvocationTargetException - { - iterate( collection, runner, false ); - } - - /** - *

- * run runner iterateing element of collection. - * - * use without null-check for collection - * - * delegate error handling to runner - * - *

- * - * - * CollectionUtil.iterate( - * new ArrayList( Arrays.asList( "hello", "Hello", "World", null, "Test" ) ), - * new IteratingRunner() { - * public void run( String arg ) { - * ... - * } - * }, - * true - * ); - * - * - * - * @param type of element in collection - * @param collection {@link Collection} containing element - * @param runner {@link Runnable} to execute - * @param bForceProcess flag to iterate continuously when exception occurs - * - * @throws InvocationTargetException when runner's {@link Runnable#run()} throws exception - * - * @see FilterIterator - */ - public static - void - iterate( - final Collection collection, - final IteratingRunner runner, - final boolean bForceProcess - ) - throws InvocationTargetException - { - if ( null == runner ) - { - return ; - } - if ( isEmpty( collection ) ) - { - return ; - } - - for ( final T arg : collection ) - { - if ( null == arg && !bForceProcess ) - { - continue ; - } - try - { - runner.run( arg ); - } catch ( Throwable e ) - { - if ( !bForceProcess ) - { - throw new InvocationTargetException( e ); - } - } - } - } - - /** - *

- * fiter collection to result using runner - * - * determined if stop or keep going using bForceProcess in case of exception. - *

- * - * @param type of element in collection - * @param collection {@link Collection} to filter - * @param results collection to save result - * @param runner object to determine if filter - * @param bForceProcess flag to keep going when exception occurs - * - * @throws InvocationTargetException when runner's {@link Runnable#run()} throws exception - */ - public static - void - filter( - final Collection collection, - final Collection results, - final IteratingAcceptor runner, - final boolean bForceProcess - ) throws InvocationTargetException - { - if ( null == results ) - { - return ; - } - if ( isEmpty( collection ) ) - { - return ; - } - - for ( final T arg : collection ) - { - if ( null == arg && !bForceProcess ) - { - continue ; - } - try - { - if ( runner.accept( arg ) ) - { - results.add( arg ); - } - } catch ( Throwable e ) - { - if ( !bForceProcess ) - { - throw new InvocationTargetException( e ); - } - } + /** + *

+ * run runner iterateing element of collection. + * + * use without null-check for collection + * + * delegate error handling to runner + *

+ * + * + * + * CollectionUtil.iterate( + * new ArrayList( Arrays.asList( "hello", "Hello", "World", null, "Test" ) ), + * new IteratingRunner() { + * public void run( String arg ) { + * ... + * } + * } + * ); + * + * + * + * @param type of element in collection + * @param collection {@link Collection} containing element + * @param runner {@link Runnable} to execute + * + * @throws InvocationTargetException when runner's {@link Runnable#run()} throws exception + * + * @see {@link #iterate(Collection, IteratingRunner, boolean)} + * @see FilterIterator + */ + public static + void + iterate( + final Collection collection, + final IteratingRunner runner + ) + throws InvocationTargetException + { + iterate( collection, runner, false ); + } + + /** + *

+ * run runner iterateing element of collection. + * + * use without null-check for collection + * + * delegate error handling to runner + * + *

+ * + * + * CollectionUtil.iterate( + * new ArrayList( Arrays.asList( "hello", "Hello", "World", null, "Test" ) ), + * new IteratingRunner() { + * public void run( String arg ) { + * ... + * } + * }, + * true + * ); + * + * + * + * @param type of element in collection + * @param collection {@link Collection} containing element + * @param runner {@link Runnable} to execute + * @param bForceProcess flag to iterate continuously when exception occurs + * + * @throws InvocationTargetException when runner's {@link Runnable#run()} throws exception + * + * @see FilterIterator + */ + public static + void + iterate( + final Collection collection, + final IteratingRunner runner, + final boolean bForceProcess + ) + throws InvocationTargetException + { + if ( null == runner ) + { + return ; + } + if ( isEmpty( collection ) ) + { + return ; + } + + for ( final T arg : collection ) + { + if ( null == arg && !bForceProcess ) + { + continue ; + } + try + { + runner.run( arg ); + } catch ( Throwable e ) + { + if ( !bForceProcess ) + { + throw new InvocationTargetException( e ); + } + } + } + } + + /** + *

+ * fiter collection to result using runner + * + * determined if stop or keep going using bForceProcess in case of exception. + *

+ * + * @param type of element in collection + * @param collection {@link Collection} to filter + * @param results collection to save result + * @param runner object to determine if filter + * @param bForceProcess flag to keep going when exception occurs + * + * @throws InvocationTargetException when runner's {@link Runnable#run()} throws exception + */ + public static + void + filter( + final Collection collection, + final Collection results, + final IteratingAcceptor runner, + final boolean bForceProcess + ) throws InvocationTargetException + { + if ( null == results ) + { + return ; + } + if ( isEmpty( collection ) ) + { + return ; + } + + for ( final T arg : collection ) + { + if ( null == arg && !bForceProcess ) + { + continue ; + } + try + { + if ( runner.accept( arg ) ) + { + results.add( arg ); + } + } catch ( Throwable e ) + { + if ( !bForceProcess ) + { + throw new InvocationTargetException( e ); + } + } - } - } - - /** - *

- * Return first element in collection
- * - * Return null if collection is null or empty - *

- * @param type of element in collection - * @param collection {@link Collection} to check - * - * @return first elemtn in collection - */ - public static - T - pickupFirst( final Collection collection ) - { - if ( isEmpty( collection ) ) - { - return null; - } - - final Iterator iter = collection.iterator(); - return (iter.hasNext())?(iter.next()):null; - } + } + } + + /** + *

+ * Return first element in collection
+ * + * Return null if collection is null or empty + *

+ * @param type of element in collection + * @param collection {@link Collection} to check + * + * @return first elemtn in collection + */ + public static + T + pickupFirst( final Collection collection ) + { + if ( isEmpty( collection ) ) + { + return null; + } + + final Iterator iter = collection.iterator(); + return (iter.hasNext())?(iter.next()):null; + } - /** - *

- * Extract and return first element in collection
- * - * Return null if collection is null or empty - *

- * @param type of element in collection - * @param collection {@link Collection} to check - * - * @return first elemtn in collection - */ - public static - T - removeFirst( final Collection collection ) - { - if ( isEmpty( collection ) ) - { - return null; - } - - final Iterator iter = collection.iterator(); - if ( iter.hasNext() ) - { - T ret = iter.next(); - iter.remove(); - return ret; - } - return null; - } + /** + *

+ * Extract and return first element in collection
+ * + * Return null if collection is null or empty + *

+ * @param type of element in collection + * @param collection {@link Collection} to check + * + * @return first elemtn in collection + */ + public static + T + removeFirst( final Collection collection ) + { + if ( isEmpty( collection ) ) + { + return null; + } + + final Iterator iter = collection.iterator(); + if ( iter.hasNext() ) + { + T ret = iter.next(); + iter.remove(); + return ret; + } + return null; + } - /** - *

- * Return last element in collection
- * - * Return null if collection is null or empty - * - * Don't use this in case of big data or looping algorithm - *

- * @param type of element in collection - * @param collection {@link Collection} to check - * - * @return last elemtn in collection - */ - public static - T - pickupLast( final Collection collection ) - { - if ( isEmpty( collection ) ) - { - return null; - } - - final Iterator iter = collection.iterator(); - - T temp = null; - while ( iter.hasNext() ) - { - temp = iter.next(); - } - return temp; - } - - /** - *

- * Extract and return last element in collection
- * - * Return null if collection is null or empty - * - * Don't use this in case of big data or looping algorithm - *

- * @param type of element in collection - * @param collection {@link Collection} to check - * - * @return last elemtn in collection - */ - public static - T - removeLast( final Collection collection ) - { - if ( isEmpty( collection ) ) - { - return null; - } - - final Iterator iter = collection.iterator(); - - T temp = null; - while ( iter.hasNext() ) - { - temp = iter.next(); - } - iter.remove(); - return temp; - } + /** + *

+ * Return last element in collection
+ * + * Return null if collection is null or empty + * + * Don't use this in case of big data or looping algorithm + *

+ * @param type of element in collection + * @param collection {@link Collection} to check + * + * @return last elemtn in collection + */ + public static + T + pickupLast( final Collection collection ) + { + if ( isEmpty( collection ) ) + { + return null; + } + + final Iterator iter = collection.iterator(); + + T temp = null; + while ( iter.hasNext() ) + { + temp = iter.next(); + } + return temp; + } + + /** + *

+ * Extract and return last element in collection
+ * + * Return null if collection is null or empty + * + * Don't use this in case of big data or looping algorithm + *

+ * @param type of element in collection + * @param collection {@link Collection} to check + * + * @return last elemtn in collection + */ + public static + T + removeLast( final Collection collection ) + { + if ( isEmpty( collection ) ) + { + return null; + } + + final Iterator iter = collection.iterator(); + + T temp = null; + while ( iter.hasNext() ) + { + temp = iter.next(); + } + iter.remove(); + return temp; + } - /** - * Convert {@link Enumeration} to {@link Iterator} using decoration pattern - * - * @param element type to be handled by enumertaion - */ - static class - EnumerationAdapter - implements Iterator - { - protected final Enumeration enumeration; - /** - * Constructor with {@link Enumeration} - * - * @param enumeration {@link Enumeration} to convert - */ - public - EnumerationAdapter( - final Enumeration enumeration - ) - { - Assert.notNull( enumeration ); - this.enumeration = enumeration; - } + /** + * Convert {@link Enumeration} to {@link Iterator} using decoration pattern + * + * @param element type to be handled by enumertaion + */ + static class + EnumerationAdapter + implements Iterator + { + protected final Enumeration enumeration; + /** + * Constructor with {@link Enumeration} + * + * @param enumeration {@link Enumeration} to convert + */ + public + EnumerationAdapter( + final Enumeration enumeration + ) + { + Assert.notNull( enumeration ); + this.enumeration = enumeration; + } - /* (non-Javadoc) - * @see java.util.Iterator#hasNext() - */ - @Override - public - boolean - hasNext() - { - return enumeration.hasMoreElements(); - } + /* (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + @Override + public + boolean + hasNext() + { + return enumeration.hasMoreElements(); + } - /* (non-Javadoc) - * @see java.util.Iterator#next() - */ - @Override - public - K - next() - { - return enumeration.nextElement(); - } + /* (non-Javadoc) + * @see java.util.Iterator#next() + */ + @Override + public + K + next() + { + return enumeration.nextElement(); + } - /* (non-Javadoc) - * @see java.util.Iterator#remove() - */ - @Override - public - void - remove() - { - throw new UnsupportedOperationException(); - } - } - - /** - * - * Return Iterator to be converted from enumeration - * - * @param element type interating enumeration - * @param enumeration {@link Enumeration} object to be converted - * - * @return converted {@link Iterator} - */ - public - static - Iterator - iterator( - final Enumeration enumeration - ) { - return new EnumerationAdapter( enumeration ); - } + /* (non-Javadoc) + * @see java.util.Iterator#remove() + */ + @Override + public + void + remove() + { + throw new UnsupportedOperationException(); + } + } + + /** + * + * Return Iterator to be converted from enumeration + * + * @param element type interating enumeration + * @param enumeration {@link Enumeration} object to be converted + * + * @return converted {@link Iterator} + */ + public + static + Iterator + iterator( + final Enumeration enumeration + ) { + return new EnumerationAdapter( enumeration ); + } - - /** - * Convert array object to {@link List} - * - * @param source array candidate object - * - * @return converted {@link List} - */ - public static - List - asList( - final Object source - ) - { - return Arrays.asList( ArrayUtil.toObjectArray( source ) ); - } + + /** + * Convert array object to {@link List} + * + * @param source array candidate object + * + * @return converted {@link List} + */ + public static + List + asList( + final Object source + ) + { + return Arrays.asList( ArrayUtil.toObjectArray( source ) ); + } - /** - * - * Add array object to collection - * - * @param array array candidate object to be added - * @param collection {@link Collection} to add - * - * @see ArrayUtil#toObjectArray(Object) - */ - public static - void - mergeArrayIntoCollection( - final Object array, - final Collection collection - ) - { - Assert.notNull( collection ); - final Object[] arr = ArrayUtil.toObjectArray( array ); - for ( int i=0, n=arr.length ; icollection + * + * @param array array candidate object to be added + * @param collection {@link Collection} to add + * + * @see ArrayUtil#toObjectArray(Object) + */ + public static + void + mergeArrayIntoCollection( + final Object array, + final Collection collection + ) + { + Assert.notNull( collection ); + final Object[] arr = ArrayUtil.toObjectArray( array ); + for ( int i=0, n=arr.length ; iiterator meet element in iteration - * - * @param iterator iterating object - * @param element object to check - * - * @return true if iterator meet element - */ - public static - boolean - contains( - final Iterator iterator, - final Object element - ) - { - if ( null == iterator ) - { - return false; - } - - while ( iterator.hasNext() ) - { - final Object candidate = iterator.next(); - if ( ObjectUtil.equals( candidate, element ) ) - { - return true; - } - } - return false; - } + /** + * Check if iterator meet element in iteration + * + * @param iterator iterating object + * @param element object to check + * + * @return true if iterator meet element + */ + public static + boolean + contains( + final Iterator iterator, + final Object element + ) + { + if ( null == iterator ) + { + return false; + } + + while ( iterator.hasNext() ) + { + final Object candidate = iterator.next(); + if ( ObjectUtil.equals( candidate, element ) ) + { + return true; + } + } + return false; + } - /** - * Check if enumeration meet element in iteration - * - * @param enumeration iterating object - * @param element object to check - * - * @return true if enumeration meet element - */ - public static - boolean - contains( - final Enumeration enumeration, - final Object element - ) - { - if ( null == enumeration ) - { - return false; - } - while( enumeration.hasMoreElements() ) - { - final Object candidate = enumeration.nextElement(); - if ( ObjectUtil.equals( candidate, element ) ) - { - return true; - } - } - return false; - } + /** + * Check if enumeration meet element in iteration + * + * @param enumeration iterating object + * @param element object to check + * + * @return true if enumeration meet element + */ + public static + boolean + contains( + final Enumeration enumeration, + final Object element + ) + { + if ( null == enumeration ) + { + return false; + } + while( enumeration.hasMoreElements() ) + { + final Object candidate = enumeration.nextElement(); + if ( ObjectUtil.equals( candidate, element ) ) + { + return true; + } + } + return false; + } - - /** - * Check if collection contains element - * - * @param collection {@link Collection} to check - * @param element object to check - * - * @return true if collection contain element - */ - public static - boolean - contains( - final Collection collection, - final Object element - ) - { - if ( null == collection ) - { - return false; - } - for ( final Object candidate : collection ) - { - if ( ObjectUtil.equals( candidate, element ) ) - { - return true; - } - } - return false; - } - - /** - * Check and return if source contain any element of candidates - * - * @param source {@link Collection} to check - * @param candidates {@link Collection} whose element is expected in source - * - * @return true if source contain any elemnt of candidates - */ - public static - boolean - containsAny( - final Collection source, - final Collection candidates - ) - { - if ( isEmpty( source ) || isEmpty( candidates) ) - { - return false; - } + + /** + * Check if collection contains element + * + * @param collection {@link Collection} to check + * @param element object to check + * + * @return true if collection contain element + */ + public static + boolean + contains( + final Collection collection, + final Object element + ) + { + if ( null == collection ) + { + return false; + } + for ( final Object candidate : collection ) + { + if ( ObjectUtil.equals( candidate, element ) ) + { + return true; + } + } + return false; + } + + /** + * Check and return if source contain any element of candidates + * + * @param source {@link Collection} to check + * @param candidates {@link Collection} whose element is expected in source + * + * @return true if source contain any elemnt of candidates + */ + public static + boolean + containsAny( + final Collection source, + final Collection candidates + ) + { + if ( isEmpty( source ) || isEmpty( candidates) ) + { + return false; + } - for ( final Object candidate : candidates ) - { - if ( source.contains( candidate ) ) - { - return true; - } - } - return false; - } + for ( final Object candidate : candidates ) + { + if ( source.contains( candidate ) ) + { + return true; + } + } + return false; + } - /** - * Check collectionType is approximable collection type - * - * @param collectionType type to check - * - * @return true if collectionType is in {@link #APPROXIMABLE_COLLECTION_TYPES} - * - * @see #APPROXIMABLE_COLLECTION_TYPES - */ - public static - boolean - isApproximableCollectionType( - final Class collectionType - ) - { - return APPROXIMABLE_COLLECTION_TYPES.contains( collectionType ); - } - - /** - * Check mapType is approximable map type - * - * @param mapType type to check - * - * @return true if mapType is in {@link #APPROXIMABLE_MAP_TYPES} - * - * @see #APPROXIMABLE_MAP_TYPES - */ - public static - boolean - isApproximableMapType( - final Class mapType - ) - { - return APPROXIMABLE_MAP_TYPES.contains( mapType ); - } - - /** - * Create collection matched approximable collection - * - * @param containing type - * @param collection {@link Collection} to convert - * @param initialCapacity initial size of created collection - * - * @return created approximable collection - */ - public static - Collection - createApproximableCollection( - final Collection collection, - final int initialCapacity - ) - { - if ( collection instanceof LinkedList ) - { - return new LinkedList(); - } - else if ( collection instanceof List ) - { - return new ArrayList( initialCapacity); - } - else if ( collection instanceof SortedSet ) - { - return new TreeSet( ( (SortedSet)collection).comparator() ); - } - else - { - return new LinkedHashSet( initialCapacity); - } - } - - /** - * @param Map's Key type - * @param Map's Value type - * @param map Map argument - * @param initialCapacity initial argument for Map which will be created - * - * @return created ApproximableMap - */ - public static - Map - createApproximableMap( - final Map map, - final int initialCapacity - ) - { - if ( map instanceof SortedMap ) - { - return new TreeMap( ( (SortedMap) map).comparator() ); - } - else - { - return new LinkedHashMap( initialCapacity ); - } - } - - /* print */ - - /** - * Converts obj object to String. - * - * @param obj object to convert - * - * @return converted String - */ - public static - String - toString( - final Object obj - ) - { - if ( null == obj ) - { - return NULL_STRING; - } + /** + * Check collectionType is approximable collection type + * + * @param collectionType type to check + * + * @return true if collectionType is in {@link #APPROXIMABLE_COLLECTION_TYPES} + * + * @see #APPROXIMABLE_COLLECTION_TYPES + */ + public static + boolean + isApproximableCollectionType( + final Class collectionType + ) + { + return APPROXIMABLE_COLLECTION_TYPES.contains( collectionType ); + } + + /** + * Check mapType is approximable map type + * + * @param mapType type to check + * + * @return true if mapType is in {@link #APPROXIMABLE_MAP_TYPES} + * + * @see #APPROXIMABLE_MAP_TYPES + */ + public static + boolean + isApproximableMapType( + final Class mapType + ) + { + return APPROXIMABLE_MAP_TYPES.contains( mapType ); + } + + /** + * Create collection matched approximable collection + * + * @param containing type + * @param collection {@link Collection} to convert + * @param initialCapacity initial size of created collection + * + * @return created approximable collection + */ + public static + Collection + createApproximableCollection( + final Collection collection, + final int initialCapacity + ) + { + if ( collection instanceof LinkedList ) + { + return new LinkedList(); + } + else if ( collection instanceof List ) + { + return new ArrayList( initialCapacity); + } + else if ( collection instanceof SortedSet ) + { + return new TreeSet( ( (SortedSet)collection).comparator() ); + } + else + { + return new LinkedHashSet( initialCapacity); + } + } + + /** + * @param Map's Key type + * @param Map's Value type + * @param map Map argument + * @param initialCapacity initial argument for Map which will be created + * + * @return created ApproximableMap + */ + public static + Map + createApproximableMap( + final Map map, + final int initialCapacity + ) + { + if ( map instanceof SortedMap ) + { + return new TreeMap( ( (SortedMap) map).comparator() ); + } + else + { + return new LinkedHashMap( initialCapacity ); + } + } + + /* print */ + + /** + * Converts obj object to String. + * + * @param obj object to convert + * + * @return converted String + */ + public static + String + toString( + final Object obj + ) + { + if ( null == obj ) + { + return NULL_STRING; + } - if ( obj instanceof String ) - { - return (String) obj; - } - else if ( obj.getClass().isArray() ) - { - int length = Array.getLength( obj ); - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer= new StringBuilder(); - - buffer.append( ARRAY_START); - for ( int i=0 ; iarray Object[] with String separator. - * - * @param array Object[] to combine - * @param separator the delimiter which is used when Object[] combined - * - * @return combined String - */ - public static - String - concatenate( - final E[] array, - final String separator - ) - { - return concatenate( (null==array)?null:new ArrayIterator( array ), separator ); - } - - /** - * Returns a String from col {@link Collection} with String separator. - * - * @param col {@link Collection} object to combine - * @param separator the delimiter which is used when {@link Collection} object combined - * - * @return combined String - */ - public static - String - concatenate( - final Collection col, - final String separator - ) - { - return concatenate( (null==col)?(null):col.iterator(), separator ); - } - - /** - * Returns a String from {@link Iterator} with String separator. - * - * @param iter {@link Iterator} to combine objects - * @param separator the delimiter which is used when {@link Iterator} combined - * - * @return combined String - */ - public static - String - concatenate( - Iterator iter, - final String separator - ) - { - if ( null == iter ) - { - return NULL_STRING; - } - - if ( !iter.hasNext() ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer= new StringBuilder(); - boolean bInit = false; - - while ( iter.hasNext() ) - { - Object obj = iter.next(); - if ( bInit ) - { - buffer.append( separator ); - } - bInit = true; - - buffer.append( toString( obj ) ); - } - return buffer.toString(); - } - - /* Hash */ - private static final int MULTIPLIER= 31; + /** + * Returns a String from array Object[] with String separator. + * + * @param array Object[] to combine + * @param separator the delimiter which is used when Object[] combined + * + * @return combined String + */ + public static + String + concatenate( + final E[] array, + final String separator + ) + { + return concatenate( (null==array)?null:new ArrayIterator( array ), separator ); + } + + /** + * Returns a String from col {@link Collection} with String separator. + * + * @param col {@link Collection} object to combine + * @param separator the delimiter which is used when {@link Collection} object combined + * + * @return combined String + */ + public static + String + concatenate( + final Collection col, + final String separator + ) + { + return concatenate( (null==col)?(null):col.iterator(), separator ); + } + + /** + * Returns a String from {@link Iterator} with String separator. + * + * @param iter {@link Iterator} to combine objects + * @param separator the delimiter which is used when {@link Iterator} combined + * + * @return combined String + */ + public static + String + concatenate( + Iterator iter, + final String separator + ) + { + if ( null == iter ) + { + return NULL_STRING; + } + + if ( !iter.hasNext() ) + { + return EMPTY_ARRAY; + } + + final StringBuilder buffer= new StringBuilder(); + boolean bInit = false; + + while ( iter.hasNext() ) + { + Object obj = iter.next(); + if ( bInit ) + { + buffer.append( separator ); + } + bInit = true; + + buffer.append( toString( obj ) ); + } + return buffer.toString(); + } + + /* Hash */ + private static final int MULTIPLIER= 31; - private static final int INITIAL_HASH = 7; - - /** - * Creates hash value about object. - *
- * In case of array, get hash value using object's hash value in the array. - * - * @param obj object to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final Object obj - ) - { - if ( null == obj ) - { - return 0; - } - if ( obj.getClass().isArray() ) - { - if ( obj instanceof Object[] ) - { - return hashCode( (Object[] )obj ); - } - else if ( obj instanceof boolean[] ) - { - return hashCode( (boolean[] )obj ); - } - else if ( obj instanceof byte[] ) - { - return hashCode( (byte[] )obj); - } - else if ( obj instanceof char[] ) - { - return hashCode( (char[] )obj); - } - else if ( obj instanceof double[] ) - { - return hashCode( (double[] )obj); - } - else if ( obj instanceof float[] ) - { - return hashCode( (float[] )obj); - } - else if ( obj instanceof int[] ) - { - return hashCode( (int[] )obj); - } - else if ( obj instanceof long[] ) - { - return hashCode( (long[] )obj); - } - else if ( obj instanceof short[] ) - { - return hashCode( (short[] )obj); - } - } - - return obj.hashCode(); - } + private static final int INITIAL_HASH = 7; + + /** + * Creates hash value about object. + *
+ * In case of array, get hash value using object's hash value in the array. + * + * @param obj object to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final Object obj + ) + { + if ( null == obj ) + { + return 0; + } + if ( obj.getClass().isArray() ) + { + if ( obj instanceof Object[] ) + { + return hashCode( (Object[] )obj ); + } + else if ( obj instanceof boolean[] ) + { + return hashCode( (boolean[] )obj ); + } + else if ( obj instanceof byte[] ) + { + return hashCode( (byte[] )obj); + } + else if ( obj instanceof char[] ) + { + return hashCode( (char[] )obj); + } + else if ( obj instanceof double[] ) + { + return hashCode( (double[] )obj); + } + else if ( obj instanceof float[] ) + { + return hashCode( (float[] )obj); + } + else if ( obj instanceof int[] ) + { + return hashCode( (int[] )obj); + } + else if ( obj instanceof long[] ) + { + return hashCode( (long[] )obj); + } + else if ( obj instanceof short[] ) + { + return hashCode( (short[] )obj); + } + } + + return obj.hashCode(); + } - /** - * Returns hash value about array Object[]. - * - * @param array Object[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final Object[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray Object[]. + * + * @param array Object[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final Object[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray boolean[]. - * - * @param array boolean[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final boolean[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray boolean[]. + * + * @param array boolean[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final boolean[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray int[]. - * - * @param array int[] to get hash value - * - * @return hash value - */ - public static int - hashCode( - final byte[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray int[]. + * + * @param array int[] to get hash value + * + * @return hash value + */ + public static int + hashCode( + final byte[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray char[]. - * - * @param array char[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final char[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray char[]. + * + * @param array char[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final char[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray double[]. - * - * @param array double[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final double[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray double[]. + * + * @param array double[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final double[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray float[]. - * - * @param array float[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final float[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray float[]. + * + * @param array float[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final float[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray int[]. - * - * @param array int[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final int[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray int[]. + * + * @param array int[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final int[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray long[]. - * - * @param array long[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final long[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray long[]. + * + * @param array long[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final long[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; iarray short[]. - * - * @param array short[] to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final short[] array - ) - { - if ( null == array ) - { - return 0; - } - - int hash = INITIAL_HASH; - for( int i=0, arraySize=array.length ; iarray short[]. + * + * @param array short[] to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final short[] array + ) + { + if ( null == array ) + { + return 0; + } + + int hash = INITIAL_HASH; + for( int i=0, arraySize=array.length ; ibool boolean. - * - * @param bool boolean type parameter to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final boolean bool - ) - { - return bool ? 1231 : 1237; - } + /** + * Returns hash value about bool boolean. + * + * @param bool boolean type parameter to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final boolean bool + ) + { + return bool ? 1231 : 1237; + } - /** - * Return hash value about dbl double. - * - * @param dbl double type parameter to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final double dbl - ) - { - long bits = Double.doubleToLongBits( dbl ); - return hashCode( bits ); - } + /** + * Return hash value about dbl double. + * + * @param dbl double type parameter to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final double dbl + ) + { + long bits = Double.doubleToLongBits( dbl ); + return hashCode( bits ); + } - /** - * Returns hash value about flt float. - * - * @param flt float type parameter to get hash value - * - * @return hash value - */ - public static - int - hashCode( - float flt - ) - { - return Float.floatToIntBits( flt ); - } + /** + * Returns hash value about flt float. + * + * @param flt float type parameter to get hash value + * + * @return hash value + */ + public static + int + hashCode( + float flt + ) + { + return Float.floatToIntBits( flt ); + } - /** - * Returns hash value about lng long. - * - * @param lng long type parameter to get hash value - * - * @return hash value - */ - public static - int - hashCode( - final long lng - ) - { - return (int) ( lng ^ ( lng >>> 32 ) ); - } - - /* Equals */ - /** - * Returns whether it is same object type or not by comparing each column's type of {@link Collection} object. - * - * @param object type about {@link Collection} - * @param cols {@link Collection} objects - * - * @return true if each column's type of the {@link Collection} object is same - */ - @SuppressWarnings("unchecked") - public static - boolean - equals( - final Collection... cols - ) - { - - // flag if collection is null - boolean bInit = false; - int size = 0; - for ( final Collection col : cols ) - { - if ( !bInit ) - { - if ( null == col ) - { - size = -1; - } - else - { - size = col.size(); - } - bInit = true; - } - if ( size < 0 ) - { - if ( null != col ) - { - return false; - } - } - else if ( null == col || col.size() != size ) - { - return false; - } - } - if ( size < 0 ) - { - return true; - } + /** + * Returns hash value about lng long. + * + * @param lng long type parameter to get hash value + * + * @return hash value + */ + public static + int + hashCode( + final long lng + ) + { + return (int) ( lng ^ ( lng >>> 32 ) ); + } + + /* Equals */ + /** + * Returns whether it is same object type or not by comparing each column's type of {@link Collection} object. + * + * @param object type about {@link Collection} + * @param cols {@link Collection} objects + * + * @return true if each column's type of the {@link Collection} object is same + */ + @SuppressWarnings("unchecked") + public static + boolean + equals( + final Collection... cols + ) + { + + // flag if collection is null + boolean bInit = false; + int size = 0; + for ( final Collection col : cols ) + { + if ( !bInit ) + { + if ( null == col ) + { + size = -1; + } + else + { + size = col.size(); + } + bInit = true; + } + if ( size < 0 ) + { + if ( null != col ) + { + return false; + } + } + else if ( null == col || col.size() != size ) + { + return false; + } + } + if ( size < 0 ) + { + return true; + } - final Iterator[] iters = new Iterator[cols.length]; - for ( int i = 0, n = iters.length ; i[] iters = new Iterator[cols.length]; + for ( int i = 0, n = iters.length ; i - * Swaps ith object's location with jth object in objs Object[]. - *

- * @param objs target - * @param i location of object to be swapped - * @param j location of object to be swapped - */ - public static - void - swap( - final Object[] objs, - final int i, - final int j - ) - { - Object temp = objs[i]; - objs[i] = objs[j]; - objs[j] = temp; - } + } + + /** + *

+ * Swaps ith object's location with jth object in objs Object[]. + *

+ * @param objs target + * @param i location of object to be swapped + * @param j location of object to be swapped + */ + public static + void + swap( + final Object[] objs, + final int i, + final int j + ) + { + Object temp = objs[i]; + objs[i] = objs[j]; + objs[j] = temp; + } + + /** + * + * Check that target class is available class to be inserted in the collection. + * If return is positive, target class is available. + * If return is negative, target class is not available. + * If return is zero, we cannot judge that target class is available or not. + * For example, if collection size is zero, or every element in the collection is null, we cannot judge it. + * Although collection is defined for Object, all of its elements are String, it returns negative, + * because we cannot know generic type exactly in runtime. + * + * @param collection + * @param targetClass + * @return + * @author ho.namkoong{@literal } + */ + public static + int + isAvailableGenericTypeForCollection( + final Collection collection, + final Class targetClass + ) + { + if(collection.size() < 1) { + return 0; + } + boolean foundNotNull = false; + for(Object o: collection) { + if(o != null) { + foundNotNull = true; + if(o.getClass().isAssignableFrom(targetClass)) { + return 1; + } + } + } + if(foundNotNull) { + return -1; + } + return 0; + } + + /** + * + * Resolve set as list. + * Result list has same order of iterator of set. + * + * @param set set to be resolved as a list. + * @return list which contains all the elements in the set. + * @author ho.namkoong{@literal } + */ + public static + List + resolveSetAsList( + final Set set + ) + { + Iterator itr = set.iterator(); + ArrayList result = new ArrayList(); + + while(itr.hasNext()) { + E obj = itr.next(); + result.add(obj); + } + + return result; + } } diff --git a/org.tizen.common/src/org/tizen/common/util/FileUtil.java b/org.tizen.common/src/org/tizen/common/util/FileUtil.java index 250a72c..0e7f335 100755 --- a/org.tizen.common/src/org/tizen/common/util/FileUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/FileUtil.java @@ -40,6 +40,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -578,4 +579,71 @@ public class FileUtil { Assert.isTrue( aDirectory.isDirectory(), "Is not a directory: " + aDirectory ); Assert.isTrue( aDirectory.canRead(), "Directory cannot be read: " + aDirectory ); } + + /** + * This method takes a URL as parameter to read the contents, and to add + * into a string buffer. + * + * @param source + * URL to read the contents. + * @return string, contents of a file specified in the URL source path. + * @throws IOException + */ + public static String readFromFile(URL source) throws IOException { + char[] chars = new char[4092]; + InputStreamReader contentsReader = null; + StringBuffer buffer = new StringBuffer(); + if (!new java.io.File(source.getFile()).exists()) { + throw new FileNotFoundException(); + } else { + contentsReader = new InputStreamReader(source.openStream()); + int c; + do { + c = contentsReader.read(chars); + if (c == -1) + break; + buffer.append(chars, 0, c); + } while (c != -1); + contentsReader.close(); + } + return buffer.toString(); + } + + /** + * Append path. + * @param originalPath original path + * @param appendPath path which will be appended to original path. + * @return appended path + */ + public static String appendPath(String originalPath, String appendPath) { + originalPath = originalPath.trim(); + appendPath = appendPath.trim(); + + if(OSChecker.isWindows()) { + originalPath = originalPath.replace('/', File.separatorChar); + appendPath = appendPath.replace('/', File.separatorChar); + } + else { + originalPath = originalPath.replace('\\', File.separatorChar); + appendPath = appendPath.replace('\\', File.separatorChar); + } + + return trimLastPath(originalPath).concat(trimFirstPath(appendPath)); + } + + private static String trimLastPath(String originalPath) { + char lastChar = originalPath.charAt(originalPath.length() - 1); + if(lastChar == File.separatorChar) { + return originalPath.substring(0, originalPath.length() - 1); + } + return originalPath; + } + + private static String trimFirstPath(String originalPath) { + char firstChar = originalPath.charAt(0); + if(firstChar != File.separatorChar) { + return ("" + File.separatorChar).concat(originalPath); + } + return originalPath; + } } diff --git a/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java b/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java old mode 100755 new mode 100644 index d548d29..b98b36b --- a/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java +++ b/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java @@ -53,6 +53,7 @@ import java.util.TreeSet; import java.util.Vector; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Before; import org.junit.Test; @@ -949,5 +950,72 @@ CollectionUtilTest } catch (Exception e) { } } + + /** + * Test {@link CollectionUtil#isAvailableGenericTypeForCollection(Collection, Class)} + * + * @throws Exception is case of failure in test + * + * @see {@link CollectionUtil#resolveSetAsList(Set)} + */ + @Test + public + void + test_isAvailableGenericTypeForCollection() { + ArrayList testList = new ArrayList(); + + int result = CollectionUtil.isAvailableGenericTypeForCollection(testList, Object.class); + assertTrue(result == 0); + + testList.add(null); + result = CollectionUtil.isAvailableGenericTypeForCollection(testList, Object.class); + assertTrue(result == 0); + + testList.add("empty"); + result = CollectionUtil.isAvailableGenericTypeForCollection(testList, File.class); + assertTrue(result == -1); + + result = CollectionUtil.isAvailableGenericTypeForCollection(testList, Object.class); + assertTrue(result == -1); + + result = CollectionUtil.isAvailableGenericTypeForCollection(testList, String.class); + assertTrue(result == 1); + + testList.add(new Object()); + result = CollectionUtil.isAvailableGenericTypeForCollection(testList, Object.class); + assertTrue(result == 1); + + testList.remove(0); + result = CollectionUtil.isAvailableGenericTypeForCollection(testList, String.class); + assertTrue(result == 1); + } + + + + /** + * Test {@link CollectionUtil#resolveSetAsList(Set)} + * + * @throws Exception is case of failure in test + * + * @see {@link CollectionUtil#resolveSetAsList(Set)} + */ + @Test + public + void + test_resolveSetAsList() { + LinkedHashSet set = new LinkedHashSet(); + String[] stringArray= {"one", "two", "three", "four", "five"}; + + for(String string: stringArray) { + set.add(string); + } + + List result = CollectionUtil.resolveSetAsList(set); + + for(int i=0; i result = compareFiles(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST); + assertTrue(result.size() == 0); + } + finally { + File destDir = new File(TEST_RESOURCE_DEST); + if(destDir.exists()) { + FileUtil.recursiveDelete(destDir); + } + } + } + + /** + * Test {@link FileUtil#copyRecursively(String, String, boolean)}} + * + * @throws Exception in case of failure in test + * + * @see {@link FileUtil#copyRecursively(String, String, boolean)} + */ + @Test + public void test_copyRecursively2() throws Exception { + + try { + if(!checkTestSrcExist()) { + return; + } + + String overwriteFileName = "about_files/LICENSE-2.0.htm"; + String originalFileName = "about_files/freemarker-LICENSE.txt"; + String copiedFileName = FileUtil.appendPath(TEST_RESOURCE_DEST, originalFileName); + + long overwriteSize = new File(overwriteFileName).getTotalSpace(); + long originalSize = new File(originalFileName).getTotalSpace(); + + FileUtil.copyTo(FileUtil.appendPath(TEST_RESOURCE_SRC, overwriteFileName), copiedFileName); + FileUtil.copyRecursively(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST, false); + + long copiedSize = new File(copiedFileName).getTotalSpace(); + assertTrue(overwriteSize == copiedSize); + + File destDir = new File(TEST_RESOURCE_DEST); + if(destDir.exists()) { + FileUtil.recursiveDelete(destDir); + } + + List result = compareFiles(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST); + assertTrue(result.size() == 0); + + FileUtil.copyRecursively(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST, true); + + copiedSize = new File(copiedFileName).getTotalSpace(); + assertTrue(originalSize == copiedSize); + + result = compareFiles(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST); + assertTrue(result.size() == 0); + } + finally { + File destDir = new File(TEST_RESOURCE_DEST); + if(destDir.exists()) { + FileUtil.recursiveDelete(destDir); + } + } + } + + /** + * Test {@link FileUtil#copyRecursively(String, String, boolean, File...)} + * + * @throws Exception in case of failure in test + * + * @see {@link FileUtil#copyRecursively(String, String, boolean, File...)} + */ + @Test + public void test_copyRecursively3() throws Exception { + + try { + if(!checkTestSrcExist()) { + return; + } + + HashSet filter = new HashSet(); + File filter1 = new File(TEST_RESOURCE_SRC + "/about_files/LICENSE-2.0.htm"); + File filter2 = new File(TEST_RESOURCE_SRC + "/resource/text.txt"); + File filter3 = new File(TEST_RESOURCE_SRC + "/resource/resource/text.txt"); + + filter.add(filter1); + filter.add(filter2); + filter.add(filter3); + + FileUtil.copyRecursively(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST, false, filter1, filter2, filter3); + + List result = compareFiles(TEST_RESOURCE_SRC, TEST_RESOURCE_DEST); + + for(File resultFile: result) { + assertTrue(filter.contains(resultFile)); + } + } + finally { + File destDir = new File(TEST_RESOURCE_DEST); + if(destDir.exists()) { + FileUtil.recursiveDelete(destDir); + } + } + } + + private boolean checkTestSrcExist() { + File src = new File(TEST_RESOURCE_SRC); + return src.exists(); + } + + /** + * This method is used for checking whether copyRecursively works fine. + * If destDir does not contain some files in srcDir, they are contained in result List. + * @param srcDir source directory + * @param destDir destination direcoty to be compared with source directory. + * @return Files in source directory destination directory does not contain. + */ + private static List compareFiles(String srcDir, String destDir) { + + List result = new ArrayList(); + File srcFiles = new File(srcDir); + + if(!srcFiles.exists()) { + return result; + } + + Stack srcStack = new Stack(); + Stack destStack = new Stack(); + + while(!srcStack.isEmpty()) { + File _srcFile = srcStack.pop(); + File _destFile = destStack.pop(); + + if(!_destFile.exists()) { + result.add(_srcFile); + } + + if(_srcFile.isDirectory()) { + for(File __srcFile:_srcFile.listFiles()) { + srcStack.add(__srcFile); + destStack.add(new File(_destFile, __srcFile.getName())); + } + } + } + + return result; + } + + /** + * Test {@link FileUtil#readFromFile(URL)} + * + * @throws Exception in case of failure in test + * + * @see {@link FileUtil#readFromFile(URL)} + * @throws Exception + */ + @Test + public void test_readFromFile() throws Exception { + + String result = "HOHOHO\nHAHAHA\nNAMKOONGHO"; + + File file = new File("test/test_files/resource/text.txt"); + + if(file.exists()) { + URL url = file.toURI().toURL(); + assertTrue(result.equals(FileUtil.readFromFile(url))); + } + } + /** + * Test {@link FileUtil#appendPath(String, String)} + * + * @throws Exception in case of failure in test + * + * @see {@link FileUtil#appendPath(String, String)} + * @throws Exception + */ + @Test + public void test_appendPath() throws Exception { + String windowFirst = "\\a\\b\\c\\d\\"; + String windowLast = "\\e\\f\\g\\h\\"; + + String linuxFirst = "/a/b/c/d/"; + String linuxLast = "/e/f/g/h/"; + + String result = File.separatorChar + "a" + File.separatorChar + "b" + File.separatorChar + "c" + + File.separatorChar + "d" + File.separatorChar + "e" + File.separatorChar + "f" + File.separatorChar + + "g" + File.separatorChar + "h" + File.separatorChar; + + assertTrue(result.equals(FileUtil.appendPath(windowFirst, linuxLast))); + assertTrue(result.equals(FileUtil.appendPath(windowFirst, windowLast))); + assertTrue(result.equals(FileUtil.appendPath(linuxFirst, linuxLast))); + assertTrue(result.equals(FileUtil.appendPath(linuxFirst, windowLast))); + } } diff --git a/org.tizen.common/test/test_files/about_files/LICENSE-2.0.htm b/org.tizen.common/test/test_files/about_files/LICENSE-2.0.htm new file mode 100644 index 0000000..f7ca656 --- /dev/null +++ b/org.tizen.common/test/test_files/about_files/LICENSE-2.0.htm @@ -0,0 +1,191 @@ + + + + Apache License, Version 2.0 + + + + + + + + + + + + + + + + + +
+ + +
+

Apache License

Version 2.0, January 2004

+http://www.apache.org/licenses/

+

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

+

1. Definitions.

+

"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document.

+

"Licensor" shall mean the copyright owner or entity authorized by the +copyright owner that is granting the License.

+

"Legal Entity" shall mean the union of the acting entity and all other +entities that control, are controlled by, or are under common control with +that entity. For the purposes of this definition, "control" means (i) the +power, direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity.

+

"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License.

+

"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files.

+

"Object" form shall mean any form resulting from mechanical transformation +or translation of a Source form, including but not limited to compiled +object code, generated documentation, and conversions to other media types.

+

"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice that +is included in or attached to the work (an example is provided in the +Appendix below).

+

"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, as +a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, or +merely link (or bind by name) to the interfaces of, the Work and Derivative +Works thereof.

+

"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor for +inclusion in the Work by the copyright owner or by an individual or Legal +Entity authorized to submit on behalf of the copyright owner. For the +purposes of this definition, "submitted" means any form of electronic, +verbal, or written communication sent to the Licensor or its +representatives, including but not limited to communication on electronic +mailing lists, source code control systems, and issue tracking systems that +are managed by, or on behalf of, the Licensor for the purpose of discussing +and improving the Work, but excluding communication that is conspicuously +marked or otherwise designated in writing by the copyright owner as "Not a +Contribution."

+

"Contributor" shall mean Licensor and any individual or Legal Entity on +behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work.

+

2. Grant of Copyright License. Subject to the +terms and conditions of this License, each Contributor hereby grants to You +a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, publicly +display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form.

+

3. Grant of Patent License. Subject to the terms +and conditions of this License, each Contributor hereby grants to You a +perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, use, +offer to sell, sell, import, and otherwise transfer the Work, where such +license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by +combination of their Contribution(s) with the Work to which such +Contribution(s) was submitted. If You institute patent litigation against +any entity (including a cross-claim or counterclaim in a lawsuit) alleging +that the Work or a Contribution incorporated within the Work constitutes +direct or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate as of the +date such litigation is filed.

+

4. Redistribution. You may reproduce and +distribute copies of the Work or Derivative Works thereof in any medium, +with or without modifications, and in Source or Object form, provided that +You meet the following conditions:

+
    +
  1. +

    You must give any other recipients of the Work or Derivative Works a +copy of this License; and

    +
  2. +
  3. +

    You must cause any modified files to carry prominent notices stating +that You changed the files; and

    +
  4. +
  5. +

    You must retain, in the Source form of any Derivative Works that You +distribute, all copyright, patent, trademark, and attribution notices from +the Source form of the Work, excluding those notices that do not pertain to +any part of the Derivative Works; and

    +
  6. +
  7. +

    If the Work includes a "NOTICE" text file as part of its distribution, +then any Derivative Works that You distribute must include a readable copy +of the attribution notices contained within such NOTICE file, excluding +those notices that do not pertain to any part of the Derivative Works, in +at least one of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or documentation, +if provided along with the Derivative Works; or, within a display generated +by the Derivative Works, if and wherever such third-party notices normally +appear. The contents of the NOTICE file are for informational purposes only +and do not modify the License. You may add Your own attribution notices +within Derivative Works that You distribute, alongside or as an addendum to +the NOTICE text from the Work, provided that such additional attribution +notices cannot be construed as modifying the License. +You may add Your own copyright statement to Your modifications and may +provide additional or different license terms and conditions for use, +reproduction, or distribution of Your modifications, or for any such +Derivative Works as a whole, provided Your use, reproduction, and +distribution of the Work otherwise complies with the conditions stated in +this License.

    +
  8. +
+

5. Submission of Contributions. Unless You +explicitly state otherwise, any Contribution intentionally submitted for +inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the +terms of any separate license agreement you may have executed with Licensor +regarding such Contributions.

+

6. Trademarks. This License does not grant +permission to use the trade names, trademarks, service marks, or product +names of the Licensor, except as required for reasonable and customary use +in describing the origin of the Work and reproducing the content of the +NOTICE file.

+

7. Disclaimer of Warranty. Unless required by +applicable law or agreed to in writing, Licensor provides the Work (and +each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, +without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You +are solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise +of permissions under this License.

+

8. Limitation of Liability. In no event and +under no legal theory, whether in tort (including negligence), contract, or +otherwise, unless required by applicable law (such as deliberate and +grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a result +of this License or out of the use or inability to use the Work (including +but not limited to damages for loss of goodwill, work stoppage, computer +failure or malfunction, or any and all other commercial damages or losses), +even if such Contributor has been advised of the possibility of such +damages.

+

9. Accepting Warranty or Additional Liability. +While redistributing the Work or Derivative Works thereof, You may choose +to offer, and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this License. +However, in accepting such obligations, You may act only on Your own behalf +and on Your sole responsibility, not on behalf of any other Contributor, +and only if You agree to indemnify, defend, and hold each Contributor +harmless for any liability incurred by, or claims asserted against, such +Contributor by reason of your accepting any such warranty or additional +liability.

+

END OF TERMS AND CONDITIONS

+ +
+ +
+ + + diff --git a/org.tizen.common/test/test_files/about_files/freemarker-LICENSE.txt b/org.tizen.common/test/test_files/about_files/freemarker-LICENSE.txt new file mode 100644 index 0000000..4c5f086 --- /dev/null +++ b/org.tizen.common/test/test_files/about_files/freemarker-LICENSE.txt @@ -0,0 +1,69 @@ +FreeMarker 1.x was released under the LGPL license. Later, by community +consensus, we have switched over to a BSD-style license. As of FreeMarker +2.2pre1, the original author, Benjamin Geer, has relinquished the copyright in +behalf of Visigoth Software Society. The current copyright holder is the +Visigoth Software Society. + +------------------------------------------------------------------------------ +Copyright (c) 2003 The Visigoth Software Society. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. The end-user documentation included with the redistribution, if any, must + include the following acknowlegement: + "This product includes software developed by the + Visigoth Software Society (http://www.visigoths.org/)." + Alternately, this acknowlegement may appear in the software itself, if and + wherever such third-party acknowlegements normally appear. + +3. Neither the name "FreeMarker", "Visigoth", nor any of the names of the + project contributors may be used to endorse or promote products derived + from this software without prior written permission. For written + permission, please contact visigoths@visigoths.org. + +4. Products derived from this software may not be called "FreeMarker" or + "Visigoth" nor may "FreeMarker" or "Visigoth" appear in their names + without prior written permission of the Visigoth Software Society. + +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +VISIGOTH SOFTWARE SOCIETY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +------------------------------------------------------------------------------ + +This software consists of voluntary contributions made by many individuals on +behalf of the Visigoth Software Society. For more information on the Visigoth +Software Society, please see http://www.visigoths.org/ + +------------------------------------------------------------------------------ + +FREEMARKER SUBCOMPONENTS UNDER DIFFERENT LICENSE: + +FreeMarker includes a number of subcomponents that are licensed by the Apache +Software Foundation under the Apache License, Version 2.0. Your use of these +subcomponents is subject to the terms and conditions of the Apache License, +Version 2.0. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +The subcomponents under this licence are the following files, which are +included both in freemarker.jar and in the source code: + + freemarker/ext/jsp/web-app_2_2.dtd + freemarker/ext/jsp/web-app_2_3.dtd + freemarker/ext/jsp/web-app_2_4.xsd + freemarker/ext/jsp/web-app_2_5.xsd + freemarker/ext/jsp/web-jsptaglibrary_1_1.dtd + freemarker/ext/jsp/web-jsptaglibrary_1_2.dtd + freemarker/ext/jsp/web-jsptaglibrary_2_0.xsd + freemarker/ext/jsp/web-jsptaglibrary_2_1.xsd diff --git a/org.tizen.common/test/test_files/resource/about_files/LICENSE-2.0.htm b/org.tizen.common/test/test_files/resource/about_files/LICENSE-2.0.htm new file mode 100644 index 0000000..f7ca656 --- /dev/null +++ b/org.tizen.common/test/test_files/resource/about_files/LICENSE-2.0.htm @@ -0,0 +1,191 @@ + + + + Apache License, Version 2.0 + + + + + + + + + + + + + + + + + +
+ + +
+

Apache License

Version 2.0, January 2004

+http://www.apache.org/licenses/

+

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

+

1. Definitions.

+

"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document.

+

"Licensor" shall mean the copyright owner or entity authorized by the +copyright owner that is granting the License.

+

"Legal Entity" shall mean the union of the acting entity and all other +entities that control, are controlled by, or are under common control with +that entity. For the purposes of this definition, "control" means (i) the +power, direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty +percent (50%) or more of the outstanding shares, or (iii) beneficial +ownership of such entity.

+

"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License.

+

"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files.

+

"Object" form shall mean any form resulting from mechanical transformation +or translation of a Source form, including but not limited to compiled +object code, generated documentation, and conversions to other media types.

+

"Work" shall mean the work of authorship, whether in Source or Object form, +made available under the License, as indicated by a copyright notice that +is included in or attached to the work (an example is provided in the +Appendix below).

+

"Derivative Works" shall mean any work, whether in Source or Object form, +that is based on (or derived from) the Work and for which the editorial +revisions, annotations, elaborations, or other modifications represent, as +a whole, an original work of authorship. For the purposes of this License, +Derivative Works shall not include works that remain separable from, or +merely link (or bind by name) to the interfaces of, the Work and Derivative +Works thereof.

+

"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor for +inclusion in the Work by the copyright owner or by an individual or Legal +Entity authorized to submit on behalf of the copyright owner. For the +purposes of this definition, "submitted" means any form of electronic, +verbal, or written communication sent to the Licensor or its +representatives, including but not limited to communication on electronic +mailing lists, source code control systems, and issue tracking systems that +are managed by, or on behalf of, the Licensor for the purpose of discussing +and improving the Work, but excluding communication that is conspicuously +marked or otherwise designated in writing by the copyright owner as "Not a +Contribution."

+

"Contributor" shall mean Licensor and any individual or Legal Entity on +behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work.

+

2. Grant of Copyright License. Subject to the +terms and conditions of this License, each Contributor hereby grants to You +a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, publicly +display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form.

+

3. Grant of Patent License. Subject to the terms +and conditions of this License, each Contributor hereby grants to You a +perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, use, +offer to sell, sell, import, and otherwise transfer the Work, where such +license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by +combination of their Contribution(s) with the Work to which such +Contribution(s) was submitted. If You institute patent litigation against +any entity (including a cross-claim or counterclaim in a lawsuit) alleging +that the Work or a Contribution incorporated within the Work constitutes +direct or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate as of the +date such litigation is filed.

+

4. Redistribution. You may reproduce and +distribute copies of the Work or Derivative Works thereof in any medium, +with or without modifications, and in Source or Object form, provided that +You meet the following conditions:

+
    +
  1. +

    You must give any other recipients of the Work or Derivative Works a +copy of this License; and

    +
  2. +
  3. +

    You must cause any modified files to carry prominent notices stating +that You changed the files; and

    +
  4. +
  5. +

    You must retain, in the Source form of any Derivative Works that You +distribute, all copyright, patent, trademark, and attribution notices from +the Source form of the Work, excluding those notices that do not pertain to +any part of the Derivative Works; and

    +
  6. +
  7. +

    If the Work includes a "NOTICE" text file as part of its distribution, +then any Derivative Works that You distribute must include a readable copy +of the attribution notices contained within such NOTICE file, excluding +those notices that do not pertain to any part of the Derivative Works, in +at least one of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or documentation, +if provided along with the Derivative Works; or, within a display generated +by the Derivative Works, if and wherever such third-party notices normally +appear. The contents of the NOTICE file are for informational purposes only +and do not modify the License. You may add Your own attribution notices +within Derivative Works that You distribute, alongside or as an addendum to +the NOTICE text from the Work, provided that such additional attribution +notices cannot be construed as modifying the License. +You may add Your own copyright statement to Your modifications and may +provide additional or different license terms and conditions for use, +reproduction, or distribution of Your modifications, or for any such +Derivative Works as a whole, provided Your use, reproduction, and +distribution of the Work otherwise complies with the conditions stated in +this License.

    +
  8. +
+

5. Submission of Contributions. Unless You +explicitly state otherwise, any Contribution intentionally submitted for +inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the +terms of any separate license agreement you may have executed with Licensor +regarding such Contributions.

+

6. Trademarks. This License does not grant +permission to use the trade names, trademarks, service marks, or product +names of the Licensor, except as required for reasonable and customary use +in describing the origin of the Work and reproducing the content of the +NOTICE file.

+

7. Disclaimer of Warranty. Unless required by +applicable law or agreed to in writing, Licensor provides the Work (and +each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, +without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You +are solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise +of permissions under this License.

+

8. Limitation of Liability. In no event and +under no legal theory, whether in tort (including negligence), contract, or +otherwise, unless required by applicable law (such as deliberate and +grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a result +of this License or out of the use or inability to use the Work (including +but not limited to damages for loss of goodwill, work stoppage, computer +failure or malfunction, or any and all other commercial damages or losses), +even if such Contributor has been advised of the possibility of such +damages.

+

9. Accepting Warranty or Additional Liability. +While redistributing the Work or Derivative Works thereof, You may choose +to offer, and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this License. +However, in accepting such obligations, You may act only on Your own behalf +and on Your sole responsibility, not on behalf of any other Contributor, +and only if You agree to indemnify, defend, and hold each Contributor +harmless for any liability incurred by, or claims asserted against, such +Contributor by reason of your accepting any such warranty or additional +liability.

+

END OF TERMS AND CONDITIONS

+ +
+ +
+ + + diff --git a/org.tizen.common/test/test_files/resource/about_files/freemarker-LICENSE.txt b/org.tizen.common/test/test_files/resource/about_files/freemarker-LICENSE.txt new file mode 100644 index 0000000..4c5f086 --- /dev/null +++ b/org.tizen.common/test/test_files/resource/about_files/freemarker-LICENSE.txt @@ -0,0 +1,69 @@ +FreeMarker 1.x was released under the LGPL license. Later, by community +consensus, we have switched over to a BSD-style license. As of FreeMarker +2.2pre1, the original author, Benjamin Geer, has relinquished the copyright in +behalf of Visigoth Software Society. The current copyright holder is the +Visigoth Software Society. + +------------------------------------------------------------------------------ +Copyright (c) 2003 The Visigoth Software Society. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. The end-user documentation included with the redistribution, if any, must + include the following acknowlegement: + "This product includes software developed by the + Visigoth Software Society (http://www.visigoths.org/)." + Alternately, this acknowlegement may appear in the software itself, if and + wherever such third-party acknowlegements normally appear. + +3. Neither the name "FreeMarker", "Visigoth", nor any of the names of the + project contributors may be used to endorse or promote products derived + from this software without prior written permission. For written + permission, please contact visigoths@visigoths.org. + +4. Products derived from this software may not be called "FreeMarker" or + "Visigoth" nor may "FreeMarker" or "Visigoth" appear in their names + without prior written permission of the Visigoth Software Society. + +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +VISIGOTH SOFTWARE SOCIETY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +------------------------------------------------------------------------------ + +This software consists of voluntary contributions made by many individuals on +behalf of the Visigoth Software Society. For more information on the Visigoth +Software Society, please see http://www.visigoths.org/ + +------------------------------------------------------------------------------ + +FREEMARKER SUBCOMPONENTS UNDER DIFFERENT LICENSE: + +FreeMarker includes a number of subcomponents that are licensed by the Apache +Software Foundation under the Apache License, Version 2.0. Your use of these +subcomponents is subject to the terms and conditions of the Apache License, +Version 2.0. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +The subcomponents under this licence are the following files, which are +included both in freemarker.jar and in the source code: + + freemarker/ext/jsp/web-app_2_2.dtd + freemarker/ext/jsp/web-app_2_3.dtd + freemarker/ext/jsp/web-app_2_4.xsd + freemarker/ext/jsp/web-app_2_5.xsd + freemarker/ext/jsp/web-jsptaglibrary_1_1.dtd + freemarker/ext/jsp/web-jsptaglibrary_1_2.dtd + freemarker/ext/jsp/web-jsptaglibrary_2_0.xsd + freemarker/ext/jsp/web-jsptaglibrary_2_1.xsd diff --git a/org.tizen.common/test/test_files/resource/resource/text.txt b/org.tizen.common/test/test_files/resource/resource/text.txt new file mode 100644 index 0000000..70b287d --- /dev/null +++ b/org.tizen.common/test/test_files/resource/resource/text.txt @@ -0,0 +1,3 @@ +HOHOHO +HAHAHA +NAMKOONGHO \ No newline at end of file diff --git a/org.tizen.common/test/test_files/resource/text.txt b/org.tizen.common/test/test_files/resource/text.txt new file mode 100644 index 0000000..70b287d --- /dev/null +++ b/org.tizen.common/test/test_files/resource/text.txt @@ -0,0 +1,3 @@ +HOHOHO +HAHAHA +NAMKOONGHO \ No newline at end of file