Search in sources :

Example 1 with SebisStopWatch

use of eu.transkribus.core.util.SebisStopWatch in project TranskribusCore by Transkribus.

the class XPathPage method main.

public static void main(String[] args) throws Exception {
    // File f = new File("/home/sebastianc/Downloads/035_320_001.xml");
    SebisStopWatch ss = new SebisStopWatch();
    // ss.start();
    // PageXmlUtils.unmarshal(new File("/home/sebastianc/Downloads/035_320_001.xml"));
    // ss.stop(true);
    XPathPage utils = XPathPage.getInstance();
    // String id = "r188";
    String id = null;
    TranscriptionLevel level = TranscriptionLevel.LINE;
    ss.start();
    String txt = utils.getUnicodeText(new File("/home/sebastianc/Downloads/035_320_001.xml").toURI().toURL(), level, id);
    ss.stop(true);
    System.out.println("txt = " + txt);
    if (true)
        return;
    ClassLoader cl = XPathPage.class.getClassLoader();
    // DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", cl);
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    // domFactory.setNamespaceAware(true);
    // XPathFactory xpathFactory = XPathFactory.newInstance(javax.xml.xpath.XPathFactory.DEFAULT_OBJECT_MODEL_URI, "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", cl);
    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    xpath.getNamespaceContext();
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    File f = new File("/mnt/dea_scratch/TRP/test/Klassikerausgaben_test/page/bsb00087391_00009.xml");
    Document catalog = builder.parse(f);
    final XPathExpression expr = xpath.compile("//*[contains(name(), 'Page')]/@imageWidth");
    // Object result = expr.evaluate(catalog, XPathConstants.NUMBER);
    // Double res = (Double)result;
    // System.out.println(res);
    Object result = expr.evaluate(catalog, XPathConstants.STRING);
    String res = (String) result;
    System.out.println(res);
// Object result = expr.evaluate(catalog, XPathConstants.NODESET);
// NodeList nodes = (NodeList) result;
// if (nodes.getLength() > 0) {
// String[] parents = new String[nodes.getLength()];
// for (int i = 0; i < nodes.getLength(); i++) {
// parents[i] = nodes.item(i).getNodeValue();
// System.out.println(parents[i]);
// }
// }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SebisStopWatch(eu.transkribus.core.util.SebisStopWatch) File(java.io.File)

Example 2 with SebisStopWatch

use of eu.transkribus.core.util.SebisStopWatch in project TranskribusCore by Transkribus.

the class TeiBuilderTest method main.

public static void main(String[] args) {
    SebisStopWatch sw = new SebisStopWatch();
    TrpDoc doc;
    try {
        // doc = LocalDocReader.load(LocalDocReaderTest.TEST_DOC1);
        doc = LocalDocReader.load(docPath);
        // test1(doc);
        test2(doc);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : TrpDoc(eu.transkribus.core.model.beans.TrpDoc) SebisStopWatch(eu.transkribus.core.util.SebisStopWatch)

Aggregations

SebisStopWatch (eu.transkribus.core.util.SebisStopWatch)2 TrpDoc (eu.transkribus.core.model.beans.TrpDoc)1 File (java.io.File)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathFactory (javax.xml.xpath.XPathFactory)1 Document (org.w3c.dom.Document)1