Example usage for org.w3c.dom Attr getValue

List of usage examples for org.w3c.dom Attr getValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getValue.

Prototype

public String getValue();

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:org.kepler.sms.util.OntologyConfiguration.java

public boolean isTagBarOntology(String filepath) {
    if (_document == null || filepath == null)
        return false;

    // get the root
    Element root = _document.getDocumentElement();
    if (root == null)
        return false;
    // iterate to find the ontology with filepath
    NodeList lst = root.getElementsByTagName("ontology");
    for (int i = 0; i < lst.getLength(); i++) {
        Element elem = (Element) lst.item(i);
        Attr att = elem.getAttributeNode("filename");
        if (att != null) {
            String filename = att.getValue();
            if (filepath.equals(getAbsoluteOntologyPath(filename))) {
                Attr libatt = elem.getAttributeNode("tagbar");
                if (libatt != null) {
                    String library = libatt.getValue();
                    if (library != null && library.equals("false")) {
                        return false;
                    }// ww w  .ja  va 2  s .c  o  m
                }
            }
        }
    }
    return true;
}

From source file:org.nuxeo.ecm.platform.ocr.service.impl.OcrServiceImpl.java

protected DocumentStructure parseXml(InputStream xmlStream) throws OcrException {
    DocumentBuilder builder;/*from  w  ww .j  a  v  a2  s .c  o  m*/
    List<TextRegion> textRegions = new ArrayList<TextRegion>();
    List<ImageRegion> imageRegions = new ArrayList<ImageRegion>();
    try {
        builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(xmlStream);
        XPath xpath = XPathFactory.newInstance().newXPath();

        // iterate over all the text regions to extract the text content and
        // the global position of the region
        NodeList textRegionNodes = (NodeList) xpath.evaluate("//TextRegion", document, XPathConstants.NODESET);
        for (int i = 0; i < textRegionNodes.getLength(); i++) {

            Node textRegionNode = textRegionNodes.item(i);
            NodeList xcoordAttrs = (NodeList) xpath.evaluate("Coords/Point/@x", textRegionNode,
                    XPathConstants.NODESET);
            int topLeftX = -1;
            int bottomRightX = -1;
            for (int xi = 0; xi < xcoordAttrs.getLength(); xi++) {
                int x = Integer.valueOf(((Attr) xcoordAttrs.item(xi)).getValue());
                if (topLeftX == -1 || topLeftX > x) {
                    topLeftX = x;
                }
                if (bottomRightX == -1 || bottomRightX < x) {
                    bottomRightX = x;
                }
            }

            NodeList ycoordAttrs = (NodeList) xpath.evaluate("Coords/Point/@y", textRegionNode,
                    XPathConstants.NODESET);
            int topLeftY = -1;
            int bottomRightY = -1;
            for (int yi = 0; yi < ycoordAttrs.getLength(); yi++) {
                int y = Integer.valueOf(((Attr) ycoordAttrs.item(yi)).getValue());
                if (topLeftY == -1 || topLeftY > y) {
                    topLeftY = y;
                }
                if (bottomRightY == -1 || bottomRightY < y) {
                    bottomRightY = y;
                }
            }
            if (topLeftX == -1 || topLeftY == -1 || bottomRightX == -1 || bottomRightY == -1
                    || topLeftX == bottomRightX || topLeftY == bottomRightY) {
                continue;
            }
            TextRegion textRegion = new TextRegion(topLeftX, topLeftY, bottomRightX, bottomRightY);

            NodeList textNodes = (NodeList) xpath.evaluate("Line/@text", textRegionNode,
                    XPathConstants.NODESET);

            StringBuilder sb = new StringBuilder();
            for (int k = 0; k < textNodes.getLength(); k++) {
                Attr textAttr = (Attr) textNodes.item(k);
                String line = textAttr.getValue();

                if (line.endsWith("-") || line.endsWith("\u2010") || line.endsWith("\u2011")) {
                    // special handling for hyphens
                    sb.append(line.substring(0, line.length() - 1));
                } else {
                    sb.append(line);
                    sb.append(" ");
                }
            }
            String paragraph = sb.toString().trim();
            // ignore empty paragraphs
            if (!paragraph.isEmpty()) {
                Matcher matcher = TESSERACT_GIBBERISH.matcher(paragraph);
                String cleaned = matcher.replaceAll("");
                if (cleaned.length() > 0.5 * paragraph.length()) {
                    // less than 50% of non-text chars, this is most likely
                    // NOT an artifact of the OCR, keep the paragraph
                    textRegion.paragraphs.add(paragraph);
                }
            }
            if (!textRegion.paragraphs.isEmpty()) {
                textRegions.add(textRegion);
            }
        }

        // iterate over all the image regions to extract their global
        // position along with any embedded text
        NodeList imageRegionNodes = (NodeList) xpath.evaluate("//ImageRegion", document,
                XPathConstants.NODESET);
        for (int i = 0; i < imageRegionNodes.getLength(); i++) {

            Node imageRegionNode = imageRegionNodes.item(i);
            NodeList xcoordAttrs = (NodeList) xpath.evaluate("Coords/Point/@x", imageRegionNode,
                    XPathConstants.NODESET);
            int topLeftX = -1;
            int bottomRightX = -1;
            for (int xi = 0; xi < xcoordAttrs.getLength(); xi++) {
                int x = Integer.valueOf(((Attr) xcoordAttrs.item(xi)).getValue());
                if (topLeftX == -1 || topLeftX > x) {
                    topLeftX = x;
                }
                if (bottomRightX == -1 || bottomRightX < x) {
                    bottomRightX = x;
                }
            }

            NodeList ycoordAttrs = (NodeList) xpath.evaluate("Coords/Point/@y", imageRegionNode,
                    XPathConstants.NODESET);
            int topLeftY = -1;
            int bottomRightY = -1;
            for (int yi = 0; yi < ycoordAttrs.getLength(); yi++) {
                int y = Integer.valueOf(((Attr) ycoordAttrs.item(yi)).getValue());
                if (topLeftY == -1 || topLeftY > y) {
                    topLeftY = y;
                }
                if (bottomRightY == -1 || bottomRightY < y) {
                    bottomRightY = y;
                }
            }
            if (topLeftX > -1 && topLeftY > -1 && bottomRightX > -1 && bottomRightY > -1
                    && topLeftX < bottomRightX && topLeftY < bottomRightY) {
                ImageRegion imageRegion = new ImageRegion(topLeftX, topLeftY, bottomRightX, bottomRightY);
                // TODO: extract embedded text if any
                imageRegions.add(imageRegion);
            }
        }
        return new DocumentStructureImpl(textRegions, imageRegions);
    } catch (ParserConfigurationException e) {
        throw new OcrException(e);
    } catch (SAXException e) {
        throw new OcrException(e);
    } catch (IOException e) {
        throw new OcrException(e);
    } catch (XPathExpressionException e) {
        throw new OcrException(e);
    }
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

public DeploymentStructure read(VirtualFile vhome, InputStream in) throws Exception {
    DeploymentStructure md = new DeploymentStructure(vhome);
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document doc = docBuilder.parse(in);
    Element root = doc.getDocumentElement();
    Attr attr = root.getAttributeNode("children");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        md.setChildren(ar);/*from   www  .  j  a  va2s .c  o  m*/
    }
    attr = root.getAttributeNode("bundles");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        md.setBundles(ar);
    }
    Node node = root.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String name = node.getNodeName().toLowerCase();
            if ("context".equalsIgnoreCase(name)) {
                readContext((Element) node, md);
            } else if ("properties".equals(name)) {
                readProperties(vhome, (Element) node, md);
            } else if ("preprocessor".equals(name)) {
                readPreprocessor((Element) node, md);
            }
        }
        node = node.getNextSibling();
    }
    return md;
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

protected void readPreprocessor(Element element, DeploymentStructure md) {
    Attr attr = element.getAttributeNode("enabled");
    String enabled = attr == null ? "true" : attr.getValue().trim();
    md.setRequirePreprocessing(Boolean.parseBoolean(enabled));
    attr = element.getAttributeNode("classpath");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        md.setPreprocessorClassPath(ar);
    }/*from   ww  w . jav a  2  s.c om*/
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

protected void readContext(Element element, DeploymentStructure md) {
    Attr attr = element.getAttributeNode("path");
    String path = attr == null ? "" : attr.getValue().trim();
    DeploymentStructure.Context ctx = new Context(path);
    attr = element.getAttributeNode("metaDataPath");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        ctx.setMetaDataPath(ar);//w  w w  .j  av  a2s.  c  o  m
    }
    attr = element.getAttributeNode("classpath");
    if (attr != null) {
        String[] ar = Utils.split(attr.getValue().trim(), ':', true);
        ctx.setClasspath(ar);
    }
    md.addContext(ctx);
}

From source file:org.nuxeo.runtime.jboss.deployer.structure.DeploymentStructureReader.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void readProperties(VirtualFile file, Element element, DeploymentStructure md) throws Exception {
    Attr attr = element.getAttributeNode("src");
    if (attr != null) {
        VirtualFile vf = file.getChild(attr.getValue().trim());
        if (vf != null) {
            InputStream in = vf.openStream();
            try {
                Properties props = new Properties();
                props.load(in);/*from   ww  w  .j a v a  2 s  .c om*/
                md.getProperties().putAll((Map) props);
            } finally {
                in.close();
            }
        } else {
            log.warn(
                    "Properties file referenced in nuxeo-structure.xml could not be found: " + attr.getValue());
        }
    }
    // load contents too if any
    Node child = element.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            if (child.getNodeName().equalsIgnoreCase("property")) {
                Element echild = (Element) child;
                attr = echild.getAttributeNode("name");
                if (attr == null) {
                    log.warn(
                            "Invalid property element format in nuxeo-structure.xml. Property name attribute is required");
                }
                md.setProperty(attr.getValue().trim(), echild.getTextContent().trim());
            }
        }
        child = child.getNextSibling();
    }
}

