Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SvlExample for juneau-svl demo #15

Merged
merged 1 commit into from Nov 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
* */
}

}