Author: fmoga
Date: Sun Jun  5 14:19:36 2011
New Revision: 1132415

URL: http://svn.apache.org/viewvc?rev=1132415&view=rev
Log:
Replace the use of absolute path with relative path when using a file in the 
webapp.

Added:
    
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/resources/
    
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/resources/countries.txt
      - copied unchanged from r1127834, 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt
Removed:
    
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt
Modified:
    
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java
    
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite

Modified: 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java?rev=1132415&r1=1132414&r2=1132415&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java
 (original)
+++ 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/CountryRepositoryImpl.java
 Sun Jun  5 14:19:36 2011
@@ -20,8 +20,8 @@ package org.apache.tuscany.sca.sample.co
 
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -39,44 +39,45 @@ import org.oasisopen.sca.annotation.Serv
 @Service(CountryRepository.class)
 public class CountryRepositoryImpl implements CountryRepository {
 
-       @Context
-       protected ComponentContext context;
+    @Context
+    protected ComponentContext context;
 
-       private String fileName;
-       private List<Country> countries;
+    private String fileName;
+    private List<Country> countries;
 
-       @Constructor
-       public CountryRepositoryImpl(@Property(name = "fileName") String 
fileName) {
-               this.fileName = fileName;
-               countries = new ArrayList<Country>();
-       }
-
-       @Init
-       public void start() {
-               try {
-                       BufferedReader reader = new BufferedReader(new 
FileReader(fileName));
-                       String line;
-                       while ((line = reader.readLine()) != null) {
-                               Country c = new Country();
-                               c.setName(line);
-                               countries.add(c);
-                       }
-               } catch (FileNotFoundException e) {
-                       e.printStackTrace();
-               } catch (IOException e) {
-                       e.printStackTrace();
-               }
-       }
-
-       @Override
-       public List<Country> getStartingWith(String text) {
-               List<Country> result = new ArrayList<Country>();
-               for (Country c : countries) {
-                       if 
(c.getName().toLowerCase().startsWith(text.toLowerCase())) {
-                               result.add(c);
-                       }
-               }
-               return result;
-       }
+    @Constructor
+    public CountryRepositoryImpl(@Property(name = "fileName") String fileName) 
{
+        this.fileName = fileName;
+        countries = new ArrayList<Country>();
+    }
+
+    @Init
+    public void start() {
+        try {
+            BufferedReader reader = new BufferedReader(new 
InputStreamReader(getClass().getClassLoader()
+                    .getResourceAsStream(fileName)));
+            String line;
+            while ((line = reader.readLine()) != null) {
+                Country c = new Country();
+                c.setName(line);
+                countries.add(c);
+            }
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public List<Country> getStartingWith(String text) {
+        List<Country> result = new ArrayList<Country>();
+        for (Country c : countries) {
+            if (c.getName().toLowerCase().startsWith(text.toLowerCase())) {
+                result.add(c);
+            }
+        }
+        return result;
+    }
 
 }

Modified: 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite?rev=1132415&r1=1132414&r2=1132415&view=diff
==============================================================================
--- 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite
 (original)
+++ 
tuscany/sca-java-2.x/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/web.composite
 Sun Jun  5 14:19:36 2011
@@ -35,7 +35,7 @@
        <component name="CountryRepositoryComponent">
                <implementation.java
                        
class="org.apache.tuscany.sca.sample.comet.CountryRepositoryImpl" />
-               <property 
name="fileName">/home/fmoga/coding/apache-tuscany/contrib/samples/learning-more/binding-comet/single-response-webapp/src/main/webapp/WEB-INF/countries.txt</property>
+               <property name="fileName">countries.txt</property>
        </component>
 
 </composite>
\ No newline at end of file


Reply via email to