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.basic;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  
21  import org.seasar.tuigwaa.cms.core.CmsRequest;
22  import org.seasar.tuigwaa.cms.core.CmsResponse;
23  import org.seasar.tuigwaa.cms.core.wiki.base.VisitorUtils;
24  import org.seasar.tuigwaa.plugin.PluginException;
25  import org.seasar.tuigwaa.plugin.PluginRequest;
26  
27  import com.lowagie.text.Chunk;
28  import com.lowagie.text.Font;
29  import com.lowagie.text.Phrase;
30  
31  public class PdfColorPlugin extends ColorPlugin {
32  
33  	public Object doPDFView(CmsRequest request, CmsResponse response, PluginRequest prequest) throws PluginException {
34  		
35  		String[] array = prequest.getArgs();
36  		Object child = prequest.getChild();
37  		
38  		if(array == null) return child;
39  		
40  		if(array.length >= 1){
41  
42  			String colorstr = array[0];
43  			String bgcolorstr = null;
44  			if(array.length >= 2) bgcolorstr = array[1];
45  			
46  		
47  			if(child instanceof Phrase){
48  				Phrase p = (Phrase) child;
49  				List list = p.getChunks();
50  				if(list != null){
51  					for(Iterator i = list.iterator();i.hasNext();){
52  						Chunk c = (Chunk)i.next();
53  						Font nf = new Font(c.font());
54  						nf.setColor(VisitorUtils.getColorByString(colorstr,true));
55  						if(bgcolorstr !=null)
56  							c.setBackground(VisitorUtils.getColorByString(bgcolorstr,false));
57  						c.setFont(nf);
58  					}
59  				}
60  			}
61  		}
62  		return child;				
63  	}
64  
65  }