Recent Notes
Displaying keyword search results 91 - 100
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 July 21, 2010 22:14:53
Last update: July 21, 2010 22:14:53
This is a Java program to test XPATH expressions with namespace option. It's been tested with JDK1.6.
import java.io.FileInputStream;
import java.uti...
Following Getting Started with XML Security , these are the test files:
Without namespace (patient.xml).
<PatientRecord>
<Name>John Doe</Nam...
With namespace (patient_ns.xml).
<med:PatientRecord xmlns:med="http://www.medic...
Test results:
C:\>java XPathExample patient.xml /PatientRecord/V...
Created by Fang on April 04, 2010 04:12:14
Last update: July 21, 2010 14:52:58
The tags <c:if> The <c:if> tag may be used with or without body content:
<!-- Without body content, used to export vari... In my opinion, the version without body content is pretty much useless (the <c:set> tag is a lot more meaningful for this purpose). If body content exists, it is inserted into the page if the testCondition is true . Optional attributes var and scope may be specified. If var is specified, a variable whose name is the value of var is exported to the associated scope ( pageScope if no scope is specified). The type of the exported variable is Boolean and its value is the value of the testCondition . <c:choose>, <c:when>, <c:otherwise> These tags imitate the Java control structure if...else...
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 James on July 06, 2010 19:35:00
Last update: July 06, 2010 19:35:00
Java has built-in functions to get the basename and dirname for a given file path, but the function names are not so self-apparent.
import java.io.File;
public class JavaFileD...
Results:
C:\tmp>java JavaFileDirNameBaseName
Dirname: .....
Created by Dr. Xi on June 20, 2010 14:35:17
Last update: June 20, 2010 14:35:17
This XML signature validator comes from the Apache XML Security project. It validates the signature according to the core validation processing rules .
It does not verify that the key used to generate the signature is a trusted key. You can override the KeySelector class to make sure that the signing key is from a trusted store.
import javax.xml.crypto.*;
import javax.xml.cry...
Created by Dr. Xi on June 03, 2010 22:43:43
Last update: June 20, 2010 14:13:05
Using the Sun BASE64Encoder :
import java.io.*;
import sun.misc.BASE64Encoder...
However, the Sun encoder is awfully slow. The Apache encoder is a lot faster. Here's the code with Apache encoder:
import java.io.*;
import org.apache.commons.cod...
Performance comparisons between Apache and Sun:
C:\>bash
bash-3.2$ time java EncodeFileWithBase...
Created by Dr. Xi on June 18, 2010 15:43:27
Last update: June 20, 2010 13:59:57
I got this error while starting jboss-5.1.0.GA on Solaris (there were no problems on Windows XP or Linux).
18:20:57,405 ERROR [AbstractKernelController] Er...
It turned out that this was a bug in jboss-5.1.0.GA and was fixed in jboss 6.
The fix was to add class="java.io.File" to conf/bootstrap/profile.xml :
<bean name="AttachmentStore"
class="org.jb...
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 Dr. Xi on June 11, 2010 23:11:59
Last update: June 11, 2010 23:14:02
Given a simple XML file like this:
<?xml version="1.0"?> <root id="1"> ... Calling Document.getElementById returns null (surprisingly!): import java.io.*; import org.w3c.dom.*; impo... In fact the JavaDoc says something along the lines that getElementById returns the Element that has an ID attribute with the given value. An attribute with the name "ID" or "id" is not of type ID unless it is so defined. How is an attribute defined as an ID attribute ? With a DTD or schema. If you are not validating the XML, then the API is useless. So, what to do if you want to find an element for which the attribute named "id" has a given value? Several options were offered in GetElementById Pitfalls . One of them is to...