Esempio n. 1
0
        /// <summary> Creates a new <code>DatabaseType</code>.
        /// 
        /// </summary>
        /// <param name="databaseType">the type of database
        /// </param>
        public DatabaseType(System.String databaseType)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            string resourceName = string.Format("AutopatchNet.{0}.resources", databaseType.ToLower());
            System.IO.Stream rs = assembly.GetManifestResourceStream(resourceName);
            if (rs == null)
            {
                throw new System.ArgumentException("Could not find SQL resources file for database '" + databaseType + "'; make sure that there is a '" + databaseType.ToLower() + ".resources' file in package.");
            }
            try
            {
                ResourceReader reader = new ResourceReader(rs);
                IDictionaryEnumerator en = reader.GetEnumerator();
                while(en.MoveNext())
                {
                    string sqlkey = (string)en.Key;
                    string sql = (string)en.Value;
                    properties.Add(sqlkey, sql);
                }

                reader.Close();
            }
            catch (System.IO.IOException e)
            {
                throw new System.ArgumentException("Could not read SQL resources file for database '" + databaseType + "'.", e);
            }
            finally
            {
                rs.Close();
            }

            this.databaseType = databaseType;
        }
Esempio n. 2
0
		/// <summary> Stemms the given term to an unique <tt>discriminator</tt>.
		/// 
		/// </summary>
		/// <param name="term"> The term that should be stemmed.
		/// </param>
		/// <returns>      Discriminator for <tt>term</tt>
		/// </returns>
		protected internal virtual System.String Stem(System.String term)
		{
			// Use lowercase for medium stemming.
			term = term.ToLower();
			if (!IsStemmable(term))
				return term;
			// Reset the StringBuffer.
			sb.Remove(0, sb.Length - 0);
			sb.Insert(0, term);
			// Stemming starts here...
			Substitute(sb);
			Strip(sb);
			Optimize(sb);
			Resubstitute(sb);
			RemoveParticleDenotion(sb);
			return sb.ToString();
		}
Esempio n. 3
0
 /// <summary> Resolves SYSTEM and PUBLIC identifiers for CML DTDs.
 /// 
 /// </summary>
 /// <param name="publicId">the PUBLIC identifier of the DTD (unused)
 /// </param>
 /// <param name="systemId">the SYSTEM identifier of the DTD
 /// </param>
 /// <returns> the CML DTD as an InputSource or null if id's unresolvable
 /// </returns>
 public virtual XmlSourceSupport resolveEntity(System.String publicId, System.String systemId)
 {
     //logger.debug("CMLResolver: resolving ", publicId, ", ", systemId);
     systemId = systemId.ToLower();
     if ((systemId.IndexOf("cml-1999-05-15.dtd") != -1) || (systemId.IndexOf("cml.dtd") != -1) || (systemId.IndexOf("cml1_0.dtd") != -1))
     {
         //logger.info("File has CML 1.0 DTD");
         return getCMLType("cml1_0.dtd");
     }
     else if ((systemId.IndexOf("cml-2001-04-06.dtd") != -1) || (systemId.IndexOf("cml1_0_1.dtd") != -1) || (systemId.IndexOf("cml_1_0_1.dtd") != -1))
     {
         //logger.info("File has CML 1.0.1 DTD");
         return getCMLType("cml1_0_1.dtd");
     }
     else
     {
         //logger.warn("Could not resolve systemID: ", systemId);
         return null;
     }
 }
