src/main/java/eu/digitisation/layout/SortPageXML.java
public static boolean isSorted(Document doc) throws IOException {
        NodeList groups = doc.getElementsByTagName("OrderedGroup");
        for (int n = 0; n < groups.getLength(); ++n) {
            Node group = groups.item(n);
            List<String> order = readingOrder(group);
            Node container = group.getParentNode().getParentNode();
            NodeList children = container.getChildNodes();

            int nreg = 0;  // region number in group
            for (int k = 0; k < children.getLength(); ++k) {
                Node child = children.item(k);
                if (child instanceof Element) {
                    String tag = child.getNodeName();
                    if (tag.equals("TextRegion")) {
                        String id = ((Element) child).getAttribute("id");
                        if (order.contains(id) && // sometimes item is not listed
                                !id.equals(order.get(nreg++))) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }
/**
     *
     * @param doc a PAGE XML document
     * @return true if doc is transformed according to the reading order
     * @throws IOException
     */
@param doc a PAGE XML document
@return true if doc is transformed according to the reading order
@throws IOException
@param doc a PAGE XML document @return true if doc is transformed according to the reading order @throws IOException
public static boolean isSorted(Document doc) throws IOException {
        NodeList groups = doc.getElementsByTagName("OrderedGroup");
        for (int n = 0; n < groups.getLength(); ++n) {
            Node group = groups.item(n);
            List<String> order = readingOrder(group);
            Node container = group.getParentNode().getParentNode();
            NodeList children = container.getChildNodes();
            int nreg = 0;  
            for (int k = 0; k < children.getLength(); ++k) {
                Node child = children.item(k);
                if (child instanceof Element) {
                    String tag = child.getNodeName();
                    if (tag.equals("TextRegion")) {
                        String id = ((Element) child).getAttribute("id");
                        if (order.contains(id) && 
                                !id.equals(order.get(nreg++))) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }
public static boolean isSorted ( Document doc ) throws IOException { NodeList groups = doc . getElementsByTagName ( "OrderedGroup" ) ; for ( int n = 0 ; n < groups . getLength ( ) ; ++ n ) { Node group = groups . item ( n ) ; List < String > order = readingOrder ( group ) ; Node container = group . getParentNode ( ) . getParentNode ( ) ; NodeList children = container . getChildNodes ( ) ; int nreg = 0 ; for ( int k = 0 ; k < children . getLength ( ) ; ++ k ) { Node child = children . item ( k ) ; if ( child instanceof Element ) { String tag = child . getNodeName ( ) ; if ( tag . equals ( "TextRegion" ) ) { String id = ( ( Element ) child ) . getAttribute ( "id" ) ; if ( order . contains ( id ) && ! id . equals ( order . get ( nreg ++ ) ) ) { return false ; } } } } } return true ; }
@param doc a PAGE XML document
 @return true if doc is transformed according to the reading order
 @throws IOException
@param doc a PAGE XML document @return true if doc is transformed according to the reading order @throws IOException
// region number in group // sometimes item is not listed