use of java.util.Enumeration in project vert.x by eclipse.
the class StarterTest method clearProperties.
private void clearProperties() {
Set<String> toClear = new HashSet<>();
Enumeration e = System.getProperties().propertyNames();
// Uhh, properties suck
while (e.hasMoreElements()) {
String propName = (String) e.nextElement();
if (propName.startsWith("vertx.options")) {
toClear.add(propName);
}
}
for (String propName : toClear) {
System.clearProperty(propName);
}
}
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());
}
use of java.util.Enumeration in project che by eclipse.
the class Util method getJdkLevel.
/**
* Get the jdk level of this root.
* The value can be:
* <ul>
* <li>major<<16 + minor : see predefined constants on ClassFileConstants </li>
* <li><code>0</null> if the root is a source package fragment root or if a Java model exception occured</li>
* </ul>
* Returns the jdk level
*/
public static long getJdkLevel(Object targetLibrary) {
try {
ClassFileReader reader = null;
if (targetLibrary instanceof IFolder) {
// only internal classfolders are allowed
IFile classFile = findFirstClassFile((IFolder) targetLibrary);
if (classFile != null)
reader = Util.newClassFileReader(classFile);
} else {
// root is a jar file or a zip file
ZipFile jar = null;
try {
IPath path = null;
if (targetLibrary instanceof IResource) {
path = ((IResource) targetLibrary).getFullPath();
} else if (targetLibrary instanceof File) {
File f = (File) targetLibrary;
if (!f.isDirectory()) {
path = new Path(((File) targetLibrary).getPath());
}
}
if (path != null) {
jar = JavaModelManager.getJavaModelManager().getZipFile(path);
for (Enumeration e = jar.entries(); e.hasMoreElements(); ) {
ZipEntry member = (ZipEntry) e.nextElement();
String entryName = member.getName();
if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
reader = ClassFileReader.read(jar, entryName);
break;
}
}
}
} catch (CoreException e) {
// ignore
} finally {
JavaModelManager.getJavaModelManager().closeZipFile(jar);
}
}
if (reader != null) {
return reader.getVersion();
}
} catch (CoreException e) {
// ignore
} catch (ClassFormatException e) {
// ignore
} catch (IOException e) {
// ignore
}
return 0;
}
Aggregations