src/main/java/eu/digitisation/layout/PAGEPage.java
TextComponent parse(Element element) {
        String id = element.getAttribute("id");
        ComponentType type = 
                ComponentType.valueOf(FileType.PAGE, element.getTagName());
        String subtype = element.getAttribute("type");
        String content = null;
        Polygon frontier = new Polygon();
        List<TextComponent> array = new ArrayList<TextComponent>();        
        NodeList children = element.getChildNodes();
        int number = components.size();
        
        components.add(null);  // reserve the place for this component
        
        for (int nchild = 0; nchild < children.getLength(); ++nchild) {
            Node child = children.item(nchild);
            if (child instanceof Element) {
                Element e = (Element) child;
                String tag = e.getTagName();
                if (tag.equals("TextEquiv")) {
                    if (content != null) {
                        throw new DOMException(DOMException.INVALID_ACCESS_ERR,
                                "Multiple content in region " + id);
                    }
                    content = child.getTextContent().trim();
                }
                if (tag.equals("Coords")) {
                    Element coords = (Element) child;
                    if (frontier.npoints > 0) {
                        throw new DOMException(DOMException.INVALID_ACCESS_ERR,
                                "Multiple Coords in region " + id);
                    }
                    NodeList nodes = coords.getChildNodes(); // points
                    for (int npoint = 0; npoint < nodes.getLength(); ++npoint) {
                        Node node = nodes.item(npoint);
                        if (node.getNodeName().equals("Point")) {
                            Element point = (Element) node;
                            int x = Integer.parseInt(point.getAttribute("x"));
                            int y = Integer.parseInt(point.getAttribute("y"));
                            frontier.addPoint(x, y);
                        }
                    }
                } else if (tag.equals("TextRegion")
                        || tag.equals("TextLine")
                        || tag.equals("Word")) {
                    TextComponent subcomponent = parse(e);
                    array.add(subcomponent);
                }
            }
        }
        TextComponent component = new TextComponent(id, type, subtype, content, frontier);
        components.set(number, component);
        subcomponents.put(component, array);
        return component;
    }
/**
     * Parse an XML element and retrieve the associated text component
     *
     * @param element an XML element
     * @return the text component associated with this element
     */
Parse an XML element and retrieve the associated text component
@param element an XML element
@return the text component associated with this element
Parse an XML element and retrieve the associated text component @param element an XML element @return the text component associated with this element
TextComponent parse(Element element) {
        String id = element.getAttribute("id");
        ComponentType type = 
                ComponentType.valueOf(FileType.PAGE, element.getTagName());
        String subtype = element.getAttribute("type");
        String content = null;
        Polygon frontier = new Polygon();
        List<TextComponent> array = new ArrayList<TextComponent>();        
        NodeList children = element.getChildNodes();
        int number = components.size();
        components.add(null);  
        for (int nchild = 0; nchild < children.getLength(); ++nchild) {
            Node child = children.item(nchild);
            if (child instanceof Element) {
                Element e = (Element) child;
                String tag = e.getTagName();
                if (tag.equals("TextEquiv")) {
                    if (content != null) {
                        throw new DOMException(DOMException.INVALID_ACCESS_ERR,
                                "Multiple content in region " + id);
                    }
                    content = child.getTextContent().trim();
                }
                if (tag.equals("Coords")) {
                    Element coords = (Element) child;
                    if (frontier.npoints > 0) {
                        throw new DOMException(DOMException.INVALID_ACCESS_ERR,
                                "Multiple Coords in region " + id);
                    }
                    NodeList nodes = coords.getChildNodes(); 
                    for (int npoint = 0; npoint < nodes.getLength(); ++npoint) {
                        Node node = nodes.item(npoint);
                        if (node.getNodeName().equals("Point")) {
                            Element point = (Element) node;
                            int x = Integer.parseInt(point.getAttribute("x"));
                            int y = Integer.parseInt(point.getAttribute("y"));
                            frontier.addPoint(x, y);
                        }
                    }
                } else if (tag.equals("TextRegion")
                        || tag.equals("TextLine")
                        || tag.equals("Word")) {
                    TextComponent subcomponent = parse(e);
                    array.add(subcomponent);
                }
            }
        }
        TextComponent component = new TextComponent(id, type, subtype, content, frontier);
        components.set(number, component);
        subcomponents.put(component, array);
        return component;
    }
TextComponent parse ( Element element ) { String id = element . getAttribute ( "id" ) ; ComponentType type = ComponentType . valueOf ( FileType . PAGE , element . getTagName ( ) ) ; String subtype = element . getAttribute ( "type" ) ; String content = null ; Polygon frontier = new Polygon ( ) ; List < TextComponent > array = new ArrayList < TextComponent > ( ) ; NodeList children = element . getChildNodes ( ) ; int number = components . size ( ) ; components . add ( null ) ; for ( int nchild = 0 ; nchild < children . getLength ( ) ; ++ nchild ) { Node child = children . item ( nchild ) ; if ( child instanceof Element ) { Element e = ( Element ) child ; String tag = e . getTagName ( ) ; if ( tag . equals ( "TextEquiv" ) ) { if ( content != null ) { throw new DOMException ( DOMException . INVALID_ACCESS_ERR , "Multiple content in region " + id ) ; } content = child . getTextContent ( ) . trim ( ) ; } if ( tag . equals ( "Coords" ) ) { Element coords = ( Element ) child ; if ( frontier . npoints > 0 ) { throw new DOMException ( DOMException . INVALID_ACCESS_ERR , "Multiple Coords in region " + id ) ; } NodeList nodes = coords . getChildNodes ( ) ; for ( int npoint = 0 ; npoint < nodes . getLength ( ) ; ++ npoint ) { Node node = nodes . item ( npoint ) ; if ( node . getNodeName ( ) . equals ( "Point" ) ) { Element point = ( Element ) node ; int x = Integer . parseInt ( point . getAttribute ( "x" ) ) ; int y = Integer . parseInt ( point . getAttribute ( "y" ) ) ; frontier . addPoint ( x , y ) ; } } } else if ( tag . equals ( "TextRegion" ) || tag . equals ( "TextLine" ) || tag . equals ( "Word" ) ) { TextComponent subcomponent = parse ( e ) ; array . add ( subcomponent ) ; } } } TextComponent component = new TextComponent ( id , type , subtype , content , frontier ) ; components . set ( number , component ) ; subcomponents . put ( component , array ) ; return component ; }
Parse an XML element and retrieve the associated text component
 @param element an XML element
 @return the text component associated with this element
Parse an XML element and retrieve the associated text component @param element an XML element @return the text component associated with this element
// reserve the place for this component // points