From source file:org.ojbc.adapters.analyticsstaging.custody.processor.BookingReportProcessor.java

private void processBookingCharges(Node arrestNode, Integer bookingArrestId) throws Exception {
    NodeList chargeRefNodes = XmlUtils.xPathNodeListSearch(arrestNode, "jxdm51:ArrestCharge/@s30:ref");

    List<BookingCharge> bookingCharges = new ArrayList<BookingCharge>();
    for (int i = 0; i < chargeRefNodes.getLength(); i++) {
        Attr chargeRefNode = (Attr) chargeRefNodes.item(i);

        String chargeRef = chargeRefNode.getValue();
        Node chargeNode = XmlUtils.xPathNodeSearch(arrestNode,
                "parent::br-doc:BookingReport/jxdm51:Charge[@s30:id = '" + chargeRef + "']");

        if (chargeNode != null) {
            BookingCharge bookingCharge = new BookingCharge();
            bookingCharge.setBookingArrestId(bookingArrestId);

            String sendingAgency = XmlUtils.xPathStringSearch(chargeNode,
                    "br-ext:HoldForAgency/nc30:OrganizationName");
            bookingCharge//from w w  w  .  j a  va 2s .  c  om
                    .setAgencyId(descriptionCodeLookupService.retrieveCode(CodeTable.Agency, sendingAgency));

            bookingCharge.setChargeCode(XmlUtils.xPathStringSearch(chargeNode,
                    "jxdm51:ChargeStatute/jxdm51:StatuteCodeSectionIdentification/nc30:IdentificationID"));
            bookingCharge.setChargeDisposition(
                    XmlUtils.xPathStringSearch(chargeNode, "jxdm51:ChargeDisposition/nc30:DispositionText"));

            String chargeClassType = XmlUtils.xPathStringSearch(chargeNode, "jxdm51:ChargeSeverityText");
            bookingCharge.setChargeClassTypeId(
                    descriptionCodeLookupService.retrieveCode(CodeTable.ChargeClassType, chargeClassType));
            setBondInfo(chargeNode, chargeRef, bookingCharge);

            String chargeJurisdictionType = XmlUtils.xPathStringSearch(chargeNode,
                    "br-ext:ChargeJurisdictionCourt/jxdm51:CourtName");
            bookingCharge.setChargeJurisdictionTypeId((descriptionCodeLookupService
                    .retrieveCode(CodeTable.JurisdictionType, chargeJurisdictionType)));

            bookingCharges.add(bookingCharge);
        }
    }

    analyticalDatastoreDAO.saveBookingCharges(bookingCharges);
}

