use of java.util.Enumeration in project jetty.project by eclipse.
the class Request method getLocales.
/* ------------------------------------------------------------ */
/*
* @see javax.servlet.ServletRequest#getLocales()
*/
@Override
public Enumeration<Locale> getLocales() {
MetaData.Request metadata = _metaData;
if (metadata == null)
return Collections.enumeration(__defaultLocale);
List<String> acceptable = metadata.getFields().getQualityCSV(HttpHeader.ACCEPT_LANGUAGE);
// handle no locale
if (acceptable.isEmpty())
return Collections.enumeration(__defaultLocale);
List<Locale> locales = acceptable.stream().map(language -> {
language = HttpFields.stripParameters(language);
String country = "";
int dash = language.indexOf('-');
if (dash > -1) {
country = language.substring(dash + 1).trim();
language = language.substring(0, dash).trim();
}
return new Locale(language, country);
}).collect(Collectors.toList());
return Collections.enumeration(locales);
}
use of java.util.Enumeration in project vert.x by eclipse.
the class BareCommand method configureFromSystemProperties.
protected void configureFromSystemProperties(Object options, String prefix) {
Properties props = System.getProperties();
Enumeration e = props.propertyNames();
// Uhh, properties suck
while (e.hasMoreElements()) {
String propName = (String) e.nextElement();
String propVal = props.getProperty(propName);
if (propName.startsWith(prefix)) {
String fieldName = propName.substring(prefix.length());
Method setter = getSetter(fieldName, options.getClass());
if (setter == null) {
log.warn("No such property to configure on options: " + options.getClass().getName() + "." + fieldName);
continue;
}
Class<?> argType = setter.getParameterTypes()[0];
Object arg;
try {
if (argType.equals(String.class)) {
arg = propVal;
} else if (argType.equals(int.class)) {
arg = Integer.valueOf(propVal);
} else if (argType.equals(long.class)) {
arg = Long.valueOf(propVal);
} else if (argType.equals(boolean.class)) {
arg = Boolean.valueOf(propVal);
} else {
log.warn("Invalid type for setter: " + argType);
continue;
}
} catch (IllegalArgumentException e2) {
log.warn("Invalid argtype:" + argType + " on options: " + options.getClass().getName() + "." + fieldName);
continue;
}
try {
setter.invoke(options, arg);
} catch (Exception ex) {
throw new VertxException("Failed to invoke setter: " + setter, ex);
}
}
}
}
use of java.util.Enumeration in project jetty.project by eclipse.
the class AnnotationParser method parse.
protected void parse(Set<? extends Handler> handlers, Bundle bundle) throws Exception {
URI uri = _bundleToUri.get(bundle);
if (!_alreadyParsed.add(uri)) {
return;
}
String bundleClasspath = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH);
if (bundleClasspath == null) {
bundleClasspath = ".";
}
//order the paths first by the number of tokens in the path second alphabetically.
TreeSet<String> paths = new TreeSet<String>(new Comparator<String>() {
public int compare(String o1, String o2) {
int paths1 = new StringTokenizer(o1, "/", false).countTokens();
int paths2 = new StringTokenizer(o2, "/", false).countTokens();
if (paths1 == paths2) {
return o1.compareTo(o2);
}
return paths2 - paths1;
}
});
boolean hasDotPath = false;
StringTokenizer tokenizer = new StringTokenizer(bundleClasspath, ",;", false);
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken().trim();
if (!token.startsWith("/")) {
token = "/" + token;
}
if (token.equals("/.")) {
hasDotPath = true;
} else if (!token.endsWith(".jar") && !token.endsWith("/")) {
paths.add(token + "/");
} else {
paths.add(token);
}
}
//however it makes our life so much easier during development.
if (bundle.getEntry("/.classpath") != null) {
if (bundle.getEntry("/bin/") != null) {
paths.add("/bin/");
} else if (bundle.getEntry("/target/classes/") != null) {
paths.add("/target/classes/");
}
}
Enumeration classes = bundle.findEntries("/", "*.class", true);
if (classes == null) {
return;
}
while (classes.hasMoreElements()) {
URL classUrl = (URL) classes.nextElement();
String path = classUrl.getPath();
//remove the longest path possible:
String name = null;
for (String prefixPath : paths) {
if (path.startsWith(prefixPath)) {
name = path.substring(prefixPath.length());
break;
}
}
if (name == null && hasDotPath) {
//remove the starting '/'
name = path.substring(1);
}
if (name == null) {
//or the bundle classpath wasn't simply ".", so skip it
continue;
}
//transform into a classname to pass to the resolver
String shortName = name.replace('/', '.').substring(0, name.length() - 6);
if (!isParsed(shortName)) {
try (InputStream classInputStream = classUrl.openStream()) {
scanClass(handlers, getResource(bundle), classInputStream);
}
}
}
}
use of java.util.Enumeration in project jetty.project by eclipse.
the class MailSessionReference method getObjectInstance.
/**
* Create a javax.mail.Session instance based on the information passed in the Reference
* @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
* @param ref the Reference
* @param arg1 not used
* @param arg2 not used
* @param arg3 not used
* @return the object found
* @throws Exception if unable to get object instance
*/
public Object getObjectInstance(Object ref, Name arg1, Context arg2, Hashtable arg3) throws Exception {
if (ref == null)
return null;
Reference reference = (Reference) ref;
Properties props = new Properties();
String user = null;
String password = null;
Enumeration refs = reference.getAll();
while (refs.hasMoreElements()) {
RefAddr refAddr = (RefAddr) refs.nextElement();
String name = refAddr.getType();
String value = (String) refAddr.getContent();
if (name.equalsIgnoreCase("user"))
user = value;
else if (name.equalsIgnoreCase("pwd"))
password = value;
else
props.put(name, value);
}
if (password == null)
return Session.getInstance(props);
else
return Session.getInstance(props, new PasswordAuthenticator(user, password));
}
use of java.util.Enumeration in project jetty.project by eclipse.
the class HttpMethodsServlet method doTrace.
/**
* @see HttpServlet#doTrace(HttpServletRequest, HttpServletResponse)
*/
protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.addHeader("Content-Type", "message/http");
StringBuffer msg = new StringBuffer();
msg.append(request.getMethod()).append(' ');
msg.append(request.getRequestURI()).append(' ');
msg.append(request.getProtocol()).append("\n");
// Now the headers
Enumeration enNames = request.getHeaderNames();
while (enNames.hasMoreElements()) {
String name = (String) enNames.nextElement();
Enumeration enValues = request.getHeaders(name);
while (enValues.hasMoreElements()) {
String value = (String) enValues.nextElement();
msg.append(name).append(": ").append(value).append("\n");
}
}
msg.append("\n");
response.getWriter().print(msg.toString());
}
Aggregations