📄 time.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package issrg.pba.rbac;
/**
* This is an extension for evaluating Time expressions in the XML Policy.
*
* <p>The Policy must contain Const values of type "Time". The values must
* conform to the
* following syntax: "ccyy-mm-ddThh:mm:ss" (like in Validity elements in XML
* Policy). Thus
* the time can be specified up to the seconds.
* The year should always have 4 digits. Other fields do not need to have 2
* digits, if they represent
* numbers less than 10. "*" asterisc can be used as a wildcard to represent
* "any value" at that position. Trailing fields can be omitted and their
* values will be considered 0.
*
* <p>Examples:
* <p><code><Constant Type="Time" Value="*-*-*T8:20" /></code>
* <p>The example matches 08:20:00 in the morning any day
* <p><code><Constant Type="Time" Value="*-*-*T8:20:*" /></code>
* <p>The above matches any second after 08:20:00 and before 08:21:00 in the
* morning any day. This is
* different from the above example in that it matches ANY second, i.e. the
* whole minute up to 8:21, whilst
* the previous example specifies exact time of day (8:20:00).
* <p><code><Constant Type="Time" Value="*-1-*T20" /></code>
* <p>This example matches 8pm any day throughout January.
* <p><code><Constant Type="Time" Value="*-1" /></code>
* <p>This example matches midnight any day through January.
*
* <p>The extension has been provided in PBA v1.1.
*/
public class Time {
public static final String TIME_TYPE="Time";
private final int [] time=new int[]{-1, -1, -1,
// -1, // the fourth was for the weekday
-1, -1, -1};
public static void register(){
issrg.pba.rbac.xmlpolicy
.ifstatement.Types.registerType(TIME_TYPE, Time.class);
}
protected Time(){}
/**
* This constructor builds a Time object out of its string representation
*
* @param timeString - the String in the format explained above.
*/
public Time(String timeString) throws IllegalArgumentException {
String d="--T::\""; // the last character is always there to ensure that the last number is parsed, too
String s;
int i;
for (int j=0; j<d.length(); j++){
s=timeString;
i=timeString.indexOf(d.charAt(j));
if (i>=0){
s=timeString.substring(0, i);
timeString=timeString.substring(i+1);
}else{
timeString=""; // that's it, since no more delimiters found, no more time components are there
}
try{
time[j]=s.intern()=="*"?-1:s.intern()==""?0:Integer.parseInt(s);
}catch (NumberFormatException nfe){
throw new IllegalArgumentException("Date format error: "+nfe.getMessage());
}
}
//System.out.println("parsed time: "+time[0]+"."+time[1]+"."+time[2]+", "+time[3]+":"+time[4]+":"+time[5]);//*************
}
/**
* Returns an array of integers representing the year, month, day
* hour, minute, second. If the value of the array element
* is -1, then the value is not specified ("don't care" when comparing)
*
* @return array of integers, each element standing for y,m,d,h,m,s
*/
public int [] getEvaluationTime(){
return time;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -