Example usage for java.util Vector addElement

List of usage examples for java.util Vector addElement

Introduction

In this page you can find the example usage for java.util Vector addElement.

Prototype

public synchronized void addElement(E obj) 

Source Link

Document

Adds the specified component to the end of this vector, increasing its size by one.

Usage

From source file:axiom.objectmodel.db.NodeManager.java

/**
 *  Similar to getNodeIDs, but returns a Vector that return's the nodes property names instead of IDs
 *///from   w  ww . ja v  a  2 s .c  om
public Vector getPropertyNames(Node home, Relation rel) throws Exception {
    // Transactor tx = (Transactor) Thread.currentThread ();
    // tx.timer.beginEvent ("getNodeIDs "+home);
    if ((rel == null) || (rel.otherType == null) || !rel.otherType.isRelational()) {
        // this should never be called for embedded nodes
        throw new RuntimeException("NodeMgr.getPropertyNames called for non-relational node " + home);
    } else {
        Vector retval = new Vector();

        // if we do a groupby query (creating an intermediate layer of groupby nodes),
        // retrieve the value of that field instead of the primary key
        String namefield = (rel.groupby == null) ? rel.accessName : rel.groupby;
        Connection con = rel.otherType.getConnection();
        // set connection to read-only mode
        if (!con.isReadOnly())
            con.setReadOnly(true);

        String table = rel.otherType.getTableName();
        StringBuffer tables = new StringBuffer(table);
        rel.appendAdditionalTables(tables);

        Statement stmt = null;
        long logTimeStart = logSql ? System.currentTimeMillis() : 0;
        String query = null;

        try {
            // NOTE: we explicitly convert tables StringBuffer to a String
            // before appending to be compatible with JDK 1.3
            StringBuffer b = new StringBuffer("SELECT ").append(namefield).append(" FROM ")
                    .append(tables.toString());

            if (home.getSubnodeRelation() != null) {
                b.append(" ").append(home.getSubnodeRelation());
            } else {
                // let relation object build the query
                b.append(rel.buildQuery(home, home.getNonVirtualParent(), null, " WHERE ", true));
            }

            stmt = con.createStatement();

            query = b.toString();

            ResultSet rs = stmt.executeQuery(query);

            while (rs.next()) {
                String n = rs.getString(1);

                if (n != null) {
                    retval.addElement(n);
                }
            }
        } finally {
            if (logSql) {
                long logTimeStop = System.currentTimeMillis();
                logSqlStatement("SQL SELECT_ACCESSNAMES", table, logTimeStart, logTimeStop, query);
            }

            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception ex) {
                    app.logError(ErrorReporter.errorMsg(this.getClass(), "getPropertyNames"), ex);
                }
            }
        }

        return retval;
    }
}

From source file:com.zeroio.webdav.WebdavServlet.java

/**
 * Propfind helper method.//from ww w  . j  a  v  a  2  s  .c  o  m
 *
 * @param resources        Resources object associated with this context
 * @param generatedXML     XML response to the Propfind request
 * @param path             Path of the current resource
 * @param type             Propfind type
 * @param propertiesVector If the propfind type is find properties by name,
 *                         then this Vector contains those properties
 * @param context          Description of the Parameter
 * @throws IOException Description of the Exception
 */
