WorldDeveloper.org - Forum Messages http://worlddeveloper.org WorldDeveloper.org 2017 info@astrientlabs.com October 23, 2017 08:40PM UTC WorldDeveloper.org is a managed social network for application developers around the world. Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=209 209 26 Aug 2009 16:46:38 GMT Wikipedia:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.net.HttpURLConnection;<br>import java.net.URL;<br><br>import com.astrientlabs.biz.db.FileRecord;<br>import com.astrientlabs.logging.LogWriter;<br>import com.astrientlabs.prefs.Preferences;<br>import com.hostj2me.xml.MiniPushHandler;<br>import com.hostj2me.xml.MiniPushParser;<br><br>public class WikipediaSearchProvider extends SearchProvider implements MiniPushHandler<br>{ <br> Preferences preferences = Preferences.getPreferences("yahoosearch");<br> private boolean cancel;<br> private MiniPushParser parser = new MiniPushParser();<br> private WikipediaSearchResult current;<br> <br> public String getName()<br> {<br> return "Wikipedia Search";<br> }<br> <br> public void _query()<br> {<br> if ( (query.getTypes() & FileRecord.TYPE_DOCUMENT) == FileRecord.TYPE_DOCUMENT )<br> {<br> StringBuffer buffer = new StringBuffer("<a href="http://en.wikipedia.org/w/api.php?action=opensearch&format=xml">http://en.wikipedia.org/w/api.php?action=opensearch&format=xml</a>")<br> .append("&search=").append(query.getTermEncoded())<br> .append("&limit=").append(Math.min(maxResults,100));<br><br> if ( cancel )<br> {<br> return;<br> }<br> <br> HttpURLConnection uc = null;<br> try<br> {<br> URL u = new URL(buffer.toString());<br> <br> uc = (HttpURLConnection) u.openConnection();<br> parser.parse(uc.getInputStream(),this,1024);<br> }<br> catch (Exception e)<br> {<br> LogWriter.system.log(getClass(),e);<br> }<br> finally<br> {<br> try<br> {<br> if ( uc != null )<br> {<br> uc.disconnect();<br> }<br> }<br> catch (Exception ignore){}<br> } <br> } <br> }<br> <br> <br> public void handleAttribute(String tag, String attribute, String value)<br> {<br><br> }<br><br> public void handleEndTag(String tag)<br> { <br> if ( tag.equalsIgnoreCase("item") )<br> {<br> if ( current != null )<br> {<br> results.add(current);<br> } <br> }<br> }<br><br><br> public void handleStartTag(String tag)<br> {<br> if ( tag.equalsIgnoreCase("item") )<br> {<br> current = new WikipediaSearchResult();<br> current.setSearchProvider(this);<br> current.setMediaType(FileRecord.TYPE_DOCUMENT);<br> current.setMimeType("text/html");<br> current.setMagic("w");<br> current.setSize(4096);<br> current.setThumbnailURL("<a href="https://hostj2me.com/images/mimes/48/doc.png">https://hostj2me.com/images/mimes/48/doc.png</a>");<br> }<br> }<br><br><br> public void handleText(String tag, String text)<br> { <br> text = text.trim();<br> if ( tag.equalsIgnoreCase("Url") )<br> {<br> current.setURL(text);<br> }<br> else if ( tag.equalsIgnoreCase("text") )<br> {<br> current.setTitle(text);<br> }<br> else if ( tag.equalsIgnoreCase("description") )<br> {<br> current.setDescription(text);<br> }<br> }<br> <br> public void discard(char c) {}<br> public void handleEndOfLineChar(char c){};<br> <br> public void cancel()<br> {<br> cancel = true;<br> parser.cancel();<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=208 208 26 Aug 2009 16:45:39 GMT Yahoo:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.net.HttpURLConnection;<br>import java.net.URL;<br>import java.net.URLEncoder;<br><br>import com.astrientlabs.biz.db.FileRecord;<br>import com.astrientlabs.logging.LogWriter;<br>import com.astrientlabs.prefs.Preferences;<br>import com.hostj2me.xml.MiniPushHandler;<br>import com.hostj2me.xml.MiniPushParser;<br><br>public class YahooSearchProvider extends SearchProvider implements MiniPushHandler<br>{ <br> Preferences preferences = Preferences.getPreferences("yahoosearch");<br> private boolean cancel;<br> private MiniPushParser parser = new MiniPushParser();<br> private YahooSearchResult current;<br> private boolean thumbnail;<br> <br> public String getName()<br> {<br> return "Yahoo Image Search";<br> }<br> <br> public void _query()<br> {<br> StringBuffer buffer = new StringBuffer("<a href="http://search.yahooapis.com/ImageSearchService/V1/imageSearch?">http://search.yahooapis.com/ImageSearchService/V1/imageSearch?</a>")<br> .append("appid=").append(preferences.get("appid", "ENTER YOUR API KEY FROM YAHOO"))<br> .append("&query=").append(URLEncoder.encode(query.getTerm()))<br> .append("&results=").append(Math.min(maxResults,50))<br> .append("&adult_ok=").append(query.isAdult()?1:0)<br> .append("&start=").append(0);<br><br> if ( cancel )<br> {<br> return;<br> }<br> <br> HttpURLConnection uc = null;<br> try<br> {<br> URL u = new URL(buffer.toString());<br> <br> uc = (HttpURLConnection) u.openConnection();<br> parser.parse(uc.getInputStream(),this,1024);<br> }<br> catch (Exception e)<br> {<br> LogWriter.system.log(getClass(),e);<br> }<br> finally<br> {<br> try<br> {<br> if ( uc != null )<br> {<br> uc.disconnect();<br> }<br> }<br> catch (Exception ignore){}<br> }<br> }<br> <br> <br> public void handleAttribute(String tag, String attribute, String value)<br> {<br><br> }<br><br> public void handleEndTag(String tag)<br> { <br> if ( tag.equalsIgnoreCase("result") )<br> {<br> if ( current != null )<br> {<br> results.add(current);<br> } <br> }<br> else if ( tag.equalsIgnoreCase("thumbnail") )<br> {<br> thumbnail = false;<br> }<br> }<br><br><br> public void handleStartTag(String tag)<br> {<br> if ( tag.equalsIgnoreCase("result") )<br> {<br> current = new YahooSearchResult();<br> current.setSearchProvider(this);<br> current.setMediaType(FileRecord.TYPE_IMAGE);<br> current.setMimeType("image/jpeg");<br> <br> }<br> else if ( tag.equalsIgnoreCase("thumbnail") )<br> {<br> thumbnail = true;<br> }<br> }<br><br><br> public void handleText(String tag, String text)<br> { <br> text = text.trim();<br> if ( tag.equalsIgnoreCase("Url") )<br> {<br> if ( thumbnail )<br> {<br> current.setThumbnailURL(text); <br> }<br> else<br> {<br> current.setURL(text);<br> }<br> }<br> else if ( tag.equalsIgnoreCase("title") )<br> {<br> current.setTitle(text);<br> }<br> else if ( tag.equalsIgnoreCase("filesize") )<br> {<br> current.setSize(Long.parseLong(text));<br> }<br> }<br> <br> public void discard(char c) {}<br> public void handleEndOfLineChar(char c){};<br> <br> public void cancel()<br> {<br> cancel = true;<br> parser.cancel();<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=207 207 26 Aug 2009 16:44:31 GMT Bing/MSN Live:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.beans.XMLDecoder;<br>import java.net.HttpURLConnection;<br>import java.net.URL;<br><br>import org.apache.axis.utils.XMLUtils;<br>import org.apache.commons.lang.StringEscapeUtils;<br><br>import a.javax.swing.text.html.HTML;<br><br>import com.astrientlabs.biz.db.FileRecord;<br>import com.astrientlabs.logging.LogWriter;<br>import com.astrientlabs.prefs.Preferences;<br>import com.hostj2me.xml.MiniPushHandler;<br>import com.hostj2me.xml.MiniPushParser;<br><br>public class MSLiveSearchProvider extends SearchProvider implements MiniPushHandler<br>{ <br> Preferences preferences = Preferences.getPreferences("livesearch");<br> private boolean cancel;<br> private MiniPushParser parser = new MiniPushParser();<br> private MSLiveSearchResult current;<br><br> public String getName()<br> {<br> return "MS Live Image Search";<br> }<br> <br> public void _query()<br> {<br> StringBuffer buffer = new StringBuffer("<a href="http://api.search.live.net/xml.aspx?">http://api.search.live.net/xml.aspx?</a>")<br> .append("appid=").append(preferences.get("appid", "ENTER YOUR API KEY FROM BING"))<br> .append("&sources=").append("image")<br> .append("&query=").append(query.getTermEncoded())<br> .append("&image.count=").append(Math.min(maxResults,50))<br> .append("&adult=").append(query.isAdult()?"off":"moderate")<br> .append("&start=").append(0);<br><br> if ( cancel )<br> {<br> return;<br> }<br> <br> HttpURLConnection uc = null;<br> try<br> {<br> URL u = new URL(buffer.toString());<br> <br> uc = (HttpURLConnection) u.openConnection();<br> parser.parse(uc.getInputStream(),this,1024);<br> }<br> catch (Exception e)<br> {<br> LogWriter.system.log(getClass(),e);<br> }<br> finally<br> {<br> try<br> {<br> if ( uc != null )<br> {<br> uc.disconnect();<br> }<br> }<br> catch (Exception ignore){}<br> }<br> }<br> <br> <br> public void handleAttribute(String tag, String attribute, String value)<br> {<br><br> }<br><br> public void handleEndTag(String tag)<br> { <br> if ( tag.equalsIgnoreCase("mms:ImageResult") )<br> {<br> if ( current != null )<br> {<br> results.add(current);<br> } <br> }<br> }<br><br><br> public void handleStartTag(String tag)<br> {<br> if ( tag.equalsIgnoreCase("mms:ImageResult") )<br> {<br> current = new MSLiveSearchResult();<br> current.setSearchProvider(this);<br> current.setMediaType(FileRecord.TYPE_IMAGE);<br> current.setMimeType("image/jpeg");<br> }<br> }<br><br><br> public void handleText(String tag, String text)<br> { <br> text = text.trim();<br> if ( tag.equalsIgnoreCase("mms:MediaUrl") )<br> {<br> current.setURL(text);<br> }<br> if ( tag.equalsIgnoreCase("mms:Url") )<br> {<br> current.setThumbnailURL(StringEscapeUtils.unescapeXml(text));<br> }<br> else if ( tag.equalsIgnoreCase("mms:title") )<br> {<br> current.setTitle(text);<br> }<br> else if ( tag.equalsIgnoreCase("mms:filesize") )<br> {<br> current.setSize(Long.parseLong(text));<br> }<br> else if ( tag.equalsIgnoreCase("mms:ContentType") )<br> {<br> current.setMimeType(text);<br> }<br> }<br> <br> public void discard(char c) {}<br> public void handleEndOfLineChar(char c){};<br> <br> public void cancel()<br> {<br> cancel = true;<br> parser.cancel();<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=206 206 26 Aug 2009 16:43:31 GMT Google:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.io.BufferedReader;<br>import java.io.IOException;<br>import java.io.InputStreamReader;<br>import java.net.HttpURLConnection;<br>import java.net.MalformedURLException;<br>import java.net.URL;<br>import java.net.URLConnection;<br><br>import org.json.JSONArray;<br>import org.json.JSONException;<br>import org.json.JSONObject;<br>import org.json.XML;<br><br>import com.astrientlabs.biz.db.FileRecord;<br>import com.astrientlabs.logging.LogWriter;<br>import com.astrientlabs.prefs.Preferences;<br><br>public class GoogleImageSearchProvider extends SearchProvider<br>{ <br> Preferences preferences = Preferences.getPreferences("googlesearch");<br> private boolean cancel;<br> <br> public String getName()<br> {<br> return "Google Image Search";<br> }<br> <br> public void _query()<br> {<br> int pageSize = 8;<br> int max = Math.min(maxResults,24);//64);<br> <br> for (int start = 0; start max; start+=pageSize)<br> {<br> getResults(start);<br> }<br> }<br> <br> private void getResults(int start)<br> {<br> <br> StringBuffer buffer = new StringBuffer("<a href="http://ajax.googleapis.com/ajax/services/search/images?v=1.0">http://ajax.googleapis.com/ajax/services/search/images?v=1.0</a>")<br> .append("&appid=").append(preferences.get("key", "ENTER YOUR API KEY FROM GOOGLE"))<br> .append("&q=").append(query.getTermEncoded())<br> .append("&rsz=").append("large")<br> <br> .append("&safe=").append(query.isAdult()?"off":"moderate")<br> .append("&start=").append(start);<br><br> if ( cancel )<br> {<br> return;<br> }<br> <br> HttpURLConnection uc = null;<br> try<br> {<br> URL u = new URL(buffer.toString());<br> <br> uc = (HttpURLConnection) u.openConnection();<br> uc.addRequestProperty("Referer", "<a href="http://m.hostj2me.com">http://m.hostj2me.com</a>");<br> prepareConnection(uc);<br> <br> String line;<br> StringBuilder builder = new StringBuilder();<br> BufferedReader reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));<br> while((line = reader.readLine()) != null) {<br> builder.append(line);<br> }<br> <br> JSONObject json = new JSONObject(builder.toString());<br> JSONArray results = json.getJSONObject("responseData").getJSONArray("results");<br> <br> GoogleSearchResult current;<br> JSONObject result;<br> for ( int i = 0, stop = results.length(); i stop && !cancel; i++ )<br> {<br> result = results.getJSONObject(i);<br> <br> current = new GoogleSearchResult();<br> current.setSearchProvider(this);<br> current.setMediaType(FileRecord.TYPE_IMAGE);<br> current.setMimeType("image/jpeg");<br> current.setThumbnailURL(result.get("tbUrl").toString());<br> current.setTitle(result.get("titleNoFormatting").toString());<br> current.setURL(result.get("url").toString());<br> current.setSize(4096);<br> <br> this.results.add(current);<br> }<br> }<br> catch (Exception e)<br> {<br> LogWriter.system.log(getClass(),e);<br> }<br> finally<br> {<br> try<br> {<br> if ( uc != null )<br> {<br> uc.disconnect();<br> }<br> }<br> catch (Exception ignore){}<br> }<br> }<br> <br> public void cancel()<br> {<br> cancel = true;<br> }<br> <br> <br> public static void main (String[] args)<br> {<br> try<br> {<br> URL url = new URL("<a href="http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=Paris%20Hilton">http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=Paris%20Hilton</a>");<br> URLConnection connection = url.openConnection();<br> connection.addRequestProperty("Referer", "<a href="http://www.mysite.com/index.html">http://www.mysite.com/index.html</a>");<br><br> String line;<br> StringBuilder builder = new StringBuilder();<br> BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));<br> while((line = reader.readLine()) != null) {<br> builder.append(line);<br> }<br><br> JSONObject json = new JSONObject(builder.toString());<br> String xml = XML.toString(json);<br> <br> System.out.println(xml);<br> }<br> catch (MalformedURLException e)<br> {<br> // TODO Auto-generated catch block<br> e.printStackTrace();<br> }<br> catch (IOException e)<br> {<br> // TODO Auto-generated catch block<br> e.printStackTrace();<br> }<br> catch (JSONException e)<br> {<br> // TODO Auto-generated catch block<br> e.printStackTrace();<br> }<br> <br> System.exit(0);<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=205 205 26 Aug 2009 16:42:00 GMT SearchResult:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>public interface SearchResult<br>{<br> public String getTitle();<br> public String getMagic();<br> public int getMediaType();<br> public String getURL();<br> public String getId();<br> public long getSize();<br> public String getDescription();<br> public String getAuthor();<br> public SearchProvider getSearchProvider();<br> public String getMimeType();<br> public long getModified();<br> public int getIntID();<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=204 204 26 Aug 2009 16:41:29 GMT SearchProvider:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.io.UnsupportedEncodingException;<br>import java.net.URLConnection;<br>import java.security.InvalidAlgorithmParameterException;<br>import java.security.InvalidKeyException;<br>import java.security.NoSuchAlgorithmException;<br>import java.security.spec.InvalidKeySpecException;<br><br>import javax.crypto.BadPaddingException;<br>import javax.crypto.IllegalBlockSizeException;<br>import javax.crypto.NoSuchPaddingException;<br><br>import com.astrientlabs.biz.web.util.Base32;<br>import com.astrientlabs.dp.task.Task;<br>import com.astrientlabs.webui.BasicUIListable;<br><br>public abstract class SearchProvider extends Task<br>{<br> protected String name;<br> protected Query query;<br> protected int maxResults;<br> protected BasicUIListable results;<br> <br> public String getName()<br> {<br> return name;<br> }<br> <br> public void setQuery(Query query, int maxResults, BasicUIListable results)<br> {<br> this.query = query;<br> this.maxResults = maxResults;<br> this.results = results;<br> }<br> <br> protected void prepareConnection(URLConnection connection)<br> {<br> for (String key : query.getHeaderMap().keySet())<br> {<br> connection.setRequestProperty(key, query.getHeaderMap().get(key));<br> }<br> }<br> <br> public void _execute()<br> {<br> _query();<br> }<br> <br> public static String obfuscateURL(String url) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeySpecException, UnsupportedEncodingException<br> {<br> return new String(Base32.encode(url.getBytes("UTF8")));<br> }<br> <br> public static String unobfuscateURL(String obfuscatedURL) throws InvalidKeyException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeySpecException<br> {<br> return new String(Base32.decode(obfuscatedURL),"UTF8");<br> }<br> <br> public abstract void _query(); <br> public abstract void cancel();<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=203 203 26 Aug 2009 16:40:52 GMT Query:<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.net.URLEncoder;<br>import java.util.HashMap;<br>import java.util.Map;<br><br>public class Query<br>{<br> private Map headers = new HashMap();<br> private String term;<br> private int types;<br> private boolean others;<br> private boolean adult;<br> <br> <br> public void addHeader(String key, String value)<br> {<br> headers.put(key, value);<br> }<br> <br> protected Map getHeaderMap()<br> {<br> return headers;<br> }<br> <br> public String cacheKey()<br> {<br> return new StringBuffer(term).append('.')<br> .append(types).append('.')<br> .append(others).append('.')<br> .append(adult).toString();<br> }<br> <br> public boolean isAdult()<br> {<br> return adult;<br> }<br> public void setAdult(boolean adult)<br> {<br> this.adult = adult;<br> }<br> public String getTerm()<br> {<br> return term;<br> }<br> <br> public String getTermEncoded()<br> {<br> return URLEncoder.encode(term);<br> }<br> <br> <br> public void setTerm(String term)<br> {<br> this.term = term;<br> }<br> public int getTypes()<br> {<br> return types;<br> }<br> public void setTypes(int types)<br> {<br> this.types = types;<br> }<br> public boolean isOthers()<br> {<br> return others;<br> }<br> public void setOthers(boolean others)<br> {<br> this.others = others;<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=333&nn=202 202 26 Aug 2009 16:40:15 GMT SearchAgent<br><br><pre><br>/*<br> * Copyright (C) 2005 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC. <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2009<br> */<br>package com.hostj2me.web.search;<br><br>import java.util.ArrayList;<br>import java.util.List;<br>import java.util.concurrent.Semaphore;<br>import java.util.concurrent.TimeUnit;<br><br>import com.astrientlabs.biz.db.FileRecord;<br>import com.astrientlabs.cache.Cache;<br>import com.astrientlabs.cache.SlotCache;<br>import com.astrientlabs.dp.task.Task;<br>import com.astrientlabs.dp.task.TaskListener;<br>import com.astrientlabs.dp.task.TaskRunner;<br>import com.astrientlabs.logging.LogWriter;<br>import com.astrientlabs.objects.ClassMap;<br>import com.astrientlabs.objects.ClassRegister;<br>import com.astrientlabs.webui.BasicUIListable;<br><br>public class SearchAgent implements TaskListener<br>{<br> private static Cache cache = new SlotCache(100);<br> <br> private static ClassMap classMap = new ClassMap("searchproviders");<br> private static TaskRunner taskRunner = new TaskRunner(8);<br> <br> private Semaphore semaphore = new Semaphore(0);<br> private boolean useCaching = true;<br> <br> private BasicUIListable results = new BasicUIListable();<br> <br> public void setUseCaching(boolean useCaching)<br> {<br> this.useCaching = useCaching;<br> }<br> <br> public synchronized BasicUIListable find(Query query, long timeout, int maxResults, String... providers)<br> {<br> StringBuffer buffer = new StringBuffer(query.cacheKey());<br> buffer.append(timeout).append('.').append(maxResults).append('.');<br> <br> for ( String provider : providers )<br> {<br> buffer.append(provider).append('.');<br> }<br> <br> BasicUIListable cachedResults = null;<br> if ( useCaching )<br> {<br> cachedResults = (BasicUIListable)cache.get(buffer.toString());<br> }<br> <br> if ( cachedResults != null )<br> {<br> LogWriter.system.log(getClass(), cachedResults.size() + " results found in cache.");<br> return cachedResults;<br> }<br> else<br> {<br> semaphore.drainPermits();<br> <br> Class clazz;<br> ClassRegister register;<br> SearchProvider searchProvider;<br> <br> List searchProviders = new ArrayList(providers.length);<br> for ( String provider : providers )<br> {<br> register = classMap.getRegister(provider);<br> LogWriter.system.log(getClass(),provider + " handled by " + register);<br> <br> if ( register != null )<br> {<br> try<br> {<br> clazz = register.getClassObject();<br> <br> searchProvider = (SearchProvider)clazz.newInstance();<br> searchProvider.addListener(this);<br> searchProvider.setQuery(query,maxResults,results);<br> taskRunner.execute(searchProvider);<br> searchProviders.add(searchProvider);<br> <br> }<br> catch (Exception e)<br> {<br> LogWriter.system.log(getClass(),e);<br> }<br> }<br> }<br> <br> try<br> {<br> semaphore.tryAcquire(searchProviders.size(), timeout, TimeUnit.MILLISECONDS);<br> }<br> catch (InterruptedException e)<br> {<br> LogWriter.system.log(getClass(),e);<br> }<br> <br> for ( SearchProvider p : searchProviders )<br> {<br> p.cancel();<br> }<br> <br> if ( useCaching )<br> {<br> cache.put(buffer.toString(),results);<br> }<br> return results;<br> }<br> }<br> <br> public void notify(Task job)<br> {<br> if ( job instanceof SearchProvider )<br> {<br> SearchProvider searchProvider = (SearchProvider)job;<br> LogWriter.system.log(getClass(), searchProvider.getName() + " completed");<br> semaphore.release();<br> }<br> } <br> <br> public static void main(String[] args)<br> { <br> SearchAgent agent = new SearchAgent();<br> Query query = new Query();<br> query.setTerm("washington");<br> query.setTypes(FileRecord.TYPE_IMAGE);<br> query.setOthers(false);<br> query.setAdult(false);<br> <br> List results = agent.find(query,5*1000,50,"livevideo");<br> for ( SearchResult result : results )<br> {<br> System.out.println(result.getTitle());<br> System.out.println(result.getURL());<br> }<br> <br> System.exit(0);<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=44&nn=176 176 21 Dec 2008 20:37:19 GMT Within the paint method:<br><br><pre><br>String longText = ...;<br>Font myFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);<br>LineEnumeration e = new LineEnumeration(myFont,,getWidth());<br>e.writeTo(g,10,10,myFont);<br><br>Alternative:<br><br>LineEnumeration e = new LineEnumeration(myFont,myText,lineWidth);<br>while ( e.hasMoreElements() )<br>{<br> g.drawString(e.nextElement().toString(), startX,startY, Graphics.TOP | Graphics.LEFT);<br> startY += myFont.getHeight();<br>}<br></pre><br><br><br>Also see:<br><br><a href="http://hostj2me.com/appdetails.html?id=6">http://hostj2me.com/appdetails.html?id=6</a> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=270&nn=117 117 30 Sep 2008 21:43:34 GMT HostJ2ME.com and WorldDeveloper.org use similar code to record application downloads and AMS notifications.<br><br>When your phone opens a connection to either server, it sends headers which contain the User-Agent. The servers record the all bytes from the connection and store them in a database. In some cases the IP addresses are resolved and the domains are normalized.<br><br>For AMS notifications, the server again records all bytes from the connection. Devices send status codes to the server. Below are some Java code excerpts.<br><br><br>download servlet:<br><br>StringBuffer buffer = new StringBuffer();<br>buffer.append(request.getRemoteAddr());<br>buffer.append("\nEncoding: ");<br>buffer.append(request.getCharacterEncoding());<br>buffer.append("\nRemote user: ");<br>buffer.append(request.getRemoteUser());<br>buffer.append("\nRemote host: ");<br>buffer.append(request.getRemoteHost());<br>buffer.append("\n\n");<br><br>Enumeration e = request.getHeaderNames();<br>while (e.hasMoreElements())<br>{<br>key = String.valueOf(e.nextElement());<br><br>if (key.toLowerCase().startsWith("cookie") || key.toLowerCase().startsWith("referer"))<br>continue;<br>buffer.append(key);<br>buffer.append("=");<br>buffer.append(request.getHeader(key));<br>buffer.append("\n");<br>}<br><br>e = request.getParameterNames();<br>while (e.hasMoreElements())<br>{<br>key = String.valueOf(e.nextElement());<br>if (key.toLowerCase().startsWith("cookie") || key.toLowerCase().startsWith("referer"))<br>continue;<br>buffer.append(key);<br>buffer.append("=");<br>buffer.append(request.getHeader(key));<br>buffer.append("\n");<br>}<br> Post by mickeystaines http://worlddeveloper.org/www/forumtopicview.html?fid=194&nn=116 116 30 Sep 2008 07:05:06 GMT I need to know how the hostj2me server manages to log the mobile configuration, profile,and the model number of the phone which downloads a mobile application from its server....How is it possible to query the phone OTA....... Post by atmaram http://worlddeveloper.org/www/forumtopicview.html?fid=130&nn=88 88 2 Apr 2008 09:37:42 GMT file connection api is meant for accessing device file system. Post by atmaram http://worlddeveloper.org/www/forumtopicview.html?fid=193&nn=87 87 2 Apr 2008 07:45:30 GMT Use registerAlram function ( supported in MIDP 2 )<br><br> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=194&nn=76 76 2 Jan 2008 18:24:19 GMT First, sorry for taking so long to respond to your post. I have been travelling since the 15th of November.<br><br>Sounds like you will need to use the RegisterAlarm functionality of the PushRegistry to accomplish your goal. During shutdown, the midlet could compute and register an alarm the next launch time from the start time of the next upcoming course.<br><br>In the shutdown logic of your midlet or destroyApp add something along the lines of<br><br>PushRegistry.registerAlarm(“myMidletClassName”,timeOfNextCourse);<br> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=124&nn=70 70 11 Sep 2007 18:44:34 GMT An updated version<br><br>32=<br>33=!<br>34="<br>35=#<br>38=&<br>39='<br>40=(<br>41=)<br>42=*<br>43=+<br>44=,;.<br>45=-<br>46=.:_<br>47=/<br>48=0<br>49=1<br>50=2<br>51=3<br>52=4<br>53=5<br>54=6<br>55=7<br>56=8<br>57=9<br>58=:<br>59=;<br>61==<br>63=?<br>64=@<br>95=_<br>97=a"<br>98=b8<br>99=c)<br>100=d+<br>101=e-<br>102=f4<br>103=g5<br>104=h6<br>105=i/<br>106=j#<br>107=k<br>108=l<br>109=m0<br>110=n9<br>111=o=<br>112=p?<br>113=q!<br>114=r1<br>115=s@<br>116=t2<br>117=u*<br>118=v7<br>119=w&<br>120=x(<br>121=y3<br>122=z'<br>183=. Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=169&nn=55 55 29 May 2007 14:22:56 GMT another example<br><br><pre><br> private boolean isPushActivated()<br> {<br> String[] connections = PushRegistry.listConnections(true);<br> if ( connections != null )<br> {<br> for ( int i = 0; i connections.length; i++ )<br> {<br> if ( connections[i].startsWith("sms") )<br> {<br> try<br> {<br> MessageConnection con = (MessageConnection) Connector.open(connections[i]);<br> Message message = con.receive();<br> <br> if ( message instanceof TextMessage )<br> {<br> TextMessage textMessage = (TextMessage) message;<br> String text = textMessage.getPayloadText();<br> <br> //do something with message<br> return true;<br> }<br> }<br> catch (InterruptedIOException e)<br> {<br> e.printStackTrace();<br> }<br> catch (IOException e)<br> {<br> e.printStackTrace();<br> }<br> }<br> }<br> }<br> <br> return false;<br> }<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=133&nn=33 33 26 Mar 2007 16:19:35 GMT If a person is has unprotected wireless network, the best thing would be to teach the person a lesson in security. The moocher is not the problem. For example, I live in a high-rise. If I play my music loud, I am pretty I cannot take my neighbor to court for listening to it. Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=132&nn=32 32 26 Mar 2007 16:10:28 GMT I was always interested in the Viability of Vonage in a world with free VOIP. If on shaky ground before, this is definitely not a welcomed development for the company. But it does raise the debate over the struggle to fostering innovation and competition while protecting the intellectual property.<br><br>Part of the problem lies in the limited ability of the patent office to determine what is patentable or rather, what should be patentable. Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=131&nn=31 31 26 Mar 2007 15:49:14 GMT I think mobile applications may be the one place where well-designed invasive ads enhance the user experience. For example, an ad can be displayed while an application is communication with the server or completing some other time/resource hungry operation. We are already accustomed to the waiting on mobile devices.<br><br>This may change as networks become faster and expectations rise. But for now, as long as the cost of delivering the ad add minimal overhead, I don't think the mobile device user will mind an ad here of there.<br><br><br>edited by hostj2me 3/26/07 11:49 AM Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=42&nn=27 27 16 Mar 2007 16:04:55 GMT You can optimize the save by using a record filter and updating the records that have changed and adding the new values. Deleting the store may be inefficient. Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=42&nn=26 26 16 Mar 2007 16:02:36 GMT Example usage.<br><br>PropertyMap properties = new PropertyMap("myappproperties");<br>properties.initialize();<br><br>properties.put("someprop","somevalue");<br>properties.write(); //save to recordstore<br><br>String somePropValue = properties.get("someProp");<br>boolean firstRun = properties.getBoolean("dosetup",true)<br> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=78&nn=25 25 15 Mar 2007 15:34:11 GMT <pre><br>/*<br> * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2006<br> */<br>package com.astrientlabs.log;<br><br>public class LogMessage<br>{<br> public long timeStamp = System.currentTimeMillis();<br> public String message;<br> <br> public LogMessage(String message)<br> {<br> this.message = message;<br> }<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=78&nn=24 24 15 Mar 2007 15:33:44 GMT <pre><br>/*<br> * Copyright (C) 2006 Astrient Labs, LLC Licensed under the Apache License,<br> * Version 2.0 (the "License"); you may not use this file except in compliance <br> * with the License. You may obtain a copy of the License at <br> * <br> * <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a> <br> * <br> * Unless required by applicable law or agreed to in writing, software <br> * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT <br> * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the <br> * License for the specific language governing permissions and limitations under<br> * the License.<br> * <br> * Astrient Labs, LLC <br> * <a href="http://www.astrientlabs.com">www.astrientlabs.com</a> <br> * rashid@astrientlabs.com<br> * Rashid Mayes 2006<br> */<br>package com.astrientlabs.log;<br><br>public interface LogListener<br>{<br> public void log(String message);<br>}<br></pre> Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=72&nn=23 23 10 Mar 2007 16:38:37 GMT I added a JSP that will return application details via a JavaScript object.<br><br>The name of the JSP in appinfo.js.html. You can included the results in your web page by using<br><br><a href="http://hostj2me.com/appinfo.js.html?id=appID">http://hostj2me.com/appinfo.js.html?id=appID</a> as the SRC of a JavaScript tag.<br><br><br>[SCRIPT LANGUAGE="JAVASCRIPT" SRC=<a href="http://www.host2me.com/appinfo.js.html?id=5">www.host2me.com/appinfo.js.html?id=5</a>][/SCRIPT]<br><br>Please view the src of<br><br><a href="http://www.hostj2me.com/jstest.html">http://www.hostj2me.com/jstest.html</a><br><br>for an example.<br><br>edited by hostj2me 3/10/07 11:42 AM Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=72&nn=22 22 10 Mar 2007 16:38:14 GMT HostJ2me.com can be used to track visits to your other web pages. Here are the steps:<br><br>1) Create a new application<br>2) Upload a small image as the application screen shot<br>3) Click save<br>4) You should see the image listed as the current application screenshot. Copy the URL of the image.<br>5) Add a new HTML image to the bottom of your web page using the image URL that you copied in step 4.<br><br>Whenever someone visits your site, their browser will request the image from HostJ2me.com. HostJ2me.com will record the IP and date of each visit in the visitor log. Post by hostj2me http://worlddeveloper.org/www/forumtopicview.html?fid=72&nn=21 21 10 Mar 2007 16:37:57 GMT Did you know that you can find out the process details and changelog for hostj2me.com by visiting <a href="http://www.hostj2me.com/build-info.html?">http://www.hostj2me.com/build-info.html?</a>