# File types supported for round trip. # Other File types may be added easily. class FileType include Singleton attr_reader :re_begin, :re_end @@types=Hash.new def initialize(type) #puts "type=#{type}" @@types[type]=self end def writeComment(str,writer) raise Warning.new(), "Internal error. Undefined method" end def beginMarker(str,id) raise Warning.new(), "Internal error. Undefined method" end def endMarker(str,id) raise Warning.new(), "Internal error. Undefined method" end def FileType.getFileType(fileName) ext=File.extname(fileName) type=@@types[ext] return type if ! type.nil? msg="Unknown File Type \"#{ext}\" for \"#{fileName}\"" log.debug(msg) raise WarningUnknownFileType.new(),msg end # escape text to be included in markers def escape(txt) return txt end #unescape text to be read from markers def unescape(txt) return txt end end class FileTypeJava < FileType include Singleton def initialize(ext=".java") super(ext) @re_begin=Regexp.new(/^[ \t]*\/\*[ _]*XMDA[ _]BEGIN[ _]+reverse="(.*)"[ _]uri="(.*)"[ _]*\*\//) @re_end=Regexp.new(/^[ \t]*\/\*[ _]*XMDA[ _]END[ _]+uri="(.*)"[ _]*\*\//) end def writeComment(str,writer) writer.write("/* #{str} */") end def thinLineComment #return context[:thinLineComment,true] ? ('_'*60) : '' #return "_____________________________________________________________________________________________________________________________________________" return "" end def beginMarker(uri,reverse) return %{\n/*XMDA_BEGIN_reverse="#{reverse ? 'yes':'no'}"_#{thinLineComment}uri="#{uri}"_*/\n} end def endMarker(uri) return %{\n/*XMDA_END_#{thinLineComment}uri="#{uri}"_*/\n} end end FileTypeJava.instance # register class FileTypeXML < FileType # a character that can not exist in a URI URI_ESCAPE_CHAR_ONE='°' def initialize(ext=".xml") super(ext) @re_begin=/^[ \t]*<\!-- *XMDA BEGIN +reverse="([^"]*)" uri="([^"]*)" *-->/ @re_end=/^[ \t]*<\!-- *XMDA END +uri="([^"]*)" *-->/ end def writeComment(str,writer) writer.write("") end def beginMarker(uri,reverse) return %{\n\n} end def endMarker(uri) return %{\n\n} end def escape(txt) return txt.tr('-',URI_ESCAPE_CHAR_ONE) end def unescape(txt) return txt.tr(URI_ESCAPE_CHAR_ONE,'-') end end FileTypeXML.instance # register class FileTypeJavaProperties < FileType def initialize(ext=".properties") super(ext) @re_begin=/^[ \t]*#[_ ]*XMDA_BEGIN_reverse="([^"]*)"_uri="([^"]*)"[ _]*$/ @re_end=/^[ \t]*#[ _]*XMDA_END_uri="([^"]*)"[ _]*$/ end def writeComment(str,writer) writer.write("# #{str} ") end def beginMarker(uri,reverse) return %{\n#_XMDA_BEGIN_reverse="#{reverse ? 'yes':'no'}"_uri="#{uri}"\n} end def endMarker(uri) return %{\n#_XMDA_END_uri="#{uri}"\n} end end FileTypeJavaProperties.instance # register class FileTypeJSP < FileType include Singleton def initialize(ext=".jsp") super(ext) @re_begin=Regexp.new(/^[ \t]*<%--*[ _]*XMDA[ _]BEGIN[ _]*reverse="(.*)"[ _]uri="(.*)"[ _]*--%>/) @re_end=Regexp.new(/^[ \t]*<%--[ _]*XMDA[ _]END[ _]*uri="(.*)"[ _]*--%>/) end def writeComment(str,writer) writer.write("<%-- #{str} --%>") end def thinLineComment #return context[:thinLineComment,true] ? ('_'*60) : '' #return "_____________________________________________________________________________________________________________________________________________" return "" end def beginMarker(uri,reverse) return %{\n<%--_XMDA_BEGIN_reverse="#{reverse ? 'yes':'no'}"_#{thinLineComment}uri="#{uri}"_--%>\n} end def endMarker(uri) return %{\n<%--_XMDA_END_#{thinLineComment}uri="#{uri}"_--%>\n} end end FileTypeJSP.instance # register