private void parseProperties(ActionContext context, ModuleContext resources, XMLWriter generatedXML,
        String path, int type, Vector propertiesVector) throws IOException {

    // Exclude any resource in the /WEB-INF and /META-INF subdirectories
    // (the "toUpperCase()" avoids problems on Windows systems)
    if (path.toUpperCase().startsWith("/WEB-INF") || path.toUpperCase().startsWith("/META-INF")) {
        return;
    }

    ResourceInfo resourceInfo = null;
    SystemStatus thisSystem = null;
    boolean actionStatus = true;
    try {
        thisSystem = this.getSystemStatus(context);
        resourceInfo = new ResourceInfo(thisSystem, path, resources);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.out);
        actionStatus = false;
    }

    if (!actionStatus) {
        return;
    }

    generatedXML.writeElement(null, "response", XMLWriter.OPENING);
    String status = new String(
            "HTTP/1.1 " + WebdavStatus.SC_OK + " " + WebdavStatus.getStatusText(WebdavStatus.SC_OK));

    // Generating href element
    generatedXML.writeElement(null, "href", XMLWriter.OPENING);

    String href = context.getRequest().getContextPath();
    if ((href.endsWith("/")) && (path.startsWith("/"))) {
        href += path.substring(1);
    } else {
        href += path;
    }
    if ((resourceInfo.collection) && (!href.endsWith("/"))) {
        href += "/";
    }

    //Encode the path information for this resource
    generatedXML.writeText(rewriteUrl(href));
    generatedXML.writeElement(null, "href", XMLWriter.CLOSING);

    String resourceName = path;
    int lastSlash = path.lastIndexOf('/');
    if (lastSlash != -1) {
        resourceName = resourceName.substring(lastSlash + 1);
    }

    //System.out.println("CLIENT FILENAME: " + resourceInfo.clientFilename);
    //System.out.println("CONTENT TYPE: " + getServletContext().getMimeType(resourceInfo.clientFilename));

    switch (type) {

    case FIND_ALL_PROP:

        generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
        generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
        generatedXML.writeProperty(null, "creationdate", resourceInfo.creationDate);
        generatedXML.writeElement(null, "displayname", XMLWriter.OPENING);
        generatedXML.writeData(resourceName);
        generatedXML.writeElement(null, "displayname", XMLWriter.CLOSING);
        if (!resourceInfo.collection) {
            generatedXML.writeProperty(null, "getlastmodified", resourceInfo.httpDate);
            generatedXML.writeProperty(null, "getcontentlength", String.valueOf(resourceInfo.length));
            String contentType = getServletContext().getMimeType(resourceInfo.clientFilename);
            if (contentType != null) {
                generatedXML.writeProperty(null, "getcontenttype", contentType);
            }
            generatedXML.writeProperty(null, "getetag", getETag(resourceInfo));
            generatedXML.writeElement(null, "resourcetype", XMLWriter.NO_CONTENT);
        } else {
            generatedXML.writeElement(null, "resourcetype", XMLWriter.OPENING);
            generatedXML.writeElement(null, "collection", XMLWriter.NO_CONTENT);
            generatedXML.writeElement(null, "resourcetype", XMLWriter.CLOSING);
        }

        generatedXML.writeProperty(null, "source", "");

        String supportedLocks = "<lockentry>" + "<lockscope><exclusive/></lockscope>"
                + "<locktype><write/></locktype>" + "</lockentry>" + "<lockentry>"
                + "<lockscope><shared/></lockscope>" + "<locktype><write/></locktype>" + "</lockentry>";
        generatedXML.writeElement(null, "supportedlock", XMLWriter.OPENING);
        generatedXML.writeText(supportedLocks);
        generatedXML.writeElement(null, "supportedlock", XMLWriter.CLOSING);

        generateLockDiscovery(path, generatedXML);

        generatedXML.writeElement(null, "prop", XMLWriter.CLOSING);
        generatedXML.writeElement(null, "status", XMLWriter.OPENING);
        generatedXML.writeText(status);
        generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
        generatedXML.writeElement(null, "propstat", XMLWriter.CLOSING);

        break;
    case FIND_PROPERTY_NAMES:
        generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
        generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
        generatedXML.writeElement(null, "creationdate", XMLWriter.NO_CONTENT);
        generatedXML.writeElement(null, "displayname", XMLWriter.NO_CONTENT);
        if (!resourceInfo.collection) {
            generatedXML.writeElement(null, "getcontentlanguage", XMLWriter.NO_CONTENT);
            generatedXML.writeElement(null, "getcontentlength", XMLWriter.NO_CONTENT);
            generatedXML.writeElement(null, "getcontenttype", XMLWriter.NO_CONTENT);
            generatedXML.writeElement(null, "getetag", XMLWriter.NO_CONTENT);
            generatedXML.writeElement(null, "getlastmodified", XMLWriter.NO_CONTENT);
        }
        generatedXML.writeElement(null, "resourcetype", XMLWriter.NO_CONTENT);
        generatedXML.writeElement(null, "source", XMLWriter.NO_CONTENT);
        generatedXML.writeElement(null, "lockdiscovery", XMLWriter.NO_CONTENT);
        generatedXML.writeElement(null, "prop", XMLWriter.CLOSING);
        generatedXML.writeElement(null, "status", XMLWriter.OPENING);
        generatedXML.writeText(status);
        generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
        generatedXML.writeElement(null, "propstat", XMLWriter.CLOSING);
        break;
    case FIND_BY_PROPERTY:
        Vector propertiesNotFound = new Vector();
        // Parse the list of properties
        generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
        generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
        Enumeration properties = propertiesVector.elements();
        while (properties.hasMoreElements()) {
            String property = (String) properties.nextElement();
            if (property.equals("creationdate")) {
                generatedXML.writeProperty(null, "creationdate", resourceInfo.creationDate);
            } else if (property.equals("displayname")) {
                generatedXML.writeElement(null, "displayname", XMLWriter.OPENING);
                generatedXML.writeData(resourceName);
                generatedXML.writeElement(null, "displayname", XMLWriter.CLOSING);
            } else if (property.equals("getcontentlanguage")) {
                if (resourceInfo.collection) {
                    propertiesNotFound.addElement(property);
                } else {
                    generatedXML.writeElement(null, "getcontentlanguage", XMLWriter.NO_CONTENT);
                }
            } else if (property.equals("getcontentlength")) {
                if (resourceInfo.collection) {
                    propertiesNotFound.addElement(property);
                } else {
                    generatedXML.writeProperty(null, "getcontentlength", (String.valueOf(resourceInfo.length)));
                }
            } else if (property.equals("getcontenttype")) {
                if (resourceInfo.collection) {
                    propertiesNotFound.addElement(property);
                } else {
                    generatedXML.writeProperty(null, "getcontenttype",
                            getServletContext().getMimeType(resourceInfo.clientFilename));
                }
            } else if (property.equals("getetag")) {
                if (resourceInfo.collection) {
                    propertiesNotFound.addElement(property);
                } else {
                    generatedXML.writeProperty(null, "getetag", getETag(resourceInfo));
                }
            } else if (property.equals("getlastmodified")) {
                if (resourceInfo.collection) {
                    //propertiesNotFound.addElement(property);
                    // change
                    generatedXML.writeProperty(null, "getlastmodified", resourceInfo.httpDate);
                } else {
                    generatedXML.writeProperty(null, "getlastmodified", resourceInfo.httpDate);
                }
            } else if (property.equals("resourcetype")) {
                if (resourceInfo.collection) {
                    generatedXML.writeElement(null, "resourcetype", XMLWriter.OPENING);
                    generatedXML.writeElement(null, "collection", XMLWriter.NO_CONTENT);
                    generatedXML.writeElement(null, "resourcetype", XMLWriter.CLOSING);
                } else {
                    generatedXML.writeElement(null, "resourcetype", XMLWriter.NO_CONTENT);
                }
            } else if (property.equals("source")) {
                generatedXML.writeProperty(null, "source", "");
            } else if (property.equals("supportedlock")) {
                supportedLocks = "<lockentry>" + "<lockscope><exclusive/></lockscope>"
                        + "<locktype><write/></locktype>" + "</lockentry>" + "<lockentry>"
                        + "<lockscope><shared/></lockscope>" + "<locktype><write/></locktype>" + "</lockentry>";
                generatedXML.writeElement(null, "supportedlock", XMLWriter.OPENING);
                generatedXML.writeText(supportedLocks);
                generatedXML.writeElement(null, "supportedlock", XMLWriter.CLOSING);
            } else if (property.equals("lockdiscovery")) {
                if (!generateLockDiscovery(path, generatedXML)) {
                    propertiesNotFound.addElement(property);
                }
            } else {
                propertiesNotFound.addElement(property);
            }
        }
        generatedXML.writeElement(null, "prop", XMLWriter.CLOSING);
        generatedXML.writeElement(null, "status", XMLWriter.OPENING);
        generatedXML.writeText(status);
        generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
        generatedXML.writeElement(null, "propstat", XMLWriter.CLOSING);
        Enumeration propertiesNotFoundList = propertiesNotFound.elements();
        if (propertiesNotFoundList.hasMoreElements()) {
            status = new String("HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND + " "
                    + WebdavStatus.getStatusText(WebdavStatus.SC_NOT_FOUND));
            generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
            generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
            while (propertiesNotFoundList.hasMoreElements()) {
                generatedXML.writeElement(null, (String) propertiesNotFoundList.nextElement(),
                        XMLWriter.NO_CONTENT);
            }
            generatedXML.writeElement(null, "prop", XMLWriter.CLOSING);
            generatedXML.writeElement(null, "status", XMLWriter.OPENING);
            generatedXML.writeText(status);
            generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
            generatedXML.writeElement(null, "propstat", XMLWriter.CLOSING);
        }
        break;
    }
    generatedXML.writeElement(null, "response", XMLWriter.CLOSING);
}

