<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: public code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 21 Jul 2008 07:41:46 GMT</pubDate>
    <description>DZone Snippets: public code</description>
    <item>
      <title>Obtaining the value of a public static field by reflexion </title>
      <link>http://snippets.dzone.com/posts/show/4501</link>
      <description>// Obtaining the value of a static public constant of a class, here Boolean for example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;        Object returnedObj = null;&lt;br /&gt;        try {&lt;br /&gt;            Class clazz = Class.forName("java.lang.Boolean");&lt;br /&gt;            returnedObj = clazz.getField("TRUE").get(clazz);&lt;br /&gt;            assert java.lang.Boolean.TRUE == returnedObj : "wrong returned object";&lt;br /&gt;        } catch (ClassNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (SecurityException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (NoSuchFieldException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (IllegalArgumentException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (IllegalAccessException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return returnedObj;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 06 Sep 2007 14:59:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4501</guid>
      <author>Archanciel (Jean-Pierre Schnyder)</author>
    </item>
    <item>
      <title>Pulling allday events from the public calendar of an exchange 2003 server vb.net webdav</title>
      <link>http://snippets.dzone.com/posts/show/4379</link>
      <description>// description of your code here&lt;br /&gt;This is code that pulls all day events from an exchange 2003 server using webdav.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Dim Request As System.Net.HttpWebRequest&lt;br /&gt;        Dim Response As System.Net.HttpWebResponse&lt;br /&gt;        Dim MyCredentialCache As System.Net.CredentialCache&lt;br /&gt;        Dim strPassword As String&lt;br /&gt;        Dim strDomain As String&lt;br /&gt;        Dim strUserName As String&lt;br /&gt;        Dim strCalendarURI As String&lt;br /&gt;        Dim strQuery As String&lt;br /&gt;        Dim bytes() As Byte&lt;br /&gt;        Dim RequestStream As System.IO.Stream&lt;br /&gt;        Dim ResponseStream As System.IO.Stream&lt;br /&gt;        Dim ResponseXmlDoc As System.Xml.XmlDocument&lt;br /&gt;        Dim HrefNodes As System.Xml.XmlNodeList&lt;br /&gt;        Dim SizeNodes As System.Xml.XmlNodeList&lt;br /&gt;        Dim SubjectNodeList As System.Xml.XmlNodeList&lt;br /&gt;        Dim LocationNodeList As System.Xml.XmlNodeList&lt;br /&gt;        Dim StartTimeNodeList As System.Xml.XmlNodeList&lt;br /&gt;        Dim EndTimeNodeList As System.Xml.XmlNodeList&lt;br /&gt;        Dim BusyStatusNodeList As System.Xml.XmlNodeList&lt;br /&gt;        Dim InstanceTypeNodeList As System.Xml.XmlNodeList&lt;br /&gt;        Dim output As String = ""&lt;br /&gt;&lt;br /&gt;        Try&lt;br /&gt;            ' Initialize variables.&lt;br /&gt;            strUserName = "user"&lt;br /&gt;            strPassword = "password"&lt;br /&gt;            strDomain = "domain"&lt;br /&gt;            &lt;br /&gt;            strCalendarURI = "http://mail-server/public/Office Calendar/"&lt;br /&gt;&lt;br /&gt;            Dim ddate As DateTime = Today&lt;br /&gt;&lt;br /&gt;            Dim sStartTime As String = String.Format("{0:yyyy/MM/dd}", ddate) &amp; " 07:00:00' "&lt;br /&gt;            Dim sEndTime As String = String.Format("{0:yyyy/MM/dd}", ddate.AddDays(1)) &amp; " 07:00:00' "&lt;br /&gt;&lt;br /&gt;            strQuery = "&lt;?xml version=""1.0""?&gt;" &amp; _&lt;br /&gt;                   "&lt;g:searchrequest xmlns:g=""DAV:""&gt;" &amp; _&lt;br /&gt;                   "&lt;g:sql&gt;SELECT ""urn:schemas:calendar:alldayevent"", ""urn:schemas:calendar:location"", ""urn:schemas:httpmail:subject"", " &amp; _&lt;br /&gt;                   """urn:schemas:calendar:dtstart"", ""urn:schemas:calendar:dtend"", " &amp; _&lt;br /&gt;                   """urn:schemas:calendar:busystatus"", ""urn:schemas:calendar:instancetype"" " &amp; _&lt;br /&gt;                   "FROM Scope('SHALLOW TRAVERSAL OF """ &amp; strCalendarURI &amp; """') " &amp; _&lt;br /&gt;                   "WHERE ""DAV:contentclass"" = 'urn:content-classes:appointment' " &amp; _&lt;br /&gt;                   "AND ""urn:schemas:calendar:alldayevent"" = TRUE " &amp; _&lt;br /&gt;                   "AND ""urn:schemas:calendar:dtstart"" &amp;lt;= '" &amp; sStartTime &amp; _&lt;br /&gt;                    "AND ""urn:schemas:calendar:dtend"" &amp;gt;= '" &amp; sEndTime &amp; _&lt;br /&gt;                    "ORDER BY ""urn:schemas:calendar:dtstart"" ASC" &amp; _&lt;br /&gt;                   "&lt;/g:sql&gt;&lt;/g:searchrequest&gt;"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            MyCredentialCache = New System.Net.CredentialCache&lt;br /&gt;            MyCredentialCache.Add(New System.Uri(strCalendarURI), _&lt;br /&gt;                "NTLM", _&lt;br /&gt;                New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _&lt;br /&gt;                )&lt;br /&gt;&lt;br /&gt;            ' Create the PUT HttpWebRequest object.&lt;br /&gt;            Request = CType(System.Net.WebRequest.Create(strCalendarURI), _&lt;br /&gt;                            System.Net.HttpWebRequest)&lt;br /&gt;&lt;br /&gt;            ' Add the network credentials to the request.&lt;br /&gt;            Request.Credentials = MyCredentialCache&lt;br /&gt;&lt;br /&gt;            ' Specify the SEARCH method.&lt;br /&gt;            Request.Method = "SEARCH"&lt;br /&gt;&lt;br /&gt;            ' Encode the body using UTF-8.&lt;br /&gt;            bytes = System.Text.Encoding.UTF8.GetBytes(strQuery)&lt;br /&gt;&lt;br /&gt;            ' Set the content header length.  This must be&lt;br /&gt;            ' done before writing data to the request stream.&lt;br /&gt;            Request.ContentLength = bytes.Length&lt;br /&gt;&lt;br /&gt;            ' Get a reference to the request stream.&lt;br /&gt;            RequestStream = Request.GetRequestStream()&lt;br /&gt;&lt;br /&gt;            ' Write the message body to the request stream.&lt;br /&gt;            RequestStream.Write(bytes, 0, bytes.Length)&lt;br /&gt;&lt;br /&gt;            ' Close the Stream object to release the connection&lt;br /&gt;            ' for further use.&lt;br /&gt;            RequestStream.Close()&lt;br /&gt;&lt;br /&gt;            ' Set the Content Type header.&lt;br /&gt;            Request.ContentType = "text/xml"&lt;br /&gt;&lt;br /&gt;            ' Set the Translate header.&lt;br /&gt;            Request.Headers.Add("Translate", "F")&lt;br /&gt;&lt;br /&gt;            ' Send the SEARCH method request and get the&lt;br /&gt;            ' response from the server.&lt;br /&gt;            Response = CType(Request.GetResponse(), System.Net.HttpWebResponse)&lt;br /&gt;&lt;br /&gt;            ' Get the XML response stream.&lt;br /&gt;            ResponseStream = Response.GetResponseStream()&lt;br /&gt;&lt;br /&gt;            ' Create the XmlDocument object from the XML response stream.&lt;br /&gt;            ResponseXmlDoc = New System.Xml.XmlDocument&lt;br /&gt;            ResponseXmlDoc.Load(ResponseStream)&lt;br /&gt;            &lt;br /&gt;            ' Build a list of the DAV:href XML nodes, corresponding to the folders&lt;br /&gt;            ' in the mailbox.  The DAV: namespace is typically assgigned the a:&lt;br /&gt;            ' prefix in the XML response body.&lt;br /&gt;            HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:href")&lt;br /&gt;&lt;br /&gt;            ' Build a list of the urn:schemas:httpmail:subject XML nodes,&lt;br /&gt;            ' corresponding to the calendar item subjects returned in the search request.&lt;br /&gt;            ' The urn:schemas:httpmail: namespace is typically&lt;br /&gt;            ' assigned the e: prefix in the XML response body.&lt;br /&gt;            SubjectNodeList = ResponseXmlDoc.GetElementsByTagName("e:subject")&lt;br /&gt;&lt;br /&gt;            ' Build a list of the urn:schemas:calendar:location XML nodes,&lt;br /&gt;            ' corresponding to the calendar item locations returned in the search request.&lt;br /&gt;            ' The urn:schemas:calendar: namespace is typically&lt;br /&gt;            ' assigned the d: prefix in the XML response body.&lt;br /&gt;            LocationNodeList = ResponseXmlDoc.GetElementsByTagName("d:location")&lt;br /&gt;&lt;br /&gt;            ' Build a list of the urn:schemas:calendar:dtstart XML nodes,&lt;br /&gt;            ' corresponding to the calendar item locations returned in the search request.&lt;br /&gt;            StartTimeNodeList = ResponseXmlDoc.GetElementsByTagName("d:dtstart")&lt;br /&gt;&lt;br /&gt;            ' Build a list of the urn:schemas:calendar:dtend XML nodes,&lt;br /&gt;            ' corresponding to the calendar item locations returned in the search request.&lt;br /&gt;            EndTimeNodeList = ResponseXmlDoc.GetElementsByTagName("d:dtend")&lt;br /&gt;&lt;br /&gt;            ' Build a list of the urn:schemas:calendar:busystatus XML nodes,&lt;br /&gt;            ' corresponding to the calendar item locations returned in the search request.&lt;br /&gt;            BusyStatusNodeList = ResponseXmlDoc.GetElementsByTagName("d:busystatus")&lt;br /&gt;&lt;br /&gt;            ' Build a list of the urn:schemas:calendar:instancetype XML nodes,&lt;br /&gt;            ' corresponding to the calendar item locations returned in the search request.&lt;br /&gt;            InstanceTypeNodeList = ResponseXmlDoc.GetElementsByTagName("d:instancetype")&lt;br /&gt;&lt;br /&gt;            ' Loop through the returned items (if any).&lt;br /&gt;            If SubjectNodeList.Count &gt; 0 Then&lt;br /&gt;&lt;br /&gt;                Dim i As Integer&lt;br /&gt;                For i = 0 To SubjectNodeList.Count - 1&lt;br /&gt;&lt;br /&gt;                    ' Display the subject.&lt;br /&gt;&lt;br /&gt;                    output = output &amp; SubjectNodeList(i).InnerText &amp; ControlChars.CrLf&lt;br /&gt;                    Console.WriteLine(" " + SubjectNodeList(i).InnerText)&lt;br /&gt;&lt;br /&gt;                    ' Display the location.&lt;br /&gt;                    'Console.WriteLine("  Location:      " + LocationNodeList(i).InnerText)&lt;br /&gt;&lt;br /&gt;                    ' Display the start time.&lt;br /&gt;                    'Console.WriteLine("  Start time:    " + StartTimeNodeList(i).InnerText)&lt;br /&gt;&lt;br /&gt;                    ' Display the end time.&lt;br /&gt;                    'Console.WriteLine("  End time:      " + EndTimeNodeList(i).InnerText)&lt;br /&gt;&lt;br /&gt;                    ' Display the busy status.&lt;br /&gt;                    'Console.WriteLine("  Busy status:   " + BusyStatusNodeList(i).InnerText)&lt;br /&gt;&lt;br /&gt;                    ' Display the instance type.&lt;br /&gt;                    'If InstanceTypeNodeList(i).InnerText = "0" Then&lt;br /&gt;                    '    Console.WriteLine("  Instance type: 0-Single appointment")&lt;br /&gt;                    'ElseIf InstanceTypeNodeList(i).InnerText = "1" Then&lt;br /&gt;                    '    Console.WriteLine("  Instance type: 1-Master recurring appointment")&lt;br /&gt;                    'ElseIf InstanceTypeNodeList(i).InnerText = "2" Then&lt;br /&gt;                    '    Console.WriteLine("  Instance type: 2-Single instance, recurring appointment")&lt;br /&gt;                    'ElseIf InstanceTypeNodeList(i).InnerText = "3" Then&lt;br /&gt;                    '    Console.WriteLine("  Instance type: 3-Exception to a recurring appointment")&lt;br /&gt;                    'Else&lt;br /&gt;                    '    Console.WriteLine("  Instance type: Unknown")&lt;br /&gt;                    '    Console.WriteLine("")&lt;br /&gt;                    'End If&lt;br /&gt;&lt;br /&gt;                Next&lt;br /&gt;&lt;br /&gt;            Else&lt;br /&gt;                Console.WriteLine("No calendar items found ...")&lt;br /&gt;&lt;br /&gt;            End If&lt;br /&gt;&lt;br /&gt;            ' Clean up.&lt;br /&gt;            ResponseStream.Close()&lt;br /&gt;            Response.Close()&lt;br /&gt;&lt;br /&gt;        Catch ex As Exception&lt;br /&gt;&lt;br /&gt;            ' Catch any exceptions. Any error codes from the&lt;br /&gt;            ' SEARCH method requests on the server will be caught&lt;br /&gt;            ' here, also.&lt;br /&gt;            Console.WriteLine(ex.Message)&lt;br /&gt;&lt;br /&gt;        End Try&lt;br /&gt;&lt;br /&gt;        SaveTextFile("C:\test.txt", output)&lt;br /&gt;        emailCalendar()&lt;br /&gt;        Me.Close()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 01 Aug 2007 18:29:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4379</guid>
      <author>mellerbeck (Michael Ellerbeck)</author>
    </item>
  </channel>
</rss>
