Source Code Cross Referenced for HTMLDocument_Reader_ActionsTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.text.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:        /**
0018:         * @author Alexander T. Simbirtsev
0019:         * @version $Revision$
0020:         */package javax.swing.text.html;
0021:
0022:        import java.io.StringReader;
0023:        import java.net.URL;
0024:        import java.util.ArrayList;
0025:
0026:        import javax.swing.text.AttributeSet;
0027:        import javax.swing.text.Element;
0028:        import javax.swing.text.MutableAttributeSet;
0029:        import javax.swing.text.SimpleAttributeSet;
0030:        import javax.swing.text.Style;
0031:        import javax.swing.text.StyleConstants;
0032:        import javax.swing.text.DefaultStyledDocument.ElementSpec;
0033:        import javax.swing.text.html.HTML.Tag;
0034:        import javax.swing.text.html.HTMLDocument.HTMLReader;
0035:        import javax.swing.text.html.HTMLEditorKit.ParserCallback;
0036:
0037:        public class HTMLDocument_Reader_ActionsTest extends
0038:                HTMLDocumentTestCase {
0039:
0040:            protected HTMLDocument.HTMLReader reader;
0041:            protected HTMLDocument doc;
0042:            protected HTMLDocument.HTMLReader.TagAction action;
0043:
0044:            protected void setUp() throws Exception {
0045:                super .setUp();
0046:                doc = new HTMLDocument();
0047:                reader = (HTMLDocument.HTMLReader) doc.getReader(0);
0048:            }
0049:
0050:            protected void tearDown() throws Exception {
0051:                action = null;
0052:                doc = null;
0053:                reader = null;
0054:                super .tearDown();
0055:            }
0056:
0057:            public void testHandleSimpleTag_Unknown() {
0058:                SimpleAttributeSet attr = new SimpleAttributeSet();
0059:                attr.addAttribute("aaaa", "bbbb");
0060:
0061:                doc.setPreservesUnknownTags(true);
0062:                reader.handleStartTag(Tag.HTML, attr, 0);
0063:                reader.handleStartTag(Tag.BODY, attr, 0);
0064:                reader.handleStartTag(Tag.P, attr, 0);
0065:                assertEquals(3, reader.parseBuffer.size());
0066:                reader.handleSimpleTag(new Tag("fake"), attr, 0);
0067:                assertEquals(4, reader.parseBuffer.size());
0068:            }
0069:
0070:            public void testBlockStart() {
0071:                SimpleAttributeSet attr = new SimpleAttributeSet();
0072:                attr.addAttribute("aaaa", "bbbb");
0073:                action = reader.new BlockAction();
0074:
0075:                action.start(Tag.B, attr);
0076:                assertEquals(0, reader.charAttr.getAttributeCount());
0077:                assertEquals(1, reader.parseBuffer.size());
0078:                final ElementSpec spec = (ElementSpec) reader.parseBuffer
0079:                        .get(0);
0080:                final AttributeSet specAttr = spec.getAttributes();
0081:                assertEquals(2, specAttr.getAttributeCount());
0082:                checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.B);
0083:                checkAttributes(specAttr, "aaaa", "bbbb");
0084:                assertSpec(spec, ElementSpec.StartTagType,
0085:                        ElementSpec.OriginateDirection, 0, null);
0086:            }
0087:
0088:            public void testBlockEnd() {
0089:                SimpleAttributeSet attr = new SimpleAttributeSet();
0090:                attr.addAttribute("aaaa", "bbbb");
0091:                action = reader.new BlockAction();
0092:
0093:                action.end(Tag.B);
0094:                assertEquals(0, reader.charAttr.getAttributeCount());
0095:                assertEquals(1, reader.parseBuffer.size());
0096:                final ElementSpec spec = (ElementSpec) reader.parseBuffer
0097:                        .get(0);
0098:                checkEndTagSpec(spec);
0099:            }
0100:
0101:            public void testCharacterStart() {
0102:                SimpleAttributeSet attr = new SimpleAttributeSet();
0103:                attr.addAttribute("aaaa", "bbbb");
0104:                action = reader.new CharacterAction();
0105:
0106:                reader.charAttr.addAttribute("bbbb", "aaaa");
0107:                action.start(Tag.B, attr);
0108:                assertEquals(0, reader.parseBuffer.size());
0109:                assertEquals(2, reader.charAttr.getAttributeCount());
0110:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0111:                checkAttributes(reader.charAttr, Tag.B, attr);
0112:                reader.popCharacterStyle();
0113:                assertEquals(1, reader.charAttr.getAttributeCount());
0114:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0115:
0116:                assertNotSame(reader.charAttr.getAttribute(Tag.B), attr);
0117:            }
0118:
0119:            public void testFontStart() {
0120:                SimpleAttributeSet attr = new SimpleAttributeSet();
0121:                attr.addAttribute(HTML.Attribute.COLOR, "black");
0122:                attr.addAttribute(HTML.Attribute.SIZE, isHarmony() ? "1pt"
0123:                        : "1");
0124:                attr.addAttribute(HTML.Attribute.FACE, "1111");
0125:                attr.addAttribute("aaaa", "bbbb");
0126:
0127:                reader.charAttr.addAttribute("bbbb", "aaaa");
0128:                reader.handleStartTag(Tag.HTML, new SimpleAttributeSet(), 0);
0129:                reader.handleStartTag(Tag.BODY, new SimpleAttributeSet(), 0);
0130:                reader.handleStartTag(Tag.FONT, attr, 0);
0131:                assertEquals(5, reader.charAttr.getAttributeCount());
0132:                assertNotNull(reader.charAttr.getAttribute("bbbb"));
0133:                assertNotNull(reader.charAttr.getAttribute(Tag.FONT));
0134:                assertNotNull(reader.charAttr.getAttribute(CSS.Attribute.COLOR));
0135:                assertNotNull(reader.charAttr
0136:                        .getAttribute(CSS.Attribute.FONT_FAMILY));
0137:                assertNotNull(reader.charAttr
0138:                        .getAttribute(CSS.Attribute.FONT_SIZE));
0139:            }
0140:
0141:            public void testCharacterStart_vs_HandleStart() {
0142:                SimpleAttributeSet attr = new SimpleAttributeSet();
0143:                attr.addAttribute("aaaa", "bbbb");
0144:                action = reader.new CharacterAction();
0145:
0146:                reader.charAttr.addAttribute("bbbb", "aaaa");
0147:                reader.handleStartTag(Tag.B, attr, 0);
0148:                assertEquals(0, reader.parseBuffer.size());
0149:                assertEquals(3, reader.charAttr.getAttributeCount());
0150:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0151:                checkAttributes(reader.charAttr, Tag.B, attr);
0152:                checkAttributes(reader.charAttr, CSS.Attribute.FONT_WEIGHT,
0153:                        "bold");
0154:                reader.popCharacterStyle();
0155:                assertEquals(1, reader.charAttr.getAttributeCount());
0156:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0157:            }
0158:
0159:            public void testCharacterEnd() {
0160:                SimpleAttributeSet attr = new SimpleAttributeSet();
0161:                attr.addAttribute("aaaa", "bbbb");
0162:                action = reader.new CharacterAction();
0163:
0164:                reader.charAttr.addAttribute("bbbb", "aaaa");
0165:                reader.pushCharacterStyle();
0166:                reader.charAttr = null;
0167:                action.end(Tag.B);
0168:                assertEquals(0, reader.parseBuffer.size());
0169:                assertEquals(1, reader.charAttr.getAttributeCount());
0170:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0171:            }
0172:
0173:            public void testParagraphStart() {
0174:                SimpleAttributeSet attr = new SimpleAttributeSet();
0175:                attr.addAttribute("aaaa", "bbbb");
0176:                action = reader.new ParagraphAction();
0177:
0178:                action.start(Tag.P, attr);
0179:                assertEquals(0, reader.charAttr.getAttributeCount());
0180:                assertEquals(1, reader.parseBuffer.size());
0181:                final ElementSpec spec = (ElementSpec) reader.parseBuffer
0182:                        .get(0);
0183:                final AttributeSet specAttr = spec.getAttributes();
0184:                assertEquals(2, specAttr.getAttributeCount());
0185:                checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.P);
0186:                checkAttributes(specAttr, "aaaa", "bbbb");
0187:                assertSpec(spec, ElementSpec.StartTagType,
0188:                        ElementSpec.OriginateDirection, 0, null);
0189:            }
0190:
0191:            public void testParagraphEnd() {
0192:                SimpleAttributeSet attr = new SimpleAttributeSet();
0193:                attr.addAttribute("aaaa", "bbbb");
0194:                action = reader.new ParagraphAction();
0195:
0196:                action.end(Tag.P);
0197:                assertEquals(0, reader.charAttr.getAttributeCount());
0198:                assertEquals(1, reader.parseBuffer.size());
0199:                final ElementSpec spec = (ElementSpec) reader.parseBuffer
0200:                        .get(0);
0201:                checkEndTagSpec(spec);
0202:            }
0203:
0204:            public void testSpecialStart() {
0205:                SimpleAttributeSet attr = new SimpleAttributeSet();
0206:                attr.addAttribute("aaaa", "bbbb");
0207:                action = reader.new SpecialAction();
0208:
0209:                action.start(Tag.IMG, attr);
0210:                assertEquals(0, reader.charAttr.getAttributeCount());
0211:                assertEquals(2, reader.parseBuffer.size());
0212:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0213:                AttributeSet specAttr;
0214:                checkOpenImpliedSpec(spec);
0215:                spec = (ElementSpec) reader.parseBuffer.get(1);
0216:                specAttr = spec.getAttributes();
0217:                assertEquals(2, specAttr.getAttributeCount());
0218:                checkAttributes(specAttr, StyleConstants.NameAttribute, "img");
0219:                checkAttributes(specAttr, "aaaa", "bbbb");
0220:                checkImplicitContentSpec(spec);
0221:
0222:                assertEquals(2, attr.getAttributeCount());
0223:                checkAttributes(attr, StyleConstants.NameAttribute, "img");
0224:                checkAttributes(attr, "aaaa", "bbbb");
0225:            }
0226:
0227:            public void testAnchorStart() {
0228:                SimpleAttributeSet attr = new SimpleAttributeSet();
0229:                // If href attribute is absent, after 4606 handleStartTag(Tag.A) does
0230:                // nothing
0231:                reader.handleStartTag(Tag.A, attr, 0);
0232:                assertEquals(0, reader.charAttr.getAttributeCount());
0233:                // After addition the href attribute, Tag.A works as before
0234:                reader.charAttr.addAttribute("bbbb", "aaaa");
0235:                attr.addAttribute(HTML.Attribute.HREF, "");
0236:                reader.handleStartTag(Tag.A, attr, 0);
0237:                assertEquals(0, reader.parseBuffer.size());
0238:                assertEquals(2, reader.charAttr.getAttributeCount());
0239:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0240:                checkAttributes(reader.charAttr, Tag.A, attr);
0241:                reader.popCharacterStyle();
0242:                assertEquals(1, reader.charAttr.getAttributeCount());
0243:                checkAttributes(reader.charAttr, "bbbb", "aaaa");
0244:
0245:                assertNotSame(reader.charAttr.getAttribute(Tag.B), attr);
0246:            }
0247:
0248:            public void testAnchorEnd() {
0249:                SimpleAttributeSet attr = new SimpleAttributeSet();
0250:                attr.addAttribute("aaaa", "bbbb");
0251:
0252:                reader.handleEndTag(Tag.A, 0);
0253:                assertEquals(0, reader.charAttr.getAttributeCount());
0254:                assertEquals(0, reader.parseBuffer.size());
0255:            }
0256:
0257:            public void testAnchorStartEnd() {
0258:                SimpleAttributeSet attr = new SimpleAttributeSet();
0259:                // If href attribute is absent, after 4606 handleStartTag(Tag.A) does
0260:                // nothing. After addition the href attribute, Tag.A works as before
0261:                attr.addAttribute(HTML.Attribute.HREF, "");
0262:                final Tag tag = Tag.A;
0263:                reader.handleStartTag(tag, attr, 0);
0264:                assertEquals(1, reader.charAttr.getAttributeCount());
0265:                assertEquals(0, reader.parseBuffer.size());
0266:                reader.handleEndTag(tag, 0);
0267:                assertEquals(0, reader.charAttr.getAttributeCount());
0268:                // The rest part of the test is deleted because according to H-4574
0269:                // there is no underscore added if no text encountered. all the
0270:                // verification in that part occurs in the testAnchorStartTextEnd        
0271:            }
0272:
0273:            public void testAnchorStartTextEnd() {
0274:                SimpleAttributeSet attr = new SimpleAttributeSet();
0275:                attr.addAttribute("aaaa", "bbbb");
0276:                attr.addAttribute(HTML.Attribute.HREF, "file:///index.html");
0277:                final Tag tag = Tag.A;
0278:                reader.handleStartTag(Tag.BODY, attr, 0);
0279:                reader.handleStartTag(tag, attr, 0);
0280:                assertEquals(1, reader.charAttr.getAttributeCount());
0281:                assertEquals(1, reader.parseBuffer.size());
0282:                reader.handleText("text".toCharArray(), 0);
0283:                assertEquals(2, reader.charAttr.getAttributeCount());
0284:                assertEquals(3, reader.parseBuffer.size());
0285:                reader.handleEndTag(tag, 0);
0286:                assertEquals(0, reader.charAttr.getAttributeCount());
0287:                assertEquals(3, reader.parseBuffer.size());
0288:            }
0289:
0290:            public void testSpecialStart_AfterSpecialStart() {
0291:                SimpleAttributeSet attr = new SimpleAttributeSet();
0292:                attr.addAttribute("aaaa", "bbbb");
0293:                reader = (HTMLReader) doc.getReader(0, 0, 0, Tag.I);
0294:                reader.new SpecialAction().start(Tag.I,
0295:                        new SimpleAttributeSet());
0296:                assertEquals(1, reader.parseBuffer.size());
0297:
0298:                reader.new SpecialAction().start(Tag.IMG, attr);
0299:                assertEquals(2, reader.parseBuffer.size());
0300:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
0301:                checkAttributes(spec.getAttributes(),
0302:                        StyleConstants.NameAttribute, Tag.IMG);
0303:                checkImplicitContentSpec(spec);
0304:            }
0305:
0306:            public void testSpecialStart_AfterCharacterStart1() {
0307:                SimpleAttributeSet attr = new SimpleAttributeSet();
0308:                attr.addAttribute("aaaa", "bbbb");
0309:                reader = (HTMLReader) doc.getReader(0, 0, 0, Tag.I);
0310:                reader.new CharacterAction().start(Tag.I,
0311:                        new SimpleAttributeSet());
0312:                assertEquals(0, reader.parseBuffer.size());
0313:                assertEquals(1, reader.charAttr.getAttributeCount());
0314:
0315:                reader.new SpecialAction().start(Tag.IMG, attr);
0316:                assertEquals(1, reader.parseBuffer.size());
0317:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0318:                checkAttributes(spec.getAttributes(),
0319:                        StyleConstants.NameAttribute, Tag.IMG);
0320:                checkImplicitContentSpec(spec);
0321:            }
0322:
0323:            public void testSpecialStart_AfterCharacterStart2() {
0324:                SimpleAttributeSet attr = new SimpleAttributeSet();
0325:                attr.addAttribute("aaaa", "bbbb");
0326:                reader = (HTMLReader) doc.getReader(10, 10, 10, null);
0327:                reader.new CharacterAction().start(Tag.I,
0328:                        new SimpleAttributeSet());
0329:                assertEquals(0, reader.parseBuffer.size());
0330:                assertEquals(1, reader.charAttr.getAttributeCount());
0331:
0332:                reader.new SpecialAction().start(Tag.IMG, attr);
0333:                assertEquals(2, reader.parseBuffer.size());
0334:            }
0335:
0336:            public void testFormStart_AfterImplied() {
0337:                SimpleAttributeSet attr = new SimpleAttributeSet();
0338:                attr.addAttribute("aaaa", "bbbb");
0339:                action = reader.new FormAction();
0340:
0341:                reader.handleStartTag(Tag.BODY, new SimpleAttributeSet(), 0);
0342:                reader.handleText("text".toCharArray(), 0);
0343:                assertEquals(3, reader.parseBuffer.size());
0344:
0345:                reader.handleStartTag(Tag.FORM, attr, 0);
0346:                assertEquals(6, reader.parseBuffer.size());
0347:
0348:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(3);
0349:                checkCRSpec(spec);
0350:
0351:                spec = (ElementSpec) reader.parseBuffer.get(4);
0352:                checkEndTagSpec(spec);
0353:
0354:                spec = (ElementSpec) reader.parseBuffer.get(5);
0355:                AttributeSet specAttr = spec.getAttributes();
0356:                assertEquals(2, specAttr.getAttributeCount());
0357:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0358:                        Tag.FORM);
0359:                checkAttributes(specAttr, "aaaa", "bbbb");
0360:                assertSpec(spec, ElementSpec.StartTagType,
0361:                        ElementSpec.OriginateDirection, 0, null);
0362:
0363:                assertEquals(2, attr.getAttributeCount());
0364:                checkAttributes(attr, StyleConstants.NameAttribute, Tag.FORM);
0365:                checkAttributes(attr, "aaaa", "bbbb");
0366:            }
0367:
0368:            public void testSpecialEnd() {
0369:                SimpleAttributeSet attr = new SimpleAttributeSet();
0370:                attr.addAttribute("aaaa", "bbbb");
0371:                HTMLDocument.HTMLReader.TagAction action = reader.new SpecialAction();
0372:
0373:                action.end(Tag.IMG);
0374:                assertEquals(0, reader.charAttr.getAttributeCount());
0375:                assertEquals(0, reader.parseBuffer.size());
0376:            }
0377:
0378:            public void testSpecialStart_Calls() {
0379:                final Marker specialMarker = new Marker();
0380:                doc = new HTMLDocument() {
0381:                    public ParserCallback getReader(int pos) {
0382:                        return new HTMLReader(0) {
0383:                            protected void addSpecialElement(final Tag tag,
0384:                                    final MutableAttributeSet attr) {
0385:                                specialMarker.setOccurred();
0386:                                ArrayList callInfo = new ArrayList();
0387:                                callInfo.add(tag);
0388:                                callInfo.add(attr);
0389:                                specialMarker.setAuxiliary(callInfo);
0390:                            }
0391:                        };
0392:                    }
0393:                };
0394:                reader = (HTMLReader) doc.getReader(0);
0395:                String text = "precontent";
0396:                Tag tag = Tag.HTML;
0397:                SimpleAttributeSet attr = new SimpleAttributeSet();
0398:                attr.addAttribute("aaaa", "bbbb");
0399:                reader.addSpecialElement(tag, attr);
0400:                assertTrue(specialMarker.isOccurred());
0401:                ArrayList callInfo = (ArrayList) specialMarker.getAuxiliary();
0402:                assertEquals(tag, callInfo.get(0));
0403:                assertEquals(attr, callInfo.get(1));
0404:            }
0405:
0406:            public void testPreStart() {
0407:                SimpleAttributeSet attr = new SimpleAttributeSet();
0408:                attr.addAttribute("aaaa", "bbbb");
0409:                action = reader.new PreAction();
0410:
0411:                action.start(Tag.PRE, attr);
0412:                assertEquals(2, reader.parseBuffer.size());
0413:                assertEquals(0, reader.charAttr.getAttributeCount());
0414:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0415:                AttributeSet specAttr = spec.getAttributes();
0416:                assertEquals(2, specAttr.getAttributeCount());
0417:                checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.PRE);
0418:                checkAttributes(specAttr, "aaaa", "bbbb");
0419:                assertSpec(spec, ElementSpec.StartTagType,
0420:                        ElementSpec.OriginateDirection, 0, null);
0421:
0422:                spec = (ElementSpec) reader.parseBuffer.get(1);
0423:                specAttr = spec.getAttributes();
0424:                assertEquals(3, specAttr.getAttributeCount());
0425:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0426:                        Tag.IMPLIED);
0427:                checkAttributes(specAttr, CSS.Attribute.WHITE_SPACE, "pre");
0428:                checkAttributes(specAttr, "aaaa", "bbbb");
0429:                assertSpec(spec, ElementSpec.StartTagType,
0430:                        ElementSpec.OriginateDirection, 0, null);
0431:            }
0432:
0433:            public void testPreStart_InParagraph() {
0434:                SimpleAttributeSet attr = new SimpleAttributeSet();
0435:                attr.addAttribute("aaaa", "bbbb");
0436:                action = reader.new PreAction();
0437:
0438:                reader.handleStartTag(Tag.P, attr, 0);
0439:                assertEquals(1, reader.parseBuffer.size());
0440:                assertEquals(0, reader.charAttr.getAttributeCount());
0441:
0442:                action.start(Tag.PRE, attr);
0443:                assertEquals(3, reader.parseBuffer.size());
0444:                assertEquals(0, reader.charAttr.getAttributeCount());
0445:
0446:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
0447:                AttributeSet specAttr = spec.getAttributes();
0448:                assertEquals(2, specAttr.getAttributeCount());
0449:                checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.PRE);
0450:                checkAttributes(specAttr, "aaaa", "bbbb");
0451:                assertSpec(spec, ElementSpec.StartTagType,
0452:                        ElementSpec.OriginateDirection, 0, null);
0453:
0454:                spec = (ElementSpec) reader.parseBuffer.get(2);
0455:                specAttr = spec.getAttributes();
0456:                assertEquals(3, specAttr.getAttributeCount());
0457:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0458:                        Tag.IMPLIED);
0459:                checkAttributes(specAttr, CSS.Attribute.WHITE_SPACE, "pre");
0460:                checkAttributes(specAttr, "aaaa", "bbbb");
0461:                assertSpec(spec, ElementSpec.StartTagType,
0462:                        ElementSpec.OriginateDirection, 0, null);
0463:            }
0464:
0465:            public void testPreStartEnd_Specs() {
0466:                SimpleAttributeSet attr = new SimpleAttributeSet();
0467:                attr.addAttribute("aaaa", "bbbb");
0468:                action = reader.new PreAction();
0469:
0470:                action.start(Tag.PRE, attr);
0471:                assertEquals(2, reader.parseBuffer.size());
0472:                assertEquals(0, reader.charAttr.getAttributeCount());
0473:                action.end(Tag.PRE);
0474:                assertEquals(5, reader.parseBuffer.size());
0475:
0476:                checkCRSpec((ElementSpec) reader.parseBuffer.get(2));
0477:                checkEndTagSpec((ElementSpec) reader.parseBuffer.get(3));
0478:                checkEndTagSpec((ElementSpec) reader.parseBuffer.get(4));
0479:            }
0480:
0481:            public void testPreStartEnd_BlockCalls() {
0482:                final Marker blockOpen = new Marker();
0483:                final Marker blockClose = new Marker();
0484:                doc = new HTMLDocument() {
0485:                    public ParserCallback getReader(int pos) {
0486:                        return new HTMLReader(0) {
0487:                            protected void blockOpen(Tag tag,
0488:                                    MutableAttributeSet attr) {
0489:                                blockOpen.setOccurred();
0490:                                ArrayList callInfo = (blockOpen.getAuxiliary() == null) ? new ArrayList()
0491:                                        : (ArrayList) blockOpen.getAuxiliary();
0492:                                callInfo.add(tag);
0493:                                callInfo.add(attr.copyAttributes());
0494:                                blockOpen.setAuxiliary(callInfo);
0495:                                super .blockOpen(tag, attr);
0496:                            }
0497:
0498:                            protected void blockClose(Tag tag) {
0499:                                super .blockClose(tag);
0500:                                ArrayList callInfo = (blockClose.getAuxiliary() == null) ? new ArrayList()
0501:                                        : (ArrayList) blockClose.getAuxiliary();
0502:                                blockClose.setOccurred();
0503:                                callInfo.add(tag);
0504:                                blockClose.setAuxiliary(callInfo);
0505:                            }
0506:                        };
0507:                    }
0508:                };
0509:                reader = (HTMLReader) doc.getReader(0);
0510:                SimpleAttributeSet attr = new SimpleAttributeSet();
0511:                attr.addAttribute("aaaa", "bbbb");
0512:                SimpleAttributeSet initial = (SimpleAttributeSet) attr
0513:                        .copyAttributes();
0514:                action = reader.new PreAction();
0515:
0516:                action.start(Tag.PRE, attr);
0517:                assertTrue(blockOpen.isOccurred());
0518:                assertFalse(blockClose.isOccurred());
0519:                ArrayList callInfo = (ArrayList) blockOpen.getAuxiliary();
0520:                assertEquals(4, callInfo.size());
0521:                assertEquals(Tag.PRE, callInfo.get(0));
0522:                assertEquals(initial, callInfo.get(1));
0523:                assertEquals(Tag.IMPLIED, callInfo.get(2));
0524:                final AttributeSet attrs = (AttributeSet) callInfo.get(3);
0525:                checkAttributes(attrs, "aaaa", "bbbb");
0526:                checkAttributes(attrs, StyleConstants.NameAttribute, Tag.PRE);
0527:                checkAttributes(attrs, CSS.Attribute.WHITE_SPACE, "pre");
0528:                blockOpen.reset();
0529:
0530:                action.end(Tag.PRE);
0531:                assertFalse(blockOpen.isOccurred());
0532:                assertTrue(blockClose.isOccurred());
0533:                callInfo = (ArrayList) blockClose.getAuxiliary();
0534:                assertEquals(2, callInfo.size());
0535:                assertEquals(Tag.IMPLIED, callInfo.get(0));
0536:                assertEquals(Tag.PRE, callInfo.get(1));
0537:            }
0538:
0539:            public void testPreStartEnd_PreContentCalls() {
0540:                final Marker preContentMarker = new Marker();
0541:                doc = new HTMLDocument() {
0542:                    public ParserCallback getReader(int pos) {
0543:                        return new HTMLReader(0) {
0544:                            protected void preContent(char[] data) {
0545:                                preContentMarker.setOccurred();
0546:                                preContentMarker.setAuxiliary(data);
0547:                                super .preContent(data);
0548:                            }
0549:                        };
0550:                    }
0551:                };
0552:                reader = (HTMLReader) doc.getReader(0);
0553:                SimpleAttributeSet attr = new SimpleAttributeSet();
0554:                attr.addAttribute("aaaa", "bbbb");
0555:                action = reader.new PreAction();
0556:
0557:                action.start(Tag.PRE, attr);
0558:                String text = "data";
0559:                assertFalse(preContentMarker.isOccurred());
0560:                reader.handleText(text.toCharArray(), 0);
0561:                assertTrue(preContentMarker.isOccurred());
0562:                assertEquals(text, new String((char[]) preContentMarker
0563:                        .getAuxiliary()));
0564:                action.end(Tag.PRE);
0565:                preContentMarker.reset();
0566:                reader.handleText(text.toCharArray(), 0);
0567:                assertFalse(preContentMarker.isOccurred());
0568:            }
0569:
0570:            public void testPre_ContentWhitespaces1() {
0571:                SimpleAttributeSet attr = new SimpleAttributeSet();
0572:                attr.addAttribute("aaaa", "bbbb");
0573:                action = reader.new PreAction();
0574:
0575:                action.start(Tag.PRE, attr);
0576:                String text = "data       \t \r \f  data";
0577:                assertEquals(2, reader.parseBuffer.size());
0578:                reader.handleText(text.toCharArray(), 0);
0579:
0580:                assertEquals(7, reader.parseBuffer.size());
0581:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(6);
0582:                assertEquals(text.length(), spec.getArray().length);
0583:            }
0584:
0585:            public void testPre_ContentWhitespaces2() {
0586:                SimpleAttributeSet attr = new SimpleAttributeSet();
0587:                attr.addAttribute("aaaa", "bbbb");
0588:                action = reader.new PreAction();
0589:
0590:                action.start(Tag.PRE, attr);
0591:                String text = "data       \t \r \f  data";
0592:                assertEquals(2, reader.parseBuffer.size());
0593:                reader.preContent(text.toCharArray());
0594:
0595:                assertEquals(7, reader.parseBuffer.size());
0596:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(6);
0597:                assertEquals(text.length(), spec.getArray().length);
0598:            }
0599:
0600:            public void testHarmony_4582() throws Exception {
0601:                final Element pre;
0602:                final HTMLDocument doc = new HTMLDocument();
0603:
0604:                new HTMLEditorKit().read(new StringReader(
0605:                        "<html><body><pre>line1\n" //$NON-NLS-1$
0606:                                + "line2</pre></body></html>"), doc, 0); //$NON-NLS-1$
0607:
0608:                assertEquals("line1", doc.getText(1, 5)); //$NON-NLS-1$
0609:                assertEquals("line2", doc.getText(7, 5)); //$NON-NLS-1$
0610:
0611:                pre = doc.getRootElements()[0].getElement(1).getElement(0);
0612:                assertEquals(1, pre.getElement(0).getStartOffset());
0613:                assertEquals(7, pre.getElement(0).getEndOffset());
0614:                assertEquals(7, pre.getElement(1).getStartOffset());
0615:                assertEquals(13, pre.getElement(1).getEndOffset());
0616:            }
0617:
0618:            public void testHarmony_4615() throws Exception {
0619:                final HTMLDocument doc = new HTMLDocument();
0620:
0621:                new HTMLEditorKit()
0622:                        .read(
0623:                                new StringReader(
0624:                                        "<html><body><pre>line1\n" //$NON-NLS-1$
0625:                                                + "<font color='red'>line2 \n line3</font>" //$NON-NLS-1$
0626:                                                + "line3</pre>line4 \n line4</body></html>"), doc, 0); //$NON-NLS-1$
0627:
0628:                assertEquals("line1\n", doc.getText(1, 6)); //$NON-NLS-1$
0629:                assertEquals("line2 \n line3", doc.getText(7, 13)); //$NON-NLS-1$
0630:                assertEquals("line3", doc.getText(20, 5)); //$NON-NLS-1$
0631:                assertEquals("line4 line4", doc.getText(26, 11)); //$NON-NLS-1$
0632:            }
0633:
0634:            public void testTag_ContentWhitespaces() {
0635:                SimpleAttributeSet attr = new SimpleAttributeSet();
0636:                attr.addAttribute("aaaa", "bbbb");
0637:                action = reader.new PreAction();
0638:
0639:                action.start(Tag.P, attr);
0640:                String text = "data       \t \r \f  data";
0641:                assertEquals(2, reader.parseBuffer.size());
0642:                reader.handleText(text.toCharArray(), 0);
0643:
0644:                assertEquals(3, reader.parseBuffer.size());
0645:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(2);
0646:                assertEquals(text.length(), spec.getLength());
0647:                assertEquals(text.length(), spec.getArray().length);
0648:            }
0649:
0650:            public void testPreEnd() {
0651:                SimpleAttributeSet attr = new SimpleAttributeSet();
0652:                attr.addAttribute("aaaa", "bbbb");
0653:                HTMLDocument.HTMLReader.TagAction action = reader.new PreAction();
0654:
0655:                action.end(Tag.PRE);
0656:                assertEquals(0, reader.charAttr.getAttributeCount());
0657:                assertEquals(2, reader.parseBuffer.size());
0658:
0659:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0660:                checkEndTagSpec(spec);
0661:
0662:                spec = (ElementSpec) reader.parseBuffer.get(1);
0663:                checkEndTagSpec(spec);
0664:            }
0665:
0666:            public void testIsindexStart() {
0667:                SimpleAttributeSet attr = new SimpleAttributeSet();
0668:                attr.addAttribute("aaaa", "bbbb");
0669:                final String prompt = "text";
0670:                attr.addAttribute(HTML.Attribute.PROMPT, prompt);
0671:                action = reader.new IsindexAction();
0672:
0673:                action.start(Tag.ISINDEX, attr);
0674:                assertEquals(0, reader.charAttr.getAttributeCount());
0675:                assertEquals(5, reader.parseBuffer.size());
0676:
0677:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0678:                checkOpenImpliedSpec(spec);
0679:
0680:                spec = (ElementSpec) reader.parseBuffer.get(1);
0681:                checkOpenImpliedSpec(spec);
0682:
0683:                spec = (ElementSpec) reader.parseBuffer.get(2);
0684:                AttributeSet specAttr = spec.getAttributes();
0685:                assertEquals(3, specAttr.getAttributeCount());
0686:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0687:                        Tag.ISINDEX);
0688:                checkAttributes(specAttr, "aaaa", "bbbb");
0689:                checkAttributes(specAttr, HTML.Attribute.PROMPT, prompt);
0690:                checkImplicitContentSpec(spec);
0691:                assertNotSame(specAttr, attr);
0692:
0693:                spec = (ElementSpec) reader.parseBuffer.get(3);
0694:                checkCRSpec(spec);
0695:
0696:                spec = (ElementSpec) reader.parseBuffer.get(4);
0697:                checkEndTagSpec(spec);
0698:            }
0699:
0700:            public void testIsindexStart_InParagraph() {
0701:                SimpleAttributeSet attr = new SimpleAttributeSet();
0702:                attr.addAttribute("aaaa", "bbbb");
0703:                final String prompt = "text";
0704:                attr.addAttribute(HTML.Attribute.PROMPT, prompt);
0705:                action = reader.new IsindexAction();
0706:
0707:                reader.handleStartTag(Tag.P, new SimpleAttributeSet(), 0);
0708:                assertEquals(1, reader.parseBuffer.size());
0709:
0710:                action.start(Tag.ISINDEX, attr);
0711:                assertEquals(0, reader.charAttr.getAttributeCount());
0712:                assertEquals(5, reader.parseBuffer.size());
0713:
0714:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0715:                AttributeSet specAttr = spec.getAttributes();
0716:                assertEquals(1, specAttr.getAttributeCount());
0717:                checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.P);
0718:                assertSpec(spec, ElementSpec.StartTagType,
0719:                        ElementSpec.OriginateDirection, 0, null);
0720:
0721:                spec = (ElementSpec) reader.parseBuffer.get(1);
0722:                checkOpenImpliedSpec(spec);
0723:
0724:                spec = (ElementSpec) reader.parseBuffer.get(2);
0725:                specAttr = spec.getAttributes();
0726:                assertEquals(3, specAttr.getAttributeCount());
0727:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0728:                        Tag.ISINDEX);
0729:                checkAttributes(specAttr, "aaaa", "bbbb");
0730:                checkAttributes(specAttr, HTML.Attribute.PROMPT, prompt);
0731:                checkImplicitContentSpec(spec);
0732:
0733:                spec = (ElementSpec) reader.parseBuffer.get(3);
0734:                checkCRSpec(spec);
0735:
0736:                spec = (ElementSpec) reader.parseBuffer.get(4);
0737:                checkEndTagSpec(spec);
0738:
0739:                reader.blockClose(Tag.IMPLIED);
0740:                int numSpecs = reader.parseBuffer.size();
0741:                reader.handleText("text".toCharArray(), 0);
0742:                assertEquals(numSpecs, reader.parseBuffer.size());
0743:            }
0744:
0745:            public void testIsindex_Calls() {
0746:                final Marker blockOpenMarker = new Marker();
0747:                final Marker blockCloseMarker = new Marker();
0748:                final Marker contentMarker = new Marker();
0749:                doc = new HTMLDocument() {
0750:                    public ParserCallback getReader(int pos) {
0751:                        return new HTMLReader(0) {
0752:                            protected void blockOpen(Tag tag,
0753:                                    MutableAttributeSet attr) {
0754:                                blockOpenMarker.setOccurred();
0755:                                ArrayList callInfo = (blockOpenMarker
0756:                                        .getAuxiliary() == null) ? new ArrayList()
0757:                                        : (ArrayList) blockOpenMarker
0758:                                                .getAuxiliary();
0759:                                callInfo.add(tag);
0760:                                callInfo.add(attr.copyAttributes());
0761:                                blockOpenMarker.setAuxiliary(callInfo);
0762:                                super .blockOpen(tag, attr);
0763:                            }
0764:
0765:                            protected void blockClose(Tag tag) {
0766:                                super .blockClose(tag);
0767:                                ArrayList callInfo = (blockCloseMarker
0768:                                        .getAuxiliary() == null) ? new ArrayList()
0769:                                        : (ArrayList) blockCloseMarker
0770:                                                .getAuxiliary();
0771:                                blockCloseMarker.setOccurred();
0772:                                callInfo.add(tag);
0773:                                blockCloseMarker.setAuxiliary(callInfo);
0774:                            }
0775:
0776:                            protected void addContent(char[] data, int offs,
0777:                                    int length,
0778:                                    boolean generateImpliedPIfNecessary) {
0779:                                ArrayList callInfo = (contentMarker
0780:                                        .getAuxiliary() == null) ? new ArrayList()
0781:                                        : (ArrayList) contentMarker
0782:                                                .getAuxiliary();
0783:                                contentMarker.setOccurred();
0784:                                callInfo.add(data);
0785:                                callInfo.add(new Integer(offs));
0786:                                callInfo.add(new Integer(length));
0787:                                callInfo.add(Boolean
0788:                                        .valueOf(generateImpliedPIfNecessary));
0789:                                contentMarker.setAuxiliary(callInfo);
0790:                                super .addContent(data, offs, length,
0791:                                        generateImpliedPIfNecessary);
0792:                            }
0793:                        };
0794:                    }
0795:                };
0796:                reader = (HTMLReader) doc.getReader(0);
0797:                SimpleAttributeSet attr = new SimpleAttributeSet();
0798:                attr.addAttribute("aaaa", "bbbb");
0799:                action = reader.new IsindexAction();
0800:
0801:                action.start(Tag.ISINDEX, attr);
0802:                assertTrue(blockOpenMarker.isOccurred());
0803:
0804:                SimpleAttributeSet a = new SimpleAttributeSet();
0805:                ArrayList callInfo = (ArrayList) blockOpenMarker.getAuxiliary();
0806:                assertEquals(2, callInfo.size() / 2);
0807:                assertEquals(Tag.IMPLIED, callInfo.get(0));
0808:                assertEquals(a, callInfo.get(1));
0809:                assertEquals(Tag.IMPLIED, callInfo.get(2));
0810:                assertEquals(a, callInfo.get(3));
0811:
0812:                assertTrue(blockCloseMarker.isOccurred());
0813:                callInfo = (ArrayList) blockCloseMarker.getAuxiliary();
0814:                assertEquals(1, callInfo.size());
0815:                assertEquals(Tag.IMPLIED, callInfo.get(0));
0816:
0817:                assertTrue(contentMarker.isOccurred());
0818:                callInfo = (ArrayList) contentMarker.getAuxiliary();
0819:                assertEquals(4, callInfo.size());
0820:                final char[] data = (char[]) callInfo.get(0);
0821:                assertEquals(1, data.length);
0822:                assertEquals('\n', data[0]);
0823:                assertEquals(new Integer(0), callInfo.get(1));
0824:                assertEquals(new Integer(1), callInfo.get(2));
0825:                assertEquals(Boolean.TRUE, callInfo.get(3));
0826:
0827:            }
0828:
0829:            public void testHiddenStart() {
0830:                SimpleAttributeSet attr = new SimpleAttributeSet();
0831:                attr.addAttribute("aaaa", "bbbb");
0832:                action = reader.new HiddenAction();
0833:
0834:                action.start(Tag.SCRIPT, attr);
0835:                assertEquals(2, reader.parseBuffer.size());
0836:                assertEquals(0, reader.charAttr.getAttributeCount());
0837:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
0838:                AttributeSet specAttr;
0839:                checkOpenImpliedSpec(spec);
0840:
0841:                spec = (ElementSpec) reader.parseBuffer.get(1);
0842:                specAttr = spec.getAttributes();
0843:                assertEquals(2, specAttr.getAttributeCount());
0844:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0845:                        Tag.SCRIPT);
0846:                checkAttributes(specAttr, "aaaa", "bbbb");
0847:                checkImplicitContentSpec(spec);
0848:
0849:                assertNotSame(specAttr, attr);
0850:            }
0851:
0852:            public void testHiddenEnd() {
0853:                SimpleAttributeSet attr = new SimpleAttributeSet();
0854:                attr.addAttribute("aaaa", "bbbb");
0855:                action = reader.new HiddenAction();
0856:
0857:                action.start(Tag.SCRIPT, attr);
0858:                assertEquals(0, reader.charAttr.getAttributeCount());
0859:                assertEquals(2, reader.parseBuffer.size());
0860:                action.end(Tag.SCRIPT);
0861:                assertEquals(0, reader.charAttr.getAttributeCount());
0862:                assertEquals(3, reader.parseBuffer.size());
0863:
0864:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(2);
0865:                AttributeSet specAttr = spec.getAttributes();
0866:                assertEquals(2, specAttr.getAttributeCount());
0867:                checkAttributes(specAttr, StyleConstants.NameAttribute,
0868:                        Tag.SCRIPT);
0869:                checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
0870:                checkImplicitContentSpec(spec);
0871:            }
0872:
0873:            public void testBaseStart() throws Exception {
0874:                SimpleAttributeSet attr = new SimpleAttributeSet();
0875:                attr.addAttribute("aaaa", "bbbb");
0876:                final String url1 = "http://www.aaa.ru/aaa";
0877:                final String url2 = "http://www.bbb.ru";
0878:                final String tail1 = "/bbb#bbb";
0879:                final String tail2 = "dumb/dumm/#attr";
0880:                final String target = "target";
0881:
0882:                attr.addAttribute(HTML.Attribute.HREF, tail2);
0883:                reader.handleSimpleTag(Tag.BASE, attr, 0);
0884:                assertNull(doc.getBase());
0885:                assertEquals(0, reader.charAttr.getAttributeCount());
0886:                assertEquals(0, reader.parseBuffer.size());
0887:
0888:                doc.setBase(new URL(url2));
0889:
0890:                attr.addAttribute(HTML.Attribute.HREF, url1 + tail1);
0891:                reader.handleSimpleTag(Tag.BASE, attr, 0);
0892:                assertEquals(0, reader.charAttr.getAttributeCount());
0893:                assertEquals(0, reader.parseBuffer.size());
0894:                assertEquals(url1 + tail1, doc.getBase().toString());
0895:
0896:                attr.addAttribute(HTML.Attribute.HREF, tail2);
0897:                reader.handleSimpleTag(Tag.BASE, attr, 0);
0898:                assertEquals(0, reader.charAttr.getAttributeCount());
0899:                assertEquals(0, reader.parseBuffer.size());
0900:                assertEquals(url1 + "/" + tail2, doc.getBase().toString());
0901:            }
0902:
0903:            public void testStyle_InHead() throws Exception {
0904:                SimpleAttributeSet attr = new SimpleAttributeSet();
0905:                attr.addAttribute("aaaa", "bbbb");
0906:                action = reader.new StyleAction();
0907:
0908:                reader.handleStartTag(Tag.HEAD, new SimpleAttributeSet(), 0);
0909:                assertEquals(0, reader.charAttr.getAttributeCount());
0910:                assertEquals(1, reader.parseBuffer.size());
0911:
0912:                action.start(Tag.STYLE, attr);
0913:                assertEquals(0, reader.charAttr.getAttributeCount());
0914:                assertEquals(1, reader.parseBuffer.size());
0915:
0916:                final String text = "H1 { color: blue }";
0917:                reader.handleText(text.toCharArray(), 0);
0918:                assertEquals(0, reader.charAttr.getAttributeCount());
0919:                assertEquals(1, reader.parseBuffer.size());
0920:
0921:                assertEquals(0, doc.getStyleSheet().getRule("BODY")
0922:                        .getAttributeCount());
0923:                action.end(Tag.STYLE);
0924:                Style rule = doc.getStyleSheet().getRule("h1");
0925:                assertEquals(0, rule.getAttributeCount());
0926:
0927:                reader.handleEndTag(Tag.HEAD, 0);
0928:                assertEquals(0, reader.charAttr.getAttributeCount());
0929:                assertEquals(5, reader.parseBuffer.size());
0930:
0931:                rule = doc.getStyleSheet().getRule("h1");
0932:                assertEquals(2, rule.getAttributeCount());
0933:                assertEquals("h1", rule
0934:                        .getAttribute(StyleConstants.NameAttribute));
0935:                assertEquals("blue", rule.getAttribute(CSS.Attribute.COLOR)
0936:                        .toString());
0937:            }
0938:
0939:            public void testStyle_InHead_Twice() throws Exception {
0940:                final String text1 = "H1 { color: blue }";
0941:                final String text2 = "H2 { color: red }";
0942:
0943:                SimpleAttributeSet attr = new SimpleAttributeSet();
0944:                attr.addAttribute("aaaa", "bbbb");
0945:                action = reader.new StyleAction();
0946:
0947:                reader.handleStartTag(Tag.HEAD, new SimpleAttributeSet(), 0);
0948:                assertEquals(0, reader.charAttr.getAttributeCount());
0949:                assertEquals(1, reader.parseBuffer.size());
0950:
0951:                action.start(Tag.STYLE, attr);
0952:                assertEquals(1, reader.parseBuffer.size());
0953:
0954:                reader.handleText(text1.toCharArray(), 0);
0955:                assertEquals(1, reader.parseBuffer.size());
0956:
0957:                assertEquals(0, doc.getStyleSheet().getRule("h1")
0958:                        .getAttributeCount());
0959:                assertEquals(0, doc.getStyleSheet().getRule("h2")
0960:                        .getAttributeCount());
0961:                action.end(Tag.STYLE);
0962:                assertEquals(0, doc.getStyleSheet().getRule("h1")
0963:                        .getAttributeCount());
0964:                assertEquals(0, doc.getStyleSheet().getRule("h2")
0965:                        .getAttributeCount());
0966:
0967:                action.start(Tag.STYLE, attr);
0968:                assertEquals(1, reader.parseBuffer.size());
0969:
0970:                reader.handleText(text2.toCharArray(), 0);
0971:                assertEquals(1, reader.parseBuffer.size());
0972:
0973:                assertEquals(0, doc.getStyleSheet().getRule("h1")
0974:                        .getAttributeCount());
0975:                assertEquals(0, doc.getStyleSheet().getRule("h2")
0976:                        .getAttributeCount());
0977:                action.end(Tag.STYLE);
0978:                assertEquals(0, doc.getStyleSheet().getRule("h1")
0979:                        .getAttributeCount());
0980:                assertEquals(0, doc.getStyleSheet().getRule("h2")
0981:                        .getAttributeCount());
0982:
0983:                reader.handleEndTag(Tag.HEAD, 0);
0984:                assertEquals(0, reader.charAttr.getAttributeCount());
0985:                assertEquals(5, reader.parseBuffer.size());
0986:
0987:                Style rule = doc.getStyleSheet().getRule("h1");
0988:                assertEquals(2, rule.getAttributeCount());
0989:                assertEquals("h1", rule
0990:                        .getAttribute(StyleConstants.NameAttribute));
0991:                assertEquals("blue", rule.getAttribute(CSS.Attribute.COLOR)
0992:                        .toString());
0993:
0994:                rule = doc.getStyleSheet().getRule("h2");
0995:                assertEquals(2, rule.getAttributeCount());
0996:                assertEquals("h2", rule
0997:                        .getAttribute(StyleConstants.NameAttribute));
0998:                assertEquals("red", rule.getAttribute(CSS.Attribute.COLOR)
0999:                        .toString());
1000:            }
1001:
1002:            public void testStyle() throws Exception {
1003:                SimpleAttributeSet attr = new SimpleAttributeSet();
1004:                attr.addAttribute("aaaa", "bbbb");
1005:                action = reader.new StyleAction();
1006:
1007:                action.start(Tag.STYLE, attr);
1008:                assertEquals(0, reader.charAttr.getAttributeCount());
1009:                assertEquals(0, reader.parseBuffer.size());
1010:
1011:                final String text = "H1 { color: blue }";
1012:                reader.handleText(text.toCharArray(), 0);
1013:                assertEquals(0, reader.charAttr.getAttributeCount());
1014:                assertEquals(0, reader.parseBuffer.size());
1015:
1016:                assertEquals(0, doc.getStyleSheet().getRule("BODY")
1017:                        .getAttributeCount());
1018:                action.end(Tag.STYLE);
1019:                assertEquals(0, reader.charAttr.getAttributeCount());
1020:                assertEquals(0, reader.parseBuffer.size());
1021:                final Style rule = doc.getStyleSheet().getRule("h1");
1022:                assertEquals(0, rule.getAttributeCount());
1023:            }
1024:
1025:            public void testTitleStart() throws Exception {
1026:                SimpleAttributeSet attr = new SimpleAttributeSet();
1027:                attr.addAttribute("aaaa", "bbbb");
1028:                reader.handleStartTag(Tag.TITLE, attr, 0);
1029:                assertEquals(0, reader.charAttr.getAttributeCount());
1030:                assertEquals(2, reader.parseBuffer.size());
1031:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
1032:                AttributeSet specAttr = spec.getAttributes();
1033:                assertEquals(1, specAttr.getAttributeCount());
1034:                checkOpenImpliedSpec(spec);
1035:
1036:                spec = (ElementSpec) reader.parseBuffer.get(1);
1037:                specAttr = spec.getAttributes();
1038:                assertEquals(2, specAttr.getAttributeCount());
1039:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1040:                        Tag.TITLE);
1041:                checkAttributes(specAttr, "aaaa", "bbbb");
1042:                checkImplicitContentSpec(spec);
1043:                assertNotSame(attr, specAttr);
1044:            }
1045:
1046:            public void testTitleText() throws Exception {
1047:                final String title = "brand new title";
1048:                SimpleAttributeSet attr = new SimpleAttributeSet();
1049:                reader.handleStartTag(Tag.TITLE, attr, 0);
1050:
1051:                assertEquals(0, reader.charAttr.getAttributeCount());
1052:                assertEquals(2, reader.parseBuffer.size());
1053:                reader.handleText(title.toCharArray(), 0);
1054:                assertEquals(0, reader.charAttr.getAttributeCount());
1055:                assertEquals(2, reader.parseBuffer.size());
1056:
1057:                assertEquals(title, doc.getProperty(HTMLDocument.TitleProperty));
1058:            }
1059:
1060:            public void testTitleEnd() throws Exception {
1061:                SimpleAttributeSet attr = new SimpleAttributeSet();
1062:                reader.handleStartTag(Tag.TITLE, attr, 0);
1063:                assertEquals(0, reader.charAttr.getAttributeCount());
1064:                assertEquals(2, reader.parseBuffer.size());
1065:                reader.handleEndTag(Tag.TITLE, 0);
1066:
1067:                assertEquals(0, reader.charAttr.getAttributeCount());
1068:                assertEquals(3, reader.parseBuffer.size());
1069:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(2);
1070:                AttributeSet specAttr = spec.getAttributes();
1071:                assertEquals(2, specAttr.getAttributeCount());
1072:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1073:                        Tag.TITLE);
1074:                checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
1075:                checkImplicitContentSpec(spec);
1076:            }
1077:
1078:            public void testTitleEnd_Impied() throws Exception {
1079:                SimpleAttributeSet attr = new SimpleAttributeSet();
1080:                reader.handleEndTag(Tag.TITLE, 0);
1081:                assertEquals(0, reader.charAttr.getAttributeCount());
1082:                assertEquals(2, reader.parseBuffer.size());
1083:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
1084:                AttributeSet specAttr;
1085:                checkOpenImpliedSpec(spec);
1086:                spec = (ElementSpec) reader.parseBuffer.get(1);
1087:                specAttr = spec.getAttributes();
1088:                assertEquals(2, specAttr.getAttributeCount());
1089:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1090:                        Tag.TITLE);
1091:                checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
1092:            }
1093:
1094:            public void testLinkStart() throws Exception {
1095:                SimpleAttributeSet attr = new SimpleAttributeSet();
1096:                attr.addAttribute("aaaa", "bbbb");
1097:
1098:                reader.handleStartTag(Tag.LINK, attr, 0);
1099:                assertEquals(2, reader.parseBuffer.size());
1100:                assertEquals(0, reader.charAttr.getAttributeCount());
1101:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
1102:                AttributeSet specAttr;
1103:                checkOpenImpliedSpec(spec);
1104:
1105:                spec = (ElementSpec) reader.parseBuffer.get(1);
1106:                specAttr = spec.getAttributes();
1107:                assertEquals(2, specAttr.getAttributeCount());
1108:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1109:                        Tag.LINK);
1110:                checkAttributes(specAttr, "aaaa", "bbbb");
1111:                checkImplicitContentSpec(spec);
1112:            }
1113:
1114:            public void testLinkStart_InTitle() throws Exception {
1115:                SimpleAttributeSet attr = new SimpleAttributeSet();
1116:                attr.addAttribute("aaaa", "bbbb");
1117:
1118:                reader.handleStartTag(Tag.TITLE, attr, 0);
1119:                assertEquals(2, reader.parseBuffer.size());
1120:                assertEquals(0, reader.charAttr.getAttributeCount());
1121:
1122:                reader.handleStartTag(Tag.LINK, attr, 0);
1123:                assertEquals(3, reader.parseBuffer.size());
1124:                assertEquals(0, reader.charAttr.getAttributeCount());
1125:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(2);
1126:                AttributeSet specAttr = spec.getAttributes();
1127:                assertEquals(2, specAttr.getAttributeCount());
1128:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1129:                        Tag.LINK);
1130:                checkAttributes(specAttr, "aaaa", "bbbb");
1131:                checkImplicitContentSpec(spec);
1132:            }
1133:
1134:            public void testLinkEnd() throws Exception {
1135:                SimpleAttributeSet attr = new SimpleAttributeSet();
1136:                attr.addAttribute("aaaa", "bbbb");
1137:                reader.handleStartTag(Tag.LINK, attr, 0);
1138:                assertEquals(0, reader.charAttr.getAttributeCount());
1139:                assertEquals(2, reader.parseBuffer.size());
1140:                reader.handleEndTag(Tag.LINK, 0);
1141:                assertEquals(0, reader.charAttr.getAttributeCount());
1142:                assertEquals(2, reader.parseBuffer.size());
1143:            }
1144:
1145:            public void testLinkEnd_InTitle() throws Exception {
1146:                SimpleAttributeSet attr = new SimpleAttributeSet();
1147:                attr.addAttribute("aaaa", "bbbb");
1148:                reader.handleStartTag(Tag.TITLE, attr, 0);
1149:                reader.handleStartTag(Tag.LINK, attr, 0);
1150:                assertEquals(0, reader.charAttr.getAttributeCount());
1151:                assertEquals(3, reader.parseBuffer.size());
1152:                reader.handleEndTag(Tag.LINK, 0);
1153:                assertEquals(0, reader.charAttr.getAttributeCount());
1154:                assertEquals(3, reader.parseBuffer.size());
1155:            }
1156:
1157:            public void testLink_LoadCSS() throws Exception {
1158:                if (!isHarmony()) {
1159:                    return;
1160:                }
1161:                SimpleAttributeSet attr = new SimpleAttributeSet();
1162:                attr.addAttribute(HTML.Attribute.TYPE, "text/css");
1163:                URL url = HTMLEditorKit.class
1164:                        .getResource(HTMLEditorKit.DEFAULT_CSS);
1165:                attr.addAttribute(HTML.Attribute.HREF, url.toString());
1166:
1167:                assertEquals(0, new SimpleAttributeSet(doc.getStyleSheet()
1168:                        .getRule("h3")).getAttributeCount());
1169:
1170:                reader.handleStartTag(Tag.TITLE, new SimpleAttributeSet(), 0);
1171:                assertEquals(2, reader.parseBuffer.size());
1172:                assertEquals(0, reader.charAttr.getAttributeCount());
1173:
1174:                reader.handleStartTag(Tag.LINK, attr, 0);
1175:                assertEquals(3, reader.parseBuffer.size());
1176:                assertEquals(0, reader.charAttr.getAttributeCount());
1177:
1178:                assertTrue(new SimpleAttributeSet(doc.getStyleSheet().getRule(
1179:                        "h3")).getAttributeCount() > 0);
1180:            }
1181:
1182:            public void testAreaStart() throws Exception {
1183:                // TODO: implement
1184:            }
1185:
1186:            public void testAreaEnd() throws Exception {
1187:                // TODO: implement
1188:            }
1189:
1190:            public void testMetaStart() throws Exception {
1191:                SimpleAttributeSet attr = new SimpleAttributeSet();
1192:                reader.handleStartTag(Tag.META, attr, 0);
1193:                assertEquals(0, reader.charAttr.getAttributeCount());
1194:                assertEquals(2, reader.parseBuffer.size());
1195:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
1196:                AttributeSet specAttr;
1197:                checkOpenImpliedSpec(spec);
1198:
1199:                spec = (ElementSpec) reader.parseBuffer.get(1);
1200:                specAttr = spec.getAttributes();
1201:                assertEquals(1, specAttr.getAttributeCount());
1202:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1203:                        Tag.META);
1204:                assertSpec(spec, ElementSpec.ContentType,
1205:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
1206:            }
1207:
1208:            public void testMetaStart_InTitle() throws Exception {
1209:                SimpleAttributeSet attr = new SimpleAttributeSet();
1210:                attr.addAttribute("aaaa", "bbbb");
1211:
1212:                reader.handleStartTag(Tag.TITLE, attr, 0);
1213:                assertEquals(2, reader.parseBuffer.size());
1214:                assertEquals(0, reader.charAttr.getAttributeCount());
1215:
1216:                reader.handleStartTag(Tag.META, attr, 0);
1217:                assertEquals(3, reader.parseBuffer.size());
1218:                assertEquals(0, reader.charAttr.getAttributeCount());
1219:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(2);
1220:                AttributeSet specAttr = spec.getAttributes();
1221:                assertEquals(2, specAttr.getAttributeCount());
1222:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1223:                        Tag.META);
1224:                checkAttributes(specAttr, "aaaa", "bbbb");
1225:                assertSpec(spec, ElementSpec.ContentType,
1226:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
1227:            }
1228:
1229:            public void testMetaEnd() throws Exception {
1230:                SimpleAttributeSet attr = new SimpleAttributeSet();
1231:                attr.addAttribute("aaaa", "bbbb");
1232:                reader.handleStartTag(Tag.META, attr, 0);
1233:                assertEquals(0, reader.charAttr.getAttributeCount());
1234:                assertEquals(2, reader.parseBuffer.size());
1235:                reader.handleEndTag(Tag.META, 0);
1236:                assertEquals(0, reader.charAttr.getAttributeCount());
1237:                assertEquals(2, reader.parseBuffer.size());
1238:            }
1239:
1240:            public void testFormStart() {
1241:                SimpleAttributeSet attr = new SimpleAttributeSet();
1242:                attr.addAttribute("aaaa", "bbbb");
1243:                action = reader.new FormAction();
1244:
1245:                action.start(Tag.FORM, attr);
1246:                assertEquals(0, reader.charAttr.getAttributeCount());
1247:                assertEquals(2, reader.parseBuffer.size());
1248:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
1249:                AttributeSet specAttr;
1250:                checkOpenImpliedSpec(spec);
1251:                spec = (ElementSpec) reader.parseBuffer.get(1);
1252:                specAttr = spec.getAttributes();
1253:                assertEquals(2, specAttr.getAttributeCount());
1254:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1255:                        Tag.FORM);
1256:                checkAttributes(specAttr, "aaaa", "bbbb");
1257:                checkImplicitContentSpec(spec);
1258:
1259:                assertEquals(2, attr.getAttributeCount());
1260:                checkAttributes(attr, StyleConstants.NameAttribute, Tag.FORM);
1261:                checkAttributes(attr, "aaaa", "bbbb");
1262:            }
1263:
1264:            public void testFormEnd() {
1265:                SimpleAttributeSet attr = new SimpleAttributeSet();
1266:                attr.addAttribute("aaaa", "bbbb");
1267:                action = reader.new FormAction();
1268:
1269:                action.end(Tag.FORM);
1270:                assertEquals(0, reader.charAttr.getAttributeCount());
1271:                assertEquals(0, reader.parseBuffer.size());
1272:            }
1273:
1274:            public void testLabelStart() throws Exception {
1275:                // TODO: implement
1276:            }
1277:
1278:            public void testLabelEnd() throws Exception {
1279:                // TODO: implement
1280:            }
1281:
1282:            private void checkCRSpec(final ElementSpec spec) {
1283:                final AttributeSet specAttr = spec.getAttributes();
1284:                assertEquals(2, specAttr.getAttributeCount());
1285:                checkAttributes(specAttr, StyleConstants.NameAttribute,
1286:                        Tag.CONTENT);
1287:                checkAttributes(specAttr, "CR", Boolean.TRUE);
1288:                assertSpec(spec, ElementSpec.ContentType,
1289:                        ElementSpec.OriginateDirection, 0, new char[] { '\n' });
1290:            }
1291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.