Fixed file path detection bug in build method polymorphism

Fixed file path detection bug in build method polymorphism
(when string was recognised as path cause of  "xml", "yml", etc. content in it)
Refactored file detection duplication in few places
Fixed xml file format detection (f variable assigned but never used)
Deleted some trailing spaces in the refactored file