connectioncontext.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,389 行 · 第 1/5 页
JAVA
2,389 行
} } return _windowContext.getPreferences(); } // -- User Attributes public Map<String, String> getUserAttributeMap() throws IOException { if (_windowContext.getUserAttributeMap() == null) { UserAttributeStore store = getUserAttributeStore(); Set<String> names = getPortal().getUserAttributeNames(); Map<String, String> userAttributeMap = store.getUserAttributeMap(getPortletRequest(), names); _windowContext.setUserAttributeMap(userAttributeMap); } return _windowContext.getUserAttributeMap(); } // Title public void setTitle(String title) { _connection.setAttribute("javax.portlet.title", title); } // -- Client information - character encoding, content type, locales // if the value has not been set for the connection, // the possibilities are defined by the client, and in the case // of locale and content type the capabilities defined by the // Window. // // Once the value is set for the conneciton, it is the only // possibility. /** * Get the locale already established or get the most preferred locale. */ public Locale getResponseLocale() { // getResponseLocalesSet() updates the windowContext.getResponseLocale() with the // first entry getResponseLocalesSet(); return _windowContext.getResponseLocale(); } /** * True if the set is null or the set contains the locale, or the locale * without the variant, or the locale without the variant and country, or * LOCALE_ANY. */ private boolean containsLocale(Set<Locale> set, Locale locale) { if (set == null || set.contains(locale)) return true; String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (variant.length() > 0) { variant = ""; Locale loc = new Locale(language, country, variant); if (set.contains(loc)) return true; } if (country.length() > 0) { country = ""; Locale loc = new Locale(language, country, variant); if (set.contains(loc)) return true; } if (language.length() > 0) { Locale loc = LOCALE_ANY; if (set.contains(loc)) return true; } return false; } /** * Get an ordered set containing all possible locales, the most preferred * Locale occurring first. If the locale is already established a Set * containing only the established locale is returned, if the established * locale is not one of the supported locales specified in the configuration * an empty set is returned. */ public Set<Locale> getResponseLocalesSet() { Set<Locale> responseLocales = _windowContext.getResponseLocales(); Locale established = _windowContext.getResponseHandler().getLocale(); // if it is established, make sure the set contains only // the established content type. Otherwise the set will // need to be rebuilt. if (established != null && responseLocales != null && (responseLocales.size() > 0) && !responseLocales.contains(established)) responseLocales = null; if (responseLocales != null) return responseLocales; responseLocales = new LinkedHashSet<Locale>(); Locale responseLocale = null; // first one added to Set Window window = getWindow(); Set<Locale> configLocales = window == null ? null : window.getSupportedLocales(); Set<Locale> clientLocales = _connection.getClientLocales(); boolean configSupportsAll = configLocales == null || configLocales.isEmpty() || configLocales.contains(LOCALE_ANY); boolean clientSupportsAll = clientLocales == null || clientLocales.isEmpty() || clientLocales.contains(LOCALE_ANY); if (established != null) { boolean configSupports = configSupportsAll || containsLocale( configLocales, established ); boolean clientSupports = clientSupportsAll || containsLocale(clientLocales, established); if (configSupports || clientSupports) { responseLocales.add(established); responseLocale = established; } } else if (configLocales == null) { Iterator<Locale> iter = clientLocales.iterator(); while (iter.hasNext()) { Locale clientLocale = iter.next(); if (clientLocale.equals(LOCALE_ANY)) continue; if (responseLocale == null) responseLocale = clientLocale; responseLocales.add(clientLocale); } } else { Iterator<Locale> iter = configLocales.iterator(); while (iter.hasNext()) { Locale configLocale = iter.next(); if (configLocale.equals(LOCALE_ANY)) continue; if (clientSupportsAll || clientLocales.contains(configLocale)) { responseLocales.add(configLocale); if (responseLocale == null) responseLocale = configLocale; } } } // XXX: default currently is platform default if (responseLocale == null && established == null) { responseLocale = Locale.getDefault(); responseLocales.add(responseLocale); } _windowContext.setResponseLocale(responseLocale); _windowContext.setResponseLocales(responseLocales); return responseLocales; } /** * Get the character encoding already established or get the most preferred * character encoding. */ public String getResponseCharacterEncoding() { // getResponseCharacterEncodingsSet() updates the // windowContext.getResponseCharacterEncoding() with the first entry getResponseCharacterEncodingsSet(); return _windowContext.getResponseCharacterEncoding(); } /** * Get an ordered set containing all possible character encodings, the most * preferred Locale occurring first. If the character encoding is already * established a Set containing only the established character encoding is * returned, if the established character encoding is not one of the * supported character encodings specified in the configuration an empty set * is returned. */ public Set<String> getResponseCharacterEncodingsSet() { Set<String> responseEncodings = _windowContext.getResponseCharacterEncodings(); String establishedEncoding = _windowContext.getResponseHandler().getCharacterEncoding(); // if it is established, make sure the set contains only // the established character encoding. Otherwise the set will // need to be rebuilt. if (establishedEncoding != null && responseEncodings != null && (responseEncodings.size() > 0 ) && !responseEncodings.contains(establishedEncoding)) responseEncodings = null; if (responseEncodings != null) return responseEncodings; responseEncodings = new LinkedHashSet<String>(); String responseEncoding = null; // first one added to Set Set<String> clientEncodings = _connection.getClientCharacterEncodings(); boolean clientSupportsAll = clientEncodings == null || clientEncodings.isEmpty() || clientEncodings.contains("*"); if (establishedEncoding != null) { if (clientSupportsAll || clientEncodings.contains(establishedEncoding)) { responseEncodings.add(establishedEncoding); responseEncoding = establishedEncoding; } } else { Iterator<String> iter = clientEncodings.iterator(); while (iter.hasNext()) { String clientEncoding = iter.next(); responseEncodings.add(clientEncoding); if (responseEncoding == null) responseEncoding = clientEncoding; } if (responseEncoding == null) { // XXX: default is platform default responseEncoding = System.getProperty("file.encoding"); responseEncodings.add(responseEncoding); } } _windowContext.setResponseCharacterEncoding(responseEncoding); _windowContext.setResponseCharacterEncodings(responseEncodings); return responseEncodings; } private String getWildcardContentType(String contentType) { // i.e "text/html" becomes "text/*", null if no wildcard possible // because there is no '/' int i = contentType.indexOf('/'); if (i < 0) return null; else return contentType.substring(0,i + 1) + "*"; } public String getResponseContentType() { // getResponseContentTypesSet() sets _windowContext.getResponseContentType // to the value of the first entry it add's to the set getResponseContentTypesSet(); return _windowContext.getResponseContentType(); } public Set<String> getResponseContentTypesSet() { Set<String> responseTypes = _windowContext.getResponseContentTypes(); String establishedType = _windowContext.getResponseHandler().getContentType(); // if it is established, make sure the set contains only // the established content type. Otherwise the set will // need to be rebuilt. if (establishedType != null && responseTypes != null && (responseTypes.size() > 0) && !responseTypes.contains(establishedType)) responseTypes = null; if (responseTypes != null) return responseTypes; responseTypes = new LinkedHashSet<String>(); String responseType = null; // first one added to Set Window window = getWindow(); Set<String> configTypes = window == null ? null : window.getSupportedContentTypes(getPortletMode()); boolean configSupportsAll = configTypes == null || configTypes.contains("*/*"); Set<String> clientTypes = _connection.getClientContentTypes(); boolean clientSupportsAll = clientTypes == null || clientTypes.isEmpty() || clientTypes.contains("*/*"); if (establishedType != null) { String wildcard = getWildcardContentType(establishedType); if ((configSupportsAll || configTypes.contains(establishedType) || configTypes.contains(wildcard)) && (clientSupportsAll || clientTypes.contains(establishedType) || clientTypes.contains(wildcard))) { responseTypes.add(establishedType); responseType = establishedType; } } else if (configSupportsAll) { Iterator<String> iter = clientTypes.iterator(); while (iter.hasNext()) { String clientType = iter.next(); if (responseType == null) responseType = clientType; responseTypes.add(clientType); } } else { Iterator<String> iter = configTypes.iterator(); // wildcards in the config are added a second time around, so that they // appear further down the list (they are less desirable as a return // value) boolean configHasWildcard = false; while (iter.hasNext()) { String configType = iter.next(); boolean isUsableConfigType = false; if (configType.indexOf('*') > -1) { configHasWildcard = true; } else if (clientSupportsAll || clientTypes.contains(configType)) { isUsableConfigType = true; } else { String wildcardConfigType = getWildcardContentType(configType); if (wildcardConfigType != null && clientTypes.contains(wildcardConfigType)) { isUsableConfigType = true; } } if (isUsableConfigType) { responseTypes.add(configType); if (responseType == null) responseType = configType; } } if (configHasWildcard) { iter = clientTypes.iterator(); while (iter.hasNext()) { String clientType = iter.next(); boolean isUsableClientType = false; if (configSupportsAll) isUsableClientType = true; else { String wildcardClientType = clientType.indexOf('*') > -1 ? clientType : getWildcardContentType(clientType); if (wildcardClientType != null && configTypes.contains(wildcardClientType)) { isUsableClientType = true; } } if (isUsableClientType) { responseTypes.add(clientType); if (responseType == null) responseType = clientType; } } } } _windowContext.setResponseContentType(responseType); _windowContext.setResponseContentTypes(responseTypes); return responseTypes; } // -- ResponseHandler public String getContentType() { return _windowContext.getResponseHandler().getContentType(); } public void setContentType(String contentType) { if (contentType.equals(_windowContext.getResponseHandler().getContentType())) return; // make sure the content type is allowed before // allowing it to be set PortletMode
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?