Monday, March 30, 2009

Java Clojure Interoperability, Calling Clojure from Java

So far, Java interoperability with Clojure is pretty seamless. Calling Java from Clojure is pretty much built into the language. Calling Clojure from Java is easy as well. I didn't do any research before coming up with this example, I essentially looked at the Clojure Java source code and went from that. Here is an example, invoking Clojure and then passing a Spring Framework Context object to the Clojure code, also calling Clojure methods.

There is the advantage in doing this, you can write concise Clojure code and then invoke that module from Java.


package test.toolkit.clojure;


import org.springframework.context.support.ClassPathXmlApplicationContext;

import clojure.lang.Namespace;
import clojure.lang.RT;
import clojure.lang.Symbol;
import clojure.lang.Var;

public class TestSpringLoadClojure {

///////////////////////////////////////////////////////////////////////////


public static void loadScripts() throws Exception {

final String [] contexts = { "conf/applicationContext-test1b.xml" };
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(contexts);

final Symbol symbolClojureMain = Symbol.create("clojure.main");
final Namespace namespaceClojureMain = Namespace.findOrCreate(symbolClojureMain);
final Var varRequire = Var.intern(RT.CLOJURE_NS, Symbol.create("require"));

final Namespace simpleUtilsNs = Namespace.findOrCreate(Symbol.create("utils.simple_utils"));
final Var locRequire = Var.intern(RT.CLOJURE_NS, Symbol.create("require"));

varRequire.invoke(symbolClojureMain);

locRequire.invoke(Symbol.create("utils.simple_utils"));
System.out.println("1");
Thread.sleep(2000);
System.out.println("*[2a]*");
locRequire.invoke(Symbol.create("utils.simple_utils"));
System.out.println("*[2b]*");
Thread.sleep(1000);

// Call require on our utility clojure code
// Set the variable spring-context for use in the clojure script
Var.intern(Namespace.findOrCreate(Symbol.create("clojure")), Symbol.create("*spring-context*"), context);
locRequire.invoke(Symbol.create("utils.test_use_utils"));

// This will work, get the length
final Var len = Var.intern(simpleUtilsNs, Symbol.create("length"));
System.out.println(len.invoke("1234"));

}

public static void main(final String [] args) throws Exception {

System.out.println("Running");
loadScripts();
System.out.println("Done");

}

}


Original Source on the Clojure Group Forum

Monday, March 9, 2009

XHtmlrenderer, for XHTML to PDF, PNG, JPEG, etc new release candidate 8




https://xhtmlrenderer.dev.java.net/news.html

BEGIN QUOTE

We once again thank the many people who contributed to this release (named in the changes that follow).

* Features
o Upgrade to use iText 2.0.8
o Support for callback on form submission using new FormSubmissionListener interface; patch from Christophe Marchand (thanks, Christophe!).
o Support reading properties which are not in our standard config file, passed in via an override config file or via System properties. This is to support extended configuration parameters for JDK logging, e.g. appenders, formatters, etc.
o Added XML-APIs to lib directory to support compilation when using Java 1.4, which includes it's own (old) version of the XML APIs. This allows us to reference classes in the newer XML APIs for which there are Java 1.4 implementations.
o Support adding custom header properties on PDF output
o Add ability to set PDF version programmatically
o Add ability to manipulate PDF output document before it's closed
o Implement -fs-keep-with-inline: keep property that instructs FS to try to avoid breaking a box so that only borders and padding appear on a page
o Expose copy of parsed entities from catalog.
o Add ability to have different starting page number for first document too
o Add API to retrieve PDF page and coordinates for boxes with an ID attribute
o Improve support for PDF encryption, patch from Josh Hayes-Sheen: allow finer control over the encryption of PDF output; default to standard 128bit but now one can choose between that, 40bit, or AES_128, and can 'or'PdfWriter.DO_NOT_ENCRYPT_METADATA against it
o Support using a Document instance with Java2DRenderer; patch from Michael Janiszewski Browser
o demo app: Add PDF export to browser (patch from Mykola Gurov)
o Implement CMYK color support for PDF output, starting with patch from Mykola Gurov
o Make FSScrollPane a bean; patch from Nicholas Sushkin.
o Add rudimentary support for data URLs (patch from Sean Bright)

Sunday, March 8, 2009

Lisp in Java (Kanji Version)




単純なJavaで実装舌足らず(オーデのリンクリストへ)
概要
私は自然言語()を記述するために多くの親和性がありませんが、私が成長してきたとプログラミングを楽しみ、その20年後に何かを続けている。しかし、私は本当にこのブログのエントリを得るために、私を見直すとreframeどうすればコードの特定の部分を見ている。だから私は違う方向、 1台のコンピュータサイエンスは、リンクされたリストの中で最も基本的なデータ構造の開始で移動するつもりです。舌足らずのコードの代わりにする(とにかく思考)としての要素の"リスト" 。舌足らずのコードの要素のリンクリストとして考えています。

*どのようにしてC言語では、リンクのリスト(またはJavaやフォートラン)を実装するのですか?
*どのようにして、すべてのリンクリストの要素を印刷するのでしょうか?
*どのようにしてすべての要素の和でしょうか?

最後の数字の操作をした後のことを考えですか?さまざまなリストの操作を実装することが可能な方法を考えることができます、舌足らず操作'のようなマップ' ?

のリンク一覧

なぜリンクされている舌足らず一覧することが重要ですか? "舌足らず名一覧言語" 。リンクリストの処理"から派生1舌足らずの言語の主要なデータ構造体の"です

は、 Java /のC / C + +や他の手続き型言語プログラムでは、リンクされたリストは通常2つのフィールドは、データ自体は(任意のオブジェクトの型の)と"ポインタ"または、次の要素にリンクされているリストを参照する構成で構成されています。以下のJavaコードの断片では、データの要素に、リスト内の現在のノードを指す。ノードオブジェクトの"次へ"をリストチェーン内の次のノードへの参照です。

...
...

結論

これはJavaでは、 Scheme /舌足らず実装連結リストのデータ構造からのスタートと通訳コードに続けて自分の実行を終えます。そのNorvigの実装に追加されることがたくさんある。 R5RS制度を実施を完全にサポートを追加します。改善の入力/出力のサポートを追加します。アークからのコピー、または共通舌足らず興味深い機能しています。コンパイラは、 Schemeを書く。実際、私の実装では、ソースコードとNorvigのはかなり簡単です、私は第四に、このコードに基づいていくつかの通訳を書くことに計画していた。舌足らずの構造を定義するデータの一覧表示されています。規定では、スタックされています。要因としてはほぼ完全なプログラミング言語としてはできませんが、楽しみでも、プロジェクトになる。


http://berlinbrowndev.blogspot.com/2008/07/simple-lisp-implementation-in-java-ode.html

Friday, March 6, 2009

Converting some blogs to Spanish and Japanese and the Light Text Editor

I am converting some of my blog to spanish and japanese.

Yo estoy converso este blog a Espanol and Japonese. Gracias. Primero, yo puedo dígale esta uso. Light editor de textos. Light escrito adentro Clojure, SWT and Java.



http://code.google.com/p/lighttexteditor/

--------

Corrected, I am still learning.

"Estoy convertiendo algunos de mi blog al español y japonés."

--------