Esempio n. 4
0
        /// <summary> Determines whether the given property value is valid according to this
        /// validator's policy.
        /// 
        /// </summary>
        /// <param name="property">the object representation of the property and its associated
        /// policy
        /// </param>
        /// <param name="value">the string representation of the value
        /// </param>
        /// <returns> true if the property is valid; false otherwise
        /// </returns>
        private bool validateValue(Property property, System.String value_Renamed)
        {
            bool isValid = false;

            // normalize the value to lowercase
            value_Renamed = value_Renamed.ToLower();

            // check if the value matches any of the allowed literal values
            System.Collections.IEnumerator allowedValues = property.AllowedValues.GetEnumerator();
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            while (allowedValues.MoveNext() && !isValid)
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                System.String allowedValue = (System.String)allowedValues.Current;

                if (allowedValue != null && allowedValue.Equals(value_Renamed))
                {
                    isValid = true;
                }
            }

            // check if the value matches any of the allowed regular expressions
            System.Collections.IEnumerator allowedRegexps = property.AllowedRegExp.GetEnumerator();
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            while (allowedRegexps.MoveNext() && !isValid)
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                //Pattern pattern = (Pattern)allowedRegexps.Current;

                //if (pattern != null && pattern.matcher(value_Renamed).matches())
                //{
                //    isValid = true;
                //}
            }

            // check if the value matches any of the allowed shorthands
            IEnumerator shorthandRefs = property.ShorthandRefs.GetEnumerator();
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            while (shorthandRefs.MoveNext() && !isValid)
            {
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                string shorthandRef = (string)shorthandRefs.Current;
                Property shorthand = policy.getPropertyByName(shorthandRef);

                if (shorthand != null)
                {
                    isValid = validateValue(shorthand, value_Renamed);
                }
            }

            return isValid;
        }
 /// <summary> Returns true if the given dictionary contains the given
 /// entry.
 /// </summary>
 public virtual bool hasEntry(System.String dictName, System.String entryID)
 {
     if (hasDictionary(dictName))
     {
         Dictionary dictionary = (Dictionary)dictionaries[dictName];
         return dictionary.hasEntry(entryID.ToLower());
     }
     else
     {
         return false;
     }
 }
 /// <summary> Returns true if the database contains the dictionary.</summary>
 public virtual bool hasDictionary(System.String name)
 {
     return dictionaries.ContainsKey(name.ToLower());
 }
Esempio n. 7
0
 public Entry(System.String id, System.String term)
 {
     this.id = id.ToLower();
     this.label = term;
     this.descriptorInfo = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
 }
Esempio n. 8
0
		private System.String getProperty (  System.String name ) {
			System.String Value=null;
			name = name.ToLower();
			this.parse();
			if ( this.headers!=null && this.headers.Count > 0 && name!=null && name.Length>0 && this.headers.Contains(name) )
				Value = this.headers[name].ToString();
			return Value;
		}
Esempio n. 9
0
		/// <summary> Factory method for generating a query (similar to
		/// {@link #getWildcardQuery}). Called when parser parses an input term
		/// token that uses prefix notation; that is, contains a single '*' wildcard
		/// character as its last character. Since this is a special case
		/// of generic wildcard term, and such a query can be optimized easily,
		/// this usually results in a different query object.
		/// <p>
		/// Depending on settings, a prefix term may be lower-cased
		/// automatically. It will not go through the default Analyzer,
		/// however, since normal Analyzers are unlikely to work properly
		/// with wildcard templates.
		/// <p>
		/// Can be overridden by extending classes, to provide custom handling for
		/// wild card queries, which may be necessary due to missing analyzer calls.
		/// 
		/// </summary>
		/// <param name="field">Name of the field query will use.
		/// </param>
		/// <param name="termStr">Term token to use for building term for the query
		/// (<b>without</b> trailing '*' character!)
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		protected internal virtual Query GetPrefixQuery(System.String field, System.String termStr)
		{
			if (lowercaseExpandedTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return new PrefixQuery(t);
		}
Esempio n. 10
0
        /*
        * Method AuthenticateSASLOTPWithInit is like the others, except
        * that is actually forces the server (if authentication succeeds)
        * to update the OTP db for this user.
        *
        * If you want to do that (I recommend it, then use the NEXT one).
        *
        * @param Session session is the session the user is authenticating on,
        * in other words, represents the peer we want to authenticate to.
        * @param String authorizeId is the identity this peer wants to be
        *               authorized to act as.
        * @param String authenticateId is the identity this peer will
        *               authenticate as
        * @param String pwd is the passphrase to authenticate with (it isn't
        * stored or kept around very long at all, it's only used in computation).
        *
        * @param String newSequence String representation of the new Sequence
        *               integer
        * @param String newAlgorithm name of the algorithm in the new OTP DB
        * @param String newSeed value of the seed in the new OTP DB
        * @param String newHas value of the lastHash in the new OTP DB
        *
        *
        * @throws SASLException if any issue is encountered (usually
        * rejection by the other peer).
        */
        public static Session AuthenticateSASLOTPWithInit(Session session, System.String authorizeId, System.String authenticateId, System.String pwd, System.String newAlgorithm, System.String newHash, System.String newSeed, System.String newSequence)
        {
            bool success = false;

            // Test the values
            convertHexToBytes(newHash);
            newSeed = newSeed.ToLower();

            if (!OTPGenerator.validateSeed(newSeed) || !OTPGenerator.validatePassphrase(pwd) || !OTPGenerator.validateSequence(newSequence))
                throw new SASLException("Unsuitable values for the parameters to init-hex");

            // @todo bad toad - clean this up with tuning move
            clearCredential(session, null);

            OTPAuthenticator auth = SASLOTPProfile.instance().startAuthentication(authorizeId, authenticateId, pwd, newAlgorithm, newHash, newSeed, newSequence);
            Channel ch = null;
            System.String startData = null;
            try
            {
                ch = session.startChannel(SASLOTPProfile.URI, auth);
                startData = ch.StartData;
            }
            catch (BEEPException x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                auth.abort(x.Message);
            }

            // @todo EITHER use the Session Event Mechanism once it's detached from
            // the session I/O thread via the Channel Message (EVENT) Queues...
            // OR
            // Embed some tuning profile logic in ChannelZero (hacky) to address stuff.
            // For now, this is ok, the only thread blocked is the users, and it waits
            // until the Authentication succeeds or fails.
            Blob blob = null;

            if ((System.Object) startData != null)
            {
                blob = new Blob(startData);
                if (blob.Status.Equals(SASL_STATUS_ABORT))
                    throw new SASLException(ERR_REJECTED);
            }

            auth.started(ch);
            auth.sendIdentity(authorizeId, authenticateId);

            // We'll get notified when either
            // (a) An Error Occurs
            // (b) The authentication succeeds
            // Everything else from here on out is basically on autopilot
            try
            {
                lock (auth)
                {
                    System.Threading.Monitor.Wait(auth);

                    SessionCredential cred = session.getLocalCredential();

                    if (cred == null)
                    {
                        auth.abort("Authentication Failed");
                    }
                    else
                    {
                        success = true;
                    }
                }
            }
            catch (System.Exception x)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                auth.abort(x.Message);
            }

            return session;
        }
