TechnoBuzz

A Techno Blog, mainly about Java

Java Reporting

http://jasperforge.org/projects/

http://jasperforge.org/projects/jasperreports – The world’s most powerful and widely used embeddable Java reporting library for report designers and developers. [getting started]

prompt> cd \program files
prompt> cd jasperreports-<ver>\demo\samples
prompt> dir
prompt> cd barbecue
prompt> ant –p
prompt> ant  javac
– Compiles the java source files of the test application
prompt> ant compile
– Compiles the XML report design and produces the .jasper file
prompt> ant fill
– Fills the compiled report design with data and produces the .jrprint file.
prompt> ant viewDesign

http://jasperforge.org/projects/ireport – iReport gives administrators and report designers total control over the contents as well as the look and feel of every report

Jasper reports includes some nice samples and tutorials:

http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/tutorial.html

http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/samples.html
Studio

http://www.jaspersoft.com/sites/default/files/jw-presentations/JW11_JaspersoftStudioinAction_GiulioToffoli.pdf

Advertisements

August 28, 2011 Posted by | J2EE, Open Source, SW Tools, XML | Leave a comment

Social Media is Killing Feed Aggregation

The world of web content is changing before us. Just this week, the N.Y Times has gone on the record and indicated :

“We Will Stop Printing The New York Times Sometime In The Future”.

The way we get news has been for a long time been changing.  Some companies have had for while  a problem on how we use their content.

With the way the content is shared and presented, there is bound to be people who wan’t a piece of the $$$ pie.  Here is a good post on some of the types of news aggregation, and some of the  litigation/settlements in the misunderstandings on who has a right to publish the data. Or even, who owns the data. On the outs is the  RSS feed reader.

September 12, 2010 Posted by | Current Affairs, Web/Tech, XML | Leave a comment

Castor similar to jaxB

http://www.castor.org/ and get full download where i placed it here

C:/java/castor-1.0.5

C:\java\castor-1.0.5\src>ant jar

put castor jars from C:\java\castor-1.0.5\dist and place in C:/java/castor-1.0.5/lib

C:/java/castor-1.0.5/src/examples/SourceGenerator

test.bat

http://www.castor.org/javadoc/org/exolab/castor/builder/SourceGeneratorMain.html

%JAVA% -cp %CP% org.exolab.castor.builder.SourceGeneratorMain -i invoice.xsd -f -binding-file bindingInvoice.xml

JavaDoc

Marshalling – is the process of traversing a content tree and
writing an XML document that reflects the tree’s content.
org.exolab.castor.xml.Marshaller

Unmarshalling –  is the process of reading an XML document and constructing a content tree of Java content objects.org.exolab.castor.xml.Unmarshaller

example

It has been a while since I got a chance to look at Struts 2 . At the time I was interested in how to get jars going with JDK 1.4.2.

December 25, 2006 Posted by | XML | Leave a comment

JAXB Validator

Good example at Bob’s place

Info from JAXB doc

A great intro:

I am interested in validator for unmarshalling, I did this:
//class MyHandler – implements class ValidationEventHandler
//contains method handleEvent
MyHandler veh = new MyHandler();
unmarshaller.setEventHandler(veh);

jaxb interest list

last one

September 22, 2004 Posted by | XML | Leave a comment

JAXME2

JAXB is now available as part of the Java Web Services developer pack from Sun. While JAXB was in Beta, you could download Sun’s implemementation of JAXB seperately . It appears that is not the case anymore. Here is my page on sun. I have posted some messages to the various Sun forums on the problem I am having using JAXB. Here is an article on user feedback with JAXB. I may look into other JAXB implementations. Specifically, Apache’s open source JAXME2. Another one is XMLBeans.

I chose JAXME.

JAXME Manual
Featured article on JAXME

How to download: go to jaxme download page and scroll to bottom for distributions (src or bin).

I grabbed the two example files (build.xml and xsd file) from the article and placed them inside the new jaxme directory that was just created when the binaries tar file was extracted.


Edit the build file to set where the jar files are located (lib).
Invoke ‘ant generate’ and the neccesary files get generated in the generated folder.
As well as generating the source code, its creates two files (configuartion.xml and jaxb.properties).



XML file (schema instance):

< ?xml version=”1.0″ encoding=”UTF-8″? >
<stu:Student xmlns:stu=”http://dw.ibm.com/jaxme/student&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; >
<stu:firstName>stu:firstName</stu:firstName >
<stu:lastName>stu:lastName</stu:lastName >
<stu:address>
<stu:name>stu:name</stu:name >
<stu:street>stu:street</stu:street >
<stu:city>stu:city</stu:city >
<stu:state>stu:state</stu:state >
<stu:zip>1</stu:zip>
</stu:address >

Read XML:

package com.ibm.dw.jaxme.student;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.StringWriter;
import java.net.MalformedURLException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.xml.sax.InputSource;