From source file:com.netscape.cms.servlet.csadmin.ConfigurationUtils.java

public static Vector<String> getUrlListFromSecurityDomain(IConfigStore config, String type, String portType)
        throws Exception {
    Vector<String> v = new Vector<String>();

    String hostname = config.getString("securitydomain.host");
    int httpsadminport = config.getInteger("securitydomain.httpsadminport");

    logger.debug("getUrlListFromSecurityDomain(): Getting domain.xml from CA...");
    String c = getDomainXML(hostname, httpsadminport, true);

    logger.debug("getUrlListFromSecurityDomain: Getting " + portType + " from Security Domain ...");
    if (!portType.equals("UnSecurePort") && !portType.equals("SecureAgentPort")
            && !portType.equals("SecurePort") && !portType.equals("SecureAdminPort")) {
        logger.debug("getUrlListFromSecurityDomain:  " + "unknown port type " + portType);
        return v;
    }/*from   w  ww  .j a v a 2  s  .c o m*/

    ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes());
    XMLObject parser = new XMLObject(bis);
    Document doc = parser.getDocument();
    NodeList nodeList = doc.getElementsByTagName(type);

    // save domain name in cfg
    config.putString("securitydomain.name", parser.getValue("Name"));

    int len = nodeList.getLength();

    logger.debug("Len " + len);
    for (int i = 0; i < len; i++) {
        Vector<String> v_name = parser.getValuesFromContainer(nodeList.item(i), "SubsystemName");
        Vector<String> v_host = parser.getValuesFromContainer(nodeList.item(i), "Host");
        Vector<String> v_port = parser.getValuesFromContainer(nodeList.item(i), portType);
        Vector<String> v_admin_port = parser.getValuesFromContainer(nodeList.item(i), "SecureAdminPort");

        if (v_host.elementAt(0).equals(hostname)
                && v_admin_port.elementAt(0).equals(new Integer(httpsadminport).toString())) {
            // add security domain CA to the beginning of list
            v.add(0, v_name.elementAt(0) + " - https://" + v_host.elementAt(0) + ":" + v_port.elementAt(0));
        } else {
            v.addElement(v_name.elementAt(0) + " - https://" + v_host.elementAt(0) + ":" + v_port.elementAt(0));
        }
    }

    return v;
}

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.EasyWorkflowPortlet.java

