Nikulina - 2011-06-27

Hi,

My programme searches for the coordinates and dimensions of  text and picture elements on the page (site). The problem is that the renderer shows for many pictures the value “0”.

I  search for the coordinates in such a way:

traversal(RCollection root, Node control, RCollection rcontrol) {

Iterator children = root.getRenderables();
Vector<Integer> line = new Vector<Integer>();
Vector<Vector<Integer>> coord = new Vector<Vector<Integer>>();

while (children != null && children.hasNext()) {

    Renderable rendNode = (Renderable) children.next();
    ModelNode mn = rendNode.getModelNode();
    Node node = (Node) mn;

if (rendNode instanceof BoundableRenderable
                        && nodeTable.contains(node)
                        && rendNode instanceof RImgControl) {
BoundableRenderable box = (BoundableRenderable) rendNode;
        Point p = box.getGUIPoint(0, 0);
        Rectangle r = box.getBounds();
        int x = p.x;
        int y = p.y;
        int width  = p.x + r.width;
        int height = p.y + r.height;
    }
}
}

readDocument(String path)
            throws MalformedURLException, IOException, SAXException {

        URL url = new URL(path);
        URLConnection connection = url.openConnection();
        connection.setRequestProperty("User-Agent",
                "Mozilla/4.0 (compatible;) Cobra/0.98.4+");
        connection.setRequestProperty("Cookie", "");
        if (connection instanceof HttpURLConnection) {
            HttpURLConnection hc = (HttpURLConnection) connection;
            hc.setInstanceFollowRedirects(true);
        }
        InputStream in = connection.getInputStream();
        byte content;
        try {
            content = IORoutines.load(in, 8192);
        } finally {
            in.close();
        }
        final FrameContext frameContext = new LocalFrameContext();
        final RenderableContainer renderableContainer = new
LocalRenderableContainer();
        ByteArrayInputStream bin = new ByteArrayInputStream(content);
        UserAgentContext ucontext = new SimpleUserAgentContext();
        HtmlRendererContext rcontext = new SimpleHtmlRendererContext(
                new HtmlPanel(), ucontext);
        DocumentBuilderImpl builder = new DocumentBuilderImpl(ucontext);
        this.document = builder.parse(new InputSourceImpl(bin, url.toString()
                ,charset));
        final Document parsedDocument = document;

        this.docBlock = new RBlock((NodeImpl) parsedDocument, 0, rcontext
                .getUserAgentContext(), rcontext, frameContext,
                renderableContainer);
        docBlock.doLayout(1300, 700, true);
}

Where could be an error? What do I do incorrectly?

Thank you very much in advance! I will be very grateful for any help!!!