Recent Notes

Displaying keyword search results 1 - 10
Created by Fang on December 06, 2011 19:03:25    Last update: December 07, 2011 08:54:11
Our custom tag, as implemented in the previous note , is broken when a template is used. Create a template file ( home-template.xhtml ): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric... and a test page that uses it ( home.xhtml ): <?xml version="1.0" encoding="UTF-8"?> <ui:comp... Then request the page with URL: http://localhost:8080/facelet-demo/home.jsf?name=Jack . You'll find that our hello tag works inside ui:repeat but fails to get the value defined by ui:param ! What's the problem? Our hello tag implementation evaluated the EL with the wrong EL context! This is the corrected implementation: package com.example; import
Created by nogeek on November 03, 2010 20:52:49    Last update: November 23, 2011 08:54:44
My problem is simple: in my XML data, a timestamp is provided as a long integer (number of milliseconds since the "the epoch"). When I do XSLT, I want to display it as a readable string, such as "Mon Nov 01 18:08:48 CDT 2010". After hours of struggle, I found: It's not so easy to get the job done with JDK 1.6 There are tons of garbage on the web in this space (suggestions, code snippets that simply don't work) Simple Xalan extension functions was the only resource that's somewhat informative. Even there some of the examples don't work. Below is a list of what worked and what didn't. This works: <xsl:stylesheet version="1.0" xmlns:xsl="h... This does not (providing long value to Date constructor): <xsl:stylesheet version="1.0" xmlns:xsl="h......
Created by Fang on October 30, 2011 20:35:17    Last update: October 30, 2011 20:37:03
This note lists some of the different behaviors I found using different JSF implementations. In the simple JSF facelet example, I used Sun's reference implementation version 2.0.0-RC: <dependency> <groupId>javax.faces</gro... With this version, the DOCTYPE declaration is dropped when the page is rendered. It doesn't matter what DOCTYPE you declare in your templates, the facelet engine simply drops it. The problem with this is, your page is always displayed in quirks mode , despite your intentions to require standards compliant mode. The DOCTYPE problem is fixed in release 2.0.2-FCS . Change the dependency in pom.xml to: <dependency> <groupId>javax.faces</gro... and test again, you'll find that DOCTYPE is faithfully passed over to the browser (view source at browser). You can delete the DOCTYPE declaration in the xhtml template...
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 September 09, 2011 11:43:36    Last update: September 09, 2011 11:45:45
When you run automated Android tests with Eclipse or from the command line, you get text output, which isn't good for reporting purposes. If you run a large set of test cases with automated build, the text report isn't very helpful. Fortunately, Android CTS generates test reports in XML with accompanying XSL to make it look nice in a browser. To run your own tests with Android CTS: Download Android CTS Make a new directory MyRepository under android-cts , alongside the existing repository directory. Copy host_config.xml from repository to MyRepository Create directory plans under MyRepository , add a test plan ( MyTests.xml ): <?xml version="1.0" encoding="UTF-8"?> <TestPla... Create directory testcases under MyRepository . Copy TestDeviceSetup.apk from repository/testcases to MyRepository/testcases Under MyRepository/testcases , create a test...
Created by freyo on May 20, 2011 09:25:20    Last update: May 23, 2011 12:11:42
The javax.xml.crypto and javax.xml.crypto.dsig packages are not available in Android (as of version 2.3). Therefore, standard Java API does not work. But you can use the Apache Santuario library to do that. Here are the steps: Download the xml security source distribution (curently version 1.4.4). Build with ant. Create your own library jar (only the apache classes, no javax): jar -cf xmlsec-1.4.4.jar -C build/classes org Copy xmlsec-1.4.4.jar to the libs directory of your Android project. Here's the Java code: import*; import javax.xml.parsers.*; ...
Created by Dr. Xi on November 23, 2010 20:20:01    Last update: March 01, 2011 13:38:51
I tried to find a GZIP compression servlet filter to compress a large log file that we send down to the browser. Most of the implementations I found were overly complicated and many buggy. This is a simple implementation that worked for me. The filter: package filter.demo; import*; i... Config web.xml : <filter> <filter-name>gzipFilter</filte... The ugly anonymous inner class could have been avoided if the servlet API did not insist on ServletResponse.getOutputStream returning the bogus ServletOutputStream class (instead of the plain OutputStream ). Additional Note: In an earlier version of this filter, the gzip headers were added in doFilter , like this: // This is NOT good! if (supportsGzip) { ... It turned out that the ServletResponse methods sendError bypasses the gzip...
Created by Dr. Xi on February 01, 2011 14:38:55    Last update: February 01, 2011 14:40:59
Create the stuff you want to manufacture with the factory: package tc.demo; public class Junk { ... Create the factory: package tc.demo; import java.util.Enumerati... Tell Tomcat to use your factory. Create file context.xml and put it under the directory META-INF of your web application: <Context> <Resource name="/find/junk/here" ... Note that beside name , type and factory , you can put any arbitrary attribute in the Resource element. Access the thing with JNDI: <%@page language="java" import="javax.naming.*,tc.... The server side log looked like this: INFO: jndiName: here INFO: name: scope, value: ... Also note that, in contrast to Tomcat documentation , resource-ref is not needed in web.xml .
Created by Fang on August 18, 2010 20:07:46    Last update: August 18, 2010 20:11:36
JSTL uses XPath expressions as a concise notation to specify or select parts of an XML document. JSTL provides EL like expressions to access web application data and comes with the core function library of the XPath specification. Accessing Web Application Data XPath Expression Mapping $foo pageContext.findAttribute("foo") $param:foo request.getParameter("foo") $header:foo request.getHeader("foo") $cookie:foo maps to the cookie's value for name foo $initParam:foo application.getInitParameter("foo") $pageScope:foo pageContext.getAttribute("foo", PageContext.PAGE_SCOPE) $requestScope:foo pageContext.getAttribute("foo", PageContext.REQUEST_SCOPE) $sessionScope:foo pageContext.getAttribute("foo", PageContext.SESSION_SCOPE) $applicationScope:foo pageContext.getAttribute("foo", PageContext.APPLICATION_SCOPE) For example, to find the bar element whose x attribute equals the value of the HTTP request parameter named paramName : /foo/bar[@x=$param:paramName] Java Type to XPath Type Mappings XPath Type Java Type java.lang.Boolean boolean java.lang.Number number java.lang.String string Object exported by <x:parse> node-set Please note that JSTL, as of version 1.2,...
Created by Fang on August 17, 2010 21:08:13    Last update: August 17, 2010 21:08:13
JSTL string manipulation functions String manipulation functions are simple and self-evident. You just need to know that they exist. Test it Make these additions to the expanded test application : Create a new Java class StringManipulation : package jstl.demo.handler; import java.... Create a new JSP ( stringmanipulation.jsp ) under webapp : <%@ taglib uri=" Compile and package the WAR with: mvn package Deploy the WAR to a servlet container of your choice (for example, Tomcat or JBoss). Test the page with this URL (Tomcat/JBoss running on port 8080): http://localhost:8080/jstl-demo/demo/StringManipulation You may adjust the URL if your servlet container runs on a different port or the web app is bound to a different context root.
Previous  1 2 Next