XML / CATATAN</>↗XML11 Jan 2012
This example show you how to get the attributes of elements in an XML file using the SAX parser. package org.kodejava.xml; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.InputStream; public class SAXElementAttribute { public static void main(String[] args) { SAXElementAttribute demo = new SAXElementAttribute(); demo.run(); }...
XML / CATATAN</>↗XML10 Jan 2012
The ErrorHandler interface implemented by the org.xml.sax.helpers.DefaultHandler class provides some methods for error handling mechanism in SAX parsing. The methods are warning(), error(), and fatalError(). package org.kodejava.xml; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.InputStream; public class SAXErrorHand...
XML / CATATAN</>↗XML10 Jan 2012
This example will show you how to parse an XML file using SAX parser and build an object graph from the parsed XML. We will read the records.xml file that contains some recording information and create the Record object from it. The DefaultHandler in this example created as an anonymous class. We override some method […]
APACHE COMMONS / CATATAN</>↗Apache Commons09 Jan 2012
The code snippet below uses the FileUtils.toFile(URL) method that can be found in the Apache Commons IO library to convert a URL into a File. The url protocol should be file or else null will be returned. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Objects; public class URLToFileObject { public static […]
XML / CATATAN</>↗XML09 Jan 2012
This example show you how to read / parse an xml file using the SAX (Simple API for XML) parser. In the main class (SAXDemo) we create the instance of SAXParserFactory and the SAXParser. The SAXParser.parse() method will parse the given InputStream and handle the xml document using the SAXHandler class that we created. package […]
ITEXT PDF / CATATAN</>↗iText PDF28 Des 2011
The following example you’ll see how to create a superscript and subscript text in the pdf document using iText. We can use the Chunk‘s class method called setTextRise(). A positive value will create a superscript text while a negative value will create a subscript text. package org.kodejava.itextpdf; import com.itextpdf.text.*; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; […]