Esempio n. 1
0
		protected XmlResponse GetAtom(Topic[] topics, string feedTitle){
			string urlBase = "http://" + Model.Manager.IniData.Domain;
			string diaryUrl = urlBase + Model.BasePath.ToString();
			string selfUrl = urlBase + Model.BasePath.Combine(Id).ToString();
			string idTagBase = string.Format(IdTagFormat, Model.Manager.IniData.Domain, Diary.BasePath);

			// 準備と last-modified の移植
			XmlResponse xr = new XmlResponse(Model);
			foreach(HatomaruData hd in myResponse.DataSource){
				xr.AddDataSource(hd);
			}
			xr.SetLastModified();

			XmlDocument atom = xr.Document;
			XmlElement feed = atom.CreateElement("feed", AtomNameSpace);
			atom.AppendChild(feed);

			XmlElement title = atom.CreateElement("title", AtomNameSpace);
			title.InnerText = feedTitle;
			feed.AppendChild(title);

			XmlElement link = atom.CreateElement("link", AtomNameSpace);
			link.SetAttribute("href", diaryUrl);
			feed.AppendChild(link);

			XmlElement selfLink = atom.CreateElement("link", AtomNameSpace);
			selfLink.SetAttribute("href", selfUrl);
			selfLink.SetAttribute("rel", "self");
			selfLink.SetAttribute("type", HatomaruResponse.AtomMediaType);
			feed.AppendChild(selfLink);

			XmlElement updated = atom.CreateElement("updated", AtomNameSpace);
			updated.InnerText = xr.LastModified.ToString(AtomDateFormat);
			feed.AppendChild(updated);

			XmlElement author = atom.CreateElement("author", AtomNameSpace);
			feed.AppendChild(author);

			XmlElement name = atom.CreateElement("name", AtomNameSpace);
			name.InnerText = "水無月ばけら";
			author.AppendChild(name);

			XmlElement id = atom.CreateElement("id", AtomNameSpace);
			id.InnerText = idTagBase;
			feed.AppendChild(id);

			// 最新のトピック
			foreach(Topic t in topics){
				AbsPath topicPath = Diary.BasePath.Combine(DiaryIndexViewTopic.Id, t.Id);
				string topicUrl = urlBase + topicPath.ToString();
				string topicIdTag = string.Format(IdTagFormat, Model.Manager.IniData.Domain, topicPath);

				XmlElement entry = atom.CreateElement("entry", AtomNameSpace);
				feed.AppendChild(entry);

				XmlElement entryTitle = atom.CreateElement("title", AtomNameSpace);
				entryTitle.InnerText = t.Title;
				entry.AppendChild(entryTitle);

				XmlElement entryLink = atom.CreateElement("link", AtomNameSpace);
				entryLink.SetAttribute("href", topicUrl);
				entry.AppendChild(entryLink);

				XmlElement entryId = atom.CreateElement("id", AtomNameSpace);
				entryId.InnerText = topicIdTag;
				entry.AppendChild(entryId);

				XmlElement entryUpdated = atom.CreateElement("updated", AtomNameSpace);
				DateTime topicUpdated = t.Date;
				if(t.Updated != default(DateTime)){
					topicUpdated = t.Updated;
				} else if(t.Created  != default(DateTime)){
					topicUpdated = t.Created;
				}
				entryUpdated.InnerText = topicUpdated.ToString(AtomDateFormat);
				entry.AppendChild(entryUpdated);

				XmlElement content = atom.CreateElement("content", AtomNameSpace);
				content.SetAttribute("type", "xhtml");
				content.SetAttribute("xml:lang", "ja");
				content.SetAttribute("xml:base", selfUrl);

				XmlElement contentDiv = atom.CreateElement("div", Xhtml.NameSpace);

				XmlNode topicHeading = GetDateHeading(t.Date, 1);
				XmlNode topicBody = GetTopicBody(t, 2);

				XmlNode atomTopicHeading = atom.ImportNode(topicHeading, true);
				XmlNode atomTopicBody = atom.ImportNode(topicBody, true);

				contentDiv.AppendChild(atomTopicHeading);
				contentDiv.AppendChild(atomTopicBody);

				content.AppendChild(contentDiv);

				entry.AppendChild(content);
			}
			return xr;
		}
