You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/02/11 15:13:30 UTC

svn commit: r743342 - in /jackrabbit/branches/1.5: ./ jackrabbit-webapp/src/main/webapp/populate.jsp

Author: jukka
Date: Wed Feb 11 14:13:30 2009
New Revision: 743342

URL: http://svn.apache.org/viewvc?rev=743342&view=rev
Log:
1.5: Merged revision 741524 (JCR-1970). Ignored other revisions.

Modified:
    jackrabbit/branches/1.5/   (props changed)
    jackrabbit/branches/1.5/jackrabbit-webapp/src/main/webapp/populate.jsp

Propchange: jackrabbit/branches/1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb 11 14:13:30 2009
@@ -1,2 +1,2 @@
 /jackrabbit/branches/1.3:631261
-/jackrabbit/trunk:703899-704158,704165,704167,704324,704358,704361,704864,704933,704939,705010,705033,705243,705496,705522,705579,705925,705932,705934,705937-705938,705961,706242,706273,706285-706286,706562,706606,706649,706655,706660,706697,706918,707303-707304,707307,707310,707630,708206,708598,708609,708613,708619,708634,708840,708863,708909,708929,708943,709115,709142,709207,709211,710047,711238,711566-711567,711595,711841-711843,712984-712985,713037,713059,713065,713072,713076,713162,713214,713956,713958,713964,713971,713975,714034,718218,718249-718250,718371,718376,718566,718632,718981,719225,719282,719575-719577,719579,719585-719586,719588,719592,720455,720484,720492,720524,720533,720540,720673,720679,720687,720784,720940,720969,721186,721191,721194,721235,721387-721389,721470,721495,722068-722069,722463,722465,722467,722470,722825,723281,723346,723728,723784,724300,724387,725292,727376,727388,727390,727395,727397,727402,727492,727701,728022,731896,731934,731941,73234
 7,732678,732686,732689,732693,732703,732715-732716,732719,732728,732730,732734-732738,732740,732742-732743,732745,732867,732883,733057-733059,733061,733080,734092,734366,734375,734400,734709,735401,736021,736030,736274,736276,736650-736651,736653-736656,736658,736680,737695,738087
+/jackrabbit/trunk:703899-704158,704165,704167,704324,704358,704361,704864,704933,704939,705010,705033,705243,705496,705522,705579,705925,705932,705934,705937-705938,705961,706242,706273,706285-706286,706562,706606,706649,706655,706660,706697,706918,707303-707304,707307,707310,707630,708206,708598,708609,708613,708619,708634,708840,708863,708909,708929,708943,709115,709142,709207,709211,710047,711238,711566-711567,711595,711841-711843,712984-712985,713037,713059,713065,713072,713076,713162,713214,713956,713958,713964,713971,713975,714034,718218,718249-718250,718371,718376,718566,718632,718981,719225,719282,719575-719577,719579,719585-719586,719588,719592,720455,720484,720492,720524,720533,720540,720673,720679,720687,720784,720940,720969,721186,721191,721194,721235,721387-721389,721470,721495,722068-722069,722463,722465,722467,722470,722825,723281,723346,723728,723784,724300,724387,725292,727376,727388,727390,727395,727397,727402,727492,727701,728022,731896,731934,731941,73234
 7,732678,732686,732689,732693,732703,732715-732716,732719,732728,732730,732734-732738,732740,732742-732743,732745,732867,732883,733057-733059,733061,733080,734092,734366,734375,734400,734709,735401,736021,736030,736274,736276,736650-736651,736653-736656,736658,736680,737695,738087,740262,740736-740738,740747,740749-740750,741052,741100,741121,741206,741208-741210,741213,741509,741524

