Apache Velocity #parse a file if it exists - velocity

I'm working with Apache Velocity and I'm trying to include another .vtl file. The problem is that this file is not nessacery to have.
#parse("${PROJECT_NAME}-variables.vtl")
I was hoping I could something like this:
#if(#parse("${PROJECT_NAME}-variables.vtl"))
dostuff
#else
dontdostuff
#end
Can I write an if statement to check if the file exists? Or is there any other alternative?

What I usually do is check that the file exists in Java and set a boolean for my if statement to check.

Related

How to create directory if it doesn't exist?

If I want to write a file to C:/output/results.csv what's a simple way to make the directory if it doesn't exist? I want to do this because CSV.write(path,data) errors if C:/output/ doesn't exist.
mkdir errors if the directory already exists. I am currently doing the following, but is there a safer/cleaner way to do this?
try
mkdir("C:/output")
catch
# if errors, likely already exists
end
Edit:
As one of the commenters pointed out, mkpath will create a directory if it doesn't exist, and in either case will return the directory name.
My question was confounding the usage of mkdir (which errors if directory exists) and mkpath which does not error in that case.
You could explicitly check whether the directory exists beforehand using isdir:
isdir(dir) || mkdir(dir)
CSV.write(joinpath(dir, "results.csv"), data)
But this will not necessarily handle all corner cases, like when the path already exists but is a link to another directory. The mkpath function in the standard library should handle everything for you:
mkpath(path)
CSV.write(joinpath(path, "results.csv"), data)
mkpath(oath) will create a directory if it does not exist and return the path after doing so. If it already exists, the path is returned.

is there any way to splitting Variables in VSCode?

I wonder there is any way to splitting some variables in VSCode?
my example will explain my question better:
I have an exe file in such path C:\path\to\workspace\main\project\project.exe
my cpp source path that will create exe file is this C:\path\to\workspace\main\project\test.cpp
I want to create a task in tasks.json but my oder of variables does not give me the right path
as you understand:
${workspaceFolder} is C:\path\to\workspace
${fileDirname} returns C:\path\to\workspace\main\project
and ${relativeFileDirname}.exe returns main\project.exe
and combination of "${fileDirname}\\${relativeFileDirname}.exe" as a command will return C:\path\to\workspace\main\project\main\project.exe that is wrong.
so I wanted to know there is any other variable that just return the parent of current file or not?
if not can we split variables with \ ?
I hope it makes some sense
thanks
Add new fileDirnameBasename variable
see https://github.com/microsoft/vscode/commit/551db7ec94f02a4bdc8999092cf8bef642b3992d
${fileDirnameBasename} is being added to vscode v1.52 which I believe is what you are looking for.
You can use the extension Command Variable
Use the commands:
extension.commandvariable.file.fileDirBasename
extension.commandvariable.file.fileDirBasename1Up
extension.commandvariable.file.fileDirBasename2Up
btw, as an workaround, this worked for me
"${fileDirname}\\*.exe"
but need a variable for getting parent folder of current open file
any idea?

How do i set working directory in sql developer in code

I'm using sql developer.
I want to run some scripts.
I don't want to have to include the folder name in the call to each script.
But I also want to use a variable to include the directory to look in (the working directory).
I can do this but i am having trouble with folder names with spaces (this is in windows).
Can anyone help me work out how to do this without having to rename my folder to remove spaces?
define dir="c:\Users\xx\Google Drive\Analytics\Recruitment\NSL\2. Data Understanding\Code"
#&dir\cb_nsl_impairments.sql;
Returns error
SP2-0310: Unable to open file: "c:\Users\xx\Google.sql"
Oops. Solved it.
Just needed double quotes around the script call:
#"&dir\cb_nsl_impairments.sql"

Apache - Custom Handler

Please consider the following 2 example lines from an Apache config file:
Action xyzHandler /cgi-bin/xyzHandler
AddHandler xyzHandler .xyz
I understand that the effect of the above 2 lines is to "map" files that end with a .xyz extension to the executable /cgi-bin/xyzHandler. I would like to better understand what is meant meant by the term, "map". Does it mean that the contents of the file ending with a .xyz extension is applied to the standard input of /cgi-bin/xyzHandler? Does it mean that a path to the file ending in the .xyz extension is passed as an argument to /cgi-bin/xyzHandler? Does it mean something else? What exactly does it mean?
Thanks for any input.
... doug
In case anyone is interested, it turns out that this question is answered here: http://httpd.apache.org/docs/2.2/mod/mod_actions.html. In a nutshell, the answer is this: The /cgi-bin/xyzHandler script is simply executed. A path to the file ending with a .xyz extension that triggered the execution is made available via the standard CGI PATH_INFO and PATH_TRANSLATED environment variables. Thanks to all for your indulgence.
... doug

Pass parameter to SQL file from within another SQL file

I thought for sure there would be an SO question on this, but I haven't been able to find one.
I have 2 SQL files, myFile1.sql and myFile2.sql. myFile1.sql calls myFile2.sql like so:
-- In myFile1.sql:
#scripts/myFile2
This works with no problem, but now I'd like to pass an argument to the file. I've tried doing the following, with no success (results in a File Not Found exception):
#scripts/myFile2 'ImAnArgument'
Does anyone know what the syntax would be to do this?
I'm guessing your problem is that scripts/myFile2.sql is a relative path from the script it is located in. If that is so, then it is following that path from the directory where SQL*Plus was started (the current working directory). If this is the problem, then it's not the parameter that is the issue, but rather that SQL*Plus can't find the file. In this case, you should use ##, which invokes the path relative to the file it's located in.
The parameter should work just as you proposed (documentation). Parameters provided when invoking a file are placed into substitution variables (rather than bind variables) and can be referenced by using an ampersand followed by the argument number. In your example, 'ImAnArgument' would be &1.
After many attempts, I wasn't able to pass a parameter in (and I still don't understand why not). But here is what I did to get the same affect:
-- In myFile1.sql:
DEFINE my_arg = 'ImAnArgument';
#scripts/myFile2
Then
-- In myFile2.sql
-- Do stuff using the variable my_arg, such as
SELECT my_arg FROM my_table;