Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2012, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.subst;
 
Compiles a previously parsed Node chain into a String.

Author(s):
Ceki Gücü
 
 public class NodeToStringTransformer {
 
   final Node node;
 
   public NodeToStringTransformer(Node nodePropertyContainer propertyContainer0PropertyContainer propertyContainer1) {
     this. = node;
     this. = propertyContainer0;
     this. = propertyContainer1;
   }
 
   public NodeToStringTransformer(Node nodePropertyContainer propertyContainer0) {
     this(nodepropertyContainer0null);
   }
 
   public static String substituteVariable(String inputPropertyContainer pc0PropertyContainer pc1throws ScanException {
     Tokenizer tokenizer = new Tokenizer(input);
     Parser parser = new Parser(tokenizer.tokenize());
     Node node = parser.parse();
     NodeToStringTransformer nodeToStringTransformer = new NodeToStringTransformer(nodepc0pc1);
     return nodeToStringTransformer.transform();
   }
 
   public String transform() {
     StringBuilder stringBuilder = new StringBuilder();
     compileNode(stringBuilder);
     return stringBuilder.toString();
   }
 
   private void compileNode(Node inputNodeStringBuilder stringBuilder) {
     Node n = inputNode;
     while (n != null) {
       switch (n.type) {
         case :
           handleLiteral(nstringBuilder);
           break;
         case :
           handleVariable(nstringBuilder);
           break;
       }
       n = n.next;
     }
   }
 
   private void handleVariable(Node nStringBuilder stringBuilder) {
     StringBuilder keyBuffer = new StringBuilder();
     Node payload = (Noden.payload;
     compileNode(payloadkeyBuffer);
     String key = keyBuffer.toString();
     String value = lookupKey(key);
     if (value != null) {
       stringBuilder.append(value);
       return;
     }
 
     if (n.defaultPart == null) {
       stringBuilder.append(key + .);
       return;
     }
 
     Node defaultPart = (Noden.defaultPart;
     StringBuilder defaultPartBuffer = new StringBuilder();
     compileNode(defaultPartdefaultPartBuffer);
     String defaultVal = defaultPartBuffer.toString();
     stringBuilder.append(defaultVal);
   }
 
   private String lookupKey(String key) {
     String value = .getProperty(key);
     if (value != null)
       return value;
 
     if ( != null) {
      value = .getProperty(key);
      if (value != null)
        return value;
    }
    value = OptionHelper.getSystemProperty(keynull);
    if (value != null)
      return value;
    value = OptionHelper.getEnv(key);
    if (value != null) {
      return value;
    }
    return null;
  }
  private void handleLiteral(Node nStringBuilder stringBuilder) {
    stringBuilder.append((Stringn.payload);
  }
New to GrepCode? Check out our FAQ X