private void processText(Segment segment) {
   String inputValue = segment.toString();
   String outputValue = inputValue;
   try {
     if (stack.isEmpty()) {
       // This can happen for whitespace outside of the root element.
       // outputValue = filterText( null, inputValue );
     } else {
       String tagType = stack.peek().getTag().getAttributeValue("type");
       String tagName = stack.peek().getTag().getName();
       if (SCRIPTTAG.equals(tagName)
           && JSTYPES.contains(tagType)
           && config != null
           && !config.getSelectors().isEmpty()) {
         // embedded javascript content
         outputValue = UrlRewriteUtil.filterJavaScript(inputValue, config, this, REGEX_COMPILER);
       } else {
         outputValue = filterText(stack.peek().getQName(), inputValue, null);
       }
     }
     if (outputValue == null) {
       outputValue = inputValue;
     }
   } catch (Exception e) {
     LOG.failedToFilterValue(inputValue, null, e);
   }
   writer.write(outputValue);
 }
 private String rewriteValue(UrlRewriter rewriter, String value, String rule) {
   try {
     Template input = Parser.parse(value);
     Template output = rewriter.rewrite(this, input, UrlRewriter.Direction.IN, rule);
     value = output.toString();
   } catch (URISyntaxException e) {
     LOG.failedToParseValueForUrlRewrite(value);
   }
   return value;
 }
 private static UrlRewriteRulesDescriptor loadDescriptor(URL url) throws IOException {
   InputStream stream = url.openStream();
   Reader reader = new InputStreamReader(stream, "UTF-8");
   UrlRewriteRulesDescriptor descriptor = UrlRewriteRulesDescriptorFactory.load("xml", reader);
   try {
     reader.close();
   } catch (IOException closeException) {
     LOG.failedToLoadRewriteRulesDescriptor(closeException);
   }
   return descriptor;
 }
 private Template getSourceUrl() {
   Template urlTemplate = null;
   StringBuffer urlString = super.getRequestURL();
   String queryString = super.getQueryString();
   if (queryString != null) {
     urlString.append('?');
     urlString.append(queryString);
   }
   try {
     urlTemplate = Parser.parse(urlString.toString());
   } catch (URISyntaxException e) {
     LOG.failedToParseValueForUrlRewrite(urlString.toString());
     // Shouldn't be possible given that the URL is constructed from parts of an existing URL.
     urlTemplate = null;
   }
   return urlTemplate;
 }
 private void processAttribute(Attribute attribute) {
   writer.write(" ");
   writer.write(attribute.getName());
   if (attribute.hasValue()) {
     String inputValue = attribute.getValue();
     String outputValue = inputValue;
     try {
       Level tag = stack.peek();
       outputValue =
           filterAttribute(tag.getQName(), tag.getQName(attribute.getName()), inputValue, null);
       if (outputValue == null) {
         outputValue = inputValue;
       }
     } catch (Exception e) {
       LOG.failedToFilterAttribute(attribute.getName(), e);
     }
     writer.write("=");
     writer.write(attribute.getQuoteChar());
     writer.write(outputValue);
     writer.write(attribute.getQuoteChar());
   }
 }