Example usage for org.w3c.dom Element hasAttribute

List of usage examples for org.w3c.dom Element hasAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element hasAttribute.

Prototype

public boolean hasAttribute(String name);

Source Link

Document

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Usage

From source file:de.erdesignerng.model.serializer.xml50.XMLSubjectAreaSerializer.java

@Override
public void deserialize(Model aModel, Document aDocument) {

    NodeList theElements = aDocument.getElementsByTagName(SUBJECTAREA);
    for (int i = 0; i < theElements.getLength(); i++) {
        Element theElement = (Element) theElements.item(i);

        SubjectArea theSubjectArea = new SubjectArea();
        deserializeProperties(theElement, theSubjectArea);

        theSubjectArea.setColor(new Color(Integer.parseInt(theElement.getAttribute(COLOR))));
        if (theElement.hasAttribute(VISIBLE)) {
            theSubjectArea.setVisible(TRUE.equals(theElement.getAttribute(VISIBLE)));
        }/*from  ww w  .ja v a  2s. c  o m*/

        if (theElement.hasAttribute(EXPANDED)) {
            theSubjectArea.setExpanded(TRUE.equals(theElement.getAttribute(EXPANDED)));
        }

        NodeList theTables = theElement.getElementsByTagName(ITEM);
        for (int j = 0; j < theTables.getLength(); j++) {

            Element theItemElement = (Element) theTables.item(j);
            String theTableId = theItemElement.getAttribute(TABLEREFID);
            String theViewId = theItemElement.getAttribute(VIEWREFID);
            String theCommentId = theItemElement.getAttribute(COMMENTREFID);

            if (!StringUtils.isEmpty(theTableId)) {
                Table theTable = aModel.getTables().findBySystemId(theTableId);
                if (theTable == null) {
                    throw new IllegalArgumentException("Cannot find table with id " + theTableId);
                }

                theSubjectArea.getTables().add(theTable);
            }

            if (!StringUtils.isEmpty(theViewId)) {
                View theView = aModel.getViews().findBySystemId(theViewId);
                if (theView == null) {
                    throw new IllegalArgumentException("Cannot find view with id " + theViewId);
                }

                theSubjectArea.getViews().add(theView);
            }

            if (!StringUtils.isEmpty(theCommentId)) {
                Comment theComment = aModel.getComments().findBySystemId(theCommentId);
                if (theComment == null) {
                    throw new IllegalArgumentException("Cannot find comment with id " + theCommentId);
                }

                theSubjectArea.getComments().add(theComment);
            }
        }

        aModel.getSubjectAreas().add(theSubjectArea);
    }
}

From source file:org.devefx.httpmapper.spring.config.ListenersBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(),
            parserContext.extractSource(element));
    parserContext.pushContainingComponent(compDefinition);

    RuntimeBeanReference pathMatcherRef = null;
    if (element.hasAttribute("path-matcher")) {
        pathMatcherRef = new RuntimeBeanReference(element.getAttribute("path-matcher"));
    }//  w ww  .ja v a 2 s.co  m

    List<Element> listeners = DomUtils.getChildElementsByTagName(element, "bean", "ref", "listener");
    for (Element listener : listeners) {
        RootBeanDefinition mappedListenerDef = new RootBeanDefinition(MappedListener.class);
        mappedListenerDef.setSource(parserContext.extractSource(listener));
        mappedListenerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        ManagedList<String> includePatterns = null;
        ManagedList<String> excludePatterns = null;
        Object listenerBean;
        if ("listener".equals(listener.getLocalName())) {
            includePatterns = getIncludePatterns(listener, "mapping");
            excludePatterns = getIncludePatterns(listener, "exclude-mapping");
            Element beanElem = DomUtils.getChildElementsByTagName(listener, "bean", "ref").get(0);
            listenerBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null);
        } else {
            listenerBean = parserContext.getDelegate().parsePropertySubElement(listener, null);
        }
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns);
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns);
        mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(2, listenerBean);

        if (pathMatcherRef != null) {
            mappedListenerDef.getPropertyValues().add("pathMatcher", pathMatcherRef);
        }

        String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedListenerDef);
        parserContext.registerComponent(new BeanComponentDefinition(mappedListenerDef, beanName));
    }

    parserContext.popAndRegisterContainingComponent();
    return null;
}

From source file:eionet.gdem.conversion.odf.ODFSpreadsheetAnalyzer.java

/**
 * Get the content from p:text node or officde:value attribute - cell value
 *
 * @param cellElement//  w ww.j  ava 2s.co m
 *            the first element of <code>&lt;table:table-cell&gt;</code> element.
 *
 * @return content inside text:p tag
 */
protected String processCell(Element cellElement) {
    String cellValue = null;
    if (cellElement.hasAttribute(officeNamespace + "value-type")) {
        String valueType = cellElement.getAttribute(officeNamespace + "value-type");
        if ("date".equals(valueType)) {
            if (cellElement.hasAttribute(officeNamespace + "date-value")) {
                cellValue = cellElement.getAttribute(officeNamespace + "date-value");
            }
        } else if ("time".equals(valueType)) {
            if (cellElement.hasAttribute(officeNamespace + "time-value")) {
                cellValue = cellElement.getAttribute(officeNamespace + "time-value");
            }
        } else {
            if (cellElement.hasAttribute(officeNamespace + "value")) {
                cellValue = cellElement.getAttribute(officeNamespace + "value");
            }
        }
    }
    // get value from p:text
    if (Utils.isNullStr(cellValue) && cellElement.hasChildNodes()) {
        Element ptext = (Element) cellElement.getFirstChild();
        if (ptext != null && ptext.hasChildNodes()) {
            cellValue = ptext.getFirstChild().getNodeValue();
        }
    }
    return cellValue;
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

public static double downloadVersionXmlFile(Context c, boolean checkOnly) {
    if (!isOnline(c))
        return -1;
    try {/*w w w  .j  a v a 2  s.  c  o  m*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document dom = null;
        Element root = null;
        URLConnection connection = getVersionUrl(c).openConnection();
        connection.setConnectTimeout(CONNECTION_TIMEOUT);
        connection.setReadTimeout(READ_TIMEOUT);
        dom = builder.parse(connection.getInputStream());
        root = dom.getDocumentElement();
        root.normalize();
        double version = Double.valueOf(root.getAttribute("latest"));
        if (MinistroService.instance().getVersion() >= version)
            return MinistroService.instance().getVersion();

        if (checkOnly)
            return version;
        String supportedFeatures = null;
        if (root.hasAttribute("features"))
            supportedFeatures = root.getAttribute("features");
        connection = getLibsXmlUrl(c, version + deviceSupportedFeatures(supportedFeatures)).openConnection();
        File file = new File(MinistroService.instance().getVersionXmlFile());
        file.delete();
        FileOutputStream outstream = new FileOutputStream(MinistroService.instance().getVersionXmlFile());
        InputStream instream = connection.getInputStream();
        byte[] tmp = new byte[2048];
        int downloaded;
        while ((downloaded = instream.read(tmp)) != -1)
            outstream.write(tmp, 0, downloaded);

        outstream.close();
        MinistroService.instance().refreshLibraries(false);
        return version;
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:org.jdal.beans.ServiceBeanDefinitionParser.java

/**
 * {@inheritDoc}//from   w  w w.j av  a2s . co m
 */
public AbstractBeanDefinition parse(Element element, ParserContext parserContext) {

    // default dao and service classes
    String daoClassName = JPA_DAO_CLASS_NAME;
    String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME;
    String name = null;
    boolean declareService = false;

    if (element.hasAttribute(DAO_CLASS))
        daoClassName = element.getAttribute(DAO_CLASS);

    if (element.hasAttribute(SERVICE_CLASS)) {
        serviceClassName = element.getAttribute(SERVICE_CLASS);
        declareService = true;
    }

    if (element.hasAttribute(NAME))
        name = element.getAttribute(NAME);

    if (element.hasAttribute(ENTITY)) {
        String className = element.getAttribute(ENTITY);
        if (name == null) {
            name = StringUtils
                    .uncapitalize(StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR));
        }
        parserContext.pushContainingComponent(
                new CompositeComponentDefinition(name, parserContext.extractSource(element)));

        // Dao
        BeanDefinitionBuilder daoBuilder = BeanDefinitionBuilder.genericBeanDefinition(daoClassName);
        NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA);
        if (nl.getLength() > 0) {
            ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength());
            for (int i = 0; i < nl.getLength(); i++) {
                Element e = (Element) nl.item(i);
                builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER)));
            }
            daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders);
        }

        daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null));
        daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        String daoBeanName;

        if (declareService) {
            // use dao suffix
            daoBeanName = name + DAO_SUFFIX;
            registerBeanDefinition(parserContext, daoBuilder, daoBeanName);

            // register service wrapper
            String serviceBeanName = name + SERVICE_SUFFIX;
            BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(serviceClassName);
            serviceBuilder.addPropertyReference("dao", daoBeanName);
            registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName);
        } else {
            // use service suffix for dao and declare an alias with dao suffix for compatibility with older api.
            daoBeanName = name + SERVICE_SUFFIX;
            String[] aliases = new String[] { name + DAO_SUFFIX };
            BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(),
                    daoBeanName, aliases);
            parserContext.registerBeanComponent(bcd);
        }

        parserContext.popAndRegisterContainingComponent();
    }

    return null;
}

