Recent Notes

Displaying keyword search results 1 - 10
Created by Dr. Xi on April 29, 2013 09:00:48    Last update: April 29, 2013 09:00:48
In the case proposed by Diony , signing multiple elements by id, simply change the newSignedInfo to: // Create the SignedInfo final List transforms0... I must admit that I don't understand transformations, so take my example code with a grain of salt. Also, signing a doc fragment by PATH does not work, simply because there's no way to identify the fragment with a URI without referring to it by id. Reference ode from org.jcp.xml.dsig.internal.dom.DOMURIDereferencer : // Check if same-document URI and register...
Created by Fang on March 06, 2012 12:24:53    Last update: March 06, 2012 12:24:53
Validation groups can be used to control which rules validation rules to run. A validation group can be identified by any Java interface (not class!). Multiple validation groups may be specified when validating. In this example, I added a validation group named MyValidationGroup ( src/main/java/com/example/MyValidationGroup.java in Maven project): package com.example; public interface MyVal... and added a @Size rule for a person's name, because my database can only store up to 15 characters for a person's name: package com.example; import javax.validatio... Now validate Person with a JUnit test ( src/test/java/com/example/TestPersonWithGroup.java in Maven project): package com.example; import java.util.Set; ... Test with " mvn clean test ". The rules where groups is not specified, which belong to the javax.validation.groups.Default group, are not executed with these tests.
Created by Fang on January 04, 2012 09:54:05    Last update: January 04, 2012 09:54:05
There are two ways to validate a form with JSF: jsf validation on the page with <f:validate...> tags (for example: <f:validateLength> , <f:validateRegex> , etc.), or JSR303 bean validation. This note is about how to customize messages for JSR303 bean validation. The validation message is specified in the message attribute for each validation annotation type. The mesage attribute is not a literal string, but a string that is interpolated in various ways. For example, the default validation message for AssertFalse is {javax.validation.constraints.AssertFalse.message} , which is replaced with the corresponding string in ValidationMessages.properties (or ValidationMessages_tr.properties , ValidationMessages_es.properties , depending on the locale). This is the contents of ValidationMessages.properties in the hibernate validator reference implementation: javax.validation.constraints.AssertFalse.message =... To customize the messages, just provide the new value in...
Created by magnum on September 11, 2011 19:46:09    Last update: September 11, 2011 19:46:09
A pair of C functions convert between an Internet address and a string (ASCII): #include <arpa/inet.h> /* * Returns a poin... However , these functions do not support IPv6. The new pair is: #include <arpa/inet.h> /* Convert a Internet ad... Examples: #include <sys/socket.h> #include <netinet/in.h>...
Created by Dr. Xi on June 22, 2011 15:15:15    Last update: June 22, 2011 15:15:15
There's no such thing as an immutable byte array in Java. What we are trying to achieve here is to protect the byte array inside the object from which it is being returned. We want to caller to have the contents of the byte array, but not be able to change the contents inside the object. The trick is to return a copy instead of the internal reference: public class ReturnByteArray { public stati...
Created by alfa on June 02, 2011 15:49:26    Last update: June 02, 2011 15:51:08
Facts: Dynamic proxy classes are generated by the Java runtime, from a list of interfaces given by the user. The generated proxy class implements all interfaces given by the user. The dynamic proxy class is not synthetic . The dynamic proxy class is useless without a user supplied InvocationHandler class, since there's only one constructor for the proxy class and it takes a InvocationHandler as parameter. Example code: import java.lang.reflect.Constructor; import ja... Output: Class: $Proxy0 isSynthetic: false Constructo...
Created by alfa on June 02, 2011 15:26:37    Last update: June 02, 2011 15:26:37
While doing some Java reflection code, I noticed the method Class.isSynthetic() , which the JavaDoc says returns " true if and only if this class is a synthetic class as defined by the Java Language Specification". However, there's no definition of "synthetic class" in the JLS ! The only thing that I can find that remotely resembles a definition is in the JVM spec , where it defines the synthetic attribute : "The Synthetic attribute is a fixed-length attribute in the attributes table of ClassFile (§4.1), field_info (§4.5), and method_info (§4.6) structures. A class member that does not appear in the source code must be marked using a Synthetic attribute." By this definition, a default constructor, which does not appear in the source code, should...
Created by woolf on February 10, 2011 13:16:34    Last update: February 10, 2011 13:16:49
%PATH:str1=str2% would expand the PATH environment variable, substituting each occurrence of " str1 " in the expanded result with " str2 ". " str2 " can be the empty string to effectively delete all occurrences of " str1 " from the expanded output. " str1 " can begin with an asterisk, in which case it will match everything from the beginning of the expanded output to the first occurrence of the remaining portion of str1. %PATH:~10,5% would expand the PATH environment variable, and then use only the 5 characters that begin at the 11th (offset 10) character of the expanded result. If the length is not specified, then it defaults to the remainder of the variable value. If either number (offset or length) is negative,...
Created by Dr. Xi on October 26, 2010 16:07:40    Last update: October 26, 2010 16:07:40
This is a more generic version, which can be expanded to accommodate additional file signatures. import java.io.*; import java.util.*; pu...
Created by Dr. Xi on August 03, 2010 16:23:55    Last update: October 22, 2010 15:35:20
According to Java documentation: The Java compiler and other Java tools can only process files which contain Latin-1 and/or Unicode-encoded (\udddd notation) characters. This utility converts a utf-8 encoded file to ascii with unicode escape strings for non-ascii characters. import java.io.*; /** * Reads file in U... It is equivalent to: native2ascii -encoding utf-8 using the standard Java native2ascii utility.
Previous  1 2 Next