RSS

Ajax Framework DWR

0 comments

Posted in ,

PdfStamper and ServletOutputStream

Display watermark in PDF documents from a byte[]

byte[] docB = null;
docB = doc.getContent();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

PdfReader reader = new PdfReader(docB);
int n = reader.getNumberOfPages();
PdfStamper stamp = new PdfStamper(reader, baos);
int i = 0;
PdfContentByte under;
Image img = Image.getInstance("iconCsn.jpg");
img.setAbsolutePosition(200, 400);
while (i < n) {
i++;
under = stamp.getUnderContent(i);
under.addImage(img);
}
stamp.close();

getResponse().setHeader("Expires", "0");
getResponse().setHeader("Cache-Control", "must-revalidate, post-check=0,pre-check=0");
getResponse().setHeader("Pragma", "public");
getResponse().setContentType("application/pdf");
getResponse().setContentLength(baos.size());
ServletOutputStream out = getResponse().getOutputStream();
baos.writeTo(out);
out.flush();

This show the pdf with waterMark in the client.

OpenSocial From Google

Semantic Web

The Semantic Web is a web of data. There is lots of data we all use every day, and its not part of the web. I can see my bank statements on the web, and my photographs, and I can see my appointments in a calendar. But can I see my photos in a calendar to see what I was doing when I took them? Can I see bank statement lines in a calendar?

Why not? Because we don't have a web of data. Because data is controlled by applications, and each application keeps it to itself.

The Semantic Web is about two things. It is about common formats for integration and combination of data drawn from diverse sources, where on the original Web mainly concentrated on the interchange of documents. It is also about language for recording how the data relates to real world objects. That allows a person, or a machine, to start off in one database, and then move through an unending set of databases which are connected not by wires but by being about the same thing.


From: W3C

XFN

XFN puts a human face on linking. As more people have come online and begun to form social networks, services such as Technorati and Feedster have arisen in an attempt to show how the various nodes are connected. Such services are useful for discovering the mechanical connections between nodes, but they do not uncover the human relationships between the people responsible for the nodes.

XFN outlines the relationships between individuals by defining a small set of values that describe personal relationships. In HTML and XHTML documents, these are given as values for the rel attribute on a hyperlink. XFN allows authors to indicate which of the weblogs they read belong to friends, whom they've physically met, and other personal relationships. Using XFN values, which can be listed in any order, people can humanize their blogrolls and links pages, both of which have become a common feature of weblogs.

In sufficiently modern browsers, authors using XFN can easily style all links of a particular type; thus, friends could be boldfaced, co-workers italicized, and so on. It is also the hope of the authors that this practice becomes widespread enough to allow the creation of a service that charts personal (as opposed to purely mechanical) links between weblogs and the people responsible for them.


From: XFN

FOAF and the Semantic Web

FOAF, like the Web itself, is a linked information system. It is built using decentralised Semantic Web technology, and has been designed to allow for integration of data across a variety of applications, Web sites and services, and software systems. To achieve this, FOAF takes a liberal approach to data exchange. It does not require you to say anything at all about yourself or others, nor does it place any limits on the things you can say or the variety of Semantic Web vocabularies you may use in doing so. This current specification provides a basic "dictionary" of terms for talking about people and the things they make and do.

FOAF was designed to be used alongside other such dictionaries ("schemas" or "ontologies"), and to beusable with the wide variety of generic tools and services that have been created for the Semantic Web. For example, the W3C work on SPARQL provides us with a rich query language for consulting databases of FOAF data, while the SKOS initiative explores in more detail than FOAF the problem of describing topics, categories, "folksonomies" and subject hierarchies. Meanwhile, other W3C groups are working on improved mechanisms for encoding all kinds of RDF data (including but not limited to FOAF) within Web pages: see the work of the GRDDL and RDFa efforts for more detail. The Semantic Web provides us with an architecture for collaboration, allowing complex technical challenges to be shared by a loosely-coordinated community of developers.

The FOAF project is based around the use of machine readable Web homepages for people, groups, companies and other kinds of thing. To achieve this we use the "FOAF vocabulary" to provide a collection of basic terms that can be used in these Web pages. At the heart of the FOAF project is a set of definitions designed to serve as a dictionary of terms that can be used to express claims about the world. The initial focus of FOAF has been on the description of people, since people are the things that link together most of the other kinds of things we describe in the Web: they make documents, attend meetings, are depicted in photos, and so on.


From: FoaFSpecification

FreeMarker vs. Velocity

Velocity is a simpler, more lightweight tool. Thus, it does not address many tasks that FreeMarker does, and its template language is less powerful in general, but it is simpler.

However, we think that for most applications, working with FreeMarker is simpler than working with Velocity, since with Velocity you have to find custom tools and find various other workarounds to solve typical template authoring tasks again and again, and you end up losing much more time in the long run than you have won on the quick starting. Also, the result of solving something with tools and workarounds is most probably not as terse or efficient as the solution in the engine core. Furthermore, according to Velocity list archives, the workaround often means extensive direct usage of Java object methods in the Velocity template (this violates the idea of simple, non-programmer HTML-designer friendly templates) or the movement of presentation tasks into the controller code (this violates the MVC idea). And, after all, if you use FreeMarker only for what Velocity can do out-of-the-box, it is as simple as Velocity.