/**
 * Rescue a given workflow einstance//from   w  w  w  . j a v a  2s . c  o  m
 */
public void doRescue(ActionRequest request, ActionResponse response) throws PortletException {
    if (UserQuotaUtils.getInstance().userQuotaIsFull(request.getRemoteUser())) {
        request.setAttribute("msg", "portal.RealWorkflowPortlet.quotaisoverfull");
    } else {
        if (WorkflowInfo(request, response)) {
            doList(request, response);
            try {
                Vector errorJobPidList = new Vector();
                String portalID = PropertyLoader.getInstance().getProperty("service.url");
                String userID = request.getRemoteUser();
                String workflowID = request.getParameter("workflow");
                System.out.println(
                        "doRescue portalID:" + portalID + " userID:" + userID + " workflowID:" + workflowID);
                WorkflowData wData = PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID);
                String runtimeID = "" + wData.getEinstanceID();
                System.out.println("doRescue portalID:" + portalID + " userID:" + userID + " workflowID:"
                        + workflowID + " runtimeID:" + runtimeID);
                //
                // 23 = running/error
                int wfStatus = PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID)
                        .getRuntime(runtimeID).getStatus();
                if (23 == wfStatus) {
                    // running workflow statusz beirasa...
                    PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID)
                            .getRuntime(runtimeID).setStatus("5", 0);
                } else {
                    // resuming workflow statusz beirasa...
                    PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID)
                            .getRuntime(runtimeID).setStatus("29", 0);
                }
                //
                ConcurrentHashMap tmp = PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID)
                        .getRuntime(runtimeID).getJobsStatus();
                Enumeration enm0 = tmp.keys();
                int ts;
                while (enm0.hasMoreElements()) {
                    Object key0 = enm0.nextElement();
                    Enumeration enm1 = ((ConcurrentHashMap) tmp.get(key0)).keys();
                    while (enm1.hasMoreElements()) {
                        Object key1 = enm1.nextElement();
                        ts = ((JobStatusData) ((ConcurrentHashMap) tmp.get(key0)).get(key1)).getStatus();
                        if (ts == 25 || ts == 21 || ts == 22 || ts == 7 || ts == 15 || ts == 13 || ts == 12) {
                            // beirja az init statuszt...
                            // PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID).getRuntime(runtimeID).addJobbStatus((String) key0, (String) key1, "1", "", 0);
                            // kitorli a jobot a nyilvantartasbol...
                            PortalCacheService.getInstance().getUser(userID).getWorkflow(workflowID)
                                    .getRuntime(runtimeID).removeJobStatus((String) key0, (String) key1);
                            // storage takaritashoz ki kell gyujteni a jobID/jobPID-eket
                            ComDataBean comDataBean = new ComDataBean();
                            comDataBean.setJobID((String) key0);
                            comDataBean.setJobPID((String) key1);
                            errorJobPidList.addElement(comDataBean);
                        }
                    }
                }
                new WorkflowRescueThread(portalID, userID, workflowID, runtimeID, "" + wfStatus,
                        errorJobPidList);
                request.setAttribute("msg", "portal.EasyWorkflowPortlet.doRescue");
            } catch (Exception e) {
                request.setAttribute("msg", "portal.EasyWorkflowPortlet.doRescue.error");
                e.printStackTrace();
            }
        }
    }
}

From source file:com.adito.agent.client.ProxyUtil.java

/**
 * Attempt to proxy settings from Firefox.
 * //from  w ww  . ja v  a2 s  .  co m
 * @return firefox proxy settings
 * @throws IOException if firefox settings could not be obtained for some
 *         reason
 */
public static BrowserProxySettings lookupFirefoxProxySettings() throws IOException {

    try {

        Vector proxies = new Vector();
        Vector bypassAddr = new Vector();

        File home = new File(Utils.getHomeDirectory());
        File firefoxAppData;

        if (System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            firefoxAppData = new File(home, "Application Data\\Mozilla\\Firefox\\profiles.ini"); //$NON-NLS-1$
        } else {
            firefoxAppData = new File(home, ".mozilla/firefox/profiles.ini"); //$NON-NLS-1$
        }

        // Look for Path elements in the profiles.ini
        BufferedReader reader = null;
        Hashtable profiles = new Hashtable();
        String line;
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(firefoxAppData)));
            String currentProfileName = ""; //$NON-NLS-1$

            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (line.startsWith("[") && line.endsWith("]")) { //$NON-NLS-1$ //$NON-NLS-2$
                    currentProfileName = line.substring(1, line.length() - 1);
                    continue;
                }

                if (line.startsWith("Path=")) { //$NON-NLS-1$
                    profiles.put(currentProfileName, new File(firefoxAppData.getParent(), line.substring(5)));
                }
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }

        // Iterate through all the profiles and load the proxy infos from
        // the prefs.js file

        File prefsJS;
        String profileName;
        for (Enumeration e = profiles.keys(); e.hasMoreElements();) {
            profileName = (String) e.nextElement();
            prefsJS = new File((File) profiles.get(profileName), "prefs.js"); //$NON-NLS-1$
            Properties props = new Properties();
            reader = null;
            try {
                if (!prefsJS.exists()) {
                    // needed to defend against un-initialised profiles.
                    // #ifdef DEBUG
                    log.info("The file " + prefsJS.getAbsolutePath() + " does not exist."); //$NON-NLS-1$
                    // #endif
                    // now remove it from the map.
                    profiles.remove(profileName);
                    continue;
                }
                reader = new BufferedReader(new InputStreamReader(new FileInputStream(prefsJS)));
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("user_pref(\"")) { //$NON-NLS-1$
                        int idx = line.indexOf("\"", 11); //$NON-NLS-1$
                        if (idx == -1)
                            continue;
                        String pref = line.substring(11, idx);

                        // Save this position
                        int pos = idx + 1;

                        // Look for another quote
                        idx = line.indexOf("\"", idx + 1); //$NON-NLS-1$

                        String value;
                        if (idx == -1) {
                            // No more quotes
                            idx = line.indexOf(" ", pos); //$NON-NLS-1$

                            if (idx == -1)
                                continue;

                            int idx2 = line.indexOf(")", pos); //$NON-NLS-1$

                            if (idx2 == -1)
                                continue;

                            value = line.substring(idx + 1, idx2);

                        } else {

                            // String value
                            int idx2 = line.indexOf("\"", idx + 1); //$NON-NLS-1$

                            if (idx2 == -1)
                                continue;

                            value = line.substring(idx + 1, idx2);
                        }

                        props.put(pref, value);

                    }
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
            ProxyInfo p;
            /**
             * Extract some proxies from the properites, if the proxy is
             * enabled
             */
            if ("1".equals(props.get("network.proxy.type"))) { //$NON-NLS-1$ //$NON-NLS-2$
                boolean isProfileActive = checkProfileActive(prefsJS);
                if (props.containsKey("network.proxy.ftp")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "ftp=" + props.get("network.proxy.ftp") + ":" + props.get("network.proxy.ftp_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.http")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "http=" + props.get("network.proxy.http") + ":" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                                    + props.get("network.proxy.http_port"), //$NON-NLS-1$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.ssl")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "ssl=" + props.get("network.proxy.ssl") + ":" + props.get("network.proxy.ssl_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.socks")) { //$NON-NLS-1$
                    p = createProxyInfo("socks=" + props.get("network.proxy.socks") + ":" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            + props.get("network.proxy.socks_port"), "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.no_proxies_on")) { //$NON-NLS-1$

                    StringTokenizer tokens = new StringTokenizer(
                            props.getProperty("network.proxy.no_proxies_on"), ","); //$NON-NLS-1$ //$NON-NLS-2$

                    while (tokens.hasMoreTokens()) {
                        bypassAddr.addElement(((String) tokens.nextToken()).trim());
                    }

                }
            }
        }

        // need to ensure that the returned values are sorted correctly...
        BrowserProxySettings bps = new BrowserProxySettings();
        bps.setBrowser("Mozilla Firefox"); //$NON-NLS-1$
        bps.setProxiesActiveFirst(proxies);
        bps.setBypassAddr(new String[bypassAddr.size()]);
        bypassAddr.copyInto(bps.getBypassAddr());
        return bps;

    } catch (Throwable t) {
        throw new IOException("Failed to get proxy information from Firefox profiles: " + t.getMessage()); //$NON-NLS-1$
    }
}

