/** Map a content type (without charset) to a {@link Lang} */ public static Lang contentTypeToLang(String contentType) { if ( contentType == null ) return null ; String key = canonicalKey(contentType) ; return mapContentTypeToLang.get(key) ; }
/** Map a colloquial name (e.g. "Turtle") to a {@link Lang} */ public static Lang shortnameToLang(String label) { if ( label == null ) return null ; String key = canonicalKey(label) ; return mapLabelToLang.get(key) ; }
/** Map a colloquial name (e.g. "Turtle") to a {@link Lang} */ public static Lang shortnameToLang(String label) { if ( label == null ) return null ; String key = canonicalKey(label) ; return mapLabelToLang.get(key) ; }
/** Map a content type (without charset) to a {@link Lang} */ public static Lang contentTypeToLang(String contentType) { if ( contentType == null ) return null ; String key = canonicalKey(contentType) ; return mapContentTypeToLang.get(key) ; }
/** Try to map a file extension to a {@link Lang}; return null on no registered mapping */ public static Lang fileExtToLang(String ext) { if ( ext == null ) return null ; if ( ext.startsWith(".") ) ext = ext.substring(1) ; ext = canonicalKey(ext) ; return mapFileExtToLang.get(ext) ; }
/** Try to map a file extension to a {@link Lang}; return null on no registered mapping */ public static Lang fileExtToLang(String ext) { if ( ext == null ) return null ; if ( ext.startsWith(".") ) ext = ext.substring(1) ; ext = canonicalKey(ext) ; return mapFileExtToLang.get(ext) ; }
/** Map a content type (without charset) to a {@link Lang} */ public static Lang contentTypeToLang(ContentType ct) { if ( ct == null ) return null ; String key = canonicalKey(ct.getContentType()) ; return mapContentTypeToLang.get(key) ; }
/** Map a content type (without charset) to a {@link Lang} */ public static Lang contentTypeToLang(ContentType ct) { if ( ct == null ) return null ; String key = canonicalKey(ct.getContentType()) ; return mapContentTypeToLang.get(key) ; }
/** Remove a registration of a language - this also removes all recorded mapping * of content types and file extensions. */ public static void unregister(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.remove(canonicalKey(lang.getLabel())) ; mapContentTypeToLang.remove(canonicalKey(lang.getContentType().getContentType())) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.remove(canonicalKey(ct)) ; for ( String ext : lang.getFileExtensions() ) mapFileExtToLang.remove(canonicalKey(ext)) ; }
public static boolean isRegistered(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return false ; checkRegistration(lang) ; return true ; }
public static boolean isRegistered(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return false ; checkRegistration(lang) ; return true ; }
/** Remove a regsitration of a language - this also removes all recorded mapping * of content types and file extensions. */ public static void unregister(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.remove(canonicalKey(lang.getLabel())) ; mapContentTypeToLang.remove(canonicalKey(lang.getContentType().getContentType())) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.remove(canonicalKey(ct)) ; for ( String ext : lang.getFileExtensions() ) mapFileExtToLang.remove(canonicalKey(ext)) ; }
/** Register a language. * To create a {@link Lang} object use {@link LangBuilder}. * See also * {@link RDFParserRegistry#registerLang} * for registering a language and it's RDF parser factory. * * @see RDFParserRegistry */ public static void register(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.put(canonicalKey(lang.getLabel()), lang) ; for (String altName : lang.getAltNames() ) mapLabelToLang.put(canonicalKey(altName), lang) ; mapContentTypeToLang.put(canonicalKey(lang.getContentType().getContentType()), lang) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.put(canonicalKey(ct), lang) ; for ( String ext : lang.getFileExtensions() ) { if ( ext.startsWith(".") ) ext = ext.substring(1) ; mapFileExtToLang.put(canonicalKey(ext), lang) ; } }
/** Register a language. * To create a {@link Lang} object use {@link LangBuilder}. * See also * {@link RDFParserRegistry#registerLang} * for registering a language and it's RDF parser fatory. * * @see RDFParserRegistry */ public static void register(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.put(canonicalKey(lang.getLabel()), lang) ; for (String altName : lang.getAltNames() ) mapLabelToLang.put(canonicalKey(altName), lang) ; mapContentTypeToLang.put(canonicalKey(lang.getContentType().getContentType()), lang) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.put(canonicalKey(ct), lang) ; for ( String ext : lang.getFileExtensions() ) { if ( ext.startsWith(".") ) ext = ext.substring(1) ; mapFileExtToLang.put(canonicalKey(ext), lang) ; } }
private static void checkRegistration(Lang lang) { if ( lang == null ) return ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return ; if ( lang.equals(lang2) ) return ; // Content type. if ( mapContentTypeToLang.containsKey(lang.getContentType().getContentType())) { String k = lang.getContentType().getContentType() ; error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(k)+" on content type "+k) ; } for (String altName : lang.getAltNames() ) if ( mapLabelToLang.containsKey(altName) ) error("Language overlap: " +lang+" and "+mapLabelToLang.get(altName)+" on name "+altName) ; for (String ct : lang.getAltContentTypes() ) if ( mapContentTypeToLang.containsKey(ct) ) error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(ct)+" on content type "+ct) ; for (String ext : lang.getFileExtensions() ) if ( mapFileExtToLang.containsKey(ext) ) error("Language overlap: " +lang+" and "+mapFileExtToLang.get(ext)+" on file extension type "+ext) ; }
private static void checkRegistration(Lang lang) { if ( lang == null ) return ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return ; if ( lang.equals(lang2) ) return ; // Content type. if ( mapContentTypeToLang.containsKey(lang.getContentType().getContentType())) { String k = lang.getContentType().getContentType() ; error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(k)+" on content type "+k) ; } for (String altName : lang.getAltNames() ) if ( mapLabelToLang.containsKey(altName) ) error("Language overlap: " +lang+" and "+mapLabelToLang.get(altName)+" on name "+altName) ; for (String ct : lang.getAltContentTypes() ) if ( mapContentTypeToLang.containsKey(ct) ) error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(ct)+" on content type "+ct) ; for (String ext : lang.getFileExtensions() ) if ( mapFileExtToLang.containsKey(ext) ) error("Language overlap: " +lang+" and "+mapFileExtToLang.get(ext)+" on file extension type "+ext) ; }