From source file:biz.webgate.domino.mywebgate.util.URLFetcher.java

public boolean fetchURL() {
    try {// w  w  w  .  ja v  a 2 s .  c o  m
        HttpClient httpClient = new DefaultHttpClient();

        HttpGet httpGet = new HttpGet(m_URL);
        httpGet.addHeader("Content-Type", "text/html; charset=utf-8");
        HttpResponse response = httpClient.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();

        String strBaseURL = m_URL;
        if (strBaseURL.lastIndexOf("/") > 8) {
            strBaseURL = strBaseURL.substring(0, strBaseURL.lastIndexOf("/"));
        }

        Document doc = null;
        if (statusCode == 200) {
            m_ThumbNails.add("no image");
            HttpEntity entity = response.getEntity();
            // String content = EntityUtils.toString(entity);

            try {
                DOMParser dpHTML = new DOMParser();
                dpHTML.setProperty("http://cyberneko.org/html/properties/default-encoding", "utf-8");
                // dpHTML.parse(new
                // InputSource(EntityUtils.toString(entity)));
                dpHTML.parse(new InputSource(entity.getContent()));
                doc = dpHTML.getDocument();
                NodeList ndlMet = doc.getElementsByTagName("meta");
                NodeList ndlTitle = doc.getElementsByTagName("title");
                NodeList ndlImage = doc.getElementsByTagName("img");
                check4OpenGraphTags(ndlMet, strBaseURL);
                if (m_Description.equals("")) {
                    for (int nCounter = 0; nCounter < ndlMet.getLength(); nCounter++) {
                        Element elCurrent = (Element) ndlMet.item(nCounter);
                        if ("description".equalsIgnoreCase(elCurrent.getAttribute("name"))) {
                            if (elCurrent.hasAttribute("content")) {
                                m_Description = elCurrent.getAttribute("content");
                                nCounter = ndlMet.getLength();
                            }
                        }
                    }
                }
                if (ndlTitle.getLength() > 0 && m_Title.equals("")) {
                    m_Title = ((Element) ndlTitle.item(0)).getFirstChild().getNodeValue();
                }
                for (int nCounter = 0; nCounter < ndlImage.getLength(); nCounter++) {
                    Element elCurrent = (Element) ndlImage.item(nCounter);
                    if (elCurrent.hasAttribute("src")) {
                        String strImage = elCurrent.getAttribute("src");
                        if (ndlImage.getLength() > 20 && elCurrent.hasAttribute("height")) {
                            String strHeight = elCurrent.getAttribute("height");
                            strHeight.replace("px", "");
                            try {
                                int nHeight = Integer.parseInt(strHeight);
                                if (nHeight > 200) {
                                    strImage = null;
                                }
                            } catch (Exception e) {
                                // TODO: handle exception
                            }
                        }
                        if (strImage != null) {
                            strImage = checkIMAGEURL(strImage, strBaseURL);

                            if (!m_ThumbNails.contains(strImage)) {
                                m_ThumbNails.add(strImage);
                            }
                        }
                    }
                }
            } catch (IllegalStateException e) {
                m_Error = e.getLocalizedMessage();
                m_Exception = e;
                e.printStackTrace();
            } catch (SAXException e) {
                m_Error = e.getLocalizedMessage();
                m_Exception = e;
                e.printStackTrace();
            } finally {
                httpClient.getConnectionManager().shutdown();
            }

        }

    } catch (Exception e) {
        m_Error = e.getLocalizedMessage();
        m_Exception = e;
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:org.jdal.vaadin.beans.ColumnBeanDefinitionParser.java

/**
 * {@inheritDoc}/*from   ww  w  .j a va2 s.c  om*/
 */
@Override
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
    beanDefinition.setScope("prototype");

    BeanDefinitionUtils.addPropertyReferenceIfNeeded(beanDefinition, element, COLUMN_GENERATOR_ATTRIBUTE);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(beanDefinition, element, RENDERER_ATTRIBUTE);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(beanDefinition, element, PROPERTY_EDITOR_ATTRIBUTE);

    if (element.hasAttribute(ALIGN_ATTRIBUTE))
        beanDefinition.addPropertyValue(ALIGN_ATTRIBUTE, getAlignValue(element.getAttribute(ALIGN_ATTRIBUTE)));
}