From source file:com.github.maven_nar.cpptasks.CCTask.java

/**
 * This method collects a Hashtable, keyed by output file name, of
 * TargetInfo's for every source file that is specified in the filesets of
 * the <cc>and nested <compiler>elements. The TargetInfo's contain the
 * appropriate compiler configurations for their possible compilation
 * /* www.  ja  va  2s.co  m*/
 */
private Map<String, TargetInfo> getTargets(final LinkerConfiguration linkerConfig,
        final Vector<File> objectFiles, final VersionInfo versionInfo, final File outputFile) {
    // FREEHEP
    final List<String> order = new ArrayList<>();

    final Map<String, TargetInfo> targets = new TreeMap<>(new Comparator<String>() {
        // Order according to "order" List followed by alphabetical order
        @Override
        public int compare(String f0, String f1) {
            if (order.isEmpty()) {
                return f0.compareTo(f1);
            }

            // Trimming the path and trailing file extension to allow for order
            // comparison
            String compf0 = FilenameUtils.getBaseName(f0);
            String compf1 = FilenameUtils.getBaseName(f1);

            // remove the hash
            // TODO: well we hope it's a hash
            compf0 = FilenameUtils.removeExtension(compf0);
            compf1 = FilenameUtils.removeExtension(compf1);

            // order according to list or alphabetical
            final int i0 = order.indexOf(compf0);
            final int i1 = order.indexOf(compf1);

            if (i0 < 0 && i1 < 0) {
                // none in list
                // compare original values
                return f0.compareTo(f1);
            } else {
                // make sure we use only one core
                CCTask.this.ordered = true;

                if (i0 > 0 && i1 > 0) {
                    // both in list
                    return i0 == i1 ? 0 : i0 < i1 ? -1 : +1;
                } else if (i1 < 0) {
                    // i0 in list
                    return -1;
                } else {
                    // i1 in list
                    return +1;
                }
            }
        }
    });

    final TargetDef targetPlatform = getTargetPlatform();

    // BEGINFREEHEP
    // a little trick here, the inner function needs the list to be final,
    // so that the map order doesn't change after we start adding items,
    // populate with all the ordered items from each compiler type
    order.clear();
    for (int i = 0; i < this._compilers.size(); i++) {
        final CompilerDef currentCompilerDef = this._compilers.elementAt(i);
        if (currentCompilerDef.isActive()) {
            final List<String> compilerFileOrder = currentCompilerDef.getOrder();
            if (compilerFileOrder != null) {
                order.addAll(compilerFileOrder);
            }
        }
    }
    // ENDFREEHEP
    //
    // find active (specialized) compilers
    //
    final Vector<ProcessorConfiguration> biddingProcessors = new Vector<>(this._compilers.size());
    for (int i = 0; i < this._compilers.size(); i++) {
        final CompilerDef currentCompilerDef = this._compilers.elementAt(i);
        if (currentCompilerDef.isActive()) {
            final ProcessorConfiguration config = currentCompilerDef.createConfiguration(this, this.linkType,
                    this.compilerDef, targetPlatform, versionInfo);
            //
            // see if this processor had a precompile child element
            //
            final PrecompileDef precompileDef = currentCompilerDef.getActivePrecompile(this.compilerDef);
            CommandLineCompilerConfiguration commandLineConfig = (CommandLineCompilerConfiguration) config;
            AbstractCompiler compiler = (AbstractCompiler) commandLineConfig.getCompiler();
            compiler.setWorkDir(currentCompilerDef.getWorkDir());
            ProcessorConfiguration[] localConfigs = new ProcessorConfiguration[] { config };
            //
            // if it does then
            //
            if (precompileDef != null) {
                final File prototype = precompileDef.getPrototype();
                //
                // will throw exceptions if prototype doesn't exist, etc
                //
                if (!prototype.exists()) {
                    throw new BuildException("prototype (" + prototype.toString() + ") does not exist.");
                }
                if (prototype.isDirectory()) {
                    throw new BuildException("prototype (" + prototype.toString() + ") is a directory.");
                }
                final String[] exceptFiles = precompileDef.getExceptFiles();
                //
                // create a precompile building and precompile using
                // variants of the configuration
                // or return null if compiler doesn't support
                // precompilation
                final CompilerConfiguration[] configs = ((CompilerConfiguration) config)
                        .createPrecompileConfigurations(prototype, exceptFiles);
                if (configs != null && configs.length == 2) {
                    //
                    // visit the precompiled file to add it into the
                    // targets list (just like any other file if
                    // compiler doesn't support precompilation)
                    final TargetMatcher matcher = new TargetMatcher(this, this._objDir,
                            new ProcessorConfiguration[] { configs[0] }, linkerConfig, objectFiles, targets,
                            versionInfo);

                    matcher.visit(new File(prototype.getParent()), prototype.getName());
                    //
                    // only the configuration that uses the
                    // precompiled header gets added to the bidding list
                    biddingProcessors.addElement(configs[1]);
                    localConfigs = new ProcessorConfiguration[2];
                    localConfigs[0] = configs[1];
                    localConfigs[1] = config;
                }
            }

            //
            // if the compiler has a fileset
            // then allow it to add its files
            // to the set of potential targets
            if (currentCompilerDef.hasFileSets()) {
                final TargetMatcher matcher = new TargetMatcher(this, this._objDir, localConfigs, linkerConfig,
                        objectFiles, targets, versionInfo);
                currentCompilerDef.visitFiles(matcher);
            }
            biddingProcessors.addElement(config);
        }
    }
    //
    // add fallback compiler at the end
    //
    if (this._compilers.size() == 0) {
        final ProcessorConfiguration config = this.compilerDef.createConfiguration(this, this.linkType, null,
                targetPlatform, versionInfo);
        biddingProcessors.addElement(config);
        final ProcessorConfiguration[] bidders = new ProcessorConfiguration[biddingProcessors.size()];
        biddingProcessors.copyInto(bidders);
        //
        // bid out the <fileset>'s in the cctask
        //
        final TargetMatcher matcher = new TargetMatcher(this, this._objDir, bidders, linkerConfig, objectFiles,
                targets, versionInfo);
        this.compilerDef.visitFiles(matcher);

        if (outputFile != null && versionInfo != null) {
            final boolean isDebug = linkerConfig.isDebug();
            try {
                linkerConfig.getLinker().addVersionFiles(versionInfo, this.linkType, outputFile, isDebug,
                        this._objDir, matcher);
            } catch (final IOException ex) {
                throw new BuildException(ex);
            }
        }
    }
    return targets;
}

