DocBook, FOP and Fonts
Apache FOP has a long history. For some reason, it seems impossible to ever arrive at a version 1.0. The versions I used at Sun unfortunately never supported the keep-with-next poperty, which resulted in weird page-endings, that I then had to manually fix. However, that has been solved with the latest versions, and I think the output generated by the DocBook stylesheets can be quite ok.
That is, if you customize them. And while customizing, you also might want to use other fonts than the standard fonts. However, if you are using Apache FOP, then simply referencing alternative fonts is not going to get you anywhere. You also need to make sure the font metrics can be found. And if you don't have these font metrics files yet, you first have to generate them.
Apache FOP is providing some utilities for generating font metrics, however none of that is based on Maven. If you are using the Maven Docbkx Plugin, then you might want something that integrates with Maven. Last weekend I realized that - although the Maven Docbkx Plugin supports something like that - it is probably one of its best kept secrets.
So, this is the way you use it.
Add a plugin
First of all, you need to add a plugin to the plugins section.
<plugin>
<groupId>com.agilejava.docbkx</groupId>
<artifactId>docbkx-fop-support</artifactId>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<ansi>true</ansi>
<sourceDirectory>...</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
The sourceDirectory parameter is pointing to a directory containing the .ttf files. To be perfectly honest, I don't remember exactly what the ansi parameter was about, but AFAIR, it had something to do with being able to search the documents. (Huge disclaimer: it may be about something completely different. Feel free to plough through the FOP documentation to understand what it is about.)
As I said, the font metrics files are required to get something done. However, just generating the files is not going to make a huge difference. In order to reap the benefits from these metrics files, you will need to tell the Maven Docbkx Plugin what to do with it.
The first thing you should do is add some font metadata to the Maven Docbkx Plugin's configuration:
<fonts>
<font>
<name>Calibri</name>
<style>normal</style>
<weight>normal</weight>
<embedFile>${fonts.dir}/calibri.ttf</embedFile>
<metricsFile>${basedir}/target/fonts/calibri-metrics.xml</metricsFile>
</font>
</fonts>
This should be enough to make the plugin aware of the existence of this font, and to have a way resolve its name to the required meta data. With this in place, making the plugin use this font is pretty easy. You can use the fonts name in all places where the stylesheets are referring to a font name. So the below will change the body font to Calibri.
<bodyFontFamily>Calibri</bodyFontFamily>
DocBook, FOP and Fonts
OOPSLA slides uploaded
OOPSLA slides uploaded
The Size of the Slice
// Example 1:
@BoundNumber(size="8") int size;
@Slice(size="size") @BoundList byte[];
// Example 2:
@LengthPrefix(size="8") @BoundList byte[];
- Determine if the size of data structure from the slice can be determined before it is encoded. In case it can, simply write the size of the slice to the BitChannel first, and then continue writing the data structure that needs to be encoded.
- Otherwise, write the entire data structure to a temporary BitChannel backed by an in memory buffer. Then, before flushing the contents of this buffer into the target BitChannel, determine the required size of the buffer, and write that value to the target channel first. Then write the contents of the temporary buffer into the BitChannel.
The Size of the Slice
Hamcrest-based Schema Validation
Anyway, I will just give a brief introduction. (And there really isn't that much to talk about.)
First of all, let's assume that you have a File reference to an XML file (xml) and a File reference to a RelaxNG schema file (schema). Now, in order to validate that file from JUnit, all you have to do is this:
assertThat(xml, isValidatedBy(schema));
java.lang.AssertionError:
Expected: conforming to sample.rng
but: tag name "foo" is not allowed. Possible tag names are: <bar> at line <2>
Hamcrest-based Schema Validation
Mystery Programming Language Hiding in Plain Sight
It probably will not strike you as a surprise that there is a lot to do these days on the next programming language. Java - wildly popular as it may be - does have some limitations and there are some things that you just cannot shoehorn into into the language without violating its conceptual integrity.
From all of these pretenders to the Java throne, we at Xebia probably like Scala most, for various reasons. We like the fact that it marries two programming paradigms (functional and OO), that it can be extended, and that there is type safety without paying a huge toll. But there are obviously alternatives such as Erlang, Clojure and LUA (and Fortress, perhaps, some day?).
But hold on, there is more… There is something out there, and you may not be aware of it. Before I reveal its name, I will refer to it as programming language Rarebit.
- Rarebit has immutable state only. In that sense, it's more like Erlang than like Scala. In terms of Scala, everyting in Rarebit is a val. (As a consequence, programming recursive structures is not uncommon in Rarebit.)
- Rarebit has pattern matching, just like Erlang and Scala. In fact, it takes pattern matching to a whole new level, since your entire program is basically driven by pattern matching. (Pattern matching driven is the new 'driven'?)
- Like Scala, XML is a first class citizen in Rarebit. There is a difference though. In Scala, if you want to address a particular node in your document, you use an XPath-alike expression. In Rarebit, it is really one-hundred-percent XPath.
- Like Scala and Clojure, Rarebit lives on the Java VM. Normally, it is interpreted, but it is also possible to compile Rarebit downto plain old bytecode.
- Unlike Scala and Clojure, Rarebit does not allow you to call native Java libraries just like that. You can however get that by using extensions that I will discuss later on. However, out of the box, it doesn't support it. That's a bless and a curse, but I am hanging towards the bless. Because of this 'limitation' Rarebit really is guaranteed to be side-effect free. And that's not all, because:
- Unlike Scala and Clojure, Rarebit does not require the VM. There are other versions that run directly on the host operating system. In that sense, Rarebit is more similar to Ruby and Python: they all come in a C-version and in a J-version.
- Unlike LUA and Ruby, the entire language is specified, submitted to a standardization organization, and officially endorsed.
- Unfortunately unlike Scala and Ruby, Rarebit is extremely stable.
- Rarebit is dynamically typed, just like Clojure and Erlang, although a later version (largely backwards compatible) allows you to work in a more strongly typed manner, more like Scala.
- Rarebit does allow you to pass around function pointers, and it does support something that - with a bit of imagination - you could consider support for closures. (Just like Scala.)
- Rarebit is extensible. That is, it allows you to add more language constructs to the language, although it's questionable if you can really talk about it in that way, since:
- In Rarebit, your code is just data, just like in Clojure. So you can manipulate programs using programs easily.
- Rarebit does however allow you to introduce new 'syntax' that will also allow you to call out to libraries outside of the set of functions supported by Rarebit itself. Note however that - if you use these features - you can introduce side-effects, which is clearly not necessarily a desirable feature.
- Unlike Scala and Clojure, Rarebit has very decent IDE support. (I guess it won't be long until Scala support in IntelliJ becomes up to par.)
Sounds pretty good huh? I bet you want to get your hands on that programming language. So here goes nothing:
Rarebit = XSLT

Mystery Programming Language Hiding in Plain Sight
Spring ME Supporting Namespaces?
<beans xmlns="..." xsi="..." util="..." schemalocation="...">
<bean id="person" class="me.springframework.sample.namespaces.Person">
<property name="age">
<util:constant field="java.lang.Integer.MAX_VALUE">
</util:constant></property>
</bean>
</beans>
org.springframework.beans.factory.config.FieldRetrievingFactoryBean result =
new org.springframework.beans.factory.config.FieldRetrievingFactoryBean();
result.setStaticField("java.lang.Integer.MAX_VALUE");
result.afterPropertiesSet();
return result.getObject();
Spring ME Supporting Namespaces?
Preon on JRockit
public class Image {
@Bound int width;
@Bound int height;
}Preon on JRockit

