package org.greenstone.gsdl3.gs3build.util; public class HTMLLocalAnchor { public static int anchorRef(HTMLBlockList anchors, String name) { int loop; String idvalue; for (loop = 0; loop < anchors.size(); loop ++) { idvalue = anchors.tagBlock(loop).headTag().idValue("name"); if (idvalue != null && idvalue.equalsIgnoreCase(name)) //TODO: check if this should be case senstitive { return loop; } } return -1; } public static int header(HTMLDoc doc, String local) { HTMLBlockList anchors; int heading; HTMLBlock headingblock; int anchor; HTMLBlock anchorblock; anchors = HTMLBlockList.anchorlist(doc); anchor = anchorRef(anchors, local); if (anchor < 0) { return -1; } anchorblock = anchors.tagBlock(anchor); for (heading = 0; heading < doc.headerBlocks().size(); heading ++) { headingblock = doc.headerBlocks().tagBlock(heading); if (headingblock.startPos() > anchorblock.endPos()) { break; } } return heading - 1; } }