Beispiel #1
0
        public void write(Collection collection, Local file)
        {
            XmlDocument plistDocument = GetPlistDocument();
            XmlNode plistElement = plistDocument.LastChild;
            XmlNode arrayElement = plistDocument.CreateElement("array");
            plistElement.AppendChild(arrayElement);

            for (Iterator i = collection.iterator(); i.hasNext();)
            {
                Serializable s = (Serializable) i.next();
                XmlNode impNode = plistDocument.ImportNode((XmlNode) s.getAsDictionary(), true);
                arrayElement.AppendChild(impNode);
            }
            plistDocument.Save(file.getAbsolute());
        }
Beispiel #2
0
        /// <summary>
        /// Convert a java list to a generic collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="applyPerItem">Apply this delegate to all list items before adding</param>
        /// <returns>A List<typeparamref name="T"/></returns>
        public static IList <T> ConvertFromJavaList <T>(Collection collection, ApplyPerItemReverseDelegate <T> applyPerItem)
        {
            List <T> result = new List <T>(collection.size());

            for (Iterator iterator = collection.iterator(); iterator.hasNext();)
            {
                Object next = iterator.next();
                if (null != applyPerItem)
                {
                    result.Add(applyPerItem(next));
                    continue;
                }
                result.Add((T)next);
            }
            return(result);
        }
Beispiel #3
0
        public void write(Collection collection, Local file)
        {
            XmlDocument plistDocument = GetPlistDocument();
            XmlNode     plistElement  = plistDocument.LastChild;
            XmlNode     arrayElement  = plistDocument.CreateElement("array");

            plistElement.AppendChild(arrayElement);

            for (Iterator i = collection.iterator(); i.hasNext();)
            {
                Serializable s       = (Serializable)i.next();
                XmlNode      impNode = plistDocument.ImportNode((XmlNode)s.getAsDictionary(), true);
                arrayElement.AppendChild(impNode);
            }
            plistDocument.Save(file.getAbsolute());
        }
Beispiel #4
0
        public bool addAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <dotSesame.Statement>(c.iterator());
            bool added = false;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (!this._g.ContainsTriple(t))
                {
                    this._g.Assert(t);
                    added = added || true;
                }
            }
            return(added);
        }
Beispiel #5
0
        public bool removeAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(c.iterator());
            bool removed = false;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (this._g.ContainsTriple(t))
                {
                    this._g.Retract(t);
                    removed = removed || true;
                }
            }

            return(removed);
        }
Beispiel #6
0
        public bool containsAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(c.iterator());
            bool contains = true;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                Triple t = SesameConverter.FromSesame(stmt, this._mapping);
                if (!this._g.ContainsTriple(t))
                {
                    contains = false;
                    break;
                }
            }

            return(contains);
        }
Beispiel #7
0
        public bool retainAll(java.util.Collection c)
        {
            JavaIteratorWrapper <dotSesame.Statement> stmtIter = new JavaIteratorWrapper <org.openrdf.model.Statement>(c.iterator());
            HashSet <Triple> retained = new HashSet <Triple>();
            bool             changed  = false;

            foreach (dotSesame.Statement stmt in stmtIter)
            {
                retained.Add(SesameConverter.FromSesame(stmt, this._mapping));
            }
            foreach (Triple t in this._g.Triples.ToList())
            {
                if (!retained.Contains(t))
                {
                    changed = true;
                    this._g.Retract(t);
                }
            }
            return(changed);
        }
Beispiel #8
0
 /// <summary>
 /// Convert a java list to a generic collection
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="collection"></param>
 /// <returns>A List<typeparamref name="T"/></returns>
 public static ICollection <T> ConvertFromJavaList <T>(Collection collection)
 {
     return(ConvertFromJavaList <T>(collection, null));
 }
Beispiel #9
0
        /// <summary>
        // RFC2818 - HTTP Over TLS, Section 3.1
        // http://www.ietf.org/rfc/rfc2818.txt
        //
        // 1.  if present MUST use subjectAltName dNSName as identity
        // 1.1.    if multiples entries a match of any one is acceptable
        // 1.2.    wildcard * is acceptable
        // 2.  URI may be an IP address -> subjectAltName.iPAddress
        // 2.1.    exact match is required
        // 3.  Use of the most specific Common Name (CN=) in the Subject
        // 3.1    Existing practice but DEPRECATED
        /// </summary>
        /// <param name="javaCert"></param>
        /// <param name="cert"></param>
        /// <param name="targetHost"></param>
        /// <returns></returns>
        ///todo We should get rid of the java certificate parameter. Means to find an easy way to get the subjectAltNames (see http://www.java2s.com/Open-Source/CSharp/2.6.4-mono-.net-core/System.Net/System/Net/ServicePointManager.cs.htm)
        public static bool CheckServerIdentity(X509Certificate javaCert,
                                               X509Certificate2 cert, string targetHost)
        {
            try
            {
                /*
                 * SubjectAltName ::= GeneralNames
                 *
                 * GeneralNames :: = SEQUENCE SIZE (1..MAX) OF GeneralName
                 *
                 * GeneralName ::= CHOICE {
                 * otherName                       [0]     OtherName,
                 * rfc822Name                      [1]     IA5String,
                 * dNSName                         [2]     IA5String,
                 * x400Address                     [3]     ORAddress,
                 * directoryName                   [4]     Name,
                 * ediPartyName                    [5]     EDIPartyName,
                 * uniformResourceIdentifier       [6]     IA5String,
                 * iPAddress                       [7]     OCTET STRING,
                 * registeredID                    [8]     OBJECT IDENTIFIER}
                 *
                 * SubjectAltName is of form \"rfc822Name=<email>,
                 * dNSName=<host name>, uri=<http://host.com/>,
                 * ipaddress=<address>, guid=<globally unique id>
                 *
                 */

                java.util.Collection ext = javaCert.getSubjectAlternativeNames();
                // subjectAltName
                if (null != ext && ext.size() > 0)
                {
                    for (Iterator i = ext.iterator(); i.hasNext();)
                    {
                        List    item = (List)i.next();
                        Integer type = (Integer)item.get(0);
                        switch (type.intValue())
                        {
                        case 0:
                            continue;     // SubjectAltName of type OtherName not

                        case 1:
                            continue;     // rfc822Name

                        case 2:
                            if (Match(targetHost, (String)item.get(1)))      //dNSName
                            {
                                return(true);
                            }
                            break;

                        case 3:
                            continue;     // x400Address

                        case 4:
                            continue;     // directoryName

                        case 5:
                            continue;     // ediPartyName

                        case 6:
                            //todo shouldn't we handle uri as well? check spec.
                            continue;     // uri

                        case 7:
                            if (targetHost.Equals((String)item.get(1)))      // ipaddress, exact match required
                            {
                                return(true);
                            }
                            break;

                        default:
                            continue;
                        }
                    }
                }
                // Common Name (CN=)
                return(Match(GetCommonName(cert), targetHost));
            }
            catch (Exception e)
            {
                Log.error("ERROR processing certificate: {0}", e);
                return(false);
            }
        }