Esempio n. 2
0
		/// <summary>
		/// データを GET し、HatomaruResponse を取得します。
		/// </summary>
		protected override HatomaruResponse GetHtmlResponse(){
			Topic[] topics = GetRecentTopics();
			if(topics.Length == 0) return NotFound();

			string urlBase = "http://" + Model.Manager.IniData.Domain;
			string rssUrl = urlBase + Path.ToString();
			string diaryUrl = urlBase + myModel.BasePath.ToString();

			// 準備と last-modified の移植
			XmlResponse xr = new XmlResponse(Model);
			foreach(HatomaruData hd in myResponse.DataSource){
				xr.AddDataSource(hd);
			}
			xr.SetLastModified();

			XmlDocument rss = xr.Document;
			XmlElement rssRoot = rss.CreateElement("rdf", "RDF", RdfNameSpace);
			rssRoot.SetAttribute("xmlns", Rss1NameSpace);
			rssRoot.SetAttribute("xmlns:dc", DublinCoreNameSpace);
			rss.AppendChild(rssRoot);

			XmlElement channel = rss.CreateElement("channel", Rss1NameSpace);
			channel.SetAttribute("about", RdfNameSpace, rssUrl);
			rssRoot.AppendChild(channel);

			XmlElement title = rss.CreateElement("title", Rss1NameSpace);
			title.InnerText = DiaryIndexViewRecently.Label;
			channel.AppendChild(title);

			XmlElement link = rss.CreateElement("link", Rss1NameSpace);
			link.InnerText = diaryUrl;
			channel.AppendChild(link);

			XmlElement description = rss.CreateElement("description", Rss1NameSpace);
			description.InnerText = Diary.Description;
			channel.AppendChild(description);

			XmlElement language = rss.CreateElement("dc", "language", DublinCoreNameSpace);
			language.InnerText = "ja";
			channel.AppendChild(language);

			XmlElement dcDate = rss.CreateElement("dc", "date", DublinCoreNameSpace);
			dcDate.InnerText = Model.LastModified.ToString(DublinCoreDateFormat);
			channel.AppendChild(dcDate);

			XmlElement items = rss.CreateElement("items", Rss1NameSpace);
			channel.AppendChild(items);

			XmlElement seq = rss.CreateElement("rdf", "Seq", RdfNameSpace);
			items.AppendChild(seq);


			// 最新のトピックを取得
			foreach(Topic t in topics){
				string topicUrl = urlBase + Diary.BasePath.Combine(DiaryIndexViewTopic.Id, t.Id).ToString();

				// Seq に追加
				XmlElement li = rss.CreateElement("rdf", "li", RdfNameSpace);
				li.SetAttribute("resource", RdfNameSpace, topicUrl);
				seq.AppendChild(li);

				// item を追加
				XmlElement item = rss.CreateElement("item", Rss1NameSpace);
				item.SetAttribute("about", RdfNameSpace, topicUrl);
				rssRoot.AppendChild(item);

				XmlElement itemTitle = rss.CreateElement("title", Rss1NameSpace);
				itemTitle.InnerText = t.Title;
				item.AppendChild(itemTitle);

				XmlElement itemLink = rss.CreateElement("link", Rss1NameSpace);
				itemLink.InnerText = topicUrl;
				item.AppendChild(itemLink);

				XmlElement itemDescription = rss.CreateElement("description", Rss1NameSpace);
				itemDescription.InnerText = t.Message.InnerText.Truncate(150);
				item.AppendChild(itemDescription);

				XmlElement itemDate = rss.CreateElement("dc", "date", DublinCoreNameSpace);
				itemDate.InnerText = t.Date.ToString(DublinCoreDateFormat);
				item.AppendChild(itemDate);
			}

			return xr;
		}