LEFT | RIGHT |
1 // Copyright (C) 2006 Google Inc. | 1 // Copyright (C) 2006 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 * {@code font: "Times New Roman"} to avoid any possible ambiguity between | 112 * {@code font: "Times New Roman"} to avoid any possible ambiguity between |
113 * the individual terms and special values such as {@code serif}. | 113 * the individual terms and special values such as {@code serif}. |
114 * | 114 * |
115 * @see CssPropertyPartType#LOOSE_WORD | 115 * @see CssPropertyPartType#LOOSE_WORD |
116 */ | 116 */ |
117 private void quoteLooseWords(AncestorChain<? extends CssTree> t) { | 117 private void quoteLooseWords(AncestorChain<? extends CssTree> t) { |
118 if (t.node instanceof CssTree.Expr) { | 118 if (t.node instanceof CssTree.Expr) { |
119 combineLooseWords(t.cast(CssTree.Expr.class).node); | 119 combineLooseWords(t.cast(CssTree.Expr.class).node); |
120 } | 120 } |
121 for (CssTree child : t.node.children()) { | 121 for (CssTree child : t.node.children()) { |
122 quoteLooseWords(new AncestorChain<CssTree>(t, child)); | 122 quoteLooseWords(AncestorChain.instance(t, child)); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 private void combineLooseWords(CssTree.Expr e) { | 126 private void combineLooseWords(CssTree.Expr e) { |
127 for (int i = 0, n = e.getNTerms(); i < n; ++i) { | 127 for (int i = 0, n = e.getNTerms(); i < n; ++i) { |
128 CssTree.Term t = e.getNthTerm(i); | 128 CssTree.Term t = e.getNthTerm(i); |
129 if (!isLooseWord(t)) { continue; } | 129 if (!isLooseWord(t)) { continue; } |
130 | 130 |
131 Name propertyPart = t.getAttributes().get(CssValidator.CSS_PROPERTY_PART); | 131 Name propertyPart = t.getAttributes().get(CssValidator.CSS_PROPERTY_PART); |
132 StringBuilder sb = new StringBuilder(); | 132 StringBuilder sb = new StringBuilder(); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 CssTree term = (CssTree.Term) node; | 434 CssTree term = (CssTree.Term) node; |
435 CssTree.CssLiteral content = | 435 CssTree.CssLiteral content = |
436 (CssTree.CssLiteral) term.children().get(0); | 436 (CssTree.CssLiteral) term.children().get(0); |
437 | 437 |
438 if (content instanceof CssTree.Substitution) { | 438 if (content instanceof CssTree.Substitution) { |
439 return true; // Handled by later pass. | 439 return true; // Handled by later pass. |
440 } | 440 } |
441 | 441 |
442 String uriStr = content.getValue(); | 442 String uriStr = content.getValue(); |
443 try { | 443 try { |
444 URI uri = new URI(uriStr); | 444 URI baseUri = content.getFilePosition().source().getUri(); |
445 ExternalReference ref | 445 URI uri = baseUri.resolve(new URI(uriStr)); |
446 = new ExternalReference(uri, content.getFilePosition()); | 446 ExternalReference ref = new ExternalReference( |
447 // the same url check as GxpCompiler | 447 uri, content.getFilePosition()); |
448 if (meta.getPluginEnvironment().rewriteUri(ref, "image/*") | 448 if (meta.getPluginEnvironment().rewriteUri(ref, "image/*") |
449 == null) { | 449 == null) { |
450 removeMsg = new Message( | 450 removeMsg = new Message( |
451 PluginMessageType.DISALLOWED_URI, | 451 PluginMessageType.DISALLOWED_URI, |
452 node.getFilePosition(), | 452 node.getFilePosition(), |
453 MessagePart.Factory.valueOf(uriStr)); | 453 MessagePart.Factory.valueOf(uriStr)); |
454 remove = true; | 454 remove = true; |
455 } | 455 } |
456 } catch (URISyntaxException ex) { | 456 } catch (URISyntaxException ex) { |
457 removeMsg = new Message( | 457 removeMsg = new Message( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 CssTree term = (CssTree.Term) node; | 527 CssTree term = (CssTree.Term) node; |
528 | 528 |
529 CssTree.CssLiteral content = | 529 CssTree.CssLiteral content = |
530 (CssTree.CssLiteral) term.children().get(0); | 530 (CssTree.CssLiteral) term.children().get(0); |
531 if (content instanceof CssTree.Substitution) { | 531 if (content instanceof CssTree.Substitution) { |
532 return true; // Handled by later pass. | 532 return true; // Handled by later pass. |
533 } | 533 } |
534 | 534 |
535 String uriStr = content.getValue(); | 535 String uriStr = content.getValue(); |
536 try { | 536 try { |
537 URI uri = new URI(uriStr); | 537 URI baseUri = content.getFilePosition().source().getUri(); |
| 538 URI uri = baseUri.resolve(new URI(uriStr)); |
538 // Rewrite the URI. | 539 // Rewrite the URI. |
539 // TODO(mikesamuel): for content: and other uri types, use | 540 // TODO(mikesamuel): for content: and other URI types, use |
540 // mime-type of text/*. | 541 // mime-type of text/*. |
541 ExternalReference ref | 542 ExternalReference ref = new ExternalReference( |
542 = new ExternalReference(uri, content.getFilePosition()); | 543 uri, content.getFilePosition()); |
543 String rewrittenUri = meta.getPluginEnvironment().rewriteUri( | 544 String rewrittenUri = meta.getPluginEnvironment().rewriteUri( |
544 ref, "image/*"); | 545 ref, "image/*"); |
545 CssTree.UriLiteral replacement = new CssTree.UriLiteral( | 546 CssTree.UriLiteral replacement = new CssTree.UriLiteral( |
546 content.getFilePosition(), URI.create(rewrittenUri)); | 547 content.getFilePosition(), URI.create(rewrittenUri)); |
547 replacement.getAttributes().putAll(content.getAttributes()); | 548 replacement.getAttributes().putAll(content.getAttributes()); |
548 term.replaceChild(replacement, content); | 549 term.replaceChild(replacement, content); |
549 } catch (URISyntaxException ex) { | 550 } catch (URISyntaxException ex) { |
550 // Should've been checked in removeUnsafeConstructs. | 551 // Should've been checked in removeUnsafeConstructs. |
551 throw new AssertionError(); | 552 throw new AssertionError(); |
552 } | 553 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 * of escape sequences. | 656 * of escape sequences. |
656 */ | 657 */ |
657 private static boolean isSafeSelectorPart(String s) { | 658 private static boolean isSafeSelectorPart(String s) { |
658 return SAFE_SELECTOR_PART.matcher(s).matches(); | 659 return SAFE_SELECTOR_PART.matcher(s).matches(); |
659 } | 660 } |
660 | 661 |
661 private static CssPropertyPartType propertyPartType(ParseTreeNode node) { | 662 private static CssPropertyPartType propertyPartType(ParseTreeNode node) { |
662 return node.getAttributes().get(CssValidator.CSS_PROPERTY_PART_TYPE); | 663 return node.getAttributes().get(CssValidator.CSS_PROPERTY_PART_TYPE); |
663 } | 664 } |
664 } | 665 } |
LEFT | RIGHT |