From source file:org.apache.catalina.servlets.DefaultServlet.java

/**
 * Parse the range header.//from  w w w  .j a  v a  2  s.  c om
 *
 * @param request      The servlet request we are processing
 * @param response     The servlet response we are creating
 * @param resourceInfo Description of the Parameter
 * @return Vector of ranges
 * @throws IOException Description of the Exception
 */
protected Vector parseRange(HttpServletRequest request, HttpServletResponse response, ResourceInfo resourceInfo)
        throws IOException {

    // Checking If-Range
    String headerValue = request.getHeader("If-Range");

    if (headerValue != null) {

        long headerValueTime = (-1L);
        try {
            headerValueTime = request.getDateHeader("If-Range");
        } catch (Exception e) {
            ;
        }

        String eTag = getETag(resourceInfo);
        long lastModified = resourceInfo.date;

        if (headerValueTime == (-1L)) {

            // If the ETag the client gave does not match the entity
            // etag, then the entire entity is returned.
            if (!eTag.equals(headerValue.trim())) {
                return null;
            }
        } else {

            // If the timestamp of the entity the client got is older than
            // the last modification date of the entity, the entire entity
            // is returned.
            if (lastModified > (headerValueTime + 1000)) {
                return null;
            }
        }

    }

    long fileLength = resourceInfo.length;

    if (fileLength == 0) {
        return null;
    }

    // Retrieving the range header (if any is specified
    String rangeHeader = request.getHeader("Range");

    if (rangeHeader == null) {
        return null;
    }
    // bytes is the only range unit supported (and I don't see the point
    // of adding new ones).
    if (!rangeHeader.startsWith("bytes")) {
        response.addHeader("Content-Range", "bytes */" + fileLength);
        response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
        return null;
    }

    rangeHeader = rangeHeader.substring(6);

    // Vector which will contain all the ranges which are successfully
    // parsed.
    Vector result = new Vector();
    StringTokenizer commaTokenizer = new StringTokenizer(rangeHeader, ",");

    // Parsing the range list
    while (commaTokenizer.hasMoreTokens()) {
        String rangeDefinition = commaTokenizer.nextToken().trim();

        Range currentRange = new Range();
        currentRange.length = fileLength;

        int dashPos = rangeDefinition.indexOf('-');

        if (dashPos == -1) {
            response.addHeader("Content-Range", "bytes */" + fileLength);
            response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
            return null;
        }

        if (dashPos == 0) {

            try {
                long offset = Long.parseLong(rangeDefinition);
                currentRange.start = fileLength + offset;
                currentRange.end = fileLength - 1;
            } catch (NumberFormatException e) {
                response.addHeader("Content-Range", "bytes */" + fileLength);
                response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                return null;
            }

        } else {

            try {
                currentRange.start = Long.parseLong(rangeDefinition.substring(0, dashPos));
                if (dashPos < rangeDefinition.length() - 1) {
                    currentRange.end = Long
                            .parseLong(rangeDefinition.substring(dashPos + 1, rangeDefinition.length()));
                } else {
                    currentRange.end = fileLength - 1;
                }
            } catch (NumberFormatException e) {
                response.addHeader("Content-Range", "bytes */" + fileLength);
                response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
                return null;
            }

        }

        if (!currentRange.validate()) {
            response.addHeader("Content-Range", "bytes */" + fileLength);
            response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
            return null;
        }

        result.addElement(currentRange);
    }

    return result;
}

