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 */ 021public class SvlExample { 022 023 /** 024 * TODO 025 * 026 * @param args 027 */ 028 public static void main(String[] args) { 029 030 VarResolver vr = VarResolver.DEFAULT; 031 032 // $E{key[,default]} for getting environment variables 033 System.out.println(vr.resolve("JAVA_HOME=$E{JAVA_HOME, not defined}")); 034 035 // $S{key[,default]} for getting system properties (uses System.getProperty() ) 036 System.out.println(vr.resolve("os.name=$S{os.name, not defined}")); 037 038 // $IF{key[,default]} general if or if-else condition 039 // $NE{arg} will return true if not empty 040 System.out.println(vr.resolve("TEST_VAR is $IF{$NE{$E{TEST_VAR}}, not empty, empty}")); 041 042 // $SW{arg,pattern1:then1[,pattern2:then2...]} switch-case 043 System.out.println(vr.resolve("$SW{Carrot, *Ap*:Fruit, *Car*:Veg, *:N/A}")); 044 045 // $PR{arg,pattern,replace} pattern replace 046 System.out.println(vr.resolve("Java version=$PR{$S{java.version}, (_([0-9]+)), \\ build=\\$2}")); 047 048 // $UC{arg} uppercase $LC{arg} lowecase 049 System.out.println(vr.resolve("$LC{JAVA_HOME} $UC{$E{JAVA_HOME}}")); 050 051 // $LN{arg[,delimiter]} length var example 052 System.out.println(vr.resolve("parts = $LN{$S{os.version},.}, charcount = $LN{$S{os.version}}")); 053 054 // $ST{arg,start[,end]} substring var example 055 System.out.println(vr.resolve("version = $ST{$S{java.version}, 0, 3}")); 056 057 // $PE{arg,start[,end]} pattern extractor var example 058 System.out.println(vr.resolve("update = $PE{$S{java.version},_([0-9]+),1}")); 059 060 /* 061 * See all supported variable types at, 062 * http://juneau.apache.org/site/apidocs-8.0.0/overview-summary.html#juneau-svl 063 * NOTE - juneau-svl supports nested variables well 064 * */ 065 } 066 067}