Recent Notes

Displaying keyword search results 1 - 8
Created by freyo on May 13, 2011 15:45:29    Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator. build.xml : <?xml version="1.0" encoding="UTF-8"?> <project... AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <man... res/layout/main.xml <?xml version="1.0" encoding="utf-8"?> <Lin... res/values/strings.xml : <?xml version="1.0" encoding="utf-8"?> <res... src/com/android/xmltool/ package; import java.ut... Screenshot Pre-built APK can be downloaded from:
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*; import javax.xml.parsers.*; ... code with namespace: import*; 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 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/ : package; import Add content provider ( src/com/android/cptest/ ): package; import 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 install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by freyo on May 17, 2011 08:46:50    Last update: May 17, 2011 08:47:35
When I used AssetManager to open an XML file in a ContentProvider : getContext().getAssets().openFd("demo.xml"); it failed with this exception: This file can not b... It turned out that openFd only works for asset files that are not compressed. It works on media files such as .mp3 , .jpg , .wmv etc., which are not compressed during packaging. XML files are compressed by dedault, causing openFd to fail. An Android ticket was opened on this issue. Till that is fixed, the workaround is to add an exclusion in build.xml : <?xml version="1.0" encoding="UTF-8"?> <pro...
Created by freyo on April 18, 2011 15:08:21    Last update: April 18, 2011 15:12:20
Generate android project $ ~/android-sdk-linux_86/tools/android create proj... Create XML file res/xml/books.xml : <?xml version="1.0"?> <catalog> <book id=... Edit layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <Lin... Edit code ( src/com/android/xmlres/ ): package; import Change activity label from app_name to booklist ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Add value for string resource ( res/values/string.xml ): <?xml version="1.0" encoding="utf-8"?> <resourc... Deploy and test: ant install
Created by Fang on April 02, 2010 21:45:47    Last update: July 17, 2010 02:55:06
This is built upon the simple test application for JSTL , which contained a single servlet and a single JSP page. If I want to use it to test all available JSTL tags, the servlet and JSP page would be too complicated. Instead, I want to group the JSTL tags into separate JSP pages and display each group based on the requested URL. For example, if the URL ends with /CoreBasic , I'll display a page that contains the basic core tags; if the URL ends with /I18N , I'll display a page that contains the internationalization tags (e.g., <fmt:message> ). Furthermore, I want to delegate the handling of each group of tags to separate Java classes. This is the application I'll use for the...
Created by Fang on April 01, 2010 22:24:58    Last update: April 02, 2010 02:49:38
In this note I'll show you how to create and package a JSP custom tag. The purpose of this tag is to display a random splash image for a home page, among a set of images. We should be able to add or delete candidate splash images from the WAR archive without the need to change the JSP. This is the intended use of the tag: <%@ taglib uri="" prefix... In the above example you provide a set of images named splash*.png (e.g., splash1.png, spalsh2.png, ...), and the tag will pick a random one to display when the JSP is rendered. Let's get started. I'll use Maven for this purpose. Create the standard Maven directory structure ./pom.xml ./src ./src/main ./src/main/jav... pom.xml <project xmlns=""... package tagdemo; import java.util.ArrayList......
Created by Fang on September 07, 2009 16:39:37    Last update: September 07, 2009 18:43:04
It's easiest to use the archetype plugin to start a new Maven project. I'll use struts 1 as example since it's not in the built-in archetypes for archetype:generate . Generate a simple webapp with archetype:generate : C:\work\maven>mvn archetype:generate -DarchetypeAr... It generates a directory structure like this: struts1app struts1app/pom.xml struts1app/src... with a simple POM: <project xmlns=""... Create settings.xml in $HOME/.m2 , add repository for Java EE dependencies: <?xml version="1.0" encoding="UTF-8"?> <setting... Add Java EE and Struts dependencies in pom.xml . Note that the Java EE dependency has scope provided , meaning that the web app container provides the jars, therefore we don't need to bundle them with our war fie. <project xmlns=""... Create a directory named java under main , create the Struts form and...