Modified: jackrabbit/branches/1.5/jackrabbit-webapp/src/main/webapp/populate.jsp
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-webapp/src/main/webapp/populate.jsp?rev=743342&r1=743341&r2=743342&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-webapp/src/main/webapp/populate.jsp (original)
+++ jackrabbit/branches/1.5/jackrabbit-webapp/src/main/webapp/populate.jsp Wed Feb 11 14:13:30 2009
@@ -13,36 +13,30 @@
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
---%><%@ page import="javax.jcr.Repository,
-                 javax.jcr.Session,
-                 org.apache.jackrabbit.j2ee.RepositoryAccessServlet,
-                 org.apache.jackrabbit.util.Text,
-                 javax.jcr.SimpleCredentials,
-                   java.util.Iterator,
-                   java.net.URL,
-                   java.net.URLEncoder,
-                   java.net.MalformedURLException,
-                   java.io.UnsupportedEncodingException,
-                   java.io.InputStream,
-                   javax.swing.text.html.HTML,
-                   javax.swing.text.html.HTMLEditorKit,
-                   javax.swing.text.html.HTMLDocument,
-                   java.util.ArrayList,
-                   java.util.List,
-                   javax.swing.text.AttributeSet,
-                   javax.jcr.Node,
-                   java.util.Arrays,
-                   java.util.Collections,
-                   java.util.Map,
-                   java.util.HashMap,
-                   java.io.BufferedInputStream,
-                   java.util.Calendar,
-                   java.net.URLConnection,
-                   java.io.IOException,
-                   javax.jcr.RepositoryException,
-                   java.io.InputStreamReader,
-                   java.net.URLDecoder,
-                   java.io.FilterInputStream"
+--%><%@ page import="java.io.FilterInputStream,
+                     java.io.IOException,
+                     java.io.InputStream,
+                     java.io.InputStreamReader,
+                     java.net.URL,
+                     java.net.URLConnection,
+                     java.net.URLDecoder,
+                     java.net.URLEncoder,
+                     java.util.ArrayList,
+                     java.util.Arrays,
+                     java.util.Calendar,
+                     java.util.Collections,
+                     java.util.Iterator,
+                     java.util.List,
+                     javax.jcr.Node,
+                     javax.jcr.Repository,
+                     javax.jcr.Session,
+                     javax.jcr.SimpleCredentials,
+                     javax.swing.text.AttributeSet,
+                     javax.swing.text.html.HTML,
+                     javax.swing.text.html.HTMLDocument,
+                     javax.swing.text.html.HTMLEditorKit,
+                     org.apache.jackrabbit.j2ee.RepositoryAccessServlet,
+                     org.apache.jackrabbit.util.Text"
  %><%@ page contentType="text/html;charset=UTF-8" %><%
     Repository rep;
     Session jcrSession;
