/*
  * @see org.mortbay.util.Attributes#getAttributeNames()
  */
 public static Enumeration getAttributeNamesCopy(Attributes attrs) {
   if (attrs instanceof AttributesMap)
     return Collections.enumeration(((AttributesMap) attrs)._map.keySet());
   ArrayList names = new ArrayList();
   Enumeration e = attrs.getAttributeNames();
   while (e.hasMoreElements()) names.add(e.nextElement());
   return Collections.enumeration(names);
 }
  /**
   * Return an <code>Enumeration</code> of the names of the initialization parameters for this
   * Filter.
   */
  @Override
  public Enumeration<String> getInitParameterNames() {
    Map<String, String> map = filterDef.getParameterMap();

    if (map == null) {
      return Collections.enumeration(emptyString);
    }

    return Collections.enumeration(map.keySet());
  }
 /**
  * Note: For element with {@code #nestedBlock}, this will hide the {@code #nestedBlock} when
  * that's a {@link MixedContent}.
  */
 public Enumeration children() {
   if (nestedBlock instanceof MixedContent) {
     return nestedBlock.children();
   }
   if (nestedBlock != null) {
     return Collections.enumeration(Collections.singletonList(nestedBlock));
   } else if (regulatedChildBuffer != null) {
     return new _ArrayEnumeration(regulatedChildBuffer, regulatedChildCount);
   }
   return Collections.enumeration(Collections.EMPTY_LIST);
 }
  @Override
  public Enumeration<URL> getResources(final String name) throws IOException {
    if (!getState().isAvailable()) {
      return null;
    }

    if ("META-INF/services/javax.servlet.ServletContainerInitializer".equals(name)) {
      final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name)));
      final Iterator<URL> it = list.iterator();
      while (it.hasNext()) {
        final URL next = it.next();
        final File file = Files.toFile(next);
        if (!file.isFile() && NewLoaderLogic.skip(next)) {
          it.remove();
        }
      }
      return Collections.enumeration(list);
    }
    if ("META-INF/services/javax.websocket.ContainerProvider".equals(name)) {
      final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name)));
      final Iterator<URL> it = list.iterator();
      while (it.hasNext()) {
        final URL next = it.next();
        final File file = Files.toFile(next);
        if (!file.isFile() && NewLoaderLogic.skip(next)) {
          it.remove();
        }
      }
      return Collections.enumeration(list);
    }
    if ("META-INF/faces-config.xml".equals(name)) { // mojarra workaround
      try {
        if (WebBeansContext.currentInstance() == null
            && Boolean.parseBoolean(
                SystemInstance.get().getProperty("tomee.jsf.ignore-owb", "true"))) {
          final Collection<URL> list = new HashSet<>(Collections.list(super.getResources(name)));
          final Iterator<URL> it = list.iterator();
          while (it.hasNext()) {
            final String fileName = Files.toFile(it.next()).getName();
            if (fileName.startsWith("openwebbeans-" /*jsf|el22*/) && fileName.endsWith(".jar")) {
              it.remove();
            }
          }
          return Collections.enumeration(list);
        }
      } catch (final Throwable th) {
        // no-op
      }
    }
    return URLClassLoaderFirst.filterResources(name, super.getResources(name));
  }
Esempio n. 5
0
  /** @see java.lang.ClassLoader#findResources(java.lang.String) */
  @Override
  public Enumeration<URL> findResources(String resourceName) throws IOException {
    ArrayList<URL> cachedUrls = resourceAllCache.get(resourceName);
    if (cachedUrls != null) return Collections.enumeration(cachedUrls);

    ArrayList<URL> urlList = new ArrayList<>();
    int classesDirectoryListSize = classesDirectoryList.size();
    for (int i = 0; i < classesDirectoryListSize; i++) {
      File classesDir = classesDirectoryList.get(i);
      File testFile = new File(classesDir.getAbsolutePath() + "/" + resourceName);
      try {
        if (testFile.exists() && testFile.isFile()) urlList.add(testFile.toURI().toURL());
      } catch (MalformedURLException e) {
        System.out.println(
            "Error making URL for ["
                + resourceName
                + "] in classes directory ["
                + classesDir
                + "]: "
                + e.toString());
      }
    }
    int jarFileListSize = jarFileList.size();
    for (int i = 0; i < jarFileListSize; i++) {
      JarFile jarFile = jarFileList.get(i);
      JarEntry jarEntry = jarFile.getJarEntry(resourceName);
      if (jarEntry != null) {
        try {
          String jarFileName = jarFile.getName();
          if (jarFileName.contains("\\")) jarFileName = jarFileName.replace('\\', '/');
          urlList.add(new URL("jar:file:" + jarFileName + "!/" + jarEntry));
        } catch (MalformedURLException e) {
          System.out.println(
              "Error making URL for ["
                  + resourceName
                  + "] in jar ["
                  + jarFile
                  + "]: "
                  + e.toString());
        }
      }
    }
    // add all resources found in parent loader too
    Enumeration<URL> superResources = getParent().getResources(resourceName);
    while (superResources.hasMoreElements()) urlList.add(superResources.nextElement());
    resourceAllCache.putIfAbsent(resourceName, urlList);
    // System.out.println("finding all resources with name " + resourceName + " got " + urlList);
    return Collections.enumeration(urlList);
  }
 @Override
 public Enumeration<String> getKeys() {
   // TODO Auto-generated method stub
   return null != delegate
       ? delegate.getKeys()
       : Collections.<String>enumeration(Collections.<String>emptyList());
 }
  /*
   * @see java.net.URLClassLoader#findResources(java.lang.String)
   */
  @Override
  public Enumeration<URL> findResources(String name) throws IOException {
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    if (fContextClassloader != null) {
      Thread.currentThread().setContextClassLoader(fContextClassloader);
    }
    ArrayList<URL> all = new ArrayList<>();
    try {
      if (fAllowPluginLoading
          || !(name.startsWith(ANT_URL_PREFIX) || name.startsWith(ANT_URL_PREFIX, 1))) {
        if (fPluginLoaders != null) {
          Enumeration<URL> result = null;
          for (int i = 0; i < fPluginLoaders.length; i++) {
            result = fPluginLoaders[i].getResources(name);
            while (result.hasMoreElements()) {
              all.add(result.nextElement());
            }
          }
        }
      }

      Enumeration<URL> superResources = super.findResources(name);
      if (all.isEmpty()) {
        return superResources;
      }

      while (superResources.hasMoreElements()) {
        all.add(superResources.nextElement());
      }
      return Collections.enumeration(all);
    } finally {
      Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
  }
 public Enumeration<String> getHeaders(String s) {
   String[] values = headerMap.get(s);
   if (values == null) {
     return null;
   }
   return Collections.enumeration(Arrays.asList(values));
 }
Esempio n. 9
0
  private void doGet(Map<String, String> parameters, boolean checkResultContent)
      throws IOException, ServletException {
    final HttpServletRequest request = createNiceMock(HttpServletRequest.class);
    expect(request.getRequestURI()).andReturn("/test/monitoring").anyTimes();
    expect(request.getRequestURL()).andReturn(new StringBuffer("/test/monitoring")).anyTimes();
    expect(request.getContextPath()).andReturn(CONTEXT_PATH).anyTimes();
    expect(request.getRemoteAddr()).andReturn("here").anyTimes();
    for (final Map.Entry<String, String> entry : parameters.entrySet()) {
      if (REQUEST_PARAMETER.equals(entry.getKey())) {
        expect(request.getHeader(entry.getKey())).andReturn(entry.getValue()).anyTimes();
      } else {
        expect(request.getParameter(entry.getKey())).andReturn(entry.getValue()).anyTimes();
      }
    }
    expect(request.getHeaders("Accept-Encoding"))
        .andReturn(Collections.enumeration(Arrays.asList("application/gzip")))
        .anyTimes();
    final HttpServletResponse response = createNiceMock(HttpServletResponse.class);
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    expect(response.getOutputStream()).andReturn(new FilterServletOutputStream(output)).anyTimes();
    final StringWriter stringWriter = new StringWriter();
    expect(response.getWriter()).andReturn(new PrintWriter(stringWriter)).anyTimes();

    replay(request);
    replay(response);
    reportServlet.doGet(request, response);
    verify(request);
    verify(response);

    if (checkResultContent) {
      assertTrue("result", output.size() != 0 || stringWriter.getBuffer().length() != 0);
    }
  }
Esempio n. 10
0
    public Enumeration<? extends ZipEntry> entries() {
      Enumeration<? extends ZipEntry> entries = null;

      if (_zipfile != null) {
        entries = _zipfile.entries();
      } else if (_url != null) {
        try {
          URLConnection con = _url.openConnection();
          con.connect();
          InputStream is = con.getInputStream();
          ZipInputStream zis = new ZipInputStream(is);
          List<ZipEntry> entryList = new ArrayList<ZipEntry>();
          ZipEntry ze;

          while ((ze = zis.getNextEntry()) != null) {
            entryList.add(ze);
          } // end while

          entries = Collections.enumeration(entryList);
        } catch (IOException ex) {
          entries = null;
        }
      } // end if

      return entries;
    }
  public void testSetParameters() {
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HashMap<String, Object> model = new HashMap<String, Object>();
    model.put("p2", "2a");
    model.put("p3", null);

    expect(request.getParameterNames())
        .andReturn(Collections.enumeration(Arrays.asList("p1", "p2", "p3", "p4")));
    expect(request.getParameter("p1")).andReturn("1");
    // expect(request.getParameter("p2")).andReturn("2");
    // expect(request.getParameter("p3")).andReturn("3");
    expect(request.getParameter("p4")).andReturn("");

    replay(request);

    RequestModelHelper.setParameters(request, model);

    assertEquals(4, model.size());
    assertEquals("1", model.get("p1"));
    assertEquals("2a", model.get("p2"));
    assertEquals(null, model.get("p3"));
    assertEquals("", model.get("p4"));

    verify(request);
  }
  public Enumeration<String> getResponseContentTypes() {
    List<String> responseContentTypes = new ArrayList<String>();

    responseContentTypes.add(getResponseContentType());

    return Collections.enumeration(responseContentTypes);
  }
 private Enumeration<URL> getUrlsEnum(String... names) throws MalformedURLException {
   List<URL> urls = new ArrayList<URL>();
   for (String name : names) {
     urls.add(new URL("file://" + name));
   }
   return Collections.enumeration(urls);
 }
Esempio n. 14
0
  @Override
  public Enumeration getHeaders(String name) {

    ArrayList list = new ArrayList<String>();
    // Never override the parent Request
    if (!name.equalsIgnoreCase("content-type")) {
      list = Collections.list(b.request.getHeaders(name));
    }

    if (name.equalsIgnoreCase("content-type")) {
      String s = getContentType();
      if (s != null) {
        list.add(s);
      }
    } else {
      if (b.headers.get(name) != null) {
        list.add(b.headers.get(name));
      }

      if (isNotNoOps()) {
        if (list.size() == 0 && name.startsWith(X_ATMOSPHERE)) {
          if (attributeWithoutException(b.request, name) != null) {
            list.add(attributeWithoutException(b.request, name));
          }
        }
      }
    }
    return Collections.enumeration(list);
  }
 @Override
 public Enumeration getAttributeNames() {
   Set nms = new LinkedHashSet();
   nms.addAll(attr.keySet());
   nms.addAll(Collections.list(super.getAttributeNames()));
   return Collections.enumeration(nms);
 }
        @Override
        protected Enumeration<URL> findResources(String name) throws IOException {
            HashSet<URL> result = new HashSet<URL>();

            if (PluginManager.FAST_LOOKUP) {
                try {
                    for (PluginWrapper pw : getTransitiveDependencies()) {
                        Enumeration<URL> urls = clt.findResources(pw.classLoader, name);
                        while (urls != null && urls.hasMoreElements())
                            result.add(urls.nextElement());
                    }
                } catch (InvocationTargetException e) {
                    throw new Error(e);
                }
            } else {
                for (Dependency dep : dependencies) {
                    PluginWrapper p = pluginManager.getPlugin(dep.shortName);
                    if (p!=null) {
                        Enumeration<URL> urls = p.classLoader.getResources(name);
                        while (urls != null && urls.hasMoreElements())
                            result.add(urls.nextElement());
                    }
                }
            }

            return Collections.enumeration(result);
        }
  @Override
  public Enumeration<URL> getResources(String name) throws IOException {
    log.warn(
        "BundleClassLoaderProxy.getResources:" + name + "  at Bundle:" + bundle.getSymbolicName());
    // 如果是读取class文件,则交给真正的ClassLoader去处理
    if (name.endsWith(".class")) {
      return super.getResources(name);
    }

    List<URL> list = new ArrayList<URL>();

    Enumeration<URL> urlEnum = bundleClassLoader.getResources(name);
    if (urlEnum != null) {
      while (urlEnum.hasMoreElements()) {
        list.add(urlEnum.nextElement());
      }
    }
    urlEnum = springClassLoader.getResources(name);
    if (urlEnum != null) {
      while (urlEnum.hasMoreElements()) {
        list.add(urlEnum.nextElement());
      }
    }
    return Collections.enumeration(list);
  }
Esempio n. 18
0
 /** @see java.lang.ClassLoader#findResources(java.lang.String) */
 @Override
 public Enumeration<URL> findResources(String resourceName) throws IOException {
   String webInfResourceName = "WEB-INF/classes/" + resourceName;
   List<URL> urlList = new ArrayList<URL>();
   int jarFileListSize = jarFileList.size();
   for (int i = 0; i < jarFileListSize; i++) {
     JarFile jarFile = jarFileList.get(i);
     JarEntry jarEntry = jarFile.getJarEntry(resourceName);
     // to better support war format, look for the resourceName in the WEB-INF/classes directory
     if (loadWebInf && jarEntry == null) jarEntry = jarFile.getJarEntry(webInfResourceName);
     if (jarEntry != null) {
       try {
         String jarFileName = jarFile.getName();
         if (jarFileName.contains("\\")) jarFileName = jarFileName.replace('\\', '/');
         urlList.add(new URL("jar:file:" + jarFileName + "!/" + jarEntry));
       } catch (MalformedURLException e) {
         System.out.println(
             "Error making URL for ["
                 + resourceName
                 + "] in jar ["
                 + jarFile
                 + "] in war file ["
                 + outerFile
                 + "]: "
                 + e.toString());
       }
     }
   }
   // add all resources found in parent loader too
   Enumeration<URL> superResources = super.findResources(resourceName);
   while (superResources.hasMoreElements()) urlList.add(superResources.nextElement());
   return Collections.enumeration(urlList);
 }
 public ArrayList<EventType> getEventTypeList() {
   if (!haveMessage()) {
     return null;
   }
   ArrayList<EventType> valueList =
       Collections.list(Collections.enumeration(mMssageTable.values()));
   return valueList;
 }
 @Override
 public Enumeration<String> getKeys() {
   List<String> keys = new LinkedList<String>();
   for (M messageCode : EnumSet.allOf(messageCodeClass)) {
     keys.add(messageCode.getCode());
   }
   return Collections.enumeration(keys);
 }
Esempio n. 21
0
  public static void saveOptions() {
    try {
      PrintWriter printwriter = new PrintWriter(new FileWriter(optionsFile));

      Enumeration<ControlPackEnumOptions> keys = Collections.enumeration(floatOptions.keySet());
      while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        ControlPackEnumOptions option = (ControlPackEnumOptions) key;
        Float value = floatOptions.get(option);
        printwriter.println(
            (new StringBuilder(option.getName()).append(":").append(value)).toString());
      }

      keys = Collections.enumeration(booleanOptions.keySet());
      while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        ControlPackEnumOptions option = (ControlPackEnumOptions) key;
        Boolean value = booleanOptions.get(option);
        printwriter.println(
            (new StringBuilder(option.getName()).append(":").append(value)).toString());
      }

      keys = Collections.enumeration(intOptions.keySet());
      while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        ControlPackEnumOptions option = (ControlPackEnumOptions) key;
        int value = intOptions.get(option);
        printwriter.println(
            (new StringBuilder(option.getName()).append(":").append(value)).toString());
      }

      keys = Collections.enumeration(stringOptions.keySet());
      while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        ControlPackEnumOptions option = (ControlPackEnumOptions) key;
        String value = stringOptions.get(option);
        printwriter.println(
            (new StringBuilder(option.getName()).append(":").append(value)).toString());
      }

      printwriter.close();
    } catch (Exception exception) {
      System.out.println("Failed to save controlpack options");
      exception.printStackTrace();
    }
  }
  @Override
  @SuppressWarnings("unchecked")
  public Enumeration getParameterNames() {
    if (parameters == null) {
      parseRequest();
    }

    return Collections.enumeration(parameters.keySet());
  }
Esempio n. 23
0
  @Override
  public InputStream getContent() throws IOException {
    final ArrayList<InputStream> parts = new ArrayList<InputStream>(3);
    parts.add(new ByteArrayInputStream(header)); // segment header
    parts.add(super.getContent()); // the segment body
    parts.add(new ByteArrayInputStream(footer)); // segment footer

    return new SequenceInputStream(Collections.enumeration(parts));
  }
  @SuppressWarnings("unchecked")
  @Override
  public Enumeration<String> getAttributeNames() throws RemoteException, RemoteException {
    Set<String> names = new HashSet<String>();
    names.addAll(getAttributes().keySet());

    return gerenciadornuvem1.<String>getReplicatedContextMultiEnumeration(
        new Enumeration[] {super.getAttributeNames(), Collections.enumeration(names)});
  }
Esempio n. 25
0
 @Override
 public Enumeration<String> getAttributeNames() {
   final Set<String> set = new HashSet<String>(attributes_.keySet());
   final Enumeration<?> e = super.getAttributeNames();
   while (e.hasMoreElements()) {
     set.add(e.nextElement().toString());
   }
   return Collections.enumeration(set);
 }
 /**
  * Returns an enumeration of all the {@code CapabilityPermission} objects in the container.
  *
  * @return Enumeration of all the CapabilityPermission objects.
  */
 @Override
 public synchronized Enumeration<Permission> elements() {
   List<Permission> all = new ArrayList<Permission>(permissions.values());
   Map<String, CapabilityPermission> pc = filterPermissions;
   if (pc != null) {
     all.addAll(pc.values());
   }
   return Collections.enumeration(all);
 }
  public Boolean concatenar(List<String> sourceFilesList, String destinationFileName)
      throws Exception {
    Boolean result = false;

    AudioInputStream audioInputStream = null;
    List<AudioInputStream> audioInputStreamList = null;
    AudioFormat audioFormat = null;
    Long frameLength = null;

    try {
      // loop through our files first and load them up
      for (String sourceFile : sourceFilesList) {
        audioInputStream = AudioSystem.getAudioInputStream(new File("TP6B/audio/" + sourceFile));

        // get the format of first file
        if (audioFormat == null) {
          audioFormat = audioInputStream.getFormat();
        }

        // add it to our stream list
        if (audioInputStreamList == null) {
          audioInputStreamList = new ArrayList<AudioInputStream>();
        }
        audioInputStreamList.add(audioInputStream);

        // keep calculating frame length
        if (frameLength == null) {
          frameLength = audioInputStream.getFrameLength();
        } else {
          frameLength += audioInputStream.getFrameLength();
        }
      }

      // now write our concatenated file
      AudioSystem.write(
          new AudioInputStream(
              new SequenceInputStream(Collections.enumeration(audioInputStreamList)),
              audioFormat,
              frameLength),
          AudioFileFormat.Type.WAVE,
          new File(destinationFileName));

      // if all is good, return true
      result = true;
    } catch (Exception e) {
      throw e;
    } finally {
      if (audioInputStream != null) {
        audioInputStream.close();
      }
      if (audioInputStreamList != null) {
        audioInputStreamList = null;
      }
    }

    return result;
  }
Esempio n. 28
0
 @Override
 public Enumeration<URL> findResources(String name) throws IOException {
   final HashSet<URL> urls = new HashSet<>();
   for (PomClassLoader cl : parents) {
     urls.addAll(Collections.list(cl.findResources(name)));
   }
   urls.addAll(Collections.list(super.findResources(name)));
   return Collections.enumeration(urls);
 }
 public Enumeration<String> getHeaders(String name) {
   String headerValue = headers.get(name);
   if (headerValue != null) {
     String[] multiValuedHeader = headerValue.split(",");
     return Collections.enumeration(Arrays.asList(multiValuedHeader));
   } else {
     return Collections.emptyEnumeration();
   }
 }
Esempio n. 30
0
 private static Enumeration<URL> getResources(ClassLoader classLoader, String name) {
   Enumeration<URL> enumer;
   try {
     enumer = classLoader.getResources(name);
   } catch (IOException e) {
     List<URL> emptyList = Collections.emptyList();
     enumer = Collections.enumeration(emptyList);
   }
   return enumer;
 }