From source file:org.apache.webdav.lib.WebdavResource.java

/**
 * Execute PROPFIND method for this WebdavResource.
 * Get list of given WebDAV properties on this WebDAV resource.
 *
 * @param propertyName the WebDAV property to find.
 * @return Enumeration list of WebDAV properties on a resource.
 * @exception HttpException//from   www  . j a v  a 2  s .  c o  m
 * @exception IOException
 */
public Enumeration propfindMethod(String propertyName) throws HttpException, IOException {

    Vector property = new Vector();
    property.addElement(propertyName);

    thisResource = true;
    return propfindMethod(httpURL.getPath(), property);
}

From source file:org.apache.webdav.lib.WebdavResource.java

/**
 * Execute PROPFIND method for the given WebdavResource path.
 * Get list of given WebDAV properties on this WebDAV resource.
 *
 * @param path the server relative path of the resource to request
 * @param propertyName the WebDAV property to find.
 * @return Enumeration list of WebDAV properties on a resource.
 * @exception HttpException//from www .  j a v  a 2  s.  c o  m
 * @exception IOException
 */
public Enumeration propfindMethod(String path, String propertyName) throws HttpException, IOException {

    Vector property = new Vector();
    property.addElement(propertyName);

    thisResource = false;
    return propfindMethod(path, property);
}

From source file:org.apache.webdav.lib.WebdavResource.java

/**
 * Set only the displayname property for this resource.
 *
 * @param depth The depth to find properties.
 *///from   w w  w  . j a v  a 2  s .c om
protected void setNameProperties(int depth) throws HttpException, IOException {

    Vector properties = new Vector();
    properties.addElement(DISPLAYNAME);

    setNamedProp(depth, properties);
}