Recent Notes

Displaying keyword search results 1 - 10
Created by Fang on March 30, 2012 10:07:25    Last update: March 08, 2013 13:41:57
After a user resets a password, I want to force the user to change the password before she gets access to secured content. This is usually done with a servlet filter. But with Spring MVC, you can also use a HandlerInterceptor . According to Spring JavaDoc: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow for exchanging the request and response objects that are handed down the chain. Note that a filter gets configured in web.xml, a HandlerInterceptor in the application context. As a basic guideline, fine-grained handler-related preprocessing tasks are candidates...
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/DumpXml.java package com.android.xmltool; import java.ut... Screenshot Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
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 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: java.io.FileNotFoundException: 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/XMLResource.java ): package com.android.xmlres; import java.io.... 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 alfa on April 06, 2011 13:23:40    Last update: April 06, 2011 13:23:40
A file can be read as URL with the java.net package. You must provide absolute path after the URI scheme name file:// . package com.demo.io; import java.io.*; i...
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 Fang on August 16, 2010 22:00:05    Last update: August 16, 2010 22:12:25
The tags <sql:update> Executes SQL INSERT , UPDATE , DELETE statements, or SQL DDL statements. Syntax: <sql:update sql="sqlUpdate" [dataSource="d... or, put the SQL within the element body: <sql:update [dataSource="dataSource"] [v... Attributes: Name Dynamic? Type Description sql true String SQL update statement. dataSource true javax.sql.DataSource or String Data source associated with the database to update. A String value represents a relative path to a JNDI resource or the parameters for the JDBC DriverManager class. var false String Name of the exported scoped variable for the result of the database update. The type of the scoped variable is java.lang.Integer . scope false String Scope of var. Defaults to "page". <sql:transaction> Establishes a transaction context for <sql:query> and <sql:update> subtags. Syntax: <sql:transaction [dataSource="dataSource"] ... where...
Created by Fang on August 16, 2010 21:44:41    Last update: August 16, 2010 22:01:46
The tags <sql:query> Queries a database. Syntax: <sql:query sql="sqlQuery" var="varName" [scope... or, put the query within the element body: <sql:query var="varName" [scope="{page|req... Attributes: Name Dynamic? Type Description sql true String SQL query statement. dataSource true javax.sql.DataSource or String Data source associated with the database to query. A String value represents a relative path to a JNDI resource or the JDBC parameters for the DriverManager class. maxRows true int The maximum number of rows to be included in the query result. If not specified, or set to -1, no limit on the maximum number of rows is enforced. startRow true int The returned Result object includes the rows starting at the specified index. The first row of the original query result set is at index...
Previous  1 2 Next