- 1. リンク先取得の前処理
1. リンク先取得の前処理
リンク先を実際に通信して結果を判断するクラスが長くなったので、リンク先を編集する処理と実際に取得する処理にわけました。。
こちらは、リンク先を編集する処理です。
=begin
外部リンク・ドメイン内リンク・イメージファイルは open してみる
=end
require('uri')
require('fetch')
require('fetchFTP')
require('exceptlog.rb')
class FetchBefore
def initialize()
end
def execute(parent, top, check, checked)
begin
if (check.include?('#')) # # のあるものはぶった切って
#binding.pry
split = check.split('#') # リンク先を取得後、id の記述があるかを検証する
sharp = split.last
check = check[0, check.length-(split.last.length+1)]
end
case check[0]
when ('/') # / で始まっているものはドメイン内リンクなのでドメインをつける
check = top + check
end
if (!check.include?('#')) # # がなければ
if (parent == check) # 自己参照かどうか判定して、自己参照はエラーとする
return 'SELF', 'NG'
end
end
# 外部リンクかどうかを判断して(ドメインで)
# 外部リンクであれば # なしにしちゃう
tempuri = URI.parse(check)
temphost = tempuri.host
if (temphost != $host)
sharp = nil
end
uri = check
if (!check.include?('%')) # '% がはいっているものはエンコード済とみなしてないものだけエンコード
uri = URI.encode(uri)
end
uri = URI.parse(uri)
if (checked.has_key?(check)) # 既にチェック済であればその結果をそのまま返す
return checked[check], check
end
if (uri.port == 21)
fetch = FetchFTP.new
return fetch.execute(uri, check)
end
print(".")
# print("\t\t"+check+"\n")
fetch = Fetch.new
#puts("check[#{check}]")
return fetch.execute(sharp, uri, check) # 実際に URI を取得してみる
rescue URI::InvalidURIError => error
return 'URI::InvalidURIError', 'NG'
rescue => error
exeptlog = ExceptLog.new
binding.pry
exeptlog.execute(self, error)
exit 1
end
end
end
|
|