📄 complextype.html
字号:
<a name="286" href="#286">286</a> }<a name="287" href="#287">287</a> <a name="288" href="#288">288</a> <em>/**<em>* Get the absolute name of this ComplexType.</em></em><a name="289" href="#289">289</a> <em> *</em><a name="290" href="#290">290</a> <em> * The absolute name is like a file path with the name of the element</em><a name="291" href="#291">291</a> <em> * prepended by all the parents names separated by slashes.</em><a name="292" href="#292">292</a> <em> * @return Absolute name.</em><a name="293" href="#293">293</a> <em> */</em><a name="294" href="#294">294</a> <strong>public</strong> String getAbsoluteName() {<a name="295" href="#295">295</a> <strong>return</strong> absoluteName;<a name="296" href="#296">296</a> }<a name="297" href="#297">297</a> <a name="298" href="#298">298</a> <em>/**<em>*</em></em><a name="299" href="#299">299</a> <em> * Get settings object valid for a URI.</em><a name="300" href="#300">300</a> <em> * <p/></em><a name="301" href="#301">301</a> <em> * This method takes an object,</em><a name="302" href="#302">302</a> <em> * try to convert it into a {@link CrawlURI} and then tries to get the</em><a name="303" href="#303">303</a> <em> * settings object from it. If this fails, then the global settings object</em><a name="304" href="#304">304</a> <em> * is returned.</em><a name="305" href="#305">305</a> <em> * <p/></em><a name="306" href="#306">306</a> <em> * If the requested attribute is not set on this settings</em><a name="307" href="#307">307</a> <em> * object it tries its parent until it gets a settings object where this</em><a name="308" href="#308">308</a> <em> * attribute is set is found. If nothing is found, global settings is</em><a name="309" href="#309">309</a> <em> * returned.</em><a name="310" href="#310">310</a> <em> *</em><a name="311" href="#311">311</a> <em> * @param o possible {@link CrawlURI}.</em><a name="312" href="#312">312</a> <em> * @param attributeName the attribute that should have a value set on the</em><a name="313" href="#313">313</a> <em> * returned settings object.</em><a name="314" href="#314">314</a> <em> * @return the settings object valid for the URI.</em><a name="315" href="#315">315</a> <em> */</em><a name="316" href="#316">316</a> Context getSettingsFromObject(Object o, String attributeName) {<a name="317" href="#317">317</a> Context context;<a name="318" href="#318">318</a> <strong>if</strong> (o == <strong>null</strong>) {<a name="319" href="#319">319</a> context = <strong>null</strong>;<a name="320" href="#320">320</a> } <strong>else</strong> <strong>if</strong> (o instanceof Context) {<a name="321" href="#321">321</a> context = (Context) o;<a name="322" href="#322">322</a> } <strong>else</strong> <strong>if</strong> (o instanceof CrawlerSettings) {<a name="323" href="#323">323</a> context = <strong>new</strong> Context((CrawlerSettings) o, <strong>null</strong>);<a name="324" href="#324">324</a> } <strong>else</strong> <strong>if</strong> (o instanceof UURI || o instanceof CandidateURI) {<a name="325" href="#325">325</a> <em class="comment">// Try to get settings for URI that has no references to a</em><a name="326" href="#326">326</a> <em class="comment">// CrawlServer [SIC - CrawlURI may have CrawlServer -gjm]</em><a name="327" href="#327">327</a> context = <strong>new</strong> Context();<a name="328" href="#328">328</a> context.uri = (o instanceof CandidateURI)?<a name="329" href="#329">329</a> ((<a href="../../../../org/archive/crawler/datamodel/CandidateURI.html">CandidateURI</a>) o).getUURI(): (UURI)o;<a name="330" href="#330">330</a> <strong>try</strong> {<a name="331" href="#331">331</a> context.settings = getSettingsHandler().<a name="332" href="#332">332</a> getSettings(context.uri.getReferencedHost(),<a name="333" href="#333">333</a> context.uri);<a name="334" href="#334">334</a> }<a name="335" href="#335">335</a> <strong>catch</strong> (URIException e1) {<a name="336" href="#336">336</a> logger.severe(<span class="string">"Failed to get host"</span>);<a name="337" href="#337">337</a> }<a name="338" href="#338">338</a> <a name="339" href="#339">339</a> <strong>if</strong> (attributeName != <strong>null</strong>) {<a name="340" href="#340">340</a> <strong>try</strong> {<a name="341" href="#341">341</a> context.settings =<a name="342" href="#342">342</a> getDataContainerRecursive(context, attributeName).<a name="343" href="#343">343</a> getSettings();<a name="344" href="#344">344</a> } <strong>catch</strong> (AttributeNotFoundException e) {<a name="345" href="#345">345</a> <em class="comment">// Nothing found, globals will be used</em><a name="346" href="#346">346</a> }<a name="347" href="#347">347</a> }<a name="348" href="#348">348</a> } <strong>else</strong> {<a name="349" href="#349">349</a> logger.warning(<span class="string">"Unknown object type: "</span> +<a name="350" href="#350">350</a> o.getClass().getName());<a name="351" href="#351">351</a> context = <strong>null</strong>;<a name="352" href="#352">352</a> }<a name="353" href="#353">353</a> <a name="354" href="#354">354</a> <em class="comment">// if settings could not be resolved use globals.</em><a name="355" href="#355">355</a> <strong>if</strong> (context == <strong>null</strong>) {<a name="356" href="#356">356</a> context = <strong>new</strong> Context(globalSettings(), <strong>null</strong>);<a name="357" href="#357">357</a> }<a name="358" href="#358">358</a> <strong>return</strong> context;<a name="359" href="#359">359</a> }<a name="360" href="#360">360</a> <a name="361" href="#361">361</a> <em>/**<em>* Get settings object valid for a URI.</em></em><a name="362" href="#362">362</a> <em> *</em><a name="363" href="#363">363</a> <em> * This method takes an object, try to convert it into a {@link CrawlURI}</em><a name="364" href="#364">364</a> <em> * and then tries to get the settings object from it. If this fails, then</em><a name="365" href="#365">365</a> <em> * the global settings object is returned.</em><a name="366" href="#366">366</a> <em> *</em><a name="367" href="#367">367</a> <em> * @param o possible {@link CrawlURI}.</em><a name="368" href="#368">368</a> <em> * @return the settings object valid for the URI.</em><a name="369" href="#369">369</a> <em> */</em><a name="370" href="#370">370</a> Context getSettingsFromObject(Object o) {<a name="371" href="#371">371</a> <strong>return</strong> getSettingsFromObject(o, <strong>null</strong>);<a name="372" href="#372">372</a> }<a name="373" href="#373">373</a> <a name="374" href="#374">374</a> <em>/**<em>* Returns true if an element is overridden for this settings object.</em></em><a name="375" href="#375">375</a> <em> *</em><a name="376" href="#376">376</a> <em> * @param settings the settings object to investigate.</em><a name="377" href="#377">377</a> <em> * @param name the name of the element to check.</em><a name="378" href="#378">378</a> <em> * @return true if element is overridden for this settings object, false</em><a name="379" href="#379">379</a> <em> * if not set here or is first defined here.</em><a name="380" href="#380">380</a> <em> * @throws AttributeNotFoundException if element doesn't exist.</em><a name="381" href="#381">381</a> <em> */</em><a name="382" href="#382">382</a> <strong>public</strong> <strong>boolean</strong> isOverridden(<a href="../../../../org/archive/crawler/settings/CrawlerSettings.html">CrawlerSettings</a> settings, String name)<a name="383" href="#383">383</a> throws AttributeNotFoundException {<a name="384" href="#384">384</a> settings = settings == <strong>null</strong> ? globalSettings() : settings;<a name="385" href="#385">385</a> <a href="../../../../org/archive/crawler/settings/DataContainer.html">DataContainer</a> data = settings.getData(<strong>this</strong>);<a name="386" href="#386">386</a> <strong>if</strong> (data == <strong>null</strong> || !data.containsKey(name)) {<a name="387" href="#387">387</a> <strong>return</strong> false;<a name="388" href="#388">388</a> }<a name="389" href="#389">389</a> <a name="390" href="#390">390</a> <em class="comment">// Try to find attribute, will throw an exception if not found.</em><a name="391" href="#391">391</a> Context context = <strong>new</strong> Context(settings.getParent(), <strong>null</strong>);<a name="392" href="#392">392</a> getDataContainerRecursive(context, name);<a name="393" href="#393">393</a> <strong>return</strong> <strong>true</strong>;<a name="394" href="#394">394</a> }<a name="395" href="#395">395</a> <a name="396" href="#396">396</a> <em>/**<em>* Obtain the value of a specific attribute from the crawl order.</em></em><a name="397" href="#397">397</a> <em> *</em><a name="398" href="#398">398</a> <em> * If the attribute doesn't exist in the crawl order, the default</em><a name="399" href="#399">399</a> <em> * value will be returned.</em><a name="400" href="#400">400</a> <em> *</em><a name="401" href="#401">401</a> <em> * @param name the name of the attribute to be retrieved.</em><a name="402" href="#402">402</a> <em> * @return The value of the attribute retrieved.</em><a name="403" href="#403">403</a> <em> * @throws AttributeNotFoundException</em><a name="404" href="#404">404</a> <em> * @throws MBeanException</em><a name="405" href="#405">405</a> <em> * @throws ReflectionException</em><a name="406" href="#406">406</a> <em> */</em><a name="407" href="#407">407</a> <strong>public</strong> Object getAttribute(String name)<a name="408" href="#408">408</a> throws AttributeNotFoundException, MBeanException, ReflectionException {<a name="409" href="#409">409</a> <strong>return</strong> getAttribute(<strong>null</strong>, name);<a name="410" href="#410">410</a> }<a name="411" href="#411">411</a> <a name="412" href="#412">412</a> <em>/**<em>* Obtain the value of a specific attribute that is valid for a</em></em><a name="413" href="#413">413</a> <em> * specific CrawlURI.</em><a name="414" href="#414">414</a> <em> *</em><a name="415" href="#415">415</a> <em> * This method will try to get the attribute from the host settings</em><a name="416" href="#416">416</a> <em> * valid for the CrawlURI. If it is not found it will traverse the</em><a name="417" href="#417">417</a> <em> * settings up to the order and as a last resort deliver the default</em><a name="418" href="#418">418</a> <em> * value. This is also the case if the CrawlURI is null or if the CrawlURI</em><a name="419" href="#419">419</a> <em> * hasn't been assigned a CrawlServer.</em><a name="420" href="#420">420</a> <em> *</em><a name="421" href="#421">421</a> <em> * @param name the name of the attribute to be retrieved.</em><a name="422" href="#422">422</a> <em> * @param uri the CrawlURI that this attribute should be valid for.</em><a name="423" href="#423">423</a> <em> * @return The value of the attribute retrieved.</em><a name="424" href="#424">424</a> <em> * @see #getAttribute(Object settings, String name)</em><a name="425" href="#425">425</a> <em> * @throws AttributeNotFoundException</em><a name="426" href="#426">426</a> <em> */</em><a name="427" href="#427">427</a> <strong>public</strong> Object getAttribute(String name, <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> uri)<a name="428" href="#428">428</a> throws AttributeNotFoundException {<a name="429" href="#429">429</a> <strong>return</strong> getAttribute(uri, name);<a name="430" href="#430">430</a> }<a name="431" href="#431">431</a> <a name="432" href="#432">432</a> <em>/**<em>*</em></em>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -