⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uurifactory.html

📁 一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫一个开源的网页爬虫
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="552" href="#552">552</a>     <strong>private</strong> String fixupAuthority(String uriAuthority) throws URIException {<a name="553" href="#553">553</a>         <em class="comment">// Lowercase the host part of the uriAuthority; don't destroy any</em><a name="554" href="#554">554</a>         <em class="comment">// userinfo capitalizations.  Make sure no illegal characters in</em><a name="555" href="#555">555</a>         <em class="comment">// domainlabel substring of the uri authority.</em><a name="556" href="#556">556</a>         <strong>if</strong> (uriAuthority != <strong>null</strong>) {<a name="557" href="#557">557</a>             <em class="comment">// Get rid of any trailing escaped spaces:</em><a name="558" href="#558">558</a>             <em class="comment">// http://www.archive.org%20.  Rare but happens.</em><a name="559" href="#559">559</a>             <em class="comment">// TODO: reevaluate: do IE or firefox do such mid-URI space-removal?</em><a name="560" href="#560">560</a>             <em class="comment">// if not, we shouldn't either. </em><a name="561" href="#561">561</a>             <strong>while</strong>(uriAuthority.endsWith(ESCAPED_SPACE)) {<a name="562" href="#562">562</a>                 uriAuthority = uriAuthority.substring(0,uriAuthority.length()-3);<a name="563" href="#563">563</a>             }<a name="564" href="#564">564</a> <a name="565" href="#565">565</a>             <em class="comment">// lowercase &amp; IDN-punycode only the domain portion</em><a name="566" href="#566">566</a>             <strong>int</strong> atIndex = uriAuthority.indexOf(COMMERCIAL_AT);<a name="567" href="#567">567</a>             <strong>int</strong> portColonIndex = uriAuthority.indexOf(COLON,(atIndex&lt;0)?0:atIndex);<a name="568" href="#568">568</a>             <strong>if</strong>(atIndex&lt;0 &amp;&amp; portColonIndex&lt;0) {<a name="569" href="#569">569</a>                 <em class="comment">// most common case: neither userinfo nor port</em><a name="570" href="#570">570</a>                 <strong>return</strong> fixupDomainlabel(uriAuthority);<a name="571" href="#571">571</a>             } <strong>else</strong> <strong>if</strong> (atIndex&lt;0 &amp;&amp; portColonIndex>-1) {<a name="572" href="#572">572</a>                 <em class="comment">// next most common: port but no userinfo</em><a name="573" href="#573">573</a>                 String domain = fixupDomainlabel(uriAuthority.substring(0,portColonIndex));<a name="574" href="#574">574</a>                 String port = uriAuthority.substring(portColonIndex);<a name="575" href="#575">575</a>                 <strong>return</strong> domain + port;<a name="576" href="#576">576</a>             } <strong>else</strong> <strong>if</strong> (atIndex>-1 &amp;&amp; portColonIndex&lt;0) {<a name="577" href="#577">577</a>                 <em class="comment">// uncommon: userinfo, no port</em><a name="578" href="#578">578</a>                 String userinfo = uriAuthority.substring(0,atIndex+1);<a name="579" href="#579">579</a>                 String domain = fixupDomainlabel(uriAuthority.substring(atIndex+1));<a name="580" href="#580">580</a>                 <strong>return</strong> userinfo + domain;<a name="581" href="#581">581</a>             } <strong>else</strong> {<a name="582" href="#582">582</a>                 <em class="comment">// uncommon: userinfo, port</em><a name="583" href="#583">583</a>                 String userinfo = uriAuthority.substring(0,atIndex+1);<a name="584" href="#584">584</a>                 String domain = fixupDomainlabel(uriAuthority.substring(atIndex+1,portColonIndex));<a name="585" href="#585">585</a>                 String port = uriAuthority.substring(portColonIndex);<a name="586" href="#586">586</a>                 <strong>return</strong> userinfo + domain + port;<a name="587" href="#587">587</a>             }<a name="588" href="#588">588</a>         }<a name="589" href="#589">589</a>         <strong>return</strong> uriAuthority;<a name="590" href="#590">590</a>     }<a name="591" href="#591">591</a>     <a name="592" href="#592">592</a>     <em>/**<em>*</em></em><a name="593" href="#593">593</a> <em>     * Fixup the domain label part of the authority.</em><a name="594" href="#594">594</a> <em>     * </em><a name="595" href="#595">595</a> <em>     * We're more lax than the spec. in that we allow underscores.</em><a name="596" href="#596">596</a> <em>     * </em><a name="597" href="#597">597</a> <em>     * @param label Domain label to fix.</em><a name="598" href="#598">598</a> <em>     * @return Return fixed domain label.</em><a name="599" href="#599">599</a> <em>     * @throws URIException</em><a name="600" href="#600">600</a> <em>     */</em><a name="601" href="#601">601</a>     <strong>private</strong> String fixupDomainlabel(String label)<a name="602" href="#602">602</a>     throws URIException {<a name="603" href="#603">603</a>         <a name="604" href="#604">604</a>         <em class="comment">// apply IDN-punycoding, as necessary</em><a name="605" href="#605">605</a>         <strong>try</strong> {<a name="606" href="#606">606</a>             <em class="comment">// TODO: optimize: only apply when necessary, or</em><a name="607" href="#607">607</a>             <em class="comment">// keep cache of recent encodings</em><a name="608" href="#608">608</a>             label = IDNA.toASCII(label);<a name="609" href="#609">609</a>         } <strong>catch</strong> (IDNAException e) {<a name="610" href="#610">610</a>             <strong>if</strong>(TextUtils.matches(ACCEPTABLE_ASCII_DOMAIN,label)) {<a name="611" href="#611">611</a>                 <em class="comment">// domain name has ACE prefix, leading/trailing dash, or </em><a name="612" href="#612">612</a>                 <em class="comment">// underscore -- but is still a name we wish to tolerate;</em><a name="613" href="#613">613</a>                 <em class="comment">// simply continue</em><a name="614" href="#614">614</a>             } <strong>else</strong> {<a name="615" href="#615">615</a>                 <em class="comment">// problematic domain: neither ASCII acceptable characters</em><a name="616" href="#616">616</a>                 <em class="comment">// nor IDN-punycodable, so throw exception </em><a name="617" href="#617">617</a>                 <em class="comment">// TODO: change to HeritrixURIException so distinguishable</em><a name="618" href="#618">618</a>                 <em class="comment">// from URIExceptions in library code</em><a name="619" href="#619">619</a>                 URIException ue = <strong>new</strong> URIException(e+<span class="string">" "</span>+label);<a name="620" href="#620">620</a>                 ue.initCause(e);<a name="621" href="#621">621</a>                 <strong>throw</strong> ue;<a name="622" href="#622">622</a>             }<a name="623" href="#623">623</a>         }<a name="624" href="#624">624</a>         label = label.toLowerCase();<a name="625" href="#625">625</a>         <strong>return</strong> label;<a name="626" href="#626">626</a>     }<a name="627" href="#627">627</a>     <a name="628" href="#628">628</a>     <em>/**<em>*</em></em><a name="629" href="#629">629</a> <em>     * Ensure that there all characters needing escaping</em><a name="630" href="#630">630</a> <em>     * in the passed-in String are escaped. Stray '%' characters</em><a name="631" href="#631">631</a> <em>     * are *not* escaped, as per browser behavior. </em><a name="632" href="#632">632</a> <em>     * </em><a name="633" href="#633">633</a> <em>     * @param u String to escape</em><a name="634" href="#634">634</a> <em>     * @param charset </em><a name="635" href="#635">635</a> <em>     * @return string with any necessary escaping applied</em><a name="636" href="#636">636</a> <em>     */</em><a name="637" href="#637">637</a>     <strong>private</strong> String ensureMinimalEscaping(String u, <strong>final</strong> String charset) {<a name="638" href="#638">638</a>         <strong>return</strong> ensureMinimalEscaping(u, charset, LaxURLCodec.EXPANDED_URI_SAFE);<a name="639" href="#639">639</a>     }<a name="640" href="#640">640</a>     <a name="641" href="#641">641</a>     <em>/**<em>*</em></em><a name="642" href="#642">642</a> <em>     * Ensure that there all characters needing escaping</em><a name="643" href="#643">643</a> <em>     * in the passed-in String are escaped. Stray '%' characters</em><a name="644" href="#644">644</a> <em>     * are *not* escaped, as per browser behavior. </em><a name="645" href="#645">645</a> <em>     * </em><a name="646" href="#646">646</a> <em>     * @param u String to escape</em><a name="647" href="#647">647</a> <em>     * @param charset </em><a name="648" href="#648">648</a> <em>     * @param bitset </em><a name="649" href="#649">649</a> <em>     * @return string with any necessary escaping applied</em><a name="650" href="#650">650</a> <em>     */</em><a name="651" href="#651">651</a>     <strong>private</strong> String ensureMinimalEscaping(String u, <strong>final</strong> String charset,<a name="652" href="#652">652</a>             <strong>final</strong> BitSet bitset) {<a name="653" href="#653">653</a>         <strong>if</strong> (u == <strong>null</strong>) {<a name="654" href="#654">654</a>             <strong>return</strong> <strong>null</strong>;<a name="655" href="#655">655</a>         }<a name="656" href="#656">656</a>         <strong>for</strong> (<strong>int</strong> i = 0; i &lt; u.length(); i++) {<a name="657" href="#657">657</a>             <strong>char</strong> c = u.<strong>char</strong>At(i);<a name="658" href="#658">658</a>             <strong>if</strong> (!bitset.get(c)) {<a name="659" href="#659">659</a>                 <strong>try</strong> {<a name="660" href="#660">660</a>                     u = LaxURLCodec.DEFAULT.encode(bitset, u, charset);<a name="661" href="#661">661</a>                 } <strong>catch</strong> (UnsupportedEncodingException e) {<a name="662" href="#662">662</a>                     e.printStackTrace();<a name="663" href="#663">663</a>                 }<a name="664" href="#664">664</a>                 <strong>break</strong>;<a name="665" href="#665">665</a>             }<a name="666" href="#666">666</a>         }<a name="667" href="#667">667</a>         <strong>return</strong> u;<a name="668" href="#668">668</a>     }<a name="669" href="#669">669</a> <a name="670" href="#670">670</a>     <em>/**<em>*</em></em><a name="671" href="#671">671</a> <em>     * Escape any whitespace found.</em><a name="672" href="#672">672</a> <em>     * </em><a name="673" href="#673">673</a> <em>     * The parent class takes care of the bulk of escaping.  But if any</em><a name="674" href="#674">674</a> <em>     * instance of escaping is found in the URI, then we ask for parent</em><a name="675" href="#675">675</a> <em>     * to do NO escaping.  Here we escape any whitespace found irrespective</em><a name="676" href="#676">676</a> <em>     * of whether the uri has already been escaped.  We do this for</em><a name="677" href="#677">677</a> <em>     * case where uri has been judged already-escaped only, its been</em><a name="678" href="#678">678</a> <em>     * incompletly done and whitespace remains.  Spaces, etc., in the URI are</em><a name="679" href="#679">679</a> <em>     * a real pain.  Their presence will break log file and ARC parsing.</em><a name="680" href="#680">680</a> <em>     * @param uri URI string to check.</em><a name="681" href="#681">681</a> <em>     * @return uri with spaces escaped if any found.</em><a name="682" href="#682">682</a> <em>     */</em><a name="683" href="#683">683</a>     <strong>protected</strong> String escapeWhitespace(String uri) {<a name="684" href="#684">684</a>         <em class="comment">// Just write a new string anyways.  The perl '\s' is not</em><a name="685" href="#685">685</a>         <em class="comment">// as inclusive as the Character.isWhitespace so there are</em><a name="686" href="#686">686</a>         <em class="comment">// whitespace characters we could miss.  So, rather than</em><a name="687" href="#687">687</a>         <em class="comment">// write some awkward regex, just go through the string</em><a name="688" href="#688">6

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -