private String CBC(String key, String text) { //mode enkripsi CBC //asumsi //1. panjang key = 8 //2. panjang text merupakan kelipatan 8 int a,b,c; int size; String temp = String.Empty; String keyGen = "00000000"; String tempKey = String.Empty; String result = String.Empty; a=0; //count jumlah char b=0; //count jumlah penggunaan key while(a<text.Length){ temp = text.substring(a,8); //melakukan XOR P dan C tempKey = varXOR(temp,keyGen); //harusnya ada fungsi XOR, tapi baru asumsi, fungsi masih salah result += varXOR(tempKey,keyGen); a+=8; b++; } return result; }
//======================================================================== //======================================================================== private String EBC(String key, String text) { //mode enkripsi EBC //asumsi //1. panjang key = 8 //2. panjang text merupakan kelipatan 8 int a,b,c; int size; String temp = String.Empty; String keyGen = String.Empty; String result = String.Empty; a=0; //count jumlah char b=0; //count jumlah penggunaan key while(a<text.Length){ temp = text.substring(a,8); //generate fungsi key //key akan di-generate berdasarkan jumlah penggunaan kunci, //key juga akan di-reversi jika telah melakukan 5 penggunaan keyGen = generatorKey(key,b); //harusnya ada fungsi XOR, tapi baru asumsi, fungsi masih salah result += varXOR(temp,keyGen); a+=8; b++; } return result; }
private int parseVerboseInt(String input) { String loadedString = String.format("%s", input); boolean negative = false; int base = 10; int shift = 3; int retVal = -1; if (input.charAt(0) == '-') { negative = true; input = input.substring(1); } if (input.indexOf("0x") == 0) { base = 16; input = input.substring(2); } if (input.indexOf("b") == input.length() - 1) { shift = 0; input = input.substring(0, input.length() - 1); } try { retVal = Integer.parseInt(input, base); } catch (Exception e) { addGeneralError(loadedString); validComponent = false; } if (validComponent) { retVal <<= shift; if (negative) retVal = 0 - retVal; } return retVal; }
static public String getRelativePath(String path1, String path2) { if (!path1.startsWith(path2)) return path1; return path1.substring(path2.length()); }
public CAttrValue(String strAttrib, String strValue) { m_strAttrib = strAttrib; m_strValue = strValue; if ( m_strAttrib.endsWith("-rhoblob") ) { m_strBlobSuffix = "-rhoblob"; m_strAttrib = m_strAttrib.substring(0,m_strAttrib.length()-m_strBlobSuffix.length()); } }
/* (non-Javadoc) * @see org.javarosa.core.reference.ReferenceFactory#derive(java.lang.String) */ public virtual Reference derive(System.String URI) { for (String root: roots) { if (URI.indexOf(root) != -1) { return(factory(URI.substring(root.length()), URI)); } } //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new InvalidReferenceException("Invalid attempt to derive a reference from a prefixed root. Valid prefixes for this factory are " + roots, URI); }
public static String changeBaseName( String path, String szFileName ) { int basePos = findLastSlash(path); if (basePos >= 0 && basePos < path.length() - 1) { String res = path.substring(0, basePos + 1); res += szFileName; return res; } return join(path, szFileName); }
private String makeStringSize(String str, int nSize) { if ( str.length() >= nSize ) return str.substring(0, nSize); else { String res = ""; for( int i = 0; i < nSize - str.length(); i++ ) res += ' '; res += str; return res; } }
public static void generateCombosHelper(List<String> combos, String prefix, String remaining) { // The current digit we are working with int digit = int.Parse(remaining.Substring(0, 1)); if (remaining.Length == 1) { // We have reached the last digit in the phone number, so add // all possible prefix-digit combinations to the list for (int i = 0; i < mappings[digit].length; i++) { combos.add(prefix + mappings[digit][i]); } } else { // Recursively call this method with each possible new // prefix and the remaining part of the phone number. for (int i = 0; i < mappings[digit].length; i++) { generateCombosHelper(combos, prefix + mappings[digit][i], remaining.substring(1)); } } }
/** * Canonicalize the path, i.e. remove ".." and "." occurences. * * @param path the path to be canonicalized * @return the canonicalized path */ public static String canonicalizePath(String path) { int dirIndex; while ((dirIndex = path.indexOf("/./")) >= 0) { //$NON-NLS-1$ path = path.substring(0, dirIndex + 1) + path.substring(dirIndex + 3); } if (path.endsWith("/.")) { //$NON-NLS-1$ path = path.substring(0, path.length() - 1); } while ((dirIndex = path.indexOf("/../")) >= 0) { //$NON-NLS-1$ if (dirIndex != 0) { path = path.substring(0, path .lastIndexOf('/', dirIndex - 1)) + path.substring(dirIndex + 3); } else { path = path.substring(dirIndex + 3); } } if (path.endsWith("/..") && path.length() > 3) { //$NON-NLS-1$ path = path.substring(0, path.lastIndexOf('/', path.length() - 4) + 1); } return path; }
/** * Decodes the string argument which is assumed to be encoded in the {@code * x-www-form-urlencoded} MIME content type using the UTF-8 encoding scheme. * <p> *'%' and two following hex digit characters are converted to the * equivalent byte value. All other characters are passed through * unmodified. * <p> * e.g. "A%20B%20C %24%25" -> "A B C $%" * <p> * Called from URI.getXYZ() methods * * @param s * java.lang.String The encoded string. * @return java.lang.String The decoded version. */ static String decode(String s) { //throws UnsupportedEncodingException { StringBuilder result = new StringBuilder(); java.io.ByteArrayOutputStream outJ = new java.io.ByteArrayOutputStream(); for (int i = 0; i < s.length();) { char c = s.charAt(i); if (c == '%') { outJ.reset(); do { if (i + 2 >= s.length()) { throw new java.lang.IllegalArgumentException("Incomplete % sequence at: "+ i); //$NON-NLS-1$ } int d1 = java.lang.Character.digit(s.charAt(i + 1), 16); int d2 = java.lang.Character.digit(s.charAt(i + 2), 16); if (d1 == -1 || d2 == -1) { throw new java.lang.IllegalArgumentException("Invalid % sequence ("+s.substring(i, i + 3)+") at: "+java.lang.StringJ.valueOf(i)); } outJ.write((byte) ((d1 << 4) + d2)); i += 3; } while (i < s.length() && s.charAt(i) == '%'); result.append(outJ.toString(encoding)); continue; } result.append(c); i++; } return result.toString(); }
/// <summary> /// This is used to acquire the name of the method in a Java Bean /// property style. Thus any "get", "is", or "set" prefix is /// removed from the name and the following character is changed /// to lower case if it does not represent an acronym. /// </summary> /// <param name="name"> /// this is the name of the method to be converted /// </param> /// <param name="type"> /// this is the type of method the name represents /// </param> /// <returns> /// this returns the Java Bean name for the method /// </returns> public String GetTypeName(String name, MethodType type) { int prefix = type.getPrefix(); int size = name.length(); if(size > prefix) { name = name.substring(prefix, size); } return Reflector.GetName(name); }
/** * Writes {@code count} characters from {@code str} starting at {@code * offset} to the target. * * @param str * the non-null string containing the characters to write. * @param offset * the index of the first character in {@code str} to write. * @param count * the number of characters from {@code str} to write. * @throws IndexOutOfBoundsException * if {@code offset < 0} or {@code count < 0}, or if {@code * offset + count} is greater than the length of {@code str}. */ public override void write(String str, int offset, int count) { write(str.substring(offset, offset + count).toCharArray()); }
/// <summary> /// Parse String with given pattern on ParsePosition to Data object /// </summary> /// <param name="s"></param> /// <param name="pos"></param> /// <returns></returns> public java.util.Date parse(String s, ParsePosition pos) { DateTime date = DateTime.ParseExact(s.substring(pos.getIndex()), pattern, CultureInfo.InvariantCulture); return new java.util.Date(date.getTime()); }
public override Preferences node(String name) { AbstractPreferences startNode = null; lock (lockJ) { checkState(); validateName(name); if ("".equals(name)) { //$NON-NLS-1$ return this; } else if ("/".equals(name)) { //$NON-NLS-1$ return root; } if (name.startsWith("/")) { //$NON-NLS-1$ startNode = root; name = name.substring(1); } else { startNode = this; } } try { return startNode.nodeImpl(name, true); } catch (BackingStoreException e) { // should not happen return null; } }
/** * Creates a new URL to the specified resource {@code spec}. This URL is * relative to the given {@code context}. The {@code handler} will be used * to parse the URL string representation. If this argument is {@code null} * the default {@code URLStreamHandler} will be used. If the protocol of the * parsed URL does not match with the protocol of the context URL, then the * newly created URL is absolute and bases only on the given URL represented * by {@code spec}. Otherwise the protocol is defined by the context URL. * * @param context * the URL which is used as the context. * @param spec * the URL string representation which has to be parsed. * @param handler * the specific stream handler to be used by this URL. * @throws MalformedURLException * if the given string {@code spec} could not be parsed as a URL * or an invalid protocol has been found. */ public URL(URL context, String spec, URLStreamHandler handler) { //throws MalformedURLException { if (handler != null) { java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager(); if (sm != null) { sm.checkPermission(specifyStreamHandlerPermission); } strmHandler = handler; } if (spec == null) { throw new MalformedURLException(); } spec = spec.trim(); // The spec includes a protocol if it includes a colon character // before the first occurrence of a slash character. Note that, // "protocol" is the field which holds this URLs protocol. int index; try { index = spec.indexOf(':'); } catch (java.lang.NullPointerException e) { throw new MalformedURLException(e.toString()); } int startIPv6Addr = spec.indexOf('['); if (index >= 0) { if ((startIPv6Addr == -1) || (index < startIPv6Addr)) { protocol = spec.substring(0, index); // According to RFC 2396 scheme part should match // the following expression: // alpha *( alpha | digit | "+" | "-" | "." ) char c = protocol.charAt(0); bool valid = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); for (int i = 1; valid && (i < protocol.length()); i++) { c = protocol.charAt(i); valid = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '+') || (c == '-') || (c == '.'); } if (!valid) { protocol = null; index = -1; } else { // Ignore case in protocol names. // Scheme is defined by ASCII characters. protocol = Util.toASCIILowerCase(protocol); } } } if (protocol != null) { // If the context was specified, and it had the same protocol // as the spec, then fill in the receiver's slots from the values // in the context but still allow them to be over-ridden later // by the values in the spec. if (context != null && protocol.equals(context.getProtocol())) { String cPath = context.getPath(); if (cPath != null && cPath.startsWith("/")) { //$NON-NLS-1$ set(protocol, context.getHost(), context.getPort(), context .getAuthority(), context.getUserInfo(), cPath, context.getQuery(), null); } if (strmHandler == null) { strmHandler = context.strmHandler; } } } else { // If the spec did not include a protocol, then the context // *must* be specified. Fill in the receiver's slots from the // values in the context, but still allow them to be over-ridden // by the values in the ("relative") spec. if (context == null) { throw new MalformedURLException("Protocol not found: " + spec); //$NON-NLS-1$ } set(context.getProtocol(), context.getHost(), context.getPort(), context.getAuthority(), context.getUserInfo(), context .getPath(), context.getQuery(), null); if (strmHandler == null) { strmHandler = context.strmHandler; } } // If the stream handler has not been determined, set it // to the default for the specified protocol. if (strmHandler == null) { setupStreamHandler(); if (strmHandler == null) { throw new MalformedURLException("Unknown protocol: " + protocol); //$NON-NLS-1$ } } // Let the handler parse the URL. If the handler throws // any exception, throw MalformedURLException instead. // // Note: We want "index" to be the index of the start of the scheme // specific part of the URL. At this point, it will be either // -1 or the index of the colon after the protocol, so we // increment it to point at either character 0 or the character // after the colon. try { strmHandler.parseURL(this, spec, ++index, spec.length()); } catch (Exception e) { throw new MalformedURLException(e.toString()); } if (port < -1) { throw new MalformedURLException("Port out of range: " + port); //$NON-NLS-1$ } }
/* RubyString[] getOrigColNames(IDBResult rows) { RubyString[] colNames = new RubyString[rows.getColCount()]; for ( int nCol = 0; nCol < rows.getColCount(); nCol ++ ) colNames[nCol] = ObjectFactory.createString(rows.getOrigColName(nCol)); return colNames; } */ private String getNameNoExt(String strPath){ int nDot = strPath.lastIndexOf('.'); String strDbName = ""; if ( nDot > 0 ) strDbName = strPath.substring(0, nDot); else strDbName = strPath; return strDbName; }
/*static{ TEST(); } public static void TEST() { //ParsedCookie cookie = new ParsedCookie(); String strClientCookie = ""; strClientCookie = URI.parseCookie("auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT, auth_token=887b2ffd30a7b97be9a0986d7746a934421eec7d; path=/; expires=Sat, 24 Oct 2009 20:56:55 GMT, rhosync_session=BAh7BzoMdXNlcl9pZGkIIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--f9b67d99397fc534107fb3b7483ccdae23b4a761; path=/; expires=Sun, 10 Oct 2010 19:10:58 GMT; HttpOnly"); strClientCookie = URI.parseCookie("auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"); strClientCookie = URI.parseCookie("rhosync_session=BAh7CToNcGFzc3dvcmQiFTiMYru1W11zuoAlN%2FPtgjc6CmxvZ2luIhU4jGK7tVtdc7qAJTfz7YI3Ogx1c2VyX2lkaQYiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA%3D--a7829a70171203d72cd4e83d07b18e8fcf5e2f78; path=/; expires=Thu, 02 Sep 2010 23:51:31 GMT; HttpOnly"); }*/ public static String readFully(Stream stream, String strContType) { String strRes = ""; byte[] byteBuffer = new byte[1024*4]; boolean bUTF8 = false; StreamReader reader = null; if ( strContType != null ) { int nCharsetPos = strContType.lastIndexOf('='); if ( nCharsetPos > 0 ) { String strEnc = strContType.substring(nCharsetPos+1); bUTF8 = strEnc.equalsIgnoreCase("UTF-8"); } } try { if(bUTF8) reader = new StreamReader(stream, Encoding.UTF8); else reader = new StreamReader(stream); strRes = reader.ReadToEnd(); } finally { if(reader != null) reader.Close(); } return strRes; }
// function REPRODUCE(x, y) returns an individual // inputs: x, y, parent individuals private String reproduce(String x, String y) { // n <- LENGTH(x); // Note: this is = this.individualLength // c <- random number from 1 to n int c = randomOffset(individualLength); // return APPEND(SUBSTRING(x, 1, c), SUBSTRING(y, c+1, n)) return x.substring(0, c) + y.substring(c); }
/** * Parses the clear text URL in {@code str} into a URL object. URL strings * generally have the following format: * <p/> * http://www.company.com/java/file1.java#reference * <p/> * The string is parsed in HTTP format. If the protocol has a different URL * format this method must be overridden. * * @param u * the URL to fill in the parsed clear text URL parts. * @param str * the URL string that is to be parsed. * @param start * the string position from where to begin parsing. * @param end * the string position to stop parsing. * @see #toExternalForm * @see URL */ protected internal void parseURL(URL u, String str, int start, int end) { if (end < start || end < 0) { // Checks to ensure string index exception ahead of // security exception for compatibility. if (end <= java.lang.Integer.MIN_VALUE + 1 && (start >= str.length() || start < 0) || str.startsWith("//", start) && str.indexOf('/', start + 2) == -1) { //$NON-NLS-1$ throw new java.lang.StringIndexOutOfBoundsException(end); } if (this != u.strmHandler) { throw new java.lang.SecurityException(); } return; } String parseString = str.substring(start, end); end -= start; int fileIdx = 0; // Default is to use info from context String host = u.getHost(); int port = u.getPort(); String refJ = u.getRef(); String file = u.getPath(); String query = u.getQuery(); String authority = u.getAuthority(); String userInfo = u.getUserInfo(); int refIdx = parseString.indexOf('#', 0); if (parseString.startsWith("//") && !parseString.startsWith("////")) { //$NON-NLS-1$ int hostIdx = 2, portIdx = -1; port = -1; fileIdx = parseString.indexOf('/', hostIdx); int questionMarkIndex = parseString.indexOf('?', hostIdx); if ((questionMarkIndex != -1) && ((fileIdx == -1) || (fileIdx > questionMarkIndex))) { fileIdx = questionMarkIndex; } if (fileIdx == -1) { fileIdx = end; // Use default file = ""; //$NON-NLS-1$ } int hostEnd = fileIdx; if (refIdx != -1 && refIdx < fileIdx) { hostEnd = refIdx; } int userIdx = parseString.lastIndexOf('@', hostEnd); authority = parseString.substring(hostIdx, hostEnd); if (userIdx > -1) { userInfo = parseString.substring(hostIdx, userIdx); hostIdx = userIdx + 1; } portIdx = parseString.indexOf(':', userIdx == -1 ? hostIdx : userIdx); int endOfIPv6Addr = parseString.indexOf(']'); // if there are square braces, ie. IPv6 address, use last ':' if (endOfIPv6Addr != -1) { try { if (parseString.length() > endOfIPv6Addr + 1) { char c = parseString.charAt(endOfIPv6Addr + 1); if (c == ':') { portIdx = endOfIPv6Addr + 1; } else { portIdx = -1; } } else { portIdx = -1; } } catch (Exception e) { // Ignored } } if (portIdx == -1 || portIdx > fileIdx) { host = parseString.substring(hostIdx, hostEnd); } else { host = parseString.substring(hostIdx, portIdx); String portString = parseString.substring(portIdx + 1, hostEnd); if (portString.length() == 0) { port = -1; } else { port = java.lang.Integer.parseInt(portString); } } } if (refIdx > -1) { refJ = parseString.substring(refIdx + 1, end); } int fileEnd = (refIdx == -1 ? end : refIdx); int queryIdx = parseString.lastIndexOf('?', fileEnd); bool canonicalize = false; if (queryIdx > -1) { query = parseString.substring(queryIdx + 1, fileEnd); if (queryIdx == 0 && file != null) { if (file.equals("")) { //$NON-NLS-1$ file = "/"; //$NON-NLS-1$ } else if (file.startsWith("/")) { //$NON-NLS-1$ canonicalize = true; } int last = file.lastIndexOf('/') + 1; file = file.substring(0, last); } fileEnd = queryIdx; } else // Don't inherit query unless only the ref is changed if (refIdx != 0) { query = null; } if (fileIdx > -1) { if (fileIdx < end && parseString.charAt(fileIdx) == '/') { file = parseString.substring(fileIdx, fileEnd); } else if (fileEnd > fileIdx) { if (file == null) { file = ""; //$NON-NLS-1$ } else if (file.equals("")) { //$NON-NLS-1$ file = "/"; //$NON-NLS-1$ } else if (file.startsWith("/")) { //$NON-NLS-1$ canonicalize = true; } int last = file.lastIndexOf('/') + 1; if (last == 0) { file = parseString.substring(fileIdx, fileEnd); } else { file = file.substring(0, last) + parseString.substring(fileIdx, fileEnd); } } } if (file == null) { file = ""; //$NON-NLS-1$ } if (host == null) { host = ""; //$NON-NLS-1$ } if (canonicalize) { // modify file if there's any relative referencing file = URLUtil.canonicalizePath(file); } setURL(u, u.getProtocol(), host, port, authority, userInfo, file, query, refJ); }
/** * Parses <code>source</code> for special double values. These values * include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY. * * @param source the string to parse * @param value the special value to parse. * @param pos input/ouput parsing parameter. * @return the special number. */ private static Number parseNumber(String source, double value, ParsePosition pos) { Number ret = null; StringBuilder sb = new StringBuilder(); sb.append('('); sb.append(value); sb.append(')'); int n = sb.length(); int startIndex = pos.getIndex(); int endIndex = startIndex + n; if (endIndex < source.length()) { if (source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) { ret = Double.valueOf(value); pos.setIndex(endIndex); } } return ret; }
/** * Parse <code>source</code> for an expected fixed string. * @param source the string to parse * @param expected expected string * @param pos input/ouput parsing parameter. * @return true if the expected string was there */ public static bool parseFixedstring(String source, String expected, ParsePosition pos) { int startIndex = pos.getIndex(); int endIndex = startIndex + expected.length(); if ((startIndex >= source.length()) || (endIndex > source.length()) || (source.substring(startIndex, endIndex).compareTo(expected) != 0)) { // set index back to start, error index should be the start index pos.setIndex(startIndex); pos.setErrorIndex(startIndex); return false; } // the string was here pos.setIndex(endIndex); return true; }
static String getHostFromUrl( String strUrl ) { int nHttp = strUrl.indexOf("://"); if ( nHttp < 0 ) nHttp = strUrl.indexOf(":\\\\"); int nStartSrv = 0; if ( nHttp >= 0 ) nStartSrv = nHttp + 3; int nEndSrv = strUrl.indexOf('/', nStartSrv); if ( nEndSrv < 0 ) nEndSrv = strUrl.indexOf('\\', nStartSrv); int nSrvLen = nEndSrv >= 0 ? nEndSrv + 1 : strUrl.length(); return strUrl.substring(nSrvLen); }
/** * <p><code>QName</code> derived from parsing the formatted * <code>String</code>.</p> * * <p>If the <code>String</code> is <code>null</code> or does not conform to * {@link #toString() QName.toString()} formatting, an * <code>IllegalArgumentException</code> is thrown.</p> * * <p><em>The <code>String</code> <strong>MUST</strong> be in the * form returned by {@link #toString() QName.toString()}.</em></p> * <p>The commonly accepted way of representing a <code>QName</code> * as a <code>String</code> was <a href="http://jclark.com/xml/xmlns.htm">defined</a> * by James Clark. Although this is not a <em>standard</em> * specification, it is in common use, e.g. {@link javax.xml.transform.Transformer#setParameter(String name, Object value)}. * This implementation parses a <code>String</code> formatted * as: "{" + Namespace URI + "}" + local part. If the Namespace * URI <code>.equals(XMLConstants.NULL_NS_URI)</code>, only the * local part should be provided.</p> * * <p>The prefix value <strong><em>CANNOT</em></strong> be * represented in the <code>String</code> and will be set to * {@link javax.xml.XMLConstants#DEFAULT_NS_PREFIX * XMLConstants.DEFAULT_NS_PREFIX}.</p> * * <p>This method does not do full validation of the resulting * <code>QName</code>. * <p>The Namespace URI is not validated as a * <a href="http://www.ietf.org/rfc/rfc2396.txt">URI reference</a>. * The local part is not validated as a * <a href="http://www.w3.org/TR/REC-xml-names/#NT-NCName">NCName</a> * as specified in * <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces in XML</a>.</p> * * @param qNameAsString <code>String</code> representation * of the <code>QName</code> * @return <code>QName</code> corresponding to the given <code>String</code> * @see #toString() QName.toString() */ public static QName valueOf(String qNameAsString) { // null is not valid if (qNameAsString == null) { throw new java.lang.IllegalArgumentException("cannot create QName from \"null\" or \"\" String"); } // "" local part is valid to preserve compatible behavior with QName 1.0 if (qNameAsString.length() == 0) { return new QName( XMLConstants.NULL_NS_URI, qNameAsString, XMLConstants.DEFAULT_NS_PREFIX); } // local part only? if (qNameAsString.charAt(0) != '{') { return new QName( XMLConstants.NULL_NS_URI, qNameAsString, XMLConstants.DEFAULT_NS_PREFIX); } // Namespace URI improperly specified? if (qNameAsString.startsWith("{" + XMLConstants.NULL_NS_URI + "}")) { throw new java.lang.IllegalArgumentException( "Namespace URI .equals(XMLConstants.NULL_NS_URI), " + ".equals(\"" + XMLConstants.NULL_NS_URI + "\"), " + "only the local part, " + "\"" + qNameAsString.substring(2 + XMLConstants.NULL_NS_URI.length()) + "\", " + "should be provided."); } // Namespace URI and local part specified int endOfNamespaceURI = qNameAsString.indexOf('}'); if (endOfNamespaceURI == -1) { throw new java.lang.IllegalArgumentException( "cannot create QName from \"" + qNameAsString + "\", missing closing \"}\""); } return new QName( qNameAsString.substring(1, endOfNamespaceURI), qNameAsString.substring(endOfNamespaceURI + 1), XMLConstants.DEFAULT_NS_PREFIX); }
void doFireSyncNotification( SyncSource src, boolean bFinish, int nErrCode, String strError, String strParams, String strServerError ) { if ( getSync().isStoppedByUser() ) return; try{ SyncNotification pSN = null; String strBody = ""; boolean bRemoveAfterFire = bFinish; { lock(m_mxSyncNotifications){ pSN = getSyncNotifyBySrc(src); if ( pSN == null ) return; strBody = ""; if ( src != null ) { strBody += "total_count=" + src.getTotalCount(); strBody += "&processed_count=" + src.getCurPageCount(); strBody += "&processed_objects_count=" + getLastSyncObjectCount(src.getID()); strBody += "&cumulative_count=" + src.getServerObjectsCount(); strBody += "&source_id=" + src.getID(); strBody += "&source_name=" + src.getName(); } if ( strParams.length() > 0 ) strBody += (strBody.length() > 0 ? "&" : "") + strParams; else strBody += (strBody.length() > 0 ? "&" : "") + "sync_type=incremental"; strBody += "&status="; if ( bFinish ) { if ( nErrCode == RhoAppAdapter.ERR_NONE ) { if ( getSync().isSchemaChanged() ) strBody += "schema_changed"; else strBody += (src == null && strParams.length() == 0) ? "complete" : "ok"; } else { if ( getSync().isStoppedByUser() ) nErrCode = RhoAppAdapter.ERR_CANCELBYUSER; strBody += "error"; strBody += "&error_code=" + nErrCode; if (strError != null && strError.length() > 0) { if (strError.length() > MAX_SERVER_ERROR_LEN) strError = strError.substring(0, MAX_SERVER_ERROR_LEN); strBody += "&error_message=" + URI.urlEncode(strError); } else if (src != null && src.m_strError != null) { if (src.m_strError.length() > MAX_SERVER_ERROR_LEN) src.m_strError = src.m_strError.substring(0, MAX_SERVER_ERROR_LEN); strBody += "&error_message=" + URI.urlEncode(src.m_strError); } if (strServerError != null && strServerError.length() > 0) { if (strServerError.length() > MAX_SERVER_ERROR_LEN) strServerError = strServerError.substring(0, MAX_SERVER_ERROR_LEN); strBody += "&" + strServerError; } else if (src != null && src.m_strServerError != null && src.m_strServerError.length() > 0) { if ( src.m_strServerError.length() > MAX_SERVER_ERROR_LEN ) src.m_strServerError = src.m_strServerError.substring(0, MAX_SERVER_ERROR_LEN); strBody += "&" + src.m_strServerError; } } if ( src != null ) strBody += makeCreateObjectErrorBody( src.getID()); } else strBody += "in_progress"; strBody += "&rho_callback=1"; if ( pSN.m_strParams != null && pSN.m_strParams.length() > 0 ) { if ( !pSN.m_strParams.startsWith("&") ) strBody += "&"; strBody += pSN.m_strParams; } bRemoveAfterFire = bRemoveAfterFire && pSN.m_bRemoveAfterFire; } } if ( bRemoveAfterFire ) clearNotification(src); LOG.INFO("Fire notification. Source : " + (src != null ? (src).getName():"") + "; " + pSN.ToString()); if ( callNotify(pSN, strBody) ) clearNotification(src); }catch(Exception exc) { LOG.ERROR("Fire notification failed.", exc); } }
private void processToolBarCommand(object sender, EventArgs e, String strAction) { boolean callback = false; if (strAction == "back") { if (m_strAppBackUrl.length() > 0) processToolBarCommand(this, e, m_strAppBackUrl); else if (m_backHistory.Count > 0) { Uri destination = m_backHistory.Peek(); m_webBrowser.Navigate(destination); } return; } if (strAction.startsWith("callback:")) { strAction = strAction.substring(9); callback = true; } if (strAction == "forward" && m_forwardHistory.Count > 0) { Uri destination = m_forwardHistory.Peek(); m_webBrowser.Navigate(destination); return; } if (strAction == "home") { String strHomePage = RhoRuby.getStartPage(); strHomePage = canonicalizeRhoUrl(strHomePage); m_webBrowser.Navigate(new Uri(strHomePage)); return; } if (strAction == "log") { showLogScreen(); return; } if (strAction == "options") { String curUrl = RhoRuby.getOptionsPage(); curUrl = canonicalizeRhoUrl(curUrl); m_webBrowser.Navigate(new Uri(curUrl)); return; } if (strAction == "refresh" && m_currentUri != null) { m_webBrowser.Navigate(m_currentUri); return; } if (strAction == "sync") { SyncThread.doSyncAllSources(true); return; } strAction = canonicalizeRhoUrl(strAction); if (callback) { RhoClassFactory.createNetRequest().pushData(strAction, "rho_callback=1", null); } else m_webBrowser.Navigate(new Uri(strAction)); }
public void callLoginCallback(SyncNotification oNotify, int nErrCode, String strMessage) { try{ if ( getSync().isStoppedByUser() ) return; String strBody = "error_code=" + nErrCode; if (strMessage != null && strMessage.length() > MAX_SERVER_ERROR_LEN) strMessage = strMessage.substring(0, MAX_SERVER_ERROR_LEN); strBody += "&error_message=" + URI.urlEncode(strMessage != null? strMessage : ""); strBody += "&rho_callback=1"; if (oNotify.m_strUrl.indexOf("?") > 0) { strBody += "&" + oNotify.m_strUrl.substring(oNotify.m_strUrl.indexOf("?") + 1, oNotify.m_strUrl.length()); oNotify.m_strUrl = oNotify.m_strUrl.Remove(oNotify.m_strUrl.indexOf("?")); } LOG.INFO( "Login callback: " + oNotify.ToString() + ". Body: "+ strBody ); callNotify(oNotify, strBody); }catch(Exception exc) { LOG.ERROR("Call Login callback failed.", exc); } }
public override bool nodeExists(String name) { //throws BackingStoreException { if (null == name) { throw new java.lang.NullPointerException(); } AbstractPreferences startNode = null; lock (lockJ) { if (isRemoved()) { if ("".equals(name)) { //$NON-NLS-1$ return false; } // prefs.9=This node has been removed throw new java.lang.IllegalStateException("This node has been removed"); //$NON-NLS-1$ } validateName(name); if ("".equals(name) || "/".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ return true; } if (name.startsWith("/")) { //$NON-NLS-1$ startNode = root; name = name.substring(1); } else { startNode = this; } } try { Preferences result = startNode.nodeImpl(name, false); return null == result ? false : true; } catch (java.lang.IllegalArgumentException e) { return false; } }
public void addObjectNotify(String strSrcName, String strObject ) { lock(m_mxObjectNotify) { m_strSingleObjectSrcName = strSrcName; m_strSingleObjectID = strObject.charAt(0) == '{' ? strObject.substring(1,strObject.length()-2) : strObject ; } }
/** * Creates a new URL instance using the given arguments. The URL uses the * specified port instead of the default port for the given protocol. * * @param protocol * the protocol of the new URL. * @param host * the host name or IP address of the new URL. * @param port * the specific port number of the URL. {@code -1} represents the * default port of the protocol. * @param file * the name of the resource. * @param handler * the stream handler to be used by this URL. * @throws MalformedURLException * if the combination of all arguments do not represent a valid * URL or the protocol is invalid. * @throws SecurityException * if {@code handler} is non-{@code null}, and a security * manager is installed that disallows user-defined protocol * handlers. */ public URL(String protocol, String host, int port, String file, URLStreamHandler handler) { // throws MalformedURLException { if (port < -1) { throw new MalformedURLException("Port out of range: " + port); //$NON-NLS-1$ } if (host != null && host.indexOf(":") != -1 && host.charAt(0) != '[') { //$NON-NLS-1$ host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } if (protocol == null) { throw new java.lang.NullPointerException("Unknown protocol: " + "null"); //$NON-NLS-1$ //$NON-NLS-2$ } this.protocol = protocol; this.host = host; this.port = port; // Set the fields from the arguments. Handle the case where the // passed in "file" includes both a file and a reference part. int index = -1; index = file.indexOf("#", file.lastIndexOf("/")); //$NON-NLS-1$ //$NON-NLS-2$ if (index >= 0) { this.file = file.substring(0, index); refJ = file.substring(index + 1); } else { this.file = file; } fixURL(false); // Set the stream handler for the URL either to the handler // argument if it was specified, or to the default for the // receiver's protocol if the handler was null. if (handler == null) { setupStreamHandler(); if (strmHandler == null) { throw new MalformedURLException("Unknown protocol: " + protocol); //$NON-NLS-1$ } } else { java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager(); if (sm != null) { sm.checkPermission(specifyStreamHandlerPermission); } strmHandler = handler; } }
/** * Returns the array of providers which meet the user supplied string * filter. The specified filter must be supplied in one of two formats: * <nl> * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li> * <p/> * (for example: "MessageDigest.SHA") * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE</li> * ATTR_NAME:ATTR_VALUE * <p/> * (for example: "Signature.MD2withRSA KeySize:512") * </nl> * * @param filter * case-insensitive filter. * @return the providers which meet the user supplied string filter {@code * filter}. A {@code null} value signifies that none of the * installed providers meets the filter specification. * @throws InvalidParameterException * if an unusable filter is supplied. * @throws NullPointerException * if {@code filter} is {@code null}. */ public static Provider[] getProviders(String filter) { if (filter == null) { throw new java.lang.NullPointerException("The filter is null"); //$NON-NLS-1$ } if (filter.length() == 0) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } java.util.HashMap<String, String> hm = new java.util.HashMap<String, String>(); int i = filter.indexOf(':'); if ((i == filter.length() - 1) || (i == 0)) { throw new InvalidParameterException("The filter is not in the required format"); //$NON-NLS-1$ } if (i < 1) { hm.put(filter, ""); //$NON-NLS-1$ } else { hm.put(filter.substring(0, i), filter.substring(i + 1)); } return getProviders(hm); }