Displaying keyword search results 1 - 11
Created by freyo on May 23, 2011 14:30:18 Last update: May 23, 2011 14:31:08
There are two distinct ways to process XPath: with namespace and without namespace. The code is different depending on whether the parser is namespace aware. Code without namespace:
import java.io.*; import javax.xml.parsers.*; ...code with namespace:
import java.io.*; import java.util.Iterator; ...XML without namespace:
<?xml version="1.0" encoding="UTF-8" standalone="n...XML with namespace:
<?xml version="1.0" encoding="UTF-8" standalone="n...The same XPath expression works for both XML files when the parser is not namespace aware. When the parser is namespace aware, you have to adjust the XPath accordingly depending on whether the XML has namespace declarations: " /test-license/licensee/name/text() " works for the XML file without namespace, while " /p:test-license/p:licensee/p:name/text() " works for the XML file with namespace.
Created by freyo on May 17, 2011 11:13:17 Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with:
tools/android create project --package com.android...Create assets directory and add an XML file ( assets/demo.xml ):
<? xml version="1.0" encoding="UTF-8"?> <people...Edit the layout ( res/layout/main.xml ):
<?xml version="1.0" encoding="utf-8"?> <LinearL...Edit src/com/android/cptest/Dummy.java :
package com.android.cptest; import java.io....Add content provider ( src/com/android/cptest/XmlResource.java ):
package com.android.cptest; import java.io....Update AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?> <manifes...Add this section to the end of build.xml :
<target name="-package-resources"> <ech...Build and install:
ant installScreenshot: Remove the Dummy activity ( AndroidManifest.xml ):
<?xml version="1.0" encoding="utf-8"?> <manifes...Create a new project for...
Created by alfa on April 06, 2011 12:48:44 Last update: April 06, 2011 12:48:44
package com.demo.io; import java.io.*; ...
Created by alfa on April 06, 2011 12:07:12 Last update: April 06, 2011 12:08:01
You can use Class.getresourceAsStream or ClassLoader.getresourceAsStream to read a file from classpath. Class.getresourceAsStream delegates to ClassLoader.getresourceAsStream , but it does some preprocessing before delegation: If the file name begins with a '/', then the absolute name of the resource is the portion of the name following the '/'. Otherwise, the absolute name is: package_name_with_dot_replaced_by_slash/file_name
package com.demo.io; import java.io.*; ...
Created by Dr. Xi on March 29, 2011 16:06:57 Last update: April 01, 2011 12:33:52
This utility class retrieves SSL certificates from the server and print them out to the stdout. The output can be saved to a file and imported to a Java keystore. This is useful in your test environment where the SSL certificate is self-signed.
import java.io.InputStream; import java.io.Outp...Retrieve and import the a certificate:
E:\test>java RetrieveSSLCert 192.168.69.144 8081 >...
Created by Dr. Xi on January 14, 2010 00:28:27 Last update: March 30, 2011 15:37:44
A task that a Java developer does so frequently is to find out where a certain class can be found - to resolve compilation errors, classpath issues, or version conflicts of the same class introduced by multiple class loaders. A long while back I wrote a simple Perl script to perform the task. Later I was informed that there are Swing based Jar Browser and Jars Browser . Then, there are a couple of shell one-liners:
# one liner 1 find -name "*.jar" -print0 | xarg...But all of them share the same problem: if a class is in a jar nested in another jar, it cannot be found. Such is the case for a class inside a jar under the WEB-INF/lib directory of a...
Created by Dr. Xi on July 19, 2010 21:58:34 Last update: July 23, 2010 21:37:23
Parsing XML in Java is really simple:
import java.io.*; import javax.xml.parsers.Docu...The parser implementation details are hidden behind the JAXP API. In case you want to know which parser implementation is used, this is what the JavaDoc for DocumentBuilderFactory.newInstance says: Use the javax.xml.parsers.DocumentBuilderFactory system property. Use the properties file " lib/jaxp.properties " in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to...
Created by Dr. Xi on January 08, 2010 03:53:37 Last update: January 08, 2010 03:54:56
This is an Ant custom task to merge Properties files I lifted from http://marc.info/?l=ant-user&m=106442688632164&w=2 , with some minor bug fixes. Example usage:
<taskdef name="mergeProperty" classname="ant.task....Implementation:
package ant.task.addon; import java.io.Buff...
Created by Dr. Xi on November 19, 2008 00:22:27 Last update: January 07, 2010 23:00:36
There is a open source project named [ini4j] for processing Windows .ini configuration files. However, I found it an overkill for my purposes. So here is my simple implementation of a .ini parser. It mimics the standard java.util.Properties class with enhancements to get and set properties by section name. There are only a few simple rules: Leading and trailing spaces are trimmed from section names, property names and property values. Section names are enclosed between [ and ] . Properties following a section header belong to that section Properties defined before the appearance of any section headers are considered global properties and should be set and get with no section names. You can use either equal sign ( = ) or colon ( : )...
Created by Dr. Xi on February 09, 2009 23:14:15 Last update: February 09, 2009 23:14:15
This example demonstrates the general steps in creating a custom Java class loader. Normally a class loader would consult its parent class loader when asked to load a class. If it's not loaded by the parent class loader, then the class loader would try to load the class on its own. This class loader tries to load the requested class on its own first, and delegates to the parent only when a java.lang.SecurityException is thrown (which happens when it tries to load core Java classes such as java.lang.String ). The classes are loaded from CLASSPATH through the getResourceAsStream call. It's important to note that when a class is loaded with a certain class loader, all classes referenced from that class are also loaded through the...
Created by Dr. Xi on September 04, 2008 18:18:07 Last update: September 04, 2008 18:18:07
If the argument to getResourceAsStream is a directory, the stream content returns a list of files under that directory. The following code returns the list of files under the first directory on CLASSPATH (not the current directory):
import java.io.*; public class TestGetResou...