001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.examples.core.svl;
014
015import org.apache.juneau.svl.*;
016
017/**
018 * TODO.
019 *
020 * <ul class='seealso'>
021 *    <li class='extlink'>{@source}
022 * </ul>
023 */
024public class SvlExample {
025
026   /**
027    * Main method.
028    *
029    * @param args Unused.
030    */
031   public static void main(String[] args) {
032
033      VarResolver vr = VarResolver.DEFAULT;
034
035      // $E{key[,default]} for getting environment variables
036      System.out.println(vr.resolve("JAVA_HOME=$E{JAVA_HOME, not defined}"));
037
038      // $S{key[,default]} for getting system properties (uses System.getProperty() )
039      System.out.println(vr.resolve("os.name=$S{os.name, not defined}"));
040
041      // $IF{key[,default]} general if or if-else condition
042      // $NE{arg} will return true if not empty
043      System.out.println(vr.resolve("TEST_VAR is $IF{$NE{$E{TEST_VAR}}, not empty, empty}"));
044
045      // $SW{arg,pattern1:then1[,pattern2:then2...]} switch-case
046      System.out.println(vr.resolve("$SW{Carrot, *Ap*:Fruit, *Car*:Veg, *:N/A}"));
047
048      // $PR{arg,pattern,replace} pattern replace
049      System.out.println(vr.resolve("Java version=$PR{$S{java.version}, (_([0-9]+)), \\ build=\\$2}"));
050
051      // $UC{arg} uppercase $LC{arg} lowecase
052      System.out.println(vr.resolve("$LC{JAVA_HOME} $UC{$E{JAVA_HOME}}"));
053
054      // $LN{arg[,delimiter]} length var example
055      System.out.println(vr.resolve("parts = $LN{$S{os.version},.}, charcount = $LN{$S{os.version}}"));
056
057      // $ST{arg,start[,end]} substring var example
058      System.out.println(vr.resolve("version = $ST{$S{java.version}, 0, 3}"));
059
060      // $PE{arg,start[,end]} pattern extractor var example
061      System.out.println(vr.resolve("update = $PE{$S{java.version},_([0-9]+),1}"));
062
063      /*
064       *  See all supported variable types at,
065       *  http://juneau.apache.org/site/apidocs-8.0.0/overview-summary.html#juneau-marshall.SimpleVariableLanguage
066       *  NOTE - juneau-marshall.SimpleVariableLanguage supports nested variables well
067       * */
068   }
069
070}