Recent Notes
Displaying keyword search results 1 - 11
Created by Fang on November 12, 2011 21:03:03
Last update: November 12, 2011 21:03:03
Experts may disagree but I found it absolutely stunning that JSF EL does not provide an operator for string concatenation. The Java "+" operator is there for the take. Java, which is a strongly typed compiled language, overloads the "+" operator in such a way that any object can be concatenated with a string. But JSF EL, which definitely isn't as strongly typed as Java, restricts the "+" operator to numerical values only! Of course, experts may argue that the "+" operator overloading is a huge design flaw of the Java language. But even so, JSF EL is not the right place to fix it! In some cases, a concatenation operator isn't needed, for example:
<ui:repeat var="tab" value="#{tabs}"> <img ... But in case the concatenated...
Created by Fang on November 10, 2011 09:26:12
Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines!
<?xml version="1.0" encoding="UTF-8"?>
<xsd:sch...
Created by James on October 25, 2011 19:44:30
Last update: October 25, 2011 19:45:40
jQuery automatically maps HTML5 custom data attributes to data storage associated with the data() method. Here's an example:
<html>
<head>
<script type="text/javascript"...
Created by freyo on July 27, 2011 13:49:26
Last update: July 27, 2011 13:52:03
Some ways to pass data from one activity to another:
Add data to the Intent :
The sending side:
// create Intent
Intent intent = new Intent();
...
The receiving side:
Bundle bundle = getIntent().getExtras();
String...
Use SharedPreferences (data is persisted in this case):
The sending side:
SharedPreferences prefs = getSharedPreferences("pr...
The receiving side:
SharedPreferences prefs = getSharedPreferences("pr...
Created by jinx on May 03, 2011 09:42:12
Last update: May 03, 2011 09:42:12
The @ operator suppresses error messages.
A usual example is:
<?php
$v = @$a['non-existing-key'];
?>
which suppresses the "undefined index" PHP notice.
Another example is:
<?php
@include('non_existent_file');
?>
In this case, @ not only suppresses error messages for non-existing file, it also suppresses any error messages coming from the included file when it does exist.
Create file test.php :
<?php
@include('test.inc');
?>
Create test.inc :
<?php
<?php
garbage
?>
The "undefined constant" PHP notice message is suppressed by @ .
Created by Dr. Xi on April 05, 2011 08:04:37
Last update: April 05, 2011 08:11:37
There's no difference between a Java HTTP client and a Java HTTPS client. Ignore JavaWorld Java Tip 96 , it's way too old. The following code gets an HTTP page as well as an HTTPS page.
import java.io.*;
import java.net.*;
pub...
There's one catch . If you are using the code on a test server with a self-signed certificate, it fails. In that case, I would suggest that you download the certificate from the server and import it to your keystore as a trusted key. You may also need to add a subject alternative name to the certificate if the host name does not match the certificate.
You may also choose to use a custom TrustManager and HostnameVerifier to ignore the certificate verification errors.
Created by Dr. Xi on November 08, 2010 20:44:12
Last update: November 08, 2010 20:44:12
Key points:
Java String.matches() matches the entire string, not a partial string. Use java.util.regex.Matcher.find() to match a partial String.
For case insensitive match, use Pattern.compile with case insensitive flags:
// Case insensitive for ASCII
Pattern p = P...
Use (?i) or (?iu) (for unicode) to inline case-insensitive flag:
boolean b = "StringToMatchAgainst".matches("(?...
Test code:
import java.util.regex.*;
public class Test...
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 June 19, 2010 04:34:01
Last update: June 19, 2010 04:39:13
Java SE 6 contains built-in utilities to generate XML signatures. This is an example that generates XML signatures using a Java keystore. It has options to generate signature for the whole document, for an element with a specific ID, or for elements matched by an XPATH expression.
The XML document used to test is taken from Getting Started with XML Security :
<?xml version="1.0"?>
<PatientRecord>
...
This is the Java code:
import java.io.FileInputStream;
import java.io....
However, it looks like the XPATH transform is not working. The digest generated with XPATH filter is exactly the same as that without it (i.e., the whole document)!
Another reference:
Programming With the Java XML Digital Signature API
Created by James on May 07, 2010 04:13:14
Last update: May 07, 2010 04:35:03
It seems that the key to aligning a checkbox with its label lies in the line-height property of the label. This simple HTML snippet aligns well:
<!DOCTYPE HTML> <html> <head> <style typ... which is rendered like this: Change the font size of the label to 12px throws off the alignment: label.checkbox { font-size: 12px; di... In case 1, the height of the checkbox is 13px with 3px top and bottom margin, for a total of 19px , which is exactly the height of the label div. As can be seen from Firebug : Checkbox layout Label layout In case 2, the height of the label div shrinks to 15px , while the height of the checkbox remains the same: Checkbox layout Label layout And...
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 ( : )...