View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.plugin.database;
17  
18  import java.util.regex.Matcher;
19  import java.util.regex.Pattern;
20  
21  import org.seasar.tuigwaa.cms.core.CmsRequest;
22  import org.seasar.tuigwaa.cms.core.CmsResponse;
23  import org.seasar.tuigwaa.cms.core.pdf.PdfUtils;
24  import org.seasar.tuigwaa.cms.core.wiki.base.WikiHelper;
25  import org.seasar.tuigwaa.plugin.PluginException;
26  import org.seasar.tuigwaa.plugin.PluginRequest;
27  
28  import com.lowagie.text.Chunk;
29  
30  /***
31   * @author someda
32   */
33  public class PdfDataPlugin extends DataPlugin {
34  
35  	private static Pattern HTML_IMG_PATTERN = Pattern.compile("<img src=(.+)/>");
36  	private static Pattern HTML_ANCHOR_PATTERN = Pattern.compile("<a href=.+>(.+)</a>");
37  
38  	
39  	public Object doPDFView(CmsRequest request, CmsResponse response, PluginRequest prequest) throws PluginException {		
40  		String htmlStr = super.doHTMLView(request,response,prequest);
41  		String str = extractString(htmlStr);		
42  		Chunk c = new Chunk(str,PdfUtils.FONT_JA_MINCHO);		
43  		return c;
44  	}	
45  	
46  	private static String extractString(String htmlString){
47  		String ret = htmlString;
48  
49  		Matcher m = HTML_ANCHOR_PATTERN.matcher(htmlString);
50  		if(m.matches()){
51  			ret = m.group(1);
52  		}
53  
54  		m = HTML_IMG_PATTERN.matcher(htmlString);
55  		if(m.matches()){
56  			ret = m.group(1);
57  		}								
58  		return WikiHelper.deleteParenthesis(ret,"\"","\"");		
59  	}	
60  }