public class FileRestrictions extends Object
#loadRestrictions(InputStream)
method and can be tested against by using the #isAllowed(VirtualFile)
method.
The XML file schema is: <root> <variables> <variable name="variable-name"> <type>INT-or-STRING</type> <value>variable-value</value> <precision> <locations>number-of-fill-locations</locations> <fill>fill-value</fill> <side>front-or-back</side> </precision> </variable> ... ... </variables> <methods> <method name="method-name"> <args> <arg name="argument-name"> <type>INT-or-STRING</type> </arg> ... ... </args> <action>method-behavior</action> </method> ... ... </methods> <dirstruct name="root-directory-name"> <nodirs/> <nofiles/> <file name="file-name"/> <dir name="directory-name"> <nodirs/> <nofiles/> <file name="file-name"/> <dir name="directory-name"> ... ... </dir> </dir> ... ... </dirstruct> </root><variables> and <methods> can be created in this XML file so that they can be used in the <dirstruct> portion of the XML file. These <variables> and <methods> can be used inside the <dir> and <file> elements within the <dirstruct> element to allow for varrying directory and file names beyond the capability of regular expressions (which are also allowed).
<variable name="myVariable"> <type>INT</type> <value>3</value> </variable>When myVariable was finally returned it would look like 3, however many times for dates you would like 03 returned. You can specify this by adding precision to the following XML:
<variable name="myVariable"> <type>INT</type> <value>3</value> <precision> <locations>2</locations> <fill>0</fill> <side>front</side> </precision> </variable>This insures that the number is always printed with 2 digits and if the number does not take up 2 digits worth of space a fill value 0 will be added to the front side of the integer, thus, in this example would give us 03. Note: <value>03</value> would NOT accomplish the same!!!!
NOTE: When passing arguments into methods the string and integer literal rules do not need to be followed because you have already defined what each argument type should be and they will be evaluated as such.
NOTE*: Also note that at present a <variable> cannot be passed as an argument to the methods. Just use the <variable> where needed inside the <action> element. This feature should hopefully be added in a later release.
-parent -child1 -grandChild1 -greatGrandChild1 -file1 -greatGrandChild2 -grandChild2 -file1 -child2 -file1 -child3 -file1 -file2 -grandChild1 -file1 -file2 -child4Now, say, we only are interested in directories and files below the two shown 'grandChild1' directories. This would mean that for our <dirstruct> 'name' parameter we would put name="parent". This is because we need access to both 'child1' and 'child3' subdirectories. Now in order to avoid crawling 'child2' and 'child4' directories we have to specify <dir> elements. This would give us the following XML:
<dirstruct name="/parent"> <dir name="child1"/> <dir name="child3"/> </dirstruct>This would restrict the directories allowed under 'parent' to only be directories with names either 'child1' or 'child3', all other directory names will be rejected. However, more must be added to this example because we have not yet specified any restrictions on files allowed beneath 'parent', we have to add the <nofiles/> element:
<dirstruct name="/parent"> <nofiles/> <dir name="child1"/> <dir name="child3"/> </dirstruct>Now the only thing acceptable below parent is 'child1' and 'child3'. We have to still further our restrictions under 'child1' and 'child3'. Since under 'child1' we only want 'grandChild1' we would have to make another <dir> element and also add a <nofiles/> element:
<dirstruct name="/parent"> <nofiles/> <dir name="child1"> <nofiles/> <dir name="grandChild1"/> </dir> <dir name="child3"/> </dirstruct>We have to do the same also for 'child3', giving us:
<dirstruct name="/parent"> <nofiles/> <dir name="child1"> <nofiles/> <dir name="grandChild1"/> </dir> <dir name="child3"> <nofiles/> <dir name="grandChild1"/> </dir> </dirstruct>From the example directory structure above, with this XML file specified, that directory structure would be limited to:
-parent -child1 -grandChild1 -greatGrandChild1 -file1 -greatGrandChild2 -child3 -grandChild1 -file1 -file2Say we now decide that we only want files below the two 'grandChild1' directories -- that is, no directories. So we would change or XML by adding in the <nodir/> element:
<dirstruct name="/parent"> <nofiles/> <dir name="child1"> <nofiles/> <dir name="grandChild1"> <nodirs/> </dir> </dir> <dir name="child3"> <nofiles/> <dir name="grandChild1"> <nodirs/> </dir> </dir> </dirstruct>Which now restricts our directory structure to:
-parent -child1 -grandChild1 -child3 -grandChild1 -file1 -file2Let's further specify now that we only want 'file1' in the '/parent/child3/grandChild1' directory. This would change the XML to:
<dirstruct name="/parent"> <nofiles/> <dir name="child1"> <nofiles/> <dir name="grandChild1"> <nodirs/> </dir> </dir> <dir name="child3"> <nofiles/> <dir name="grandChild1"> <nodirs/> <file name="file1"/> </dir> </dir> </dirstruct>Our new allowed directory structure would now be:
-parent -child1 -grandChild1 -child3 -grandChild1 -file1NOTES: -You would not want to use the <nofiles/> and <file> elements in the same directory (same goes for the <nodirs/> and <dir> elements) because you would be specifying that you don't want any files in that directory, and then contradict yourself by specifying a <file> element that is okay to have. The <file> element states that no other file but the file I specified is allowed. The only exception is if you have two or more <file> elements in the same directory -- this is allowed. It follows the same rules as the <dir> element in the example given above where only 'child1' and 'child3' were allow. The two don't cancel each other out.
<dirstruct name="/.../temp/test"> <nofiles/> <dir name="\d{4}-\d{2}-\d{2}"> <nodirs/> </dir> </dirstruct>This would restrict the directory files in directories below /.../temp/test to only directories whose names are dates of the format: YYYY-MM-DD.
[DATE.DAY] - day of today's date [DATE.MONTH] - month of today's date [DATE.YEAR] - year of today's date [DATE-N.DAY] - the day of the date N days ago [DATE-N.MONTH] - the month of the date N days ago [DATE-N.YEAR] - the year of the date N days ago [DATE+N.DAY] - the day of the date N days from now [DATE+N.MONTH] - the month of the date N days from now [DATE+N.YEAR] - the year of the date N days from now -sorry, no DayOfYear implemented yet -- hopefully in a later releaseUsage:
<root> <variables> <variable name="todaysDay"> <type>INT</type> <value>[DATE.DAY]</value> <precision> <locations>2</locations> <fill>0</fill> <side>front</side> </precision> </variable> </variabls> <dirstruct name="/path/to/parent/dir"> <nofiles/> <dir name="MyFiles"> <nodirs/> <file name="MyPaper_${todaysDay}"/> </dir> </dirstruct> </root>This would allow only a file in /path/to/parent/dir/MyFiles which had the name which started with MyPaper_ and ended with the day of the current day of the month. For example, if to days date was 03/23/2005, then the file name allowed would be MyPaper_23.
<root> <variables> <variable name="DAY"> <type>INT</type> <value>[DATE.DAY]</value> <precision> <locations>2</locations> <fill>0</fill> <side>front</side> </precision> </variable> <variable name="MONTH"> <type>INT</type> <value>[DATE.MONTH]</value> <precision> <locations>2</locations> <fill>0</fill> <side>front</side> </precision> </variable> <variable name="YEAR"> <type>INT</type> <value>[DATE.YEAR]</value> </variable> </variables> <methods> <method name="ADD"> <args> <arg name="1"> <type>INT</type> </arg> </args> <action>"THE_YEAR_PLUS_"+$1+": "+(${YEAR}+$1)</action> </method> <method name="HOW_OLD_AM_I"> <action>${YEAR}-#1984</action> </method> <method name="DATE"> <action>${YEAR}+"-"+${MONTH}+"-"+${DAY}</action> </method> </methods> <dirstruct name="/path/to/parent/dir"> <nofiles/> <dir name="AGE_%HOW_OLD_AM_I()"/> <dir name="DATE"> <nodirs/> <file name="%ADD(5)"/> </dir> </dirstruct> </root>This would accept only the directories under /path/to/parent/dir which had the name (given today is 9/7/2007) 'AGE_23' or '2007-09-07'. This would allow any file or directory in under 'AGE_23', but would only allow a file with the name 'THE_YEAR_PLUS_5: 2012' in the directory '2007-09-07'.
Modifier and Type | Method and Description |
---|---|
static boolean |
isAllowed(ProtocolPath path,
VirtualFile root) |
static boolean |
isAllowed(VirtualFile file,
VirtualFile root) |
static LinkedList<String> |
toStringList(VirtualFile root) |
public static boolean isAllowed(ProtocolPath path, VirtualFile root)
path
- public static boolean isAllowed(VirtualFile file, VirtualFile root)
public static LinkedList<String> toStringList(VirtualFile root)
Copyright © 1999-2014 Apache OODT. All Rights Reserved.