An advantage of Velocity over FreeMarker is that Velocity has wider third party support and a much larger user community. However, you might need less support for FreeMarker because instead of creating and discussing workarounds you might often be able to simply use FreeMarker standard features. And in case you have difficulties there are of course active web forums and mailing lists. Moreover, since with FreeMarker you can use Model-2 frameworks as Struts and any JSP tag libraries out-of-the-box, perhaps third-party support is not a that big problem if you are in the servlet segment. Also, more and more servlet frameworks adapt FreeMarker as their view layer, next to JSP and Velocity.

There are other parameters that should be considered when you compare tools, like code quality and documentation quality. But of course, we as the authors of the product should not say anything about this. It is up to the users to judge.

Feature comparison sheet

Here's a quick, non-comprehensive listing of things you can do with FreeMarker out of the box, and which you can not do with Velocity (or, you can but only with nontrivial workarounds). This list is originally based on a comparison with Velocity 1.2. Contact us for change suggestions.

Number and date support

  • You can perform arithmetic calculations and comparisons on arbitrary number types, including the arbitrary-precision types, not just integers.
  • You can compare and display (format) date/time values.

Internationalization:

  • You can format numbers locale-sensitively, based on a variety of built-in and custom number-formatting patterns.
  • You can format dates locale- and timezone-sensitively, based on variety of built-in and custom date-formatting patterns.
  • Identifiers (variable names) can contain non-English letters like accented letters, Arabic letters, Chinese letters, etc.

Loop handling:

  • You can break out of loops.
  • You can access control variables of outer loops from bodies of inner loops.
  • You can test whether you are in the last iteration of the loop.

Array handling on the template language level:

  • You can access array elements, both primitive and non-primitive by index using the familiar [i] syntax.
  • You can query the length of an array.

Macros:

  • Macro invocations can pass parameters either by position or by name.
  • Macro parameters can have default values which are effective when the parameter is omitted on invocation.
  • Macro invocations can have a nested body (<@myMacro>body) that can be called by the macro for processing.
  • Macros are plain variables, so you can select the macro to execute based on an expression, or pass a macro to another macro as parameter.
  • Invoke a macro that is defined later in the template.
  • Local variables in macros, and recursive invocation of macros. In Velocity it is now possible with the currently (Feb. 2005) not officially documented #local function.

Name-spaces:

  • You can use multiple name-spaces for variables. This is invaluable when you build "macro libraries", because you can prevent name collisions with application specific variables or with variables of other macro libraries.

Java-independent string, list, and map manipulations with built-in functions/operators:

  • You can turn a string upper-, lower-, or title-case, turn upper-/lowercase only the first letter, convert (escape) the string to HTML, XML, or RTF, extract substrings, split strings, query string length, find/replace substring, ...etc.
  • Access elements of lists by index, extract sublists, concatenate lists, query size of a lists, sort lists.
  • Access map elements by variable key, check if the map is empty, obtain the key or value list.

Expose typos and other mistakes in template:

  • When you try to access an undefined variable, FreeMarker will not accept that silently. You can configure FreeMarker to stop template rendering with an error message, or skip the wrong part. In either case, FreeMarker will log the problem, so it does not remain hidden.
  • FreeMarker will throw an exception if you mistype a directive name, and will not print the statement silently to the output (unless you use the now deprecated non-strict syntax).

Advanced rendering control:

  • You can enclose a block of template in a set of tags that will cause it to apply HTML escaping or XML escaping (or any other transformation you can express as a FreeMarker expression for that matter) on all interpolations (${foo}) in the block.
  • FreeMarker has transforms, which are blocks of template that when rendered, go through a transforming filter. Built-in transforms include whitespace compressor, HTML and XML escaper. Best of all, you can implement your own transformers as well (i.e. if you generate Java source code, you can write a Java code pretty-printer transform and insert it into the template). Naturally, transforms can be nested.
  • You can explicitly flush the output writer with a built-in flush-directive.
  • You can stop the rendering with a built-in stop-directive.

Literals:

  • Beside the usual string, number, and boolean literals you can define list and map literals as well inside templates.
  • There is a support for all Java string literal escapes: \b, \t, \n, \f, \r, \", \', \\, also we support \xXXXX to specify characters with their UNICODE code.

Advanced white-space removal:

  • FreeMarker consistently removes white-space (spaces, tabs and line-break) from lines that contain non-outputting FreeMarker tags only, thus eliminates most annoying, obviously superfluous white-space.
  • There are directives to explicitly trim lines from needless white-space, just for the extreme cases, when white-space is a real problem.

Integration with other technologies:

  • You can use JSP custom tag libraries in templates.
  • You can work directly on Python objects.

Powerful XML transformation capabilities:

  • As of version 2.3, FreeMarker has powerful new XML transformation capabilities that make it a viable replacement for XSLT. Though there have been some attempts to make Velocity more capable in this domain (i.e. DVSL) Velocity is not really competitive in this regard. In our view, it never will be unless certain improvements to the core engine are made, such as support for macro libraries mapped to namespaces, and local variables in macros.
  • See here for a more detailed comparison of FreeMarker and XSLT.

Advanced template metaprogramming:

  • You can capture the output of an arbitrary part of the template into a context variable.
  • You can interpret arbitrary context variable as if it were a template definition.
  • You can imagine what can you do when you combine the two...
From: FreeMarker