Skip to content

Commit

Permalink
Merge pull request #15 from shalithasuranga/patch006
Browse files Browse the repository at this point in the history
Add SvlExample for juneau-svl demo
  • Loading branch information
jamesbognar committed Nov 12, 2018
2 parents b53216c + 0a44e61 commit 718da4b
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
// * with the License. You may obtain a copy of the License at *
// * *
// * http://www.apache.org/licenses/LICENSE-2.0 *
// * *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
// * specific language governing permissions and limitations under the License. *
// ***************************************************************************************************************************
package org.apache.juneau.examples.core.svl;

import org.apache.juneau.svl.*;

/**
* TODO
*
*/
public class SvlExample {

/**
* TODO
*
* @param args
*/
public static void main(String[] args) {

VarResolver vr = VarResolver.DEFAULT;

// $E{key[,default]} for getting environment variables
System.out.println(vr.resolve("JAVA_HOME=$E{JAVA_HOME, not defined}"));

// $S{key[,default]} for getting system properties (uses System.getProperty() )
System.out.println(vr.resolve("os.name=$S{os.name, not defined}"));

// $IF{key[,default]} general if or if-else condition
// $NE{arg} will return true if not empty
System.out.println(vr.resolve("TEST_VAR is $IF{$NE{$E{TEST_VAR}}, not empty, empty}"));

// $SW{arg,pattern1:then1[,pattern2:then2...]} switch-case
System.out.println(vr.resolve("$SW{Carrot, *Ap*:Fruit, *Car*:Veg, *:N/A}"));

// $PR{arg,pattern,replace} pattern replace
System.out.println(vr.resolve("Java version=$PR{$S{java.version}, (_([0-9]+)), \\ build=\\$2}"));

// $UC{arg} uppercase $LC{arg} lowecase
System.out.println(vr.resolve("$LC{JAVA_HOME} $UC{$E{JAVA_HOME}}"));

/*
* See all supported variable types at,
* http://juneau.apache.org/site/apidocs-7.2.1/overview-summary.html#juneau-svl
* NOTE - juneau-svl supports nested variables well
* */
}

}

0 comments on commit 718da4b

Please sign in to comment.