📄 wirefeedoutput.html
字号:
<a name="97" href="#97">97</a> <em> * default charset encoding is used to write the feed to the file. It is the responsibility</em><a name="98" href="#98">98</a> <em> * of the developer to ensure the feed encoding is set to the platform charset encoding.</em><a name="99" href="#99">99</a> <em> * <p></em><a name="100" href="#100">100</a> <em> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.</em><a name="101" href="#101">101</a> <em> * <p></em><a name="102" href="#102">102</a> <em> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match</em><a name="103" href="#103">103</a> <em> * the type given to the FeedOuptut constructor.</em><a name="104" href="#104">104</a> <em> * @param file the file where to write the XML representation for the given WireFeed.</em><a name="105" href="#105">105</a> <em> * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.</em><a name="106" href="#106">106</a> <em> * @throws IOException thrown if there was some problem writing to the File.</em><a name="107" href="#107">107</a> <em> * @throws FeedException thrown if the XML representation for the feed could not be created.</em><a name="108" href="#108">108</a> <em> *</em><a name="109" href="#109">109</a> <em> */</em><a name="110" href="#110">110</a> <strong>public</strong> <strong>void</strong> output(<a href="../../../../com/sun/syndication/feed/WireFeed.html">WireFeed</a> feed,File file) throws IllegalArgumentException,IOException,FeedException {<a name="111" href="#111">111</a> Writer writer = <strong>new</strong> FileWriter(file);<a name="112" href="#112">112</a> output(feed,writer);<a name="113" href="#113">113</a> writer.close();<a name="114" href="#114">114</a> }<a name="115" href="#115">115</a> <a name="116" href="#116">116</a> <em>/**<em>*</em></em><a name="117" href="#117">117</a> <em> * Writes to an Writer the XML representation for the given WireFeed.</em><a name="118" href="#118">118</a> <em> * <p></em><a name="119" href="#119">119</a> <em> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility</em><a name="120" href="#120">120</a> <em> * of the developer to ensure the Writer instance is using the same charset encoding.</em><a name="121" href="#121">121</a> <em> * <p></em><a name="122" href="#122">122</a> <em> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.</em><a name="123" href="#123">123</a> <em> * <p></em><a name="124" href="#124">124</a> <em> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match</em><a name="125" href="#125">125</a> <em> * the type given to the FeedOuptut constructor.</em><a name="126" href="#126">126</a> <em> * @param writer Writer to write the XML representation for the given WireFeed.</em><a name="127" href="#127">127</a> <em> * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.</em><a name="128" href="#128">128</a> <em> * @throws IOException thrown if there was some problem writing to the Writer.</em><a name="129" href="#129">129</a> <em> * @throws FeedException thrown if the XML representation for the feed could not be created.</em><a name="130" href="#130">130</a> <em> *</em><a name="131" href="#131">131</a> <em> */</em><a name="132" href="#132">132</a> <strong>public</strong> <strong>void</strong> output(<a href="../../../../com/sun/syndication/feed/WireFeed.html">WireFeed</a> feed,Writer writer) throws IllegalArgumentException,IOException, FeedException {<a name="133" href="#133">133</a> Document doc = outputJDom(feed);<a name="134" href="#134">134</a> String encoding = feed.getEncoding();<a name="135" href="#135">135</a> Format format = Format.getPrettyFormat();<a name="136" href="#136">136</a> <strong>if</strong> (encoding!=<strong>null</strong>) {<a name="137" href="#137">137</a> format.setEncoding(encoding);<a name="138" href="#138">138</a> }<a name="139" href="#139">139</a> XMLOutputter outputter = <strong>new</strong> XMLOutputter(format);<a name="140" href="#140">140</a> outputter.output(doc,writer);<a name="141" href="#141">141</a> }<a name="142" href="#142">142</a> <a name="143" href="#143">143</a> <em>/**<em>*</em></em><a name="144" href="#144">144</a> <em> * Creates a W3C DOM document for the given WireFeed.</em><a name="145" href="#145">145</a> <em> * <p></em><a name="146" href="#146">146</a> <em> * This method does not use the feed encoding property.</em><a name="147" href="#147">147</a> <em> * <p></em><a name="148" href="#148">148</a> <em> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.</em><a name="149" href="#149">149</a> <em> * <p></em><a name="150" href="#150">150</a> <em> * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must match</em><a name="151" href="#151">151</a> <em> * the type given to the FeedOuptut constructor.</em><a name="152" href="#152">152</a> <em> * @return the W3C DOM document for the given WireFeed.</em><a name="153" href="#153">153</a> <em> * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.</em><a name="154" href="#154">154</a> <em> * @throws FeedException thrown if the W3C DOM document for the feed could not be created.</em><a name="155" href="#155">155</a> <em> *</em><a name="156" href="#156">156</a> <em> */</em><a name="157" href="#157">157</a> <strong>public</strong> org.w3c.dom.Document outputW3CDom(<a href="../../../../com/sun/syndication/feed/WireFeed.html">WireFeed</a> feed) throws IllegalArgumentException,FeedException {<a name="158" href="#158">158</a> Document doc = outputJDom(feed);<a name="159" href="#159">159</a> DOMOutputter outputter = <strong>new</strong> DOMOutputter();<a name="160" href="#160">160</a> <strong>try</strong> {<a name="161" href="#161">161</a> <strong>return</strong> outputter.output(doc);<a name="162" href="#162">162</a> }<a name="163" href="#163">163</a> <strong>catch</strong> (JDOMException jdomEx) {<a name="164" href="#164">164</a> <strong>throw</strong> <strong>new</strong> <a href="../../../../com/sun/syndication/io/FeedException.html">FeedException</a>(<span class="string">"Could not create DOM"</span>,jdomEx);<a name="165" href="#165">165</a> }<a name="166" href="#166">166</a> }<a name="167" href="#167">167</a> <a name="168" href="#168">168</a> <em>/**<em>*</em></em><a name="169" href="#169">169</a> <em> * Creates a JDOM document for the given WireFeed.</em><a name="170" href="#170">170</a> <em> * <p></em><a name="171" href="#171">171</a> <em> * This method does not use the feed encoding property.</em><a name="172" href="#172">172</a> <em> * <p></em><a name="173" href="#173">173</a> <em> * NOTE: All other output methods delegate to this method.</em><a name="174" href="#174">174</a> <em> * <p></em><a name="175" href="#175">175</a> <em> * @param feed Abstract feed to create JDOM document from. The type of the WireFeed must match</em><a name="176" href="#176">176</a> <em> * the type given to the FeedOuptut constructor.</em><a name="177" href="#177">177</a> <em> * @return the JDOM document for the given WireFeed.</em><a name="178" href="#178">178</a> <em> * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.</em><a name="179" href="#179">179</a> <em> * @throws FeedException thrown if the JDOM document for the feed could not be created.</em><a name="180" href="#180">180</a> <em> *</em><a name="181" href="#181">181</a> <em> */</em><a name="182" href="#182">182</a> <strong>public</strong> Document outputJDom(<a href="../../../../com/sun/syndication/feed/WireFeed.html">WireFeed</a> feed) throws IllegalArgumentException,FeedException {<a name="183" href="#183">183</a> String type = feed.getFeedType();<a name="184" href="#184">184</a> <a href="../../../../com/sun/syndication/io/WireFeedGenerator.html">WireFeedGenerator</a> generator = GENERATORS.getGenerator(type);<a name="185" href="#185">185</a> <strong>if</strong> (generator==<strong>null</strong>) {<a name="186" href="#186">186</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Invalid feed type ["</span>+type+<span class="string">"]"</span>);<a name="187" href="#187">187</a> }<a name="188" href="#188">188</a> <a name="189" href="#189">189</a> <strong>if</strong> (!generator.getType().equals(type)) {<a name="190" href="#190">190</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"WireFeedOutput type["</span>+type+<span class="string">"] and WireFeed type ["</span>+<a name="191" href="#191">191</a> type+<span class="string">"] don't match"</span>);<a name="192" href="#192">192</a> }<a name="193" href="#193">193</a> <strong>return</strong> generator.generate(feed);<a name="194" href="#194">194</a> }<a name="195" href="#195">195</a> <a name="196" href="#196">196</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -