WorldDeveloper.org - Forum Topics http://worlddeveloper.org WorldDeveloper.org 2010 info@astrientlabs.com March 9, 2010 08:08PM EST WorldDeveloper.org is a managed social network for application developers around the world. HostJ2ME.com Search Proxy http://worlddeveloper.org/www/forumtopicview.html?fid=333 333 26 Aug 2009 16:36:29 GMT Provides search results for the OSM client by aggregating results from Google, Bing, Wikipedia, and Yahoo using the respective search APIs.<br><br>Example Usage:<br><br><pre><br> SearchAgent agent = new SearchAgent();<br> Query query = new Query();<br> query.addHeader("user-agent","MySearchClient"));<br> <br> query.setTerm("volvo xc60");<br> query.setTypes(FileRecord.TYPE_ALL);<br><br> <br> List providers = new ArrayList();<br> providers.add("yahoo");<br> providers.add("live");<br> providers.add("google");<br> providers.add("googlevideo");<br> providers.add("wikipedia");<br><br> BasicUIListable results = agent.find(query,5*1000,100,providers.toArray(new String[0]));<br><br> for ( SearchResult record : results.items(pn,ps) )<br> {<br> System.out.println(record.getTitle());<br> }<br></pre><br><br>Contact me if you need the full source code Need help http://worlddeveloper.org/www/forumtopicview.html?fid=328 328 14 Jun 2009 11:57:11 GMT I downloaded the application but,when opening it,I'm told 'invalid code,get key name' Please advise Midlet Icon Extractor http://worlddeveloper.org/www/forumtopicview.html?fid=309 309 21 Jan 2009 17:13:33 GMT HostJ2ME.com uses the code below to extract application icons from Midlet jars and display them in the HostJ2ME.com midlet directory.<br><br><pre><br>package com.astrientlabs.hostj2me.util;<br><br>import java.io.ByteArrayOutputStream;<br>import java.io.File;<br>import java.io.FileOutputStream;<br>import java.io.IOException;<br>import java.io.InputStream;<br>import java.util.Properties;<br>import java.util.zip.ZipEntry;<br>import java.util.zip.ZipException;<br>import java.util.zip.ZipFile;<br><br>import com.astrientlabs.files.AstrientFile;<br>import com.astrientlabs.util.Strings;<br><br>public class IconExtractor<br>{<br> private String MANIFEST = "META-INF/MANIFEST.MF";<br> <br> public byte[] extract(String path) throws ZipException, IOException<br> {<br> return extract(new File(path));<br> }<br> <br> public byte[] extract(File jarFile) throws ZipException, IOException<br> {<br> ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);<br> ZipFile zipFile = new ZipFile(jarFile);<br> try<br> {<br> /*for ( Enumeration? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); )<br> {<br> System.out.println(e.nextElement().getName());<br> }*/<br> <br> ZipEntry entry = zipFile.getEntry(MANIFEST);<br><br> InputStream is = zipFile.getInputStream(entry);<br> if ( is != null )<br> {<br> Properties props = new Properties();<br> props.load(is);<br> <br> String iconFile = props.getProperty("MIDlet-Icon");<br> if ( Strings.isNull(iconFile) )<br> {<br> props.list(System.out);<br> String midlet1 = props.getProperty("MIDlet-1");<br> if ( !Strings.isNull(midlet1) )<br> {<br> String[] parts = midlet1.split(",");<br> if ( parts.length > 2 )<br> {<br> iconFile = parts[1].trim();<br> if ( iconFile.startsWith("/") )<br> {<br> iconFile = iconFile.substring(1);<br> }<br> }<br> }<br> }<br> <br> if ( iconFile != null )<br> {<br> ZipEntry iconEntry = zipFile.getEntry(iconFile);<br> <br> if ( iconEntry != null )<br> {<br> FileOutputStream fos = new FileOutputStream("/tmp/icon.png");<br> InputStream zis = zipFile.getInputStream(iconEntry);<br> int r = 0;<br> byte[] buffer = new byte[4*1024];<br> while( (r = zis.read(buffer)) != -1 )<br> {<br> baos.write(buffer,0,r);<br> fos.write(buffer,0,r);<br> }<br> <br> fos.close();<br> zis.close();<br> }<br> }<br> } <br> }<br> finally<br> {<br> zipFile.close(); <br> }<br> <br> return baos.toByteArray();<br> }<br> <br> public static void main(String[] args)<br> {<br> <br> File jarFile = new File("/projects/workspace/cliqmobile/builds/cliqmobile.jar");<br> IconExtractor extractor = new IconExtractor();<br> try<br> {<br> byte[] data = extractor.extract(jarFile);<br> System.out.println(data.length + " " + AstrientFile.fileType(data));<br> }<br> catch (ZipException 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> <br> System.exit(0);<br> }<br>}<br></pre> Java Utility for perfrorming DNS Blacklist lookups. For more information on DNSBL see http://en.wikipedia.org/wiki/DNSBL http://worlddeveloper.org/www/forumtopicview.html?fid=308 308 16 Jan 2009 17:43:06 GMT <pre><br>package com.astrientlabs.net.dns;<br><br>import java.util.ArrayList;<br>import java.util.Hashtable;<br>import java.util.List;<br><br>import javax.naming.Context;<br>import javax.naming.NameNotFoundException;<br>import javax.naming.NamingException;<br>import javax.naming.directory.Attribute;<br>import javax.naming.directory.Attributes;<br>import javax.naming.directory.DirContext;<br>import javax.naming.directory.InitialDirContext;<br><br>import com.astrientlabs.prefs.Preferences;<br><br>public class DNSBL<br>{<br> private static String[] RECORD_TYPES = { "A", "TXT" };<br> <br> private DirContext ictx;<br> private List lookupServices = new ArrayList();<br> <br> <br> public DNSBL() throws NamingException<br> {<br> StringBuilder dnsServers = new StringBuilder(""); <br> List nameservers = sun.net.dns.ResolverConfiguration.open().nameservers();<br> for( Object dns : nameservers ) <br> {<br> dnsServers.append("dns://").append(dns).append(" ");<br> }<br> <br> Hashtable env = new Hashtable();<br> env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); <br> env.put("com.sun.jndi.dns.timeout.initial", Preferences.system.get("dns.timeout","4000"));<br> env.put("com.sun.jndi.dns.timeout.retries", Preferences.system.get("dns.retry","1"));<br> env.put(Context.PROVIDER_URL,Preferences.system.get("dns.url",dnsServers.toString()));<br> <br> ictx = new InitialDirContext(env);<br> }<br> <br> public void addLookupService(String service)<br> {<br> lookupServices.add(service);<br> }<br> <br> public void check(String ip) throws DNSBLException<br> {<br> String[] parts = ip.split("\\.");<br> StringBuilder buffer = new StringBuilder();<br><br> for (int i = 0; i parts.length; i++)<br> {<br> buffer.insert(0, '.');<br> buffer.insert(0, parts[i]);<br> }<br> <br> ip = buffer.toString();<br> <br><br> <br> Attribute attribute;<br> Attributes attributes;<br> <br> <br> String lookupHost;<br> for ( String service : lookupServices )<br> {<br> lookupHost = ip + service;<br> try<br> {<br> attributes = ictx.getAttributes(lookupHost, RECORD_TYPES);<br> attribute = attributes.get("TXT");<br> <br> if ( attribute != null )<br> {<br> throw new DNSBLException(lookupHost + ": " + attribute.get());<br> }<br> }<br> catch (NameNotFoundException e)<br> {<br> //this is good<br> //LogWriter.system.log(getClass(),e);<br> }<br> catch (NamingException e)<br> {<br> //LogWriter.system.log(getClass(),e);<br> }<br> }<br> }<br> <br> <br> public static void main (String[] args)<br> {<br> <br> <br> try<br> {<br> DNSBL dnsBL = new DNSBL();<br> <br> dnsBL.addLookupService("blackholes.easynet.nl");<br> dnsBL.addLookupService("cbl.abuseat.org");<br> dnsBL.addLookupService("proxies.blackholes.wirehub.net");<br> dnsBL.addLookupService("bl.spamcop.net");<br> dnsBL.addLookupService("sbl.spamhaus.org");<br> dnsBL.addLookupService("dnsbl.njabl.org");<br> dnsBL.addLookupService("list.dsbl.org");<br> dnsBL.addLookupService("multihop.dsbl.org"); <br> dnsBL.addLookupService("cbl.abuseat.org"); <br> <br> try<br> {<br> dnsBL.check("201.223.47.44");<br> }<br> catch (DNSBLException se)<br> {<br> System.out.println(se.getMessage());<br> }<br> <br> try<br> {<br> dnsBL.check("38.100.193.183");<br> }<br> catch (DNSBLException se)<br> {<br> System.out.println(se.getMessage());<br> }<br> <br> try<br> {<br> dnsBL.check("189.94.149.137");<br> }<br> catch (DNSBLException se)<br> {<br> System.out.println(se.getMessage());<br> }<br> <br> try<br> {<br> dnsBL.check("220.227.113.25");<br> }<br> catch (DNSBLException se)<br> {<br> System.out.println(se.getMessage());<br> }<br> <br> <br> <br> }<br> catch (Exception e)<br> {<br> e.printStackTrace();<br> }<br> <br> System.exit(0);<br> }<br>}<br>class DNSBLException extends Exception<br>{<br><br> public DNSBLException()<br> {<br> super();<br> }<br><br> public DNSBLException(String message, Throwable cause)<br> {<br> super(message, cause);<br> }<br><br> public DNSBLException(String message)<br> {<br> super(message);<br> }<br><br> public DNSBLException(Throwable cause)<br> {<br> super(cause);<br> }<br>}<br></pre> Line Wrapping Utility for Drawing Strings on a Canvas http://worlddeveloper.org/www/forumtopicview.html?fid=44 44 29 Jan 2007 20:14:22 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.text;<br><br>import java.util.Enumeration;<br>import java.util.NoSuchElementException;<br><br>import javax.microedition.lcdui.Font;<br>import javax.microedition.lcdui.Graphics;<br><br>public class LineEnumeration implements Enumeration<br>{<br> private Font font;<br><br> private String text;<br> private int width;<br> private int position;<br> private int length;<br> private int start = 0;<br><br> public LineEnumeration(Font font, String text, int width)<br> {<br> this.font = font;<br> this.text = text;<br> this.width = width;<br> this.length = text.length();<br> }<br><br> public boolean hasMoreElements()<br> {<br> return (position (length - 1));<br> }<br><br> public Object nextElement() throws NoSuchElementException<br> {<br> try<br> {<br> int next = next();<br><br> String s = text.substring(start, next);<br> start = next;<br><br> if (text.length() - 1 > start && (text.charAt(start) == ' ' <br> || text.charAt(start) == '\n'))<br> {<br> position++;<br> start++;<br> }<br><br> return s;<br> }<br> catch (IndexOutOfBoundsException e)<br> {<br> throw new NoSuchElementException(e.getMessage());<br> }<br> catch (Exception e)<br> {<br> throw new NoSuchElementException(e.getMessage());<br> }<br> }<br><br> private int next()<br> {<br> int i = position;<br> int lastBreak = -1;<br><br> for (; i length <br> && font.stringWidth(text.substring(position, i)) = width; i++)<br> {<br> if (text.charAt(i) == ' ')<br> {<br> lastBreak = i;<br> }<br> else if (text.charAt(i) == '\n')<br> {<br> lastBreak = i;<br> break;<br> }<br> }<br><br> if (i == length)<br> {<br> position = i;<br> }<br> else if (lastBreak == position)<br> {<br> position++;<br> }<br> else if (lastBreak position)<br> {<br> position = i;<br> }<br> else<br> {<br> position = lastBreak;<br> }<br><br> return position;<br> }<br><br> public int writeTo(Graphics g, int startx, int starty, int maxY, Font font)<br> {<br> int fontHeight = font.getHeight() + 1;<br><br> while (hasMoreElements() && starty maxY)<br> {<br> g.drawString(String.valueOf(nextElement()).trim(), <br> startx, starty, Graphics.TOP | Graphics.LEFT);<br> starty += fontHeight;<br> }<br><br> return starty;<br> }<br><br> public void reset()<br> {<br> start = 0;<br> position = 0;<br> }<br>}</pre> download reporting http://worlddeveloper.org/www/forumtopicview.html?fid=270 270 30 Sep 2008 07:26:23 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.......<br> I need some code post on this http://worlddeveloper.org/www/forumtopicview.html?fid=194 194 14 Nov 2007 09:16:21 GMT I wrote a Time Table midlet using persistence storage API for university students to save course code with time. I want the midlet to alert the user when they have that particular course or some minutes before even when the midlet is closed. I need some code post on this. Thanks J2ME: Getting a list of files in a directory (inside the .jar file) http://worlddeveloper.org/www/forumtopicview.html?fid=130 130 26 Mar 2007 15:04:26 GMT Hi,<br><br>I have a problem which should be quite simple, but I haven't been able to work it out. I want to create a list of files inside a directory within the .jar file, but all the instructions I've seen for listing files within a directory assume you're using the fileConnection API and listing an external directory. I don't want to require JSR75, and I've got a feeling that that can't see inside the .jar file anyway.<br><br>I can load the files themselves with no problems, and my current solution is to create a text file with a list of all the files in the directory, but this is a nuisance to keep updating. So can someone give me some pointers about how to create a String[] with a list of files inside an internal directory? Need some assistance http://worlddeveloper.org/www/forumtopicview.html?fid=193 193 14 Nov 2007 09:14:22 GMT I wrote a Time Table midlet using persistence storage API for university students to save course code with time. I want the midlet to alert the user when they have that particular course or some minutes before even when the midlet is closed. I need assistance on this area. Kindly help me on this. Thanks Paging utility for displaying lists in web UI http://worlddeveloper.org/www/forumtopicview.html?fid=197 197 2 Jan 2008 18:29:23 GMT <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 2005<br> */<br>package com.astrientlabs.webui;<br><br>import java.util.LinkedList;<br>import java.util.List;<br>import java.util.Random;<br><br>import com.astrientlabs.logging.LogWriter;<br><br><br>public class BasicUIListable extends LinkedList implements UIListable<br>{<br> /**<br> * <br> */<br> private static final long serialVersionUID = -7369036906003073472L;<br> private int pageSize = 10;<br> private int pageNumber = -1;<br> private Random random = new Random();<br> <br> <br> public List getItems(int pageNumber)<br> {<br> int start = pageNumber * pageSize;<br> int end = start + pageSize;<br> <br> return getItems(start,end);<br> }<br> <br> public List items(int pageNumber, int pageSize)<br> {<br> int start = (pageNumber * pageSize);<br> int end = start + pageSize;<br> <br> return getItems(start,end);<br> }<br> <br> <br> public List getItems(int start, int end)<br> {<br> try<br> {<br> if ( start > -1 && start size() )<br> {<br> if ( end > size() ) <br> {<br> end = size();<br> }<br><br> return this.subList(start,end);<br> }<br> }<br> catch (Exception e)<br> {<br> LogWriter.system.log(getClass(),e);<br> } <br> <br> return this.subList(0,0);//(List)EMPTY_LIST; <br> }<br><br> <br> public void resetPageNumber()<br> {<br> pageNumber = -1;<br> }<br> <br> public List next()<br> {<br> return getItems(++pageNumber);<br> }<br> <br> <br> public List current()<br> {<br> return ( pageNumber == -1 ) ? next() : getItems(pageNumber);<br> }<br> <br> <br> public List previous()<br> {<br> return getItems(--pageNumber);<br> }<br> <br> /**<br> * Returns the pageNumber.<br> * @return int<br> */<br> public int getPageNumber()<br> {<br> return pageNumber;<br> }<br><br> /**<br> * Returns the pageSize.<br> * @return int<br> */<br> public int getPageSize()<br> {<br> return pageSize;<br> }<br><br> /**<br> * Sets the pageNumber.<br> * @param pageNumber The pageNumber to set<br> */<br> public void setPageNumber(int pageNumber)<br> {<br> this.pageNumber = pageNumber;<br> }<br><br> /**<br> * Sets the pageSize.<br> * @param pageSize The pageSize to set<br> */<br> public void setPageSize(int pageSize)<br> {<br> this.pageSize = pageSize;<br> }<br><br><br> public int totalPages()<br> {<br> int size = size();<br> int pageSize = getPageSize();<br> <br> int total = size / pageSize;<br> if ( (size % pageSize ) > 0 ) <br> {<br> total++;<br> }<br> <br> return total;<br> }<br> <br> public int totalPages(int pageSize)<br> {<br> int size = size();<br><br> int total = size / pageSize;<br> if ( (size % pageSize ) > 0 ) <br> {<br> total++;<br> }<br> <br> return total;<br> }<br> <br> /*<br> public synchronized void buildIndexes(Indexer indexer)<br> {<br> indexes.clear();<br> <br> <br> Object o;<br> Object index;<br> for ( Iterator iter = this.iterator(); iter.hasNext(); )<br> {<br> o = iter.next();<br> index = indexer.index(indexes,this);<br> }<br> }*/<br> <br> /*<br> public static void main(String[] args)<br> {<br> BasicUIListable list = new BasicUIListable();<br> list.setPageSize(2);<br> for(int i = 0; i 5;list.add(String.valueOf(i++)));<br> for (String s : list)<br> {<br> System.out.println(s);<br> }<br> <br> System.out.println("\n\n");<br> List l = list.getItems(2);<br> for (String s : l)<br> {<br> System.out.println(s);<br> }<br> <br> System.exit(0);<br> }*/<br> <br> public E random()<br> {<br> return this.get(random.nextInt(this.size()));<br> }<br>}<br></pre><br><br><br>edited by hostj2me 1/2/08 1:31 PM