1 16 17 package org.apache.jetspeed.services.transformer; 18 19 import java.io.Reader ; 21 22 import javax.servlet.ServletConfig ; 23 24 import org.apache.jetspeed.util.rewriter.ClipperRewriter; 25 import org.apache.turbine.services.TurbineBaseService; 26 import org.apache.turbine.util.Log; 27 28 33 public class JetspeedTransformerService 34 extends TurbineBaseService 35 implements TransformerService 36 { 37 protected ClipperRewriter rewriter = null; 38 String convertedString; 39 40 45 public void init(ServletConfig conf) 46 { 47 if (getInit()) 49 { 50 return; 51 } 52 53 rewriter = new ClipperRewriter(); 54 setInit(true); 55 } 56 57 60 public void init() 61 { 62 while (!getInit()) 63 { 64 try 65 { 66 Thread.sleep(500); 67 Log.info("JetspeedTransformerService: Waiting for init()..."); 68 } 69 catch (InterruptedException ie) 70 { 71 Log.error(ie); 72 } 73 } 74 } 75 76 83 public String findElement(Reader htmlReader, String url, String element) 84 { 85 return clipElementsNumber(htmlReader, url, element, null, 1); 87 } 88 89 97 public String clipElements( 98 Reader htmlReader, 99 String url, 100 String startElement, 101 String stopElement) 102 { 103 return clipElementsNumber( 105 htmlReader, 106 url, 107 startElement, 108 stopElement, 109 1); 110 } 111 112 125 public String findElementNumber( 126 Reader htmlReader, 127 String url, 128 String element, 129 int tagNumber) 130 { 131 return clipElementsNumber(htmlReader, url, element, null, tagNumber); 132 } 133 134 149 public String clipElementsNumber( 150 Reader htmlReader, 151 String url, 152 String startElement, 153 String stopElement, 154 int tagNumber) 155 { 156 rewriter.setStartElement(startElement); 157 rewriter.setStopElement(stopElement); 158 rewriter.setStartElementNumber(tagNumber); 159 160 try 161 { 162 convertedString = rewriter.rewrite(htmlReader, url); 163 } 164 catch (Exception e) 165 { 166 Log.info("Exception occurred:" + e.toString()); 167 e.printStackTrace(); 168 } 169 170 return convertedString; 171 } 172 173 } 174 | Popular Tags |