From source file:org.ojbc.adapters.analyticsstaging.custody.processor.CustodyStatusChangeReportProcessor.java

private void processCustodyStatusChangeCharges(Node arrestNode, Integer custodyStatusChangeArrestId)
        throws Exception {

    NodeList chargeRefNodes = XmlUtils.xPathNodeListSearch(arrestNode, "jxdm51:ArrestCharge/@s30:ref");

    List<CustodyStatusChangeCharge> custodyStatusChangeCharges = new ArrayList<CustodyStatusChangeCharge>();

    for (int i = 0; i < chargeRefNodes.getLength(); i++) {
        Attr chargeRefNode = (Attr) chargeRefNodes.item(i);
        String chargeRef = chargeRefNode.getValue();

        Node chargeNode = XmlUtils.xPathNodeSearch(arrestNode,
                "parent::cscr-ext:Custody/jxdm51:Charge[@s30:id = '" + chargeRef + "']");

        CustodyStatusChangeCharge custodyStatusChangeCharge = new CustodyStatusChangeCharge();
        custodyStatusChangeCharge.setCustodyStatusChangeArrestId(custodyStatusChangeArrestId);

        String sendingAgency = XmlUtils.xPathStringSearch(chargeNode,
                "cscr-ext:HoldForAgency/nc30:OrganizationName");
        custodyStatusChangeCharge/*from ww w  .  j ava2s  .  c om*/
                .setAgencyId(descriptionCodeLookupService.retrieveCode(CodeTable.Agency, sendingAgency));

        custodyStatusChangeCharge.setChargeCode(XmlUtils.xPathStringSearch(chargeNode,
                "jxdm51:ChargeStatute/jxdm51:StatuteCodeSectionIdentification/nc30:IdentificationID"));
        custodyStatusChangeCharge.setChargeDisposition(
                XmlUtils.xPathStringSearch(chargeNode, "jxdm51:ChargeDisposition/nc30:DispositionText"));

        String chargeClassType = XmlUtils.xPathStringSearch(chargeNode, "jxdm51:ChargeSeverityText");
        custodyStatusChangeCharge.setChargeClassTypeId(
                descriptionCodeLookupService.retrieveCode(CodeTable.ChargeClassType, chargeClassType));

        String chargeJurisdictionType = XmlUtils.xPathStringSearch(chargeNode,
                "cscr-ext:ChargeJurisdictionCourt/jxdm51:CourtName");
        custodyStatusChangeCharge.setChargeJurisdictionTypeId((descriptionCodeLookupService
                .retrieveCode(CodeTable.JurisdictionType, chargeJurisdictionType)));

        setBondInfo(chargeNode, custodyStatusChangeCharge);

        custodyStatusChangeCharges.add(custodyStatusChangeCharge);
    }
    analyticalDatastoreDAO.saveCustodyStatusChangeCharges(custodyStatusChangeCharges);
}

From source file:org.omg.bpmn.miwg.util.xml.diff.AbstractXmlDifferenceListener.java

private boolean containsIgnorableAttributeValues(Node node) {
    NamedNodeMap attrs = node.getAttributes();
    if (attrs == null) {
        return false;
    }/* ww w. j  ava  2 s  . c o m*/

    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        if (isEmptyOrIgnorableAttributeValue(attr.getValue(), attr.getName())) {
            return true;
        }
    }
    return false;
}

From source file:org.openmeetings.cli.ConnectionPropertiesPatcher.java

static ConnectionProperties getConnectionProperties(File conf) throws Exception {
    ConnectionProperties connectionProperties = new ConnectionProperties();
    Document doc = getDocument(conf);
    Attr attr = getConnectionProperties(doc);
    String[] tokens = attr.getValue().split(",");
    processBasicProperties(tokens, null, null, connectionProperties);

    return connectionProperties;
}