Package com.volantis.mcs.dissection

Examples of com.volantis.mcs.dissection.Dissector


        }
        DissectionURLManager urlManager = new MyDissectionURLManager();
        DocumentInformationImpl docInfo = new DocumentInformationImpl();
        docInfo.setDocumentURL(new MarinerURL("common1.xml"));

        Dissector dissector = new Dissector();
        DissectedDocumentImpl dissected = (DissectedDocumentImpl)
            dissector.createDissectedDocument(context, characteristics,
                                              document, urlManager, docInfo);

        // Check the characteristics of the dissected document.
        NodeCounts expectedDocumentNodeCounts
            = expectedDocumentStats.nodeCounts;
        int dissectableAreaCount
            = expectedDocumentNodeCounts.dissectableAreaCount;
        assertEquals(failures,
                     "Incorrect number of dissectable areas,",
                     dissectableAreaCount,
                     dissected.getDissectableAreaCount());

        // Check the node counts.
        NodeCounts actualNodeCounts = null;

        // Gather statistics by visiting all the nodes.
        VisitingStatisticsGatherer visitor = new VisitingStatisticsGatherer();
        document.visitDocument(visitor);
        NodeCounts visitorStatistics = visitor.getStatistics().nodeCounts;

        // Gather statistics by iterating over all the nodes.
        IteratingStatisticsGatherer iterator = new IteratingStatisticsGatherer();
        document.visitDocument(iterator);
        NodeCounts iteratorStatistics = iterator.getStatistics().nodeCounts;

        // Make sure that all the different methods of gathering statistics
        // agree.
        assertEquals("Discrepancy between statistics gatherers",
                     visitorStatistics, iteratorStatistics);

        // Set the actualStatistics value so they can be output later.
        actualNodeCounts = visitorStatistics;

        // Check that the statistics match the expectation.
        checkNodeCount(failures,
                       expectedDocumentStats.nodeCounts,
                       actualNodeCounts);

        // Check the shared content usages.
        checkSharedContentUsages(failures,
                                 "Total Cost",
                                 details,
                                 expectedDocumentStats.getTotalContentUsages(),
                                 dissected.getTotalContentUsages());

        checkSharedContentUsages(failures,
                                 "Fixed Cost",
                                 details,
                                 expectedDocumentStats.getFixedContentUsages(),
                                 dissected.getFixedContentUsages());

        // Check that the dissectable areas are correct.
        for (int i = 0; i < dissectableAreaCount; i += 1) {
            DissectableArea area = dissected.getDissectableArea(i);
            DissectableAreaStats expectedDAStats
                = expectedDocumentStats.getDissectableAreaStats(i);
            checkDissectableArea(failures, details, context, area,
                                 expectedDAStats);
        }

        OutputDocument output = createOutputDocument();
        DissectedContentHandler outputHandler
            = createDissectedContentHandler(output);
        RequestedShards requestedShards = dissected.createRequestedShards();
        dissector.serialize(context, dissected,
                            requestedShards, outputHandler);
        int totalCost = dissected.getTotalCost();
        int outputSize = output.getSize();
        // Check output size is reasonable; we allow explicit output size to
        // be greater than the total cost to handle WBDOM generating WML.
View Full Code Here


                DissectionTestCaseHelper.createDissectableDocument(builder,
                this.getClass(), name);
        WBDOMDissectableDocument dissectionDocument = (WBDOMDissectableDocument)
                details.getDocument();
       
        Dissector dissector = new Dissector();
        DissectionContext context = new MyDissectionContext();
        DissectionCharacteristicsImpl characteristics =
                new DissectionCharacteristicsImpl();
        DissectionURLManager urlManager = new MyDissectionURLManager();
        DocumentInformationImpl information = new DocumentInformationImpl();
        information.setDocumentURL(new MarinerURL("document-url.xml"));
        System.out.println("Page Size=" + pageSize);
        characteristics.setMaxPageSize(pageSize);
        DissectedDocument dissectedDocument =
                dissector.createDissectedDocument(context, characteristics,
                dissectionDocument, urlManager, information);

        // Interate over the shards.
        RequestedShards shards = dissectedDocument.createRequestedShards();
        int dissectableArea = 0;
        ShardIterator iterator =
                dissectedDocument.getShardIterator(context, dissectableArea);
        int count = 0;
        while (iterator.hasMoreShards()) {
            iterator.populateNextShard();
            count += 1;
        }
        for (int i = 0; i < count; i += 1) {
            System.out.println();
            System.out.println("Shard " + (i+1) + " of " + count +
                    " of dissectable area " + dissectableArea);
            shards.setShard(0, i);

            // Create a producer for XML.
            CharArrayWriter textBuffer = new CharArrayWriter();
            CharacterEncoder pce = new DebugCharacterEncoder();
            EncodingWriter enc = new EncodingWriter(textBuffer, pce);
            WBSAXContentHandler textProducer = new WMLProducer(textBuffer, enc);

            if (logger.isDebugEnabled()) {
                textProducer = new WBSAXDisassembler(textProducer);
            }
           
            // Create a producer for WBXML.
            ByteArrayOutputStream binaryBuffer = new ByteArrayOutputStream();
            WBXMLProducer binaryProducer = new WBXMLProducer(binaryBuffer);
            // Create a "tee" producer which will generate the XML and WBXML
            // simultaneously.
            WBSAXContentHandler producer = new WBSAXTeeHandler(
                    textProducer, binaryProducer);
            // Create content handler used by the dissector to serialise with.
            WBDOMDissectedContentHandler dissectedContentHandler =
                    new WBDOMDissectedContentHandler(producer, conf, urlListener);
           
            // And finally, create the XML and WBXML simultaneously.
            dissector.serialize(context, dissectedDocument, shards,
                    dissectedContentHandler);

            String text = textBuffer.toString();
            byte[] binary = binaryBuffer.toByteArray();
View Full Code Here

        importantProperties = new HashSet();

        blockyElements = new HashSet();

        if (supportsDissection) {
            dissector = new Dissector();
        } else {
            dissector = null;
        }

        hrefRuleSet = new NoOpRuleSet();
View Full Code Here

TOP

Related Classes of com.volantis.mcs.dissection.Dissector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.