HOWTO: Change Title, Autor, Subject of a PDF
0 Kommentar(e). Veröffentlicht von Christian Ullenboom am Dienstag, September 30, 2008.package com.tutego.traida.util;
import java.io.FileOutputStream;
import java.util.HashMap;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class PdfUtils
{
public static void setMetaData( String sourceFilename, String targetFilename )
{
try
{
PdfReader pdfReader = new PdfReader( sourceFilename );
PdfStamper stamp = new PdfStamper( pdfReader, new FileOutputStream( targetFilename ) );
@SuppressWarnings("unchecked")
HashMap<String, String> info = pdfReader.getInfo();
info.put( "Title", "Rechnung für Beratung" );
info.put( "Author", "tutego" );
info.put( "Subject", "Rechnung" );
info.put( "Keywords", "Rechnung, tutego" );
info.put( "Creator", "http://www.tutego.com/" );
info.put( "Producer", "tutego Training Software 1.2" );
stamp.setMoreInfo( info );
stamp.close();
pdfReader.close();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
public static void main( String[] args )
{
setMetaData( "c:/a.pdf", "c:/new.pdf" );
}
}
With iText of course: http://www.lowagie.com/iText/
Labels: Open Source
Tja, Neal Gafter geht zu Microsoft
0 Kommentar(e). Veröffentlicht von Christian Ullenboom am Montag, September 29, 2008.Also mich wundert's nicht... Von Nealls Webseite http://gafter.com/~neal/:
I work for Microsoft on the dotNet platform languages. To balance my life, my hobby is designing and developing the future of the Java programming language. See, for example, my proposal to add closures to the Java Programming Language. I've also been discussing it on my blog.
Also von Sun zu Google und dann zu MS. (Eigentlich hatte MS immer damit zu kämpfen, dass die Mitarbeiter zu Google abwandern.)
Alpha-Version vom JAva COm Bridge (JACOB) Plug-In
0 Kommentar(e). Veröffentlicht von Christian Ullenboom am Montag, September 29, 2008.Das Eclipse-Plugin http://jacob-project.wiki.sourceforge.net/Jacob+Gen+Plugin erlaubt über einen Menüeintrag einfach das Erzeugen von Stub-Code für den Zugriff auf Windows-DLLs.
Der Generator geht einen interessanten Weg über Eclipse JET, wie es die Webseite erklärt:
The plug-in uses the old, JacobGen 0.7, c++ program (dll) which reads a Microsoft's proprietary TLB file and writes out what it finds on stdout. From the information gathered the plug-in produces an ecore model based of what is found inside the TLB. At this point the plug-in has created a model of what's inside the DLL file. I.E. what classes and enums exist. The plug-in uses Java Emitter Templates (JET) to generate java code based on the above ecore model. It also produces the java method bodies to automatically call JACOB methods with the correct parameters. This will create a strongly typed java proxy, via JACOB, into the windows DLL.
So to wrap up. The plug-in reads the TLB file (using the existing JacobGEN DLL), creates a model based on the TLB / DLL file, and then produces a java proxy. The JET generated classes are really a proxy into the DLL via JACOB. So the end result is a set of java classes hiding all JACOB internal knowledge.
Labels: Open Source
Und überall sitzt die OSGi Service Platform drunter...
2 Kommentar(e). Veröffentlicht von Christian Ullenboom am Montag, September 29, 2008.Unter http://www.earthtimes.org/articles/show/world-leading-enterprise-application-server-providers,541827.shtml und http://www.osgi.org/blog/2008/09/impressive-press-release.html führen die Autoren auf, wie beliebt mittlerweile OSGi als Basis für Java EE Container ist. Peter Kriens führt folgende Container auf:
- IBM Websphere. They started in 2006 and aggresively moved their code on OSGi. Obviously it helped that IBM has committed itself to OSGi since day -1.
- Oracle WebLogic. Formerly known as BEA weblogic. BEA was one of the first companies public touting the advantages of OSGi, clearing the road for others.
- Paremus Infiniflow. Paremus has pioneered the use of OSGi in highly distributed application servers allowing the system to scale to unprecendented heights.
- ProSyst ModuleFusion. ProSyst is the key provider of OSGi technology in the embedded worlds but originated from the development of a J2EE server. They are now back in this market with an offering based completely on OSGi.
- Redhat JBoss. JBoss already worked with a microkernel approach but recognized the advantages of a standard two years ago.
- SAP Netweaver. Well, they are not yet based on OSGi, but they clearly see their future based on the OSGi specifications and are becoming more and more active in the OSGi Alliance.
- SpringSource Application Platform. The company that simplified Enterprise development with their Spring Framework decided to create their own offering in the application server market completely based on the OSGi specifications.
- Sun Glassfish. And last, but definitely not least, Sun decided to use OSGi in the JEE reference implementation Glassfish. They clearly take OSGi extremely serious nowadays since they also hired Richard S. Hall. It is so good to see Sun back at the OSGi Alliance.
Interessant sind zwei Feststellungen:
- In der Regel geben die Container die OSGi-Implementierung nicht nach oben weiter, abstrahieren also von den Internas. Nur einige Produkte erlauben, auch selbst OSGi-Bundles anzumelden.
- Java EE und das SpringFramework sind beides Nutznießer der OSGi-Plattform. Man kann nun fragen, ob man sich überhaupt noch mit OSGi selbst beschäftigen muss, wenn etwa GlassFish oder http://www.springsource.com/products/suite/applicationplatform gute Abstraktionen bieten.
Labels: Java EE, Open Source, Spring
Das erste Android Programm
1 Kommentar(e). Veröffentlicht von Christian Ullenboom am Freitag, September 26, 2008.Im Moment gibt es ein großes Rumgezampel wegen der NDA von Apple bei der Entwicklung von iPhone-Applikationen und das, was es als Applikationen in den Apple App Store darf und was nicht
- http://www.heise.de/newsticker/Programmierer-kritisieren-Apples-App-Store--/meldung/115950
- http://www.alleyinsider.com/2008/9/apple-s-iphone-developer-nda-kills-book-for-iphone-developers
Google macht das mit Android besser, da hier alles frei sind wird und auch jede Applikation in den Store kommt. Und ein erstes Programm ist schnell aufgebaut:
- Gehe auf http://code.google.com/android/download_list.html.
- Lade unter Windows zum Beispiel android-sdk-windows-1.0_r1.zip. Entpacke das Zip, etwa nach C:\Program Files\Java\android-sdk-windows-1.0_r1.
- Installiere über den Eclipse Update-Manager das Plugin unter der URL http://dl-ssl.google.com/android/eclipse/. Das dauert! Starte Eclipse neu.
- Unter Window > Preferences > Android trage das Verzeichnis C:\Program Files\Java\android-sdk-windows-1.0_r1 ein.
- Gehe auf http://code.google.com/android/intro/hello-android.html und führe die Schritte für ein neues Android-Projekt durch.
- In die generierte onCreate()-Methode setzte rein:
- Starte die Applikation wie unter http://code.google.com/android/intro/hello-android.html#run beschrieben im Emulator. Das dauert leider sehr lange!
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
Labels: Android, Open Source
Thema der Woche: Continuous Integration mit Hudson
1 Kommentar(e). Veröffentlicht von Christian Ullenboom am Mittwoch, September 24, 2008.Lies zunächst http://martinfowler.com/articles/continuousIntegration.html von Martin Fowler über die Motivation von CI in der Softwareentwicklung.
In den letzten Monaten hat sich das Hudson zu einem Publikumslieblig entwickelt. Studiere die folgende Präsentation:
(Hudson stammt vom Kohsuke Kawaguchi, der eine ganze Reihe sehr interessanter Projekte bei Sun macht, etwas JAXB oder auch https://com4j.dev.java.net/. Wer ein Podcast von ihm und Husdon hören möchte: http://blogs.sun.com/glassfishpodcast/entry/episode_007_interview_with_kohsuke)
Blättere ein wenig auf den Seiten unter http://hudson.gotdns.com/wiki/display/HUDSON/Meet+Hudson. Falls ein Projekt mit CSV- oder SVN-Zugriff verfügbar ist teste Hudson.
Labels: Die wöchentliche Dosis Java
Java Tipp: Initialisierung einer Map
2 Kommentar(e). Veröffentlicht von Christian Ullenboom am Mittwoch, September 24, 2008.Der übliche Weg führt über ein put(), wobei man das unterschiedlich schreiben kann:
Map<String, String> map = new HashMap<String, String>();
map.put( "name", "chris" );
map.put( "email", "a@b.c" );
Oder auch mit einem Exemplarinitialisierer (das ist aber schmutzig in meinen Augen!):
Map<String, String> map = new HashMap<String, String>() {{
put( "name", "chris" );
put( "email", "a@b.c" );
}};
Alternative: http://commons.apache.org/collections/api-release/org/apache/commons/collections/MapUtils.html#putAll(java.util.Map,%20java.lang.Object[]). Die API nennt ein Beispiel:
Map colorMap = MapUtils.putAll(new HashMap(), new String[][] {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}
});
Die Apache Common Collections sind aber erst einmal nicht generisch!
Für http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Maps.html ist so was wohl geplant, aber bisher noch nicht implementiert.
Eclipse 3.5M2
0 Kommentar(e). Veröffentlicht von Christian Ullenboom am Dienstag, September 23, 2008.ist raus. Die Neuerungen halten sich auf der Java-Seite sehr in Grenzen -- echte Knaller (New and Noteworthy) sind nicht dabei.
- Links in Javadoc headers
- Select comment with double click
- Open *.jardesc files with JAR Export Wizard
- Open test result files in JUnit view
- JUnit 4.5
Interessanter sind da schon zwei Dinge:
1. Compiler problem for missing synchronized modifier
The compiler now issues a warning when a method overrides a synchronized method but the method itself is not synchronized.

You can use the quick fix to add the synchronized modifier, and you can configure the problem severity on Preferences > Java > Compiler > Errors/Warnings in the Potential programming problems section.
2. Suppress compiler problem for 'switch' case fall-through
The compiler problem for expected fall-throughs in switch case statements can now be suppressed by preceding the following case statement with a comment that starts with $FALL-THROUGH$. This is especially interesting for code that can't use the J2SE-5.0-style @SuppressWarnings("fallthrough") annotation.

This problem is not reported by default. You can enable the 'switch' case fall-through warning on Preferences > Java > Compiler > Errors/Warnings in the Potential programming problems section.
Vielleicht ist ja mit 3.5M3 mehr dabei. Geplant ist Milestone M3 am 2008-10-31.
Labels: Eclipse, Entwicklungsumgebung
Java Wikipedia API
1 Kommentar(e). Veröffentlicht von Christian Ullenboom am Sonntag, September 14, 2008.Wer von Java aus auf die Inhalte von Wikipedia zugreifen, und die Inhalte auch noch Rendern möchte, findet mit der quelloffenen Java Wikipedia API (http://www.matheclipse.org/en/Java_Wikipedia_API) eine passende Unterstützung.
Zum Laden einer Wikipedia-Seite und Renderer in eine Datei ist lediglich nötig:
User user = new User( "", "", "http://de.wikipedia.org/w/api.php" );
List<Page> queryContent = user.queryContent( Arrays.asList( "Java (Programmiersprache)" ) );
String content = queryContent.get( 0 ).getCurrentContent();
WikiModel wikiModel = new WikiModel( "http://de.wikipedia.org/wiki/${image}",
"http://de.wikipedia.org/wiki/${title}" );
String rendererdHtmlContent = wikiModel.render( content );
FileWriter fw = new FileWriter("c:/test.html");
fw.write( rendererdHtmlContent );
fw.close();
Einige Dinge löst der Renderer aber nicht auf. So verbleiben im Text Wiki-Templates wie
- {{Infobox Programmiersprache}}
- {{IPA}}
- {{Wikiversity}}
- {{Wikibooks}}
oder bei anderen Texten
- {{Begriffsklärungshinweis}}
- {{Commonscat}}
- {{internetquelle}}
- {Literatur}}
Auch Bilder werden standardmäßig nicht richtig umgesetzt. So wird bei http://de.wikipedia.org/wiki/Linux aus
[[Bild:Linus Torvalds.jpeg|thumb|right|Linus Torvalds 2004]]
kein Bild, sondern ein Link
<a href="http://de.wikipedia.org/wiki/Bild:Linus_Torvalds.jpeg%7Cthumb%7Cright" id="w">Linus Torvalds 2004</a>
Dumm nur, dass %7Cthumb%7Cright falsch ist, sonst wäre wenigstens der Link korrekt. (%7C ist |)
Labels: Open Source

