List of usage examples for java.util Vector copyInto
public synchronized void copyInto(Object[] anArray)
From source file:org.apache.jasper.compiler.TagLibraryInfoImpl.java
private TagInfo createTagInfo(TreeNode elem) throws JasperException { String tagName = null;//from w ww. java2 s . com String tagClassName = null; String teiClassName = null; /* * Default body content for JSP 1.2 tag handlers (<body-content> has * become mandatory in JSP 2.0, because the default would be invalid * for simple tag handlers) */ String bodycontent = "JSP"; String info = null; String displayName = null; String smallIcon = null; String largeIcon = null; boolean dynamicAttributes = false; Vector attributeVector = new Vector(); Vector variableVector = new Vector(); Iterator list = elem.findChildren(); while (list.hasNext()) { TreeNode element = (TreeNode) list.next(); String tname = element.getName(); if ("name".equals(tname)) { tagName = element.getBody(); } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) { tagClassName = element.getBody(); } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) { teiClassName = element.getBody(); } else if ("bodycontent".equals(tname) || "body-content".equals(tname)) { bodycontent = element.getBody(); } else if ("display-name".equals(tname)) { displayName = element.getBody(); } else if ("small-icon".equals(tname)) { smallIcon = element.getBody(); } else if ("large-icon".equals(tname)) { largeIcon = element.getBody(); } else if ("info".equals(tname) || "description".equals(tname)) { info = element.getBody(); } else if ("variable".equals(tname)) { variableVector.addElement(createVariable(element)); } else if ("attribute".equals(tname)) { attributeVector.addElement(createAttribute(element)); } else if ("dynamic-attributes".equals(tname)) { dynamicAttributes = JspUtil.booleanValue(element.getBody()); } else if ("example".equals(tname)) { // Ignored elements } else if ("tag-extension".equals(tname)) { // Ignored } else { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tag", tname)); } } } TagExtraInfo tei = null; if (teiClassName != null && !teiClassName.equals("")) { try { Class teiClass = ctxt.getClassLoader().loadClass(teiClassName); tei = (TagExtraInfo) teiClass.newInstance(); } catch (Exception e) { err.jspError("jsp.error.teiclass.instantiation", teiClassName, e); } } TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector.size()]; attributeVector.copyInto(tagAttributeInfo); TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()]; variableVector.copyInto(tagVariableInfos); TagInfo taginfo = new TagInfo(tagName, tagClassName, bodycontent, info, this, tei, tagAttributeInfo, displayName, smallIcon, largeIcon, tagVariableInfos, dynamicAttributes); return taginfo; }
From source file:org.tinygroup.jspengine.compiler.TagLibraryInfoImpl.java
private void parseTLD(JspCompilationContext ctxt, String uri, InputStream in, URL jarFileUrl) throws JasperException { Vector tagVector = new Vector(); Vector tagFileVector = new Vector(); Hashtable functionTable = new Hashtable(); // Create an iterator over the child elements of our <taglib> element ParserUtils pu = new ParserUtils(); TreeNode tld = pu.parseXMLDocument(uri, in); // Check to see if the <taglib> root element contains a 'version' // attribute, which was added in JSP 2.0 to replace the <jsp-version> // subelement this.jspversion = tld.findAttribute("version"); // Process each child element of our <taglib> element Iterator list = tld.findChildren(); while (list.hasNext()) { TreeNode element = (TreeNode) list.next(); String tname = element.getName(); if ("tlibversion".equals(tname) // JSP 1.1 || "tlib-version".equals(tname)) { // JSP 1.2 this.tlibversion = element.getBody(); } else if ("jspversion".equals(tname) || "jsp-version".equals(tname)) { this.jspversion = element.getBody(); } else if ("shortname".equals(tname) || "short-name".equals(tname)) this.shortname = element.getBody(); else if ("uri".equals(tname)) this.urn = element.getBody(); else if ("info".equals(tname) || "description".equals(tname)) this.info = element.getBody(); else if ("validator".equals(tname)) this.tagLibraryValidator = createValidator(element); else if ("tag".equals(tname)) tagVector.addElement(createTagInfo(element, jspversion)); else if ("tag-file".equals(tname)) { TagFileInfo tagFileInfo = createTagFileInfo(element, uri, jarFileUrl); tagFileVector.addElement(tagFileInfo); } else if ("function".equals(tname)) { // JSP2.0 FunctionInfo funcInfo = createFunctionInfo(element); String funcName = funcInfo.getName(); if (functionTable.containsKey(funcName)) { err.jspError("jsp.error.tld.fn.duplicate.name", funcName, uri); }/*from w w w .j av a 2 s. co m*/ functionTable.put(funcName, funcInfo); } else if ("display-name".equals(tname) || // Ignored elements "small-icon".equals(tname) || "large-icon".equals(tname) || "listener".equals(tname)) { ; } else if ("taglib-extension".equals(tname)) { // Recognized but ignored } else { err.jspError("jsp.error.unknown.element.in.taglib", tname); } } if (tlibversion == null) { err.jspError("jsp.error.tld.mandatory.element.missing", "tlib-version"); } if (jspversion == null) { err.jspError("jsp.error.tld.mandatory.element.missing", "jsp-version"); } this.tags = new TagInfo[tagVector.size()]; tagVector.copyInto(this.tags); this.tagFiles = new TagFileInfo[tagFileVector.size()]; tagFileVector.copyInto(this.tagFiles); this.functions = new FunctionInfo[functionTable.size()]; int i = 0; Enumeration enumeration = functionTable.elements(); while (enumeration.hasMoreElements()) { this.functions[i++] = (FunctionInfo) enumeration.nextElement(); } }
From source file:org.kaaproject.kaa.server.control.cli.ControlApiCommandProcessor.java
/** * Parses the command./*from w ww.j a va 2 s . co m*/ * * @param toProcess the to process * @return the string[] * @throws ParseException the parse exception */ private static String[] parseCommand(String toProcess) throws ParseException { if (toProcess == null || toProcess.length() == 0) { //no command? no string return new String[0]; } // parse with a simple finite state machine final int normal = 0; final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); Vector<String> v = new Vector<>(); StringBuffer current = new StringBuffer(); boolean lastTokenHasBeenQuoted = false; while (tok.hasMoreTokens()) { String nextTok = tok.nextToken(); switch (state) { case inQuote: if ("\'".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; case inDoubleQuote: if ("\"".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; default: if ("\'".equals(nextTok)) { state = inQuote; } else if ("\"".equals(nextTok)) { state = inDoubleQuote; } else if (" ".equals(nextTok)) { if (lastTokenHasBeenQuoted || current.length() != 0) { v.addElement(current.toString()); current = new StringBuffer(); } } else { current.append(nextTok); } lastTokenHasBeenQuoted = false; break; } } if (lastTokenHasBeenQuoted || current.length() != 0) { v.addElement(current.toString()); } if (state == inQuote || state == inDoubleQuote) { throw new ParseException("unbalanced quotes in " + toProcess); } String[] args = new String[v.size()]; v.copyInto(args); return args; }
From source file:org.tinygroup.jspengine.compiler.TagLibraryInfoImpl.java
private TagInfo createTagInfo(TreeNode elem, String jspVersion) throws JasperException { String tagName = null;//from www .j av a 2s . co m String tagClassName = null; String teiClassName = null; /* * Default body content for JSP 1.2 tag handlers (<body-content> has * become mandatory in JSP 2.0, because the default would be invalid * for simple tag handlers) */ String bodycontent = "JSP"; String info = null; String displayName = null; String smallIcon = null; String largeIcon = null; boolean dynamicAttributes = false; Vector attributeVector = new Vector(); Vector variableVector = new Vector(); Iterator list = elem.findChildren(); while (list.hasNext()) { TreeNode element = (TreeNode) list.next(); String tname = element.getName(); if ("name".equals(tname)) { tagName = element.getBody(); } else if ("tagclass".equals(tname) || "tag-class".equals(tname)) { tagClassName = element.getBody(); } else if ("teiclass".equals(tname) || "tei-class".equals(tname)) { teiClassName = element.getBody(); } else if ("bodycontent".equals(tname) || "body-content".equals(tname)) { bodycontent = element.getBody(); } else if ("display-name".equals(tname)) { displayName = element.getBody(); } else if ("small-icon".equals(tname)) { smallIcon = element.getBody(); } else if ("large-icon".equals(tname)) { largeIcon = element.getBody(); } else if ("icon".equals(tname)) { TreeNode icon = element.findChild("small-icon"); if (icon != null) { smallIcon = icon.getBody(); } icon = element.findChild("large-icon"); if (icon != null) { largeIcon = icon.getBody(); } } else if ("info".equals(tname) || "description".equals(tname)) { info = element.getBody(); } else if ("variable".equals(tname)) { variableVector.addElement(createVariable(element)); } else if ("attribute".equals(tname)) { attributeVector.addElement(createAttribute(element, jspVersion)); } else if ("dynamic-attributes".equals(tname)) { dynamicAttributes = JspUtil.booleanValue(element.getBody()); } else if ("example".equals(tname)) { // Ignored elements } else if ("tag-extension".equals(tname)) { // Ignored } else { err.jspError("jsp.error.unknown.element.in.tag", tname); } } // JSP 2.0 removed the capital versions of TAGDEPENDENT, EMPTY, and // SCRIPTLESS enumerations in body-contentType, see JSP.E.2 ("Changes // between JSP 2.0 PFD2 and JSP 2.0 PFD3"), section "Changes to Tag // Library Descriptor (TLD)". Enforce that from JSP 2.0 and up, only // "JSP", "tagdependent", "empty", and "scriptless" may be specified // as body-content values. Double jspVersionDouble = Double.valueOf(jspversion); if (Double.compare(jspVersionDouble, Constants.JSP_VERSION_2_0) >= 0) { if (!bodycontent.equals(TagInfo.BODY_CONTENT_JSP) && !bodycontent.equals(TagInfo.BODY_CONTENT_EMPTY) && !bodycontent.equals(TagInfo.BODY_CONTENT_TAG_DEPENDENT) && !bodycontent.equals(TagInfo.BODY_CONTENT_SCRIPTLESS)) { err.jspError("jsp.error.tld.badbodycontent", bodycontent, tagName); } } TagExtraInfo tei = null; if (teiClassName != null && !teiClassName.equals("")) { try { Class teiClass = ctxt.getClassLoader().loadClass(teiClassName); tei = (TagExtraInfo) teiClass.newInstance(); } catch (Exception e) { err.jspError("jsp.error.teiclass.instantiation", teiClassName, e); } } TagAttributeInfo[] tagAttributeInfo = new TagAttributeInfo[attributeVector.size()]; attributeVector.copyInto(tagAttributeInfo); TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector.size()]; variableVector.copyInto(tagVariableInfos); TagInfo taginfo = new TagInfo(tagName, tagClassName, bodycontent, info, this, tei, tagAttributeInfo, displayName, smallIcon, largeIcon, tagVariableInfos, dynamicAttributes); return taginfo; }
From source file:com.netscape.ca.CertificateAuthority.java
/** * Process OCSPRequest.//from w w w . j a v a 2 s. co m */ public OCSPResponse validate(OCSPRequest request) throws EBaseException { if (!mEnableOCSP) { logger.debug("CertificateAuthority: OCSP service disabled"); throw new EBaseException("OCSP service disabled"); } TBSRequest tbsReq = request.getTBSRequest(); if (tbsReq.getRequestCount() == 0) { logger.error("CertificateAuthority: No request found"); log(ILogger.LL_FAILURE, CMS.getLogMessage("OCSP_REQUEST_FAILURE", "No Request Found")); throw new EBaseException("OCSP request is empty"); } /* An OCSP request can contain CertIDs for certificates * issued by different CAs, but each SingleResponse is valid * only if the combined response was signed by its issuer or * an authorised OCSP signing delegate. * * Even though it is silly to send an OCSP request * asking about certs issued by different CAs, we must * employ some heuristic to deal with this case. Our * heuristic is: * * 0. If caMap contains no CAs, then lightweight CAs are not * enabled. There is only one CA, and 'this' is it. Go * straight to validation. * * 1. Find the issuer of the cert identified by the first * CertID in the request. * * 2. If this CA is *not* the issuer, look up the issuer * by its DN in the caMap. If not found, fail. If * found, dispatch to its 'validate' method. Otherwise * continue. * * 3. If this CA is NOT the issuing CA, we locate the * issuing CA and dispatch to its 'validate' method. * Otherwise, we move forward to generate and sign the * aggregate OCSP response. */ ICertificateAuthority ocspCA = this; if (caMap.size() > 0 && tbsReq.getRequestCount() > 0) { Request req = tbsReq.getRequestAt(0); BigInteger serialNo = req.getCertID().getSerialNumber(); X509CertImpl cert = mCertRepot.getX509Certificate(serialNo); X500Name certIssuerDN = (X500Name) cert.getIssuerDN(); ocspCA = getCA(certIssuerDN); } if (ocspCA == null) { logger.error("CertificateAuthority: Could not locate issuing CA"); throw new CANotFoundException("Could not locate issuing CA"); } if (ocspCA != this) return ((IOCSPService) ocspCA).validate(request); logger.debug("CertificateAuthority: validating OCSP request"); mNumOCSPRequest++; IStatsSubsystem statsSub = (IStatsSubsystem) CMS.getSubsystem("stats"); long startTime = CMS.getCurrentDate().getTime(); try { //log(ILogger.LL_INFO, "start OCSP request"); // (3) look into database to check the // certificate's status Vector<SingleResponse> singleResponses = new Vector<SingleResponse>(); if (statsSub != null) { statsSub.startTiming("lookup"); } long lookupStartTime = CMS.getCurrentDate().getTime(); for (int i = 0; i < tbsReq.getRequestCount(); i++) { Request req = tbsReq.getRequestAt(i); SingleResponse sr = processRequest(req); singleResponses.addElement(sr); } long lookupEndTime = CMS.getCurrentDate().getTime(); mLookupTime += lookupEndTime - lookupStartTime; if (statsSub != null) { statsSub.endTiming("lookup"); } if (statsSub != null) { statsSub.startTiming("build_response"); } SingleResponse res[] = new SingleResponse[singleResponses.size()]; singleResponses.copyInto(res); ResponderID rid = null; if (mByName) { if (mResponderIDByName == null) { mResponderIDByName = getResponderIDByName(); } rid = mResponderIDByName; } else { if (mResponderIDByHash == null) { mResponderIDByHash = getResponderIDByHash(); } rid = mResponderIDByHash; } Extension nonce[] = null; for (int j = 0; j < tbsReq.getExtensionsCount(); j++) { Extension thisExt = tbsReq.getRequestExtensionAt(j); if (thisExt.getExtnId().equals(OCSP_NONCE)) { nonce = new Extension[1]; nonce[0] = thisExt; } } ResponseData rd = new ResponseData(rid, new GeneralizedTime(CMS.getCurrentDate()), res, nonce); if (statsSub != null) { statsSub.endTiming("build_response"); } if (statsSub != null) { statsSub.startTiming("signing"); } long signStartTime = CMS.getCurrentDate().getTime(); BasicOCSPResponse basicRes = sign(rd); long signEndTime = CMS.getCurrentDate().getTime(); mSignTime += signEndTime - signStartTime; if (statsSub != null) { statsSub.endTiming("signing"); } OCSPResponse response = new OCSPResponse(OCSPResponseStatus.SUCCESSFUL, new ResponseBytes(ResponseBytes.OCSP_BASIC, new OCTET_STRING(ASN1Util.encode(basicRes)))); //log(ILogger.LL_INFO, "done OCSP request"); long endTime = CMS.getCurrentDate().getTime(); mTotalTime += endTime - startTime; return response; } catch (EBaseException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_CA_OCSP_REQUEST", e.toString())); throw e; } }
From source file:org.castor.cpa.persistence.sql.engine.SQLEngine.java
public SQLEngine(final ClassDescriptor clsDesc, final PersistenceFactory factory) throws MappingException { _clsDesc = clsDesc;//from w w w . ja v a 2 s . c o m _factory = factory; // construct field and id info Vector<SQLColumnInfo> idsInfo = new Vector<SQLColumnInfo>(); Vector<SQLFieldInfo> fieldsInfo = new Vector<SQLFieldInfo>(); /* * Implementation Note: * Extends and Depends has some special mutual exclusive * properties, which implementator should aware of. * * A Depended class may depends on another depended class * A class should either extends or depends on other class * A class should not depend on extending class. * because, it is the same as depends on the base class * A class may be depended by zero or more classes * A class may be extended by zero or more classes * A class may extends only zero or one class * A class may depends only zero or one class * A class may depend on extended class * A class may extend a dependent class. * A class may extend a depended class. * No loop or circle should exist */ // then, we put depended class ids in the back ClassDescriptor base = clsDesc; // walk until the base class which this class extends base = clsDesc; Stack<ClassDescriptor> stack = new Stack<ClassDescriptor>(); stack.push(base); while (base.getExtends() != null) { // if (base.getDepends() != null) { // throw new MappingException( // "Class should not both depends on and extended other classes"); // } base = base.getExtends(); stack.push(base); // do we need to add loop detection? } // now base is either the base of extended class, or // clsDesc // we always put the original id info in front // [oleg] except for SQL name, it may differ. FieldDescriptor[] baseIdDescriptors = ((ClassDescriptorImpl) base).getIdentities(); FieldDescriptor[] idDescriptors = ((ClassDescriptorImpl) clsDesc).getIdentities(); for (int i = 0; i < baseIdDescriptors.length; i++) { if (baseIdDescriptors[i].hasNature(FieldDescriptorJDONature.class.getName())) { String name = baseIdDescriptors[i].getFieldName(); String[] sqlName = new FieldDescriptorJDONature(baseIdDescriptors[i]).getSQLName(); int[] sqlType = new FieldDescriptorJDONature(baseIdDescriptors[i]).getSQLType(); FieldHandlerImpl fh = (FieldHandlerImpl) baseIdDescriptors[i].getHandler(); // The extending class may have other SQL names for identity fields for (int j = 0; j < idDescriptors.length; j++) { if (name.equals(idDescriptors[j].getFieldName()) && (idDescriptors[j].hasNature(JDO_FIELD_NATURE))) { sqlName = new FieldDescriptorJDONature(idDescriptors[j]).getSQLName(); break; } } idsInfo.add(new SQLColumnInfo(sqlName[0], sqlType[0], fh.getConvertTo(), fh.getConvertFrom())); } else { throw new MappingException("Except JDOFieldDescriptor"); } } // then do the fields while (!stack.empty()) { base = stack.pop(); FieldDescriptor[] fieldDescriptors = base.getFields(); for (int i = 0; i < fieldDescriptors.length; i++) { // fieldDescriptors[i] is persistent in db if it is not transient // and it is a JDOFieldDescriptor or has a ClassDescriptor if (!fieldDescriptors[i].isTransient()) { if ((fieldDescriptors[i].hasNature(FieldDescriptorJDONature.class.getName())) || (fieldDescriptors[i].getClassDescriptor() != null)) { SQLFieldInfo inf = new SQLFieldInfo(clsDesc, fieldDescriptors[i], new ClassDescriptorJDONature(base).getTableName(), !stack.empty()); fieldsInfo.add(inf); if (inf.isJoined()) { String alias = inf.getTableName() + "_f" + i; inf.setTableAlias(alias); } else { inf.setTableAlias(inf.getTableName()); } } } } } InfoFactory infoFactory = new InfoFactory(); _tableInfo = infoFactory.createTableInfo(clsDesc); _ids = new SQLColumnInfo[idsInfo.size()]; idsInfo.copyInto(_ids); _fields = new SQLFieldInfo[fieldsInfo.size()]; fieldsInfo.copyInto(_fields); _queryStatement = new SQLStatementQuery(this, factory); _loadStatement = new SQLStatementLoad(this, factory); _createStatement = new SQLStatementInsert(this, factory); _removeStatement = new SQLStatementDelete(this); _storeStatement = new SQLStatementUpdate(this); }
From source file:com.adito.agent.client.ProxyUtil.java
/** * Attempt to proxy settings from Internet Explorer. * /* w w w. j a va 2 s. com*/ * @return internet explorer proxy settings * @throws IOException if IE settings could not be obtained for some reason */ public static BrowserProxySettings lookupIEProxySettings() throws IOException { try { Vector addresses = new Vector(); Vector proxies = new Vector(); String proxyServerValue = null; String proxyOveride = null; /* Only use jRegistry if on Windows, running 1.3 or up Java * and NOT Windows Vista with JDK6.0 (because of jvm crash) */ if (Utils.isSupportedJRE("+1.3") && Utils.isSupportedPlatform( "Windows") /*&& !(Utils.isSupportedOSVersion("+6.0") && Utils.isSupportedJRE("+1.6"))*/) { /* * We can use jRegistryKey API to lookup IE settings in the * registry */ // RegistryKey key = new RegistryKey(RootKey.HKEY_CURRENT_USER, // "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); //$NON-NLS-1$ String proxyEnable = WinRegistry.getRegistryValue("user", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", "0"); if (proxyEnable != null) { //$NON-NLS-1$ /* * We have ProxyEnable so check to see if we are using a * proxy */ if (proxyEnable.equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$ proxyServerValue = WinRegistry.getRegistryValue("user", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyServer", null); if (proxyServerValue != null) { //$NON-NLS-1$ /** * We have some proxy settings. The values will be * in the format "server.proxy.net:8888" or */ proxyOveride = WinRegistry.getRegistryValue("user", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyOverride", null); } } else { } } } else { if (System.getProperty("java.vendor").startsWith("Microsoft")) { //$NON-NLS-1$ //$NON-NLS-2$ try { Class clazz = Class.forName("com.ms.lang.RegKey"); //$NON-NLS-1$ int userRoot = clazz.getField("USER_ROOT").getInt(null); //$NON-NLS-1$ int keyOpenAll = clazz.getField("KEYOPEN_ALL").getInt(null); //$NON-NLS-1$ // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.lookingForRoot")); //$NON-NLS-1$ // #endif Object rootKey = clazz.getMethod("getRootKey", new Class[] { int.class }).invoke(null, //$NON-NLS-1$ new Object[] { new Integer(userRoot) }); // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.getIERegistryKey")); //$NON-NLS-1$ // #endif Object key = clazz.getConstructor(new Class[] { clazz, String.class, int.class }) .newInstance(new Object[] { rootKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", //$NON-NLS-1$ new Integer(keyOpenAll) }); // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.checkingIfProxyEnabled")); //$NON-NLS-1$ // #endif if (((Integer) (clazz.getMethod("getIntValue", new Class[] { String.class }).invoke(key, //$NON-NLS-1$ new Object[] { "ProxyEnable" }))).intValue() == 1) { //$NON-NLS-1$ // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.gettingProxyServerList")); //$NON-NLS-1$ // #endif proxyServerValue = (String) (clazz.getMethod("getStringValue", //$NON-NLS-1$ new Class[] { String.class, String.class }) .invoke(key, new Object[] { "ProxyServer", "" })); //$NON-NLS-1$ //$NON-NLS-2$ // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.gettingProxyOverides")); //$NON-NLS-1$ // #endif proxyOveride = (String) (clazz .getMethod("getStringValue", new Class[] { String.class, String.class }) //$NON-NLS-1$ .invoke(key, new Object[] { "ProxyOverride", "" })); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (Throwable t) { t.printStackTrace(); } } else { // #ifdef DEBUG log.info(MessageFormat.format(Messages.getString("ProxyUtil.unsupportedJavaRuntime"), //$NON-NLS-1$ new Object[] { System.getProperty("java.version"), //$NON-NLS-1$ System.getProperty("java.vendor") })); //$NON-NLS-1$ // #endif } } ProxyInfo p; if (proxyServerValue != null && proxyServerValue.indexOf(';') > -1) { /** * Format is multiple * "ftp=ftp.com:4444;gopher=gopher.com:3333;http=198.162.1.119:8888;https=https.com:2222;socks=socks.com:1111" */ StringTokenizer tokens = new StringTokenizer(proxyServerValue, ";"); //$NON-NLS-1$ while (tokens.hasMoreTokens()) { p = createProxyInfo(tokens.nextToken(), "IE Proxy Settings"); //$NON-NLS-1$ proxies.addElement(p); } } else if (proxyServerValue != null) { /** * Format is single "http=server.proxy.net:8888" or * "server.proxy.net:8888" */ p = createProxyInfo(proxyServerValue, "IE Proxy Settings"); //$NON-NLS-1$ proxies.addElement(p); } BrowserProxySettings bps = new BrowserProxySettings(); bps.setBrowser("Internet Explorer"); //$NON-NLS-1$ bps.setProxies(new ProxyInfo[proxies.size()]); proxies.copyInto(bps.getProxies()); if (proxyOveride != null) { StringTokenizer tokens = new StringTokenizer(proxyOveride, ";"); //$NON-NLS-1$ while (tokens.hasMoreTokens()) { addresses.addElement(tokens.nextToken()); } } bps.setBypassAddr(new String[addresses.size()]); addresses.copyInto(bps.getBypassAddr()); return bps; } catch (Throwable t) { t.printStackTrace(); throw new IOException(MessageFormat.format(Messages.getString("ProxyUtil.failedToLookupIEProxies"), //$NON-NLS-1$ new Object[] { t.getMessage() })); } }
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 * //from w w w . j ava 2 s. 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:com.github.maven_nar.cpptasks.compiler.CommandLineCompiler.java
@Override protected CompilerConfiguration createConfiguration(final CCTask task, final LinkType linkType, final ProcessorDef[] baseDefs, final CompilerDef specificDef, final TargetDef targetPlatform, final VersionInfo versionInfo) { this.prefix = specificDef.getCompilerPrefix(); this.objDir = task.getObjdir(); final Vector<String> args = new Vector<>(); final CompilerDef[] defaultProviders = new CompilerDef[baseDefs.length + 1]; for (int i = 0; i < baseDefs.length; i++) { defaultProviders[i + 1] = (CompilerDef) baseDefs[i]; }//w ww. jav a 2 s. c om defaultProviders[0] = specificDef; final Vector<CommandLineArgument> cmdArgs = new Vector<>(); // // add command line arguments inherited from <cc> element // any "extends" and finally the specific CompilerDef CommandLineArgument[] commandArgs; for (int i = defaultProviders.length - 1; i >= 0; i--) { commandArgs = defaultProviders[i].getActiveProcessorArgs(); for (final CommandLineArgument commandArg : commandArgs) { if (commandArg.getLocation() == 0) { String arg = commandArg.getValue(); if (isWindows() && arg.matches(".*[ \"].*")) { // Work around inconsistent quoting by Ant arg = "\"" + arg.replaceAll("[\\\\\"]", "\\\\$0") + "\""; } args.addElement(arg); } else { cmdArgs.addElement(commandArg); } } } final Vector<ProcessorParam> params = new Vector<>(); // // add command line arguments inherited from <cc> element // any "extends" and finally the specific CompilerDef ProcessorParam[] paramArray; for (int i = defaultProviders.length - 1; i >= 0; i--) { paramArray = defaultProviders[i].getActiveProcessorParams(); Collections.addAll(params, paramArray); } paramArray = params.toArray(new ProcessorParam[params.size()]); if (specificDef.isClearDefaultOptions() == false) { final boolean multithreaded = specificDef.getMultithreaded(defaultProviders, 1); final boolean debug = specificDef.getDebug(baseDefs, 0); final boolean exceptions = specificDef.getExceptions(defaultProviders, 1); final Boolean rtti = specificDef.getRtti(defaultProviders, 1); final OptimizationEnum optimization = specificDef.getOptimization(defaultProviders, 1); this.addImpliedArgs(args, debug, multithreaded, exceptions, linkType, rtti, optimization); } // // add all appropriate defines and undefines // buildDefineArguments(defaultProviders, args); final int warnings = specificDef.getWarnings(defaultProviders, 0); addWarningSwitch(args, warnings); Enumeration<CommandLineArgument> argEnum = cmdArgs.elements(); int endCount = 0; while (argEnum.hasMoreElements()) { final CommandLineArgument arg = argEnum.nextElement(); switch (arg.getLocation()) { case 1: args.addElement(arg.getValue()); break; case 2: endCount++; break; } } final String[] endArgs = new String[endCount]; argEnum = cmdArgs.elements(); int index = 0; while (argEnum.hasMoreElements()) { final CommandLineArgument arg = argEnum.nextElement(); if (arg.getLocation() == 2) { endArgs[index++] = arg.getValue(); } } // // Want to have distinct set of arguments with relative // path names for includes that are used to build // the configuration identifier // final Vector<String> relativeArgs = (Vector) args.clone(); // // add all active include and sysincludes // final StringBuffer includePathIdentifier = new StringBuffer(); final File baseDir = specificDef.getProject().getBaseDir(); String baseDirPath; try { baseDirPath = baseDir.getCanonicalPath(); } catch (final IOException ex) { baseDirPath = baseDir.toString(); } final Vector<String> includePath = new Vector<>(); final Vector<String> sysIncludePath = new Vector<>(); for (int i = defaultProviders.length - 1; i >= 0; i--) { String[] incPath = defaultProviders[i].getActiveIncludePaths(); for (final String element : incPath) { includePath.addElement(element); } incPath = defaultProviders[i].getActiveSysIncludePaths(); for (final String element : incPath) { sysIncludePath.addElement(element); } } final File[] incPath = new File[includePath.size()]; for (int i = 0; i < includePath.size(); i++) { incPath[i] = new File(includePath.elementAt(i)); } final File[] sysIncPath = new File[sysIncludePath.size()]; for (int i = 0; i < sysIncludePath.size(); i++) { sysIncPath[i] = new File(sysIncludePath.elementAt(i)); } addIncludes(baseDirPath, incPath, args, relativeArgs, includePathIdentifier, false); addIncludes(baseDirPath, sysIncPath, args, null, null, true); final StringBuffer buf = new StringBuffer(getIdentifier()); for (int i = 0; i < relativeArgs.size(); i++) { buf.append(' '); buf.append(relativeArgs.elementAt(i)); } for (final String endArg : endArgs) { buf.append(' '); buf.append(endArg); } final String configId = buf.toString(); final String[] argArray = new String[args.size()]; args.copyInto(argArray); final boolean rebuild = specificDef.getRebuild(baseDefs, 0); final File[] envIncludePath = getEnvironmentIncludePath(); final String path = specificDef.getToolPath(); CommandLineCompiler compiler = this; Environment environment = specificDef.getEnv(); if (environment == null) { for (final ProcessorDef baseDef : baseDefs) { environment = baseDef.getEnv(); if (environment != null) { compiler = (CommandLineCompiler) compiler.changeEnvironment(baseDef.isNewEnvironment(), environment); } } } else { compiler = (CommandLineCompiler) compiler.changeEnvironment(specificDef.isNewEnvironment(), environment); } return new CommandLineCompilerConfiguration(compiler, configId, incPath, sysIncPath, envIncludePath, includePathIdentifier.toString(), argArray, paramArray, rebuild, endArgs, path, specificDef.getCcache()); }
From source file:com.adito.agent.client.ProxyUtil.java
/** * Attempt to proxy settings from Firefox. * // www . j a va 2s.c o 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$ } }