< prev index next >

src/java.base/share/classes/sun/security/provider/PolicyParser.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 374         if (peek("\"")) {
 375             keyStoreProvider = match("quoted string");
 376         } else {
 377             throw new ParsingException(st.lineno(),
 378                 LocalizedMessage.getNonlocalized("expected.keystore.provider"));
 379         }
 380     }
 381 
 382     private void parseStorePassURL() throws ParsingException, IOException {
 383         match("keyStorePasswordURL");
 384         storePassURL = match("quoted string");
 385     }
 386 
 387     /**
 388      * writes the (unexpanded) keystore entry
 389      */
 390     private void writeKeyStoreEntry(PrintWriter out) {
 391         out.print("keystore \"");
 392         out.print(keyStoreUrlString);
 393         out.print('"');
 394         if (keyStoreType != null && keyStoreType.length() > 0)
 395             out.print(", \"" + keyStoreType + "\"");
 396         if (keyStoreProvider != null && keyStoreProvider.length() > 0)
 397             out.print(", \"" + keyStoreProvider + "\"");
 398         out.println(";");
 399         out.println();
 400     }
 401 
 402     private void writeStorePassURL(PrintWriter out) {
 403         out.print("keystorePasswordURL \"");
 404         out.print(storePassURL);
 405         out.print('"');
 406         out.println(";");
 407         out.println();
 408     }
 409 
 410     /**
 411      * parse a Grant entry
 412      */
 413     private GrantEntry parseGrantEntry()
 414         throws ParsingException, IOException
 415     {
 416         GrantEntry e = new GrantEntry();


 429                                 ("multiple.Codebase.expressions"));
 430                 e.codeBase = match("quoted string");
 431                 peekAndMatch(",");
 432             } else if (peekAndMatch("SignedBy")) {
 433                 if (e.signedBy != null)
 434                     throw new ParsingException(
 435                             st.lineno(),
 436                             LocalizedMessage.getNonlocalized
 437                                 ("multiple.SignedBy.expressions"));
 438                 e.signedBy = match("quoted string");
 439 
 440                 // verify syntax of the aliases
 441                 StringTokenizer aliases = new StringTokenizer(e.signedBy,
 442                                                               ",", true);
 443                 int actr = 0;
 444                 int cctr = 0;
 445                 while (aliases.hasMoreTokens()) {
 446                     String alias = aliases.nextToken().trim();
 447                     if (alias.equals(","))
 448                         cctr++;
 449                     else if (alias.length() > 0)
 450                         actr++;
 451                 }
 452                 if (actr <= cctr)
 453                     throw new ParsingException(
 454                             st.lineno(),
 455                             LocalizedMessage.getNonlocalized
 456                                 ("SignedBy.has.empty.alias"));
 457 
 458                 peekAndMatch(",");
 459             } else if (peekAndMatch("Principal")) {
 460                 if (principals == null) {
 461                     principals = new LinkedList<>();
 462                 }
 463 
 464                 String principalClass;
 465                 String principalName;
 466 
 467                 if (peek("\"")) {
 468                     // both the principalClass and principalName
 469                     // will be replaced later




 374         if (peek("\"")) {
 375             keyStoreProvider = match("quoted string");
 376         } else {
 377             throw new ParsingException(st.lineno(),
 378                 LocalizedMessage.getNonlocalized("expected.keystore.provider"));
 379         }
 380     }
 381 
 382     private void parseStorePassURL() throws ParsingException, IOException {
 383         match("keyStorePasswordURL");
 384         storePassURL = match("quoted string");
 385     }
 386 
 387     /**
 388      * writes the (unexpanded) keystore entry
 389      */
 390     private void writeKeyStoreEntry(PrintWriter out) {
 391         out.print("keystore \"");
 392         out.print(keyStoreUrlString);
 393         out.print('"');
 394         if (keyStoreType != null && !keyStoreType.isEmpty())
 395             out.print(", \"" + keyStoreType + "\"");
 396         if (keyStoreProvider != null && !keyStoreProvider.isEmpty())
 397             out.print(", \"" + keyStoreProvider + "\"");
 398         out.println(";");
 399         out.println();
 400     }
 401 
 402     private void writeStorePassURL(PrintWriter out) {
 403         out.print("keystorePasswordURL \"");
 404         out.print(storePassURL);
 405         out.print('"');
 406         out.println(";");
 407         out.println();
 408     }
 409 
 410     /**
 411      * parse a Grant entry
 412      */
 413     private GrantEntry parseGrantEntry()
 414         throws ParsingException, IOException
 415     {
 416         GrantEntry e = new GrantEntry();


 429                                 ("multiple.Codebase.expressions"));
 430                 e.codeBase = match("quoted string");
 431                 peekAndMatch(",");
 432             } else if (peekAndMatch("SignedBy")) {
 433                 if (e.signedBy != null)
 434                     throw new ParsingException(
 435                             st.lineno(),
 436                             LocalizedMessage.getNonlocalized
 437                                 ("multiple.SignedBy.expressions"));
 438                 e.signedBy = match("quoted string");
 439 
 440                 // verify syntax of the aliases
 441                 StringTokenizer aliases = new StringTokenizer(e.signedBy,
 442                                                               ",", true);
 443                 int actr = 0;
 444                 int cctr = 0;
 445                 while (aliases.hasMoreTokens()) {
 446                     String alias = aliases.nextToken().trim();
 447                     if (alias.equals(","))
 448                         cctr++;
 449                     else if (!alias.isEmpty())
 450                         actr++;
 451                 }
 452                 if (actr <= cctr)
 453                     throw new ParsingException(
 454                             st.lineno(),
 455                             LocalizedMessage.getNonlocalized
 456                                 ("SignedBy.has.empty.alias"));
 457 
 458                 peekAndMatch(",");
 459             } else if (peekAndMatch("Principal")) {
 460                 if (principals == null) {
 461                     principals = new LinkedList<>();
 462                 }
 463 
 464                 String principalClass;
 465                 String principalName;
 466 
 467                 if (peek("\"")) {
 468                     // both the principalClass and principalName
 469                     // will be replaced later


< prev index next >