@@ -72,9 +66,9 @@
         }
         String[] types = request.getParameterValues("filetype");
         if (types != null) {
-            for (int i = 0; i < types.length; i++) {
-                filetypes.add(types[i]);
-            }
+            filetypes.addAll(Arrays.asList(types));
+        } else {
+            filetypes = DEFAULT_TYPES;
         }
 
 if (seedWord != null && numDocs > 0 && filetypes.size() > 0) { %>
@@ -153,7 +147,7 @@
                 String type = (String) filetypes.get(typeIdx);
                 int offset = 0;
                 while (n < numDocs * (typeIdx + 1) / filetypes.size()) {
-                    final URL[] urls = new Search(type, seedWord, offset).getURLs(out);
+                    final URL[] urls = new Search(type, seedWord, offset).getURLs();
                     if (urls.length == 0) {
                         break;
                     }
@@ -191,7 +185,6 @@
                                     try {
                                         String info = fileName + " (" + host + ")";
                                         URLConnection con = currentURL.openConnection();
-                                        con.setReadTimeout(10000); // 10 seconds
                                         InputStream in = con.getInputStream();
                                         try {
                                             synchronized (fOut) {
@@ -267,7 +260,7 @@
 </p>
     <form method="POST">
       <table>
-      <tr><td>Seed word:</td><td><input name="seed" type="text" size="30" value="<%= seedWord == null ? "download" : Text.encodeIllegalXMLCharacters(seedWord) %>"/></td></tr>
+      <tr><td>Seed word (optional):</td><td><input name="seed" type="text" size="30" value="<%= seedWord == null ? "" : Text.encodeIllegalXMLCharacters(seedWord) %>"/></td></tr>
       <tr><td>Number of documents:</td><td><input name="num" type="text" size="30" value="<%= numDocs == 0 ? 100 : numDocs %>"/></td></tr>
       <tr valign="top"><td>Document types:</td><td><input name="filetype" type="checkbox" value="pdf" <%= filetypes.contains("pdf") ? "checked" : "" %>/> Adobe Acrobat PDF<br/><input name="filetype" type="checkbox" value="rtf" <%= filetypes.contains("rtf") ? "checked" : "" %>/> Rich Text Format<br/><input name="filetype" type="checkbox" value="doc" <%= filetypes.contains("doc") ? "checked" : "" %>/> Microsoft Word<br/><input name="filetype" type="checkbox" value="ppt" <%= filetypes.contains("ppt") ? "checked" : "" %>/> Microsoft PowerPoint<br/><input name="filetype" type="checkbox" value="xls" <%= filetypes.contains("xls") ? "checked" : "" %>/> Microsoft Excel<br/></td></tr>
       <tr><td>&nbsp;</td><td><input type="submit" value="Populate!"/></td></tr>
@@ -281,21 +274,9 @@
         }
     }
 %><%!
-    public Iterator getDocuments(String mimeType, String searchTerm) {
-        return new Iterator() {
-            public boolean hasNext() {
-                return false;
-            }
 
-            public Object next() {
-                return null;
-            }
-
-            public void remove() {
-                throw new UnsupportedOperationException();
-            }
-        };
-    }
+    public static final List DEFAULT_TYPES = Arrays.asList(
+            new String[]{"pdf", "rtf", "doc", "ppt", "xls"});
 
     public static class Search {
 
@@ -311,41 +292,37 @@
             this.start = start;
         }
 
-        public URL[] getURLs(JspWriter out) throws Exception {
+        public URL[] getURLs() throws Exception {
+            List urls = new ArrayList();
+            String query = term + " filetype:" + filetype;
+            URL google = new URL("http://www.google.com/search?q=" +
+                    URLEncoder.encode(query, "UTF-8") + "&start=" + start);
+            URLConnection con = google.openConnection();
+            con.setRequestProperty("User-Agent", "");
+            InputStream in = con.getInputStream();
             try {
-                List urls = new ArrayList();
-                String query = term + " filetype:" + filetype;
-                URL google = new URL("http://www.google.com/search?q=" +
-                        URLEncoder.encode(query, "UTF-8") + "&start=" + start);
-                URLConnection con = google.openConnection();
-                con.setRequestProperty("User-Agent", "");
-                InputStream in = con.getInputStream();
-                try {
-                    HTMLEditorKit kit = new HTMLEditorKit();
-                    HTMLDocument doc = new HTMLDocument();
-                    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
-                    kit.read(new InputStreamReader(in, "UTF-8"), doc, 0);
-                    HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
-                    while (it.isValid()) {
-                        AttributeSet attr = it.getAttributes();
-                        if (attr != null) {
-                            String href = (String) attr.getAttribute(HTML.Attribute.HREF);
-                            if (href != null && href.endsWith("." + filetype)) {
-                                URL url = new URL(new URL("http", "www.google.com", "dummy"), href);
-                                if (url.getHost().indexOf("google") == -1) {
-                                    urls.add(url);
-                                }
+                HTMLEditorKit kit = new HTMLEditorKit();
+                HTMLDocument doc = new HTMLDocument();
+                doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
+                kit.read(new InputStreamReader(in, "UTF-8"), doc, 0);
+                HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
+                while (it.isValid()) {
+                    AttributeSet attr = it.getAttributes();
+                    if (attr != null) {
+                        String href = (String) attr.getAttribute(HTML.Attribute.HREF);
+                        if (href != null && href.endsWith("." + filetype)) {
+                            URL url = new URL(new URL("http", "www.google.com", "dummy"), href);
+                            if (url.getHost().indexOf("google") == -1) {
+                                urls.add(url);
                             }
                         }
-                        it.next();
                     }
-                } finally {
-                    in.close();
+                    it.next();
                 }
-                return (URL[]) urls.toArray(new URL[urls.size()]);
-            } catch (Exception e) {
-                throw e;
+            } finally {
+                in.close();
             }
+            return (URL[]) urls.toArray(new URL[urls.size()]);
         }
     }