• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

http://sourceforge.jp/projects/futonwriter/の旧リポジトリ


Commit MetaInfo

Revision41e1624398247ded15c66c77ef9b661dc8a3e6d6 (tree)
Zeit2011-05-11 19:28:48
Autorazyobuzin <azyobuzin@user...>
Commiterazyobuzin

Log Message

・フォトライフの対応一応完了
・その他いろいろWsseAtomConnectionとかいじった

Ändern Zusammenfassung

Diff

--- a/HatenaDiaryClient/Models/Hatena/FotolifeEntry.cs
+++ b/HatenaDiaryClient/Models/Hatena/FotolifeEntry.cs
@@ -1,9 +1,7 @@
11 using System;
2-using System.Collections.Generic;
32 using System.Linq;
4-using System.Text;
5-using System.Xml.Linq;
63 using System.Text.RegularExpressions;
4+using System.Xml.Linq;
75
86 namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
97 {
@@ -19,26 +17,28 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
1917 public string HatenaSyntax { set; get; }
2018
2119 public FotolifeEntry() { }
22- public FotolifeEntry(XElement xml, bool isRdf)
20+ public FotolifeEntry(XElement xml)
2321 {
24- if (isRdf)
25- {
26- //TODO
27- }
28- else
29- {
30- this.Title = xml.Element(XmlNamespaces.Atom02Spec + "title").Value;
31- this.PageUri = xml.Elements(XmlNamespaces.Atom02Spec + "link")
32- .Where(_ => _.Attribute("rel").Value == "alternate")
33- .Select(_ => _.Attribute("href").Value)
34- .FirstOrDefault();
35- this.Id = Regex.Match(this.PageUri, @"\d+$").ToString();
36- this.Issued = DateTime.Parse(xml.Element(XmlNamespaces.Atom02Spec + "issued").Value);
37- this.Folder = xml.Element(XmlNamespaces.DublinCore + "subject").Value;
38- this.ImageUri = xml.Element(XmlNamespaces.HatenaNs + "imageurl").Value;
39- this.ThumbnailUri = xml.Element(XmlNamespaces.HatenaNs + "imageurlsmall").Value;
40- this.HatenaSyntax = xml.Element(XmlNamespaces.HatenaNs + "syntax").Value;
41- }
22+ Console.WriteLine(xml.ToString());
23+ this.Title = xml.Element(XmlNamespaces.Atom02Spec + "title").Value;
24+ this.PageUri = xml.Elements(XmlNamespaces.Atom02Spec + "link")
25+ .Where(_ => _.Attribute("rel").Value == "alternate")
26+ .Select(_ => _.Attribute("href").Value)
27+ .FirstOrDefault();
28+ this.Id = Regex.Match(this.PageUri, @"\d+$").ToString();
29+ var issuedXml = xml.Element(XmlNamespaces.Atom02Spec + "issued").Value;
30+ if (!string.IsNullOrWhiteSpace(issuedXml))
31+ this.Issued = DateTime.Parse(issuedXml);
32+ var folderXml = xml.Element(XmlNamespaces.DublinCore + "subject");
33+ if (folderXml != null)
34+ this.Folder = folderXml.Value;
35+ this.ImageUri = xml.Element(XmlNamespaces.HatenaNs + "imageurl").Value;
36+ this.ThumbnailUri = xml.Element(XmlNamespaces.HatenaNs + "imageurlsmall").Value;
37+ this.HatenaSyntax = string.Format(
38+ "f:id:{0}:{1}j:image",
39+ xml.Element(XmlNamespaces.Atom02Spec + "author")
40+ .Element(XmlNamespaces.Atom02Spec + "name").Value,
41+ this.Id);
4242 }
4343 }
4444 }
--- a/HatenaDiaryClient/Models/Hatena/HatenaDiary.cs
+++ b/HatenaDiaryClient/Models/Hatena/HatenaDiary.cs
@@ -1,9 +1,8 @@
11 using System;
22 using System.Collections.Generic;
3+using System.Collections.Specialized;
34 using System.Linq;
4-using System.Net;
55 using System.Text;
6-using System.Text.RegularExpressions;
76 using System.Xml.Linq;
87
98 namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
@@ -23,6 +22,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
2322 {
2423 var xdoc = WsseAtomConnection.Get(
2524 string.Format("http://d.hatena.ne.jp/{0}/atom/blog?page={1}", this.userName, page),
25+ Encoding.UTF8,
2626 this.userName,
2727 this.password);
2828 var title = xdoc.Root.Element(XmlNamespaces.Atom + "title").Value;
@@ -58,6 +58,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
5858 {
5959 var xdoc = WsseAtomConnection.Get(
6060 string.Format("http://d.hatena.ne.jp/{0}/atom/blog/{1}", this.userName, dateId),
61+ Encoding.UTF8,
6162 this.userName,
6263 this.password);
6364 return new BlogEntry(xdoc.Root);
@@ -89,6 +90,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
8990 {
9091 var xdoc = WsseAtomConnection.Get(
9192 string.Format("http://d.hatena.ne.jp/{0}/atom/draft?page={1}", this.userName, page),
93+ Encoding.UTF8,
9294 this.userName,
9395 this.password);
9496 var title = xdoc.Root.Element(XmlNamespaces.Atom + "title").Value;
@@ -114,6 +116,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
114116 {
115117 var xdoc = WsseAtomConnection.Get(
116118 string.Format("http://d.hatena.ne.jp/{0}/atom/draft/{1}", this.userName, id),
119+ Encoding.UTF8,
117120 this.userName,
118121 this.password);
119122 return new BlogEntry(xdoc.Root);
@@ -141,22 +144,22 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
141144 this.password);
142145 }
143146
144- public string PublishDraft(string id)
147+ public BlogEntry PublishDraft(string id)
145148 {
146- var req = (HttpWebRequest)WebRequest.Create(string.Format(
147- "http://d.hatena.ne.jp/{0}/atom/draft/{1}",
148- this.userName,
149- id));
150- req.Method = "PUT";
151- req.AllowAutoRedirect = false;
152- req.Headers.Add(WsseAtomConnection.CreateHeader(this.userName, this.password));
153- req.Headers.Add("X-HATENA-PUBLISH: 1");
154- using (var res = req.GetResponse())
155- return Regex.Match(
156- res.Headers[HttpResponseHeader.Location],
157- @"\d+/\d+"
149+ return new BlogEntry(
150+ XElement.Parse(
151+ WsseAtomConnection.Put(
152+ string.Format(
153+ "http://d.hatena.ne.jp/{0}/atom/draft/{1}",
154+ this.userName,
155+ id),
156+ new NameValueCollection() { { "X-HATENA-PUBLISH", "1" } },
157+ null,
158+ Encoding.UTF8,
159+ this.userName,
160+ this.password)
158161 )
159- .ToString();
162+ );
160163 }
161164 }
162165 }
--- a/HatenaDiaryClient/Models/Hatena/HatenaFotolife.cs
+++ b/HatenaDiaryClient/Models/Hatena/HatenaFotolife.cs
@@ -1,10 +1,9 @@
11 using System;
22 using System.Collections.Generic;
3+using System.IO;
34 using System.Linq;
45 using System.Text;
5-using System.IO;
66 using System.Xml.Linq;
7-using System.Net;
87
98 namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
109 {
@@ -38,30 +37,30 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
3837 case "bmp":
3938 mimeType = "image/x-bmp";
4039 break;
41- case "mov":
42- mimeType = "video/quicktime";
43- break;
44- case "mpg":
45- case "mpeg":
46- case "m1v":
47- mimeType = "video/mpeg";
48- break;
49- case "wmv":
50- mimeType = "video/x-ms-wmv";
51- break;
52- case "avi":
53- mimeType = "video/avi";
54- break;
55- case "flv":
56- mimeType = "video/x-flv";
57- break;
58- case "3gp":
59- case "3gpp":
60- mimeType = "video/3gpp";
61- break;
62- case "3g2":
63- mimeType = "video/3gpp2";
64- break;
40+ //case "mov":
41+ // mimeType = "video/quicktime";
42+ // break;
43+ //case "mpg":
44+ //case "mpeg":
45+ //case "m1v":
46+ // mimeType = "video/mpeg";
47+ // break;
48+ //case "wmv":
49+ // mimeType = "video/x-ms-wmv";
50+ // break;
51+ //case "avi":
52+ // mimeType = "video/avi";
53+ // break;
54+ //case "flv":
55+ // mimeType = "video/x-flv";
56+ // break;
57+ //case "3gp":
58+ //case "3gpp":
59+ // mimeType = "video/3gpp";
60+ // break;
61+ //case "3g2":
62+ // mimeType = "video/3gpp2";
63+ // break;
6564 default:
6665 throw new ArgumentException("対応してないファイルです。");
6766 }
@@ -84,7 +83,59 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
8483 Encoding.GetEncoding("shift_jis"),
8584 this.userName,
8685 this.password);
87- return new FotolifeEntry(reXml.Root, false);
86+ return new FotolifeEntry(reXml.Root);
87+ }
88+
89+ public FotolifeEntry GetEntry(string id)
90+ {
91+ return new FotolifeEntry(
92+ WsseAtomConnection.Get(
93+ "http://f.hatena.ne.jp/atom/edit/" + id,
94+ Encoding.UTF8,
95+ this.userName,
96+ this.password
97+ )
98+ .Root
99+ );
100+ }
101+
102+ public void EditEntry(string id, string newTitle)
103+ {
104+ WsseAtomConnection.Put(
105+ "http://f.hatena.ne.jp/atom/edit/" + id,
106+ null,
107+ Encoding.GetEncoding("shift_jis").GetBytes(
108+ new XDocument(
109+ new XElement(XmlNamespaces.Atom02Spec + "entry",
110+ new XElement(XmlNamespaces.Atom02Spec + "title", newTitle)
111+ )
112+ )
113+ .ToString()
114+ ),
115+ null,
116+ this.userName,
117+ this.password);
118+ }
119+
120+ public void DeleteEntry(string id)
121+ {
122+ WsseAtomConnection.Delete(
123+ "http://f.hatena.ne.jp/atom/edit/" + id,
124+ this.userName,
125+ this.password);
126+ }
127+
128+ public IEnumerable<FotolifeEntry> GetEntrys(int page = 1)
129+ {
130+ return WsseAtomConnection.Get(
131+ "http://f.hatena.ne.jp/atom/feed?page=" + page.ToString(),
132+ Encoding.UTF8,
133+ this.userName,
134+ this.password
135+ )
136+ .Root
137+ .Elements(XmlNamespaces.Atom02Spec + "entry")
138+ .Select(_ => new FotolifeEntry(_));
88139 }
89140 }
90141 }
--- a/HatenaDiaryClient/Models/Hatena/WsseAtomConnection.cs
+++ b/HatenaDiaryClient/Models/Hatena/WsseAtomConnection.cs
@@ -1,4 +1,6 @@
11 using System;
2+using System.Collections.Specialized;
3+using System.IO;
24 using System.Linq;
35 using System.Net;
46 using System.Security.Cryptography;
@@ -25,13 +27,13 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
2527 userName, digest, Convert.ToBase64String(nonce), created);
2628 }
2729
28- public static XDocument Get(string reqUri, string userName, string password)
30+ public static XDocument Get(string reqUri, Encoding enc, string userName, string password)
2931 {
3032 using (var wc = new WebClient())
3133 {
3234 wc.Headers.Add(CreateHeader(userName, password));
33- using (var stream = wc.OpenRead(reqUri))
34- return XDocument.Load(stream);
35+ using (var sr = new StreamReader(wc.OpenRead(reqUri), enc ?? Encoding.UTF8))
36+ return XDocument.Load(sr);
3537 }
3638 }
3739
@@ -49,7 +51,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
4951 req.Method = method;
5052 req.Headers.Add(CreateHeader(userName, password));
5153 req.ContentType = "application/x.atom+xml";
52- var bs = Encoding.GetEncoding("shift_jis").GetBytes(reqData.ToString());
54+ var bs = enc.GetBytes(reqData.ToString());
5355 req.ContentLength = bs.Length;
5456 using (var stream = req.GetRequestStream())
5557 stream.Write(bs, 0, bs.Length);
@@ -66,5 +68,21 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
6668 {
6769 return PostOrPut(reqUri, "PUT", reqData, enc, userName, password);
6870 }
71+
72+ public static string Put(string reqUri, NameValueCollection headers, byte[] data, Encoding enc, string userName, string password)
73+ {
74+ var req = WebRequest.Create(reqUri);
75+ req.Method = "PUT";
76+ req.Headers.Add(CreateHeader(userName, password));
77+ if (headers != null)
78+ req.Headers.Add(headers);
79+ if (data != null && data.Any())
80+ {
81+ using (var stream = req.GetRequestStream())
82+ stream.Write(data, 0, data.Length);
83+ }
84+ using (var sr = new StreamReader(req.GetResponse().GetResponseStream(), enc ?? Encoding.UTF8))
85+ return sr.ReadToEnd();
86+ }
6987 }
7088 }
\ No newline at end of file