[jboss-identity-commits] JBoss Identity SVN: r189 - identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util.
jboss-identity-commits at lists.jboss.org
jboss-identity-commits at lists.jboss.org
Tue Jan 6 20:51:06 EST 2009
Author: anil.saldhana at jboss.com
Date: 2009-01-06 20:51:05 -0500 (Tue, 06 Jan 2009)
New Revision: 189
Added:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/XMLTimeUtil.java
Log:
util for xml time
Added: identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/XMLTimeUtil.java
===================================================================
--- identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/XMLTimeUtil.java (rev 0)
+++ identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/XMLTimeUtil.java 2009-01-07 01:51:05 UTC (rev 189)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.identity.federation.core.saml.v2.util;
+
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+import javax.xml.datatype.DatatypeConstants;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+/**
+ * Util class dealing with xml based time
+ * @author Anil.Saldhana at redhat.com
+ * @since Jan 6, 2009
+ */
+public class XMLTimeUtil
+{
+ /**
+ * Add additional time in miliseconds
+ * @param value calendar whose value needs to be updated
+ * @param milis
+ * @return calendar value with the addition
+ * @throws Exception
+ */
+ public static XMLGregorianCalendar add(XMLGregorianCalendar value, long milis) throws Exception
+ {
+ XMLGregorianCalendar newVal = (XMLGregorianCalendar) value.clone();
+
+ Duration duration = DatatypeFactory.newInstance().newDuration(milis);
+ newVal.add(duration);
+ return newVal;
+ }
+
+ /**
+ * Returns a XMLGregorianCalendar in the timezone specified.
+ * If the timezone is not valid, then the timezone falls back
+ * to "GMT"
+ * @param timezone
+ * @return
+ * @throws Exception
+ */
+ public static XMLGregorianCalendar getIssueInstant(String timezone) throws Exception
+ {
+ TimeZone tz = TimeZone.getTimeZone(timezone);
+ DatatypeFactory dtf = DatatypeFactory.newInstance();
+
+ GregorianCalendar gc = new GregorianCalendar(tz);
+ XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar(gc);
+
+ return xgc;
+ }
+
+ /**
+ * Get the current instant of time
+ * @return
+ */
+ public static XMLGregorianCalendar getIssueInstant() throws Exception
+ {
+ return getIssueInstant(TimeZone.getDefault().getID());
+ }
+
+ /**
+ * Convert the minutes into miliseconds
+ * @param valueInMins
+ * @return
+ */
+ public static long inMilis(int valueInMins)
+ {
+ return valueInMins * 60 * 1000;
+ }
+
+ /**
+ * Validate that the current time falls between the two boundaries
+ * @param now
+ * @param notbefore
+ * @param notOnOrAfter
+ * @return
+ */
+ public static boolean isValid(XMLGregorianCalendar now,
+ XMLGregorianCalendar notbefore, XMLGregorianCalendar notOnOrAfter)
+ {
+ int val = notbefore.compare(now);
+
+ if(val == DatatypeConstants.INDETERMINATE || val == DatatypeConstants.GREATER)
+ return false;
+
+ val = notOnOrAfter.compare(now);
+ if(val == DatatypeConstants.INDETERMINATE || val == DatatypeConstants.LESSER)
+ return false;
+ return true;
+ }
+}
\ No newline at end of file
More information about the jboss-identity-commits
mailing list