All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.util.URLExpander Maven / Gradle / Ivy

/*
 * $Id: URLExpander.java 12345 2004-08-22 04:56:09Z fielding $
 *
 * Copyright 1997-2004 Day Management AG
 * Barfuesserplatz 6, 4001 Basel, Switzerland
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Day Management AG, ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Day.
 */
package com.day.util;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;

import com.day.text.GlobPattern;
import com.day.text.Text;


/**
 * The handler expander is used to expand a globbing pattern to a list of
 * handles, that match the given pattern.
 *
 * @version $Revision: 1.12 $, $Date: 2004-08-22 06:56:09 +0200 (Sun, 22 Aug 2004) $
 * @author tripod
 * @since antbear
 */
public class URLExpander implements HandleExpander {
    /**
     * Expand the handles. assuming fully qualified URI's
     * @param pattern the pattern to match.
     */
    public String[] expand(String pattern) {
        try {
            URI uri=new URI(pattern);
            if (uri.getScheme()==null || uri.getScheme().equals("file")) {
                // expand while checking against files in directories resursively
                ArrayList list=new ArrayList();

                // Pattern may be an url - get the path component of it
                String path = uri.getPath();

                // StringBuffer should be empty not "."
                traverse_directory(list,new StringBuffer(path.length()), path.toCharArray(), 0);

                return (String[]) list.toArray(new String[list.size()]);
            } else {
                // assume url can handle this. only allow 'patterns' without wildcards
                URL url=uri.toURL();
                /** todo implement */
                throw new UnsupportedOperationException("hmpf. still have to do this");
            }
        } catch (URISyntaxException e) {
            /* ignore this */
        } catch (IOException e) {
            /* ignore this */
        }
        return new String[0];
    }
    /**
     * traverses directories an gets the filename, that match the pattern
     */
    private void traverse_directory(ArrayList list, StringBuffer dir, char[] ptr, int p) {
        // search last slash before next wildcard
        int lastslash=p;
        int first=p;
        while ((pfirst) {
                // add part until slash to basis
                dir.append('/');
                dir.append(ptr,first,lastslash-first);
                lastslash++;
            }
            // get next slash
            while (p




© 2015 - 2024 Weber Informatics LLC | Privacy Policy