public class Main {

public static Student getAddress(InputSource pSource)
throws JAXBException {
JAXBContext context =
JAXBContext.newInstance(“com.ibm.dw.jaxme.student”);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (Student) unmarshaller.unmarshal(pSource);
}
public static void main(String[] args) throws Exception {
File f = new File(“src/student.xml”);
InputSource isource = new InputSource(new FileInputStream(f));
isource.setSystemId(f.toURL().toString());
Student student = getAddress(isource);
System.out.println(student.getFirstName());
}
}

August 4, 2004 Posted by | XML | Leave a comment

Using JAXB

Marshalling – is the process of traversing a content tree and
writing an XML document that reflects the tree’s content.
Unmarshalling – is the process of reading an XML document and constructing a content tree of Java content objects.

The JAXB binding framework (javax.xml.bind package) is a runtime API that
provides interfaces for unmarshalling, marshalling, and validating XML content
in a Java application.

JAXB is now contained within the Web Services Developer Pack [download] [Tutorial]

C:\jwsdp-1.4\docs\GettingStarted.html

C:\jwsdp-1.4\jaxb

JWSDP_HOME C:\jwsdp-1.4\

Set environment variables for JWSDP_HOME :

C:\>set JWSDP_HOME=C:\jwsdp-1.4\
C:\>echo %JWSDP_HOME%
C:\jwsdp-1.4\
cd C:\jwsdp-1.4\jaxb\samples\ unmarshal-read
This directory contains files po.xsd, po.xml, build.xml, and src/Main.java
po.xsd is the name of the source XML schema
po.xml is the name of the source XML instance file

Use the xjc.bat command to generate JAXB Java classes from the source XML
schema:

C:\jwsdp-1.4\jaxb\samples\unmarshal-read>%JWSDP_HOME%\jaxb\bin\xjc.bat po.xsd -p
primer.po

The -p primer.po switch tells the JAXB compiler to put the generated classes in a Java package named primer.po.

Here is the output:
parsing a schema…
compiling a schema…
primer\po\impl\CommentImpl.java
primer\po\impl\ItemsImpl.java
primer\po\impl\JAXBVersion.java
primer\po\impl\PurchaseOrderImpl.java
primer\po\impl\PurchaseOrderTypeImpl.java
primer\po\impl\USAddressImpl.java
primer\po\impl\runtime\ValidatorImpl.java
primer\po\impl\runtime\SAXUnmarshallerHandlerImpl.java
primer\po\impl\runtime\PrefixCallback.java
primer\po\impl\runtime\GrammarInfoImpl.java
primer\po\impl\runtime\ErrorHandlerAdaptor.java
primer\po\impl\runtime\InterningUnmarshallerHandler.java
primer\po\impl\runtime\XMLSerializable.java
primer\po\impl\runtime\UnmarshallerImpl.java
primer\po\impl\runtime\SAXMarshaller.java
primer\po\impl\runtime\UnmarshallingContext.java
primer\po\impl\runtime\UnmarshallingEventHandlerAdaptor.java
primer\po\impl\runtime\XMLSerializer.java
primer\po\impl\runtime\Util.java
primer\po\impl\runtime\UnmarshallableObject.java
primer\po\impl\runtime\ValidatableObject.java
primer\po\impl\runtime\MarshallerImpl.java
primer\po\impl\runtime\GrammarInfo.java
primer\po\impl\runtime\UnmarshallingEventHandler.java
primer\po\impl\runtime\ValidationContext.java
primer\po\impl\runtime\SAXUnmarshallerHandler.java
primer\po\impl\runtime\AbstractUnmarshallingEventHandlerImpl.java
primer\po\impl\runtime\DefaultJAXBContextImpl.java
primer\po\impl\runtime\Discarder.java
primer\po\impl\runtime\MSVValidator.java
primer\po\impl\runtime\NamespaceContextImpl.java
primer\po\impl\runtime\NamespaceContext2.java
primer\po\impl\runtime\ContentHandlerAdaptor.java
primer\po\impl\runtime\GrammarInfoFacade.java
primer\po\impl\runtime\ValidatingUnmarshaller.java
primer\po\Comment.java
primer\po\Items.java
primer\po\ObjectFactory.java
primer\po\PurchaseOrder.java
primer\po\PurchaseOrderType.java
primer\po\USAddress.java
primer\po\jaxb.properties
primer\po\bgm.ser
C:\jwsdp-1.4\jaxb\samples\unmarshal-read>

C:\jwsdp-1.4\jaxb\samples\unmarshal-read>%JAVA_HOME%\bin\javadoc -package primer.po -sourcepath . -d docs\api -windowtitle “Generated Interfaces for po.xsd”

Update CLASSPATH:
set CLASSPATH=%CLASSPATH%;C:\jwsdp-1.4\jaxb\lib\jaxb-api.jar;C:\jwsdp-1.4\jaxb\lib\jaxb-impl.jar;C:\jwsdp-1.4\jaxb\lib\jaxb-libs.jar;C:\jwsdp-1.4\jaxb\lib\jaxb-xj
c.jar;C:\jwsdp-1.4\jwsdp-shared\lib\activation.jar;C:\jwsdp-1.4\jwsdp-shared\lib\commons-beanutils.jar;C:\jwsdp-1.4\jwsdp-shared\lib\commons-collections.jar;C:\
jwsdp-1.4\jwsdp-shared\lib\commons-digester.jar;C:\jwsdp-1.4\jwsdp-shared\lib\commons-logging.jar;C:\jwsdp-1.4\jwsdp-shared\lib\jaas.jar;C:\jwsdp-1.4\jwsdp-shar
ed\lib\jax-qname.jar;C:\jwsdp-1.4\jwsdp-shared\lib\jta-spec1_0_1.jar;C:\jwsdp-1.4\jwsdp-shared\lib\namespace.jar;C:\jwsdp-1.4\jwsdp-shared\lib\mail.jar;C:\jwsdp
-1.4\jwsdp-shared\lib\relaxngDatatype.jar;C:\jwsdp-1.4\jwsdp-shared\lib\xsdlib.jar;C:\jwsdp-1.4\jaxp\lib\jaxp-api.jar;C:\jwsdp-1.4\jaxp\lib\endorsed\dom.jar;C:\
jwsdp-1.4\jaxp\lib\endorsed\sax.jar;C:\jwsdp-1.4\jaxp\lib\endorsed\xalan.jar;C:\jwsdp-1.4\jaxp\lib\endorsed\xercesImpl.jar

Compile the Main.java

C:\jwsdp-1.4\jaxb\samples\unmarshal-read>%JAVA_HOME%\bin\javac src/Main.java primer\po\*.java primer\po\impl\*.java

I copied the src Main.java and Main.class to the unmarshal-read directory

C:\jwsdp-1.4\jaxb\samples\unmarshal-read>java Main
Ship the following items to:
Alice Smith
123 Maple Street
Cambridge, MA 12345
US

5 copies of “Nosferatu – Special Edition (1929)”
3 copies of “The Mummy (1959)”
3 copies of “Godzilla and Mothra: Battle for Earth/Godzilla vs. King Ghi
dora”

Note that the unmarshal-read comes with a build.xml for use with ant. It performs the two distinct phases for JAXB:

1. Generating and compiling JAXB Java classes from an XML source schema
2. Unmarshalling, validating, processing, and marshalling XML content

Now if all you just want to do is generate the classes for use in an IDE, after ANT does its thing just
grab the folder in the gen-src directory and copy it within the JAVA Source section within a project. You must have the jars listed above in your build path for it to compile. When executing there are two gotchas to be carefull of. You have to determine the base path within the IDE where it looks for input files. I had a problem where it could not find a file. It was either the jaxb property file or the input xml file. Also, the namespace.jar file would not work when executing the Main. It gave me a security error and had to remove the .sfa file from the namespace.jar and rebuild the jar and it worked fine.

July 29, 2004 Posted by | XML | 1 Comment

XML and Java

An XSD refresher:
XMLSchema

Definition (XSD)
– industry standard, platform independent XML Schema Language.

Namespaces

Default Schema Namespace: states that all the elements used within the schema belong to that particular namespace
<schema xmlns=”http://www.w3.org/2001/XMLSchema”&gt;

However, usually in form with a a default prefix:
<xsd:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;

More than one namespace may be declared. One may be declared as the default namespace, another as a namespace that will be associated with certain elements :

xmlns:prefix=URI

The targetNamespace attribute defines the namespace for the document instance (the XML document.)

By default only globally declared (top-Level) elements are associated with the targetNamespace attribute. These are elements that are directly descended from the RootElement.

If the targetNamespace attribute is added to the schema element, then the prefix DOES NEED to be added to each and every component of the schema.
To add locally declared attributes to the targetNamespace, add the attributeFormDefault attribute to the schema element and use the value of “qualified.”

Stating form=”unqualified” within an schema’s element declaration will unqualify that element from the namespace.

SAX

SAX Project (old URL)
SAX is the Simple API for
XML. SAX has recently switched over to the SourceForge project infrastructure.
It is a standard for XML parsers. It reads the XML document and sends an event
for each element it encounters. Provides “sequential access” into the xml
document. It is fast, requires little memory. Sax works by callbacks. You call
the parser, its calls the methods that you supply.
– SAXParserFactory factory
= SAXParserFactory factory.newInstance();
– SAXParser saxParser =
factory.NewSAXParser();
– XMLReader parser = saxParser.getXMLReader();

[slides]





DOM

DOM

standard for XML parsers. It reads the entire XML document into memory and

stores it into a tree data structure. Provides “random access” into the xml

document. It is slow, requires huge amounts of memory.

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();
– Document document
builder.parse(file.xml);
[slides]



XERCES
(named after the Xerces Blue butterfly)

Xerces2 – next generation
of high performance, fully compliant XML parsers in the Apache Xerces family.



[slides] [devshed]






JAXB (Java API for XML Binding)

Generate XML Mapping Code
with JAXB
: “It rapidly generates XML mapping code for you, saving time and
effort, and reducing both costs and risks.



XML
ADVISOR: JAXB: A Foundation for Web Services
:Learn all about the Java Architecture for XML Data Binding and implement
lightweight XML-processing applications using the reference implementation



[slides

July 27, 2004 Posted by | XML | Leave a comment