Esempio n. 11
0
		/// <summary> Factory method for generating a query (similar to
		/// {@link #getWildcardQuery}). Called when parser parses an input term
		/// token that uses prefix notation; that is, contains a single '*' wildcard
		/// character as its last character. Since this is a special case
		/// of generic wildcard term, and such a query can be optimized easily,
		/// this usually results in a different query object.
		/// <p/>
		/// Depending on settings, a prefix term may be lower-cased
		/// automatically. It will not go through the default Analyzer,
		/// however, since normal Analyzers are unlikely to work properly
		/// with wildcard templates.
		/// <p/>
		/// Can be overridden by extending classes, to provide custom handling for
		/// wild card queries, which may be necessary due to missing analyzer calls.
		/// 
		/// </summary>
		/// <param name="field">Name of the field query will use.
		/// </param>
		/// <param name="termStr">Term token to use for building term for the query
		/// (<b>without</b> trailing '*' character!)
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		public /*protected internal*/ virtual Query GetPrefixQuery(System.String field, System.String termStr)
		{
			if (!allowLeadingWildcard && termStr.StartsWith("*"))
				throw new ParseException("'*' not allowed as first character in PrefixQuery");
			if (lowercaseExpandedTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return NewPrefixQuery(t);
		}
Esempio n. 12
0
 /// <summary> Method generateHash generate a hash value using the appropriate
 /// hash function.
 /// 
 /// </summary>
 /// <param name="s">The data to be hashed
 /// </param>
 /// <returns> byte[] the hash value in binary form.
 /// 
 /// @throws SASLException if an error is encountered during the 
 /// generation of hte hash.
 /// 
 /// </returns>
 public virtual sbyte[] generateHash(System.String s)
 {
     return generateHash(SupportClass.ToSByteArray(SupportClass.ToByteArray(s.ToLower()))); ///@TODO use encoding
 }
Esempio n. 13
0
 private static void FixVarType(ref System.String vartype)
 {
     if (string.Compare(vartype, "float", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "float array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "float []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "float array";
     else if (string.Compare(vartype, "float[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "float array";
     else if (string.Compare(vartype, "int", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "int array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "int []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "int array";
     else if (string.Compare(vartype, "int[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "int array";
     else if (string.Compare(vartype, "boolean", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "bool";
     else if (string.Compare(vartype, "boolean array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "bool array";
     else if (string.Compare(vartype, "boolean []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "bool array";
     else if (string.Compare(vartype, "boolean[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "bool array";
     else if (string.Compare(vartype, "bool", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "bool array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "bool []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "bool array";
     else if (string.Compare(vartype, "bool[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "bool array";
     else if (string.Compare(vartype, "char", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "byte", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "byte array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "byte []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "byte array";
     else if (string.Compare(vartype, "byte[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "byte array";
     else if (string.Compare(vartype, "string", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "string array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = vartype.ToLower();
     else if (string.Compare(vartype, "string []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "string array";
     else if (string.Compare(vartype, "string[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "string array";
     else if (string.Compare(vartype, "vector2", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector2";
     else if (string.Compare(vartype, "vector2 array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector2 array";
     else if (string.Compare(vartype, "vector2 []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector2 array";
     else if (string.Compare(vartype, "vector2[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector2 array";
     else if (string.Compare(vartype, "vector3", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3";
     else if (string.Compare(vartype, "vector3 array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3 array";
     else if (string.Compare(vartype, "vector3 []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3 array";
     else if (string.Compare(vartype, "vector3[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3 array";
     else if (string.Compare(vartype, "vector", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3";
     else if (string.Compare(vartype, "vector array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3 array";
     else if (string.Compare(vartype, "vector []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3 array";
     else if (string.Compare(vartype, "vector[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Vector3 array";
     else if (string.Compare(vartype, "color", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color";
     else if (string.Compare(vartype, "color array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color array";
     else if (string.Compare(vartype, "color []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color array";
     else if (string.Compare(vartype, "color[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color array";
     else if (string.Compare(vartype, "color32", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color32";
     else if (string.Compare(vartype, "color32 array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color32 array";
     else if (string.Compare(vartype, "color32 []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color32 array";
     else if (string.Compare(vartype, "color32[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Color32 array";
     else if (string.Compare(vartype, "quaternion", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion";
     else if (string.Compare(vartype, "quaternion array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion array";
     else if (string.Compare(vartype, "quaternion []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion array";
     else if (string.Compare(vartype, "quaternion[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion array";
     else if (string.Compare(vartype, "quat", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion";
     else if (string.Compare(vartype, "quat array", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion array";
     else if (string.Compare(vartype, "quat []", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion array";
     else if (string.Compare(vartype, "quat[]", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Quaternion array";
     else if (string.Compare(vartype, "ignore", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Ignore";
     else if (string.Compare(vartype, "void", System.StringComparison.InvariantCultureIgnoreCase) == 0)
         vartype = "Ignore";
 }
Esempio n. 14
0
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		protected internal virtual Query GetRangeQuery(System.String field, System.String part1, System.String part2, bool inclusive)
		{
			if (lowercaseExpandedTerms)
			{
				part1 = part1.ToLower();
				part2 = part2.ToLower();
			}
			try
			{
                System.DateTime d1;
                System.DateTime d2;

                try
                {
                    d1 = System.DateTime.Parse(part1, locale);
                }
                catch (System.Exception)
                {
                    d1 = System.DateTime.Parse(part1);
                }
                try
                {
                    d2 = System.DateTime.Parse(part2, locale);
                }
                catch (System.Exception)
                {
                    d2 = System.DateTime.Parse(part2);
                }

                if (inclusive)
                {
                    // The user can only specify the date, not the time, so make sure
                    // the time is set to the latest possible time of that date to really
                    // include all documents:
                    System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar();
                    System.DateTime tempDate = d2;
                    d2 = d2.AddHours(23 - tempDate.Hour);
                    d2 = d2.AddMinutes(59 - tempDate.Minute);
                    d2 = d2.AddSeconds(59 - tempDate.Second);
                    d2 = d2.AddMilliseconds(999 - tempDate.Millisecond);
                }
                part1 = DateField.DateToString(d1);
                part2 = DateField.DateToString(d2);
            }
			catch (System.Exception)
			{
			}
			
			return new RangeQuery(new Term(field, part1), new Term(field, part2), inclusive);
		}
Esempio n. 15
0
		/// <summary> Factory method for generating a query. Called when parser
		/// parses an input term token that contains one or more wildcard
		/// characters (? and *), but is not a prefix term token (one
		/// that has just a single * character at the end)
		/// <p>
		/// Depending on settings, prefix term may be lower-cased
		/// automatically. It will not go through the default Analyzer,
		/// however, since normal Analyzers are unlikely to work properly
		/// with wildcard templates.
		/// <p>
		/// Can be overridden by extending classes, to provide custom handling for
		/// wildcard queries, which may be necessary due to missing analyzer calls.
		/// 
		/// </summary>
		/// <param name="field">Name of the Field query will use.
		/// </param>
		/// <param name="termStr">Term token that contains one or more wild card
		/// characters (? or *), but is not simple prefix term
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref=""> ParseException throw in overridden method to disallow
		/// </exception>
		protected internal virtual Query GetWildcardQuery(System.String field, System.String termStr)
		{
			if (lowercaseWildcardTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return new WildcardQuery(t);
		}
Esempio n. 16
0
        // Used only for init calls
        internal virtual OTPAuthenticator startAuthentication(System.String authorizeId, System.String authenticateId, System.String password, System.String newAlgorithm, System.String newHash, System.String newSeed, System.String newSequence)
        {
            UserDatabase db = userDatabase.getUser(authenticateId);

            if (db == null)
            {
                throw new SASLException("User OTP data not found");
            }

            newSeed = newSeed.ToLower();
            OTPAuthenticator a = new OTPAuthenticator(this, db, password, authorizeId, authenticateId, newAlgorithm, newHash, newSeed, newSequence);
            return a;
        }
Esempio n. 17
0
 /// <summary>
 /// Parse a rfc 2822 header field with parameters
 /// </summary>
 /// <param name="field">field name</param>
 /// <param name="fieldbody">field body to parse</param>
 /// <returns>A <see cref="System.Collections.Specialized.StringDictionary" /> from the parsed field body</returns>
 public static System.Collections.Specialized.StringDictionary parseHeaderFieldBody( System.String field, System.String fieldbody )
 {
     if ( fieldbody==null )
         return null;
     // FIXME: rewrite parseHeaderFieldBody to being regexp based.
     fieldbody = anmar.SharpMimeTools.SharpMimeTools.uncommentString (fieldbody);
     System.Collections.Specialized.StringDictionary fieldbodycol = new System.Collections.Specialized.StringDictionary ();
     System.String[] words = fieldbody.Split(new Char[]{';'});
     if ( words.Length>0 ) {
         fieldbodycol.Add (field.ToLower(), words[0].ToLower());
         for (int i=1; i<words.Length; i++ ) {
             System.String[] param = words[i].Trim(new Char[]{' ', '\t'}).Split(new Char[]{'='}, 2);
             if ( param.Length==2 ) {
                 param[0] = param[0].Trim(new Char[]{' ', '\t'});
                 param[1] = param[1].Trim(new Char[]{' ', '\t'});
                 if ( param[1].StartsWith("\"") && !param[1].EndsWith("\"")) {
                     do {
                         param[1] += ";" + words[++i];
                     } while  ( !words[i].EndsWith("\"") && i<words.Length);
                 }
                 fieldbodycol.Add ( param[0], anmar.SharpMimeTools.SharpMimeTools.parserfc2047Header (param[1].TrimEnd(';').Trim('\"')) );
             }
         }
     }
     return fieldbodycol;
 }
Esempio n. 18
0
 private System.String GetProperty (  System.String name ) {
     System.String Value=null;
     name = name.ToLower();
     this.Parse();
     if (this._headers == null || this._headers.Count <= 0 || name.Length <= 0 ||
         !this._headers.Contains(name))
         Value = _headers[name].ToString();
     return Value;
 }
Esempio n. 19
0
		/// <summary> Factory method for generating a query. Called when parser
		/// parses an input term token that contains one or more wildcard
		/// characters (? and *), but is not a prefix term token (one
		/// that has just a single * character at the end)
		/// <p/>
		/// Depending on settings, prefix term may be lower-cased
		/// automatically. It will not go through the default Analyzer,
		/// however, since normal Analyzers are unlikely to work properly
		/// with wildcard templates.
		/// <p/>
		/// Can be overridden by extending classes, to provide custom handling for
		/// wildcard queries, which may be necessary due to missing analyzer calls.
		/// 
		/// </summary>
		/// <param name="field">Name of the field query will use.
		/// </param>
		/// <param name="termStr">Term token that contains one or more wild card
		/// characters (? or *), but is not simple prefix term
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		public /*protected internal*/ virtual Query GetWildcardQuery(System.String field, System.String termStr)
		{
			if ("*".Equals(field))
			{
				if ("*".Equals(termStr))
					return NewMatchAllDocsQuery();
			}
			if (!allowLeadingWildcard && (termStr.StartsWith("*") || termStr.StartsWith("?")))
				throw new ParseException("'*' or '?' not allowed as first character in WildcardQuery");
			if (lowercaseExpandedTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return NewWildcardQuery(t);
		}
Esempio n. 20
0
		protected new bool IsNoiseWord(System.String term)
		{
			int len = term.Length;
			var minWordLen = GetMinWordLen();
			var maxWordLen = GetMaxWordLen();
			var stopWords = GetStopWords();
			if (minWordLen > 0 && len < minWordLen)
			{
				return true;
			}
			if (maxWordLen > 0 && len > maxWordLen)
			{
				return true;
			}
			if (stopWords != null && stopWords.Contains(term.ToLower()))
			{
				return true;
			}
			return false;
		}
Esempio n. 21
0
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		protected internal virtual Query GetRangeQuery(System.String field, System.String part1, System.String part2, bool inclusive)
		{
			if (lowercaseExpandedTerms)
			{
				part1 = part1.ToLower();
				part2 = part2.ToLower();
			}
            try
            {
                System.DateTime d1;
                System.DateTime d2;

                try
                {
                    d1 = System.DateTime.Parse(part1, locale);
                }
                catch (System.Exception)
                {
                    d1 = System.DateTime.Parse(part1);
                }
                try
                {
                    d2 = System.DateTime.Parse(part2, locale);
                }
                catch (System.Exception)
                {
                    d2 = System.DateTime.Parse(part2);
                }

                if (inclusive)
                {
                    // The user can only specify the date, not the time, so make sure
                    // the time is set to the latest possible time of that date to really
                    // include all documents:
                    System.Globalization.Calendar cal = new System.Globalization.GregorianCalendar();
                    System.DateTime tempDate = d2;
                    d2 = d2.AddHours(23 - tempDate.Hour);
                    d2 = d2.AddMinutes(59 - tempDate.Minute);
                    d2 = d2.AddSeconds(59 - tempDate.Second);
                    d2 = d2.AddMilliseconds(999 - tempDate.Millisecond);
                }
                DateTools.Resolution resolution = GetDateResolution(field);
                if (resolution == null)
                {
                    // no default or field specific date resolution has been set,
					// use deprecated DateField to maintain compatibility with
                    // pre-1.9 Lucene versions.
                    part1 = DateField.DateToString(d1);
                    part2 = DateField.DateToString(d2);
                }
                else
                {
                    part1 = DateTools.DateToString(d1, resolution);
                    part2 = DateTools.DateToString(d2, resolution);
                }
            }
            catch (System.Exception)
            {
            }

            return NewRangeQuery(field, part1, part2, inclusive);
        }
Esempio n. 22
0
		/// <summary> Translates a single string selection into it's internal 0-based equivalent
		/// 
		/// </summary>
		/// <param name="single">the string representing the selection (eg: 1 first last)
		/// </param>
		/// <returns> the number corresponding to the selected value
		/// </returns>
		protected internal virtual int rangeSingle(System.String single)
		{
			
			if (single.ToLower().Equals("first"))
			{
				return 0;
			}
			if (single.ToLower().Equals("last"))
			{
				return m_Upper;
			}
			int index = System.Int32.Parse(single) - 1;
			if (index < 0)
			{
				index = 0;
			}
			if (index > m_Upper)
			{
				index = m_Upper;
			}
			return index;
		}
Esempio n. 23
0
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		protected internal virtual Query GetRangeQuery(System.String field, System.String part1, System.String part2, bool inclusive)
		{
			if (lowercaseExpandedTerms)
			{
				part1 = part1.ToLower();
				part2 = part2.ToLower();
			}
			try
			{
                System.DateTime d1 = System.DateTime.Parse(part1, locale);
                System.DateTime d2 = System.DateTime.Parse(part2, locale);
                part1 = DateField.DateToString(d1);
                part2 = DateField.DateToString(d2);
            }
			catch (System.Exception e)
			{
			}
			
			return new RangeQuery(new Term(field, part1), new Term(field, part2), inclusive);
		}
Esempio n. 24
0
		/// <summary> Determines if a string represents a valid index or simple range.
		/// Examples: <code>first  last   2   first-last  first-4  4-last</code>
		/// Doesn't check that a < b for a-b
		/// 
		/// </summary>
		/// <param name="range">
		/// </param>
		/// <returns> true if the range is valid
		/// </returns>
		protected internal virtual bool isValidRange(System.String range)
		{
			
			if (range == null)
			{
				return false;
			}
			int hyphenIndex;
			if ((hyphenIndex = range.IndexOf('-')) >= 0)
			{
				if (isValidRange(range.Substring(0, (hyphenIndex) - (0))) && isValidRange(range.Substring(hyphenIndex + 1)))
				{
					return true;
				}
				return false;
			}
			if (range.ToLower().Equals("first"))
			{
				return true;
			}
			if (range.ToLower().Equals("last"))
			{
				return true;
			}
			try
			{
				int index = System.Int32.Parse(range);
				if ((index > 0) && (index <= m_Upper + 1))
				{
					return true;
				}
				return false;
			}
			catch (System.FormatException ex)
			{
				return false;
			}
		}
Esempio n. 25
0
		/// <summary> Factory method for generating a query (similar to
		/// {@link #getWildcardQuery}). Called when parser parses
		/// an input term token that has the fuzzy suffix (~) appended.
		/// 
		/// </summary>
		/// <param name="field">Name of the field query will use.
		/// </param>
		/// <param name="termStr">Term token to use for building term for the query
		/// 
		/// </param>
		/// <returns> Resulting {@link Query} built for the term
		/// </returns>
		/// <exception cref="ParseException">throw in overridden method to disallow
		/// </exception>
		protected internal virtual Query GetFuzzyQuery(System.String field, System.String termStr, float minSimilarity)
		{
			if (lowercaseExpandedTerms)
			{
				termStr = termStr.ToLower();
			}
			Term t = new Term(field, termStr);
			return new FuzzyQuery(t, minSimilarity, fuzzyPrefixLength);
		}
 /// <summary> Reads a custom dictionary into the database.</summary>
 //UPGRADE_ISSUE: Class hierarchy differences between 'java.io.Reader' and 'System.IO.StreamReader' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'"
 public virtual void readDictionary(System.IO.StreamReader reader, System.String name)
 {
     name = name.ToLower();
     //logger.debug("Reading dictionary: ", name);
     if (!dictionaries.ContainsKey(name))
     {
         try
         {
             Dictionary dictionary = Dictionary.unmarshal(reader);
             dictionaries[name] = dictionary;
             //logger.debug("  ... loaded and stored");
         }
         catch (System.Exception exception)
         {
             //logger.error("Could not read dictionary: ", name);
             //logger.debug(exception);
         }
     }
     else
     {
         //logger.error("Dictionary already loaded: ", name);
     }
 }
Esempio n. 27
0
        /// <summary>
        /// Parses a number in the specified radix.
        /// </summary>
        /// <param name="s">An input System.String.</param>
        /// <param name="radix">A radix.</param>
        /// <returns>The parsed number in the specified radix.</returns>
        public static long Parse(System.String s, int radix)
        {
            if (s == null)
            {
                throw new ArgumentException("null");
            }

            if (radix < MIN_RADIX)
            {
                throw new NotSupportedException("radix " + radix +
                                                " less than Number.MIN_RADIX");
            }
            if (radix > MAX_RADIX)
            {
                throw new NotSupportedException("radix " + radix +
                                                " greater than Number.MAX_RADIX");
            }

            long result = 0;
            long mult = 1;

            s = s.ToLower();

            for (int i = s.Length - 1; i >= 0; i--)
            {
                int weight = digits.IndexOf(s[i]);
                if (weight == -1)
                    throw new FormatException("Invalid number for the specified radix");

                result += (weight * mult);
                mult *= radix;
            }

            return result;
        }
Esempio n. 28
0
 // Weird init version
 internal OTPAuthenticator(SASLOTPProfile otpProfile, UserDatabase db, System.String pwd, System.String authorizedId, System.String authenticateId, System.String newAlgorithm, System.String newHash, System.String newSeed, System.String newSequence)
 {
     InitBlock();
     System.Text.StringBuilder sb = new System.Text.StringBuilder(128);
     sb.Append(COLON);
     sb.Append(newAlgorithm);
     sb.Append(SPACE);
     sb.Append(newSequence);
     sb.Append(SPACE);
     sb.Append(newSeed.ToLower());
     sb.Append(COLON);
     sb.Append(newHash);
     initData = sb.ToString();
     init(otpProfile, db, pwd, authorizedId, authenticateId);
 }