2009年4月22日 星期三

java 的 odt 轉換工具 JODConverter

官方網頁
http://www.artofsolving.com/opensource/jodconverter

首先啟動openoffice的服務模式,最簡單的方式是,到openoffice安裝目錄下的program,如:
C:\Program Files\OpenOffice.org 3\program執行
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

可以使用 netstat -a 檢查 8100 port 是否有在 LISTENING
下載 jodconverter-2.2.2.zip 並將裡面的 lib 下的 jar放到classpath下

轉換的程式碼:
public static void main(String[] args) throws Exception {
File inputFile = new File("test.odt");
File outputFile = new File("test.doc");

// connect to an OpenOffice.org instance running on port 8100
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();

// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);

// close the connection
connection.disconnect();
}

jodconverter是透過輸入的副檔名來做為轉換的依據的。

2009年4月16日 星期四

Junit 4.5 的 TestAll寫法

Junit 4.5 的 TestAll寫法

@RunWith(Suite.class)
@SuiteClasses( { TestAllDao.class, TestAllController.class })
public class TestAllXdna {

}

2009年4月11日 星期六

hinet 中華電信 DNS 列表

DNS Server 中華電信的全區 168.95.1.1
中華電信分區如下
北區 DNS 139.175.55.244(主) 139.175.252.16(次) 適用地區範圍:台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗
中區 DNS 139.175.150.20(主) 139.175.55.244(次) 適用地區範圍:台中, 彰化, 南投, 雲林
南區 DNS 139.175.10.20(主) 139.175.55.244(次) 適用地區範圍:高雄, 台南, 嘉義, 屏東, 台東

2009年4月8日 星期三

spring 3.0.0.M2 整合 Apache Tiles 2 模版

一、
tiles相關的jar加到WEB-INF/lib,以3.0.0.M2的情型,必需下載tiles-2.0.7的版本,
tiles-2.1.x以上的版本,尚有問題,tiles本身也相依commons-beanutils 及 commons-digester,
都可以在Tiles-2.0.7-bin.tar.gz下載得到。固與Tiles相關的jar有:
commons-beanutils-1.7.0.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
tiles-api-2.0.7.jar
tiles-core-2.0.7.jar
tiles-jsp-2.0.7.jar

二、
在spring的bean設定檔稍做修改,
a在viewResolver將InternalResourceViewResolver改用UrlBasedViewResolver
b並加入viewClass 設定為 org.springframework.web.servlet.view.tiles2.TilesView
c加入 TilesConfigurer
如下:
<!-- test jsp view -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>

<!-- Tiles 模版 -->
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/defs/templates.xml</value>
</list>
</property>
</bean>

三、
在上面的TilesConfigurer bean中指定了/WEB-INF/defs/templates.xml這個模版定義檔
建立templates.xml內容為:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="/WEB-INF/jsp/test.jsp" template="/WEB-INF/jsp/templates/layout.jsp">
<put-attribute name="title" value="TPMA Tiles tutorial homepage" />
<put-attribute name="header" value="/WEB-INF/jsp/templates/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/jsp/templates/menu.jsp" />
<put-attribute name="body" value="/WEB-INF/jsp/body.jsp" />
<put-attribute name="footer" value="/WEB-INF/jsp/templates/footer.jsp" />
</definition>
</tiles-definitions>

四、
上面的定義了當Controller的return
return new ModelAndView("test", "test", model);
的時後,test會被UrlBasedViewResolver組合成/WEB-INF/jsp/test.jsp,而TilesView則會到,
templates.xml找到/WEB-INF/jsp/test.jsp的定義,並根據layout.jsp頁面組合title、header、
menu、body、footer等頁面,layout.jsp的內容如下:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:getAsString name="title" /></title>
</head>
<body>
<table border="0" width="100%" cellspacing="5">
<tr>
<td colspan="2"><tiles:insertAttribute name="header" /></td>
</tr>
<tr>
<td width="140" valign="top"><tiles:insertAttribute name="menu" /></td>
<td valign="top" align="left"><tiles:insertAttribute name="body" /></td>
</tr>
<tr>
<td colspan="2"><tiles:insertAttribute name="footer" /></td>
</tr>
</table>
</body>
</html>

以tiles:getAsString插入templates.xml定義的value為文字
以tiles:insertAttribute插入templates.xml定義的value的網頁

五、
準備templates.xml中定義的其他jsp頁面。

六、
每個網頁一樣可以使用EL取得model的值
${test.name } ${test.passwd }