Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Firestar Software, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Firestar Software, Inc. - initial API and implementation
 *
 * Author:
 *     Gabriel Oancea
 *
 *******************************************************************************/

import org.w3c.dom.*;

public class Main {
    /**
     * Get the value of the specified attribute as an integer. If the element has no attribute by the specified name, 0
     * is returned.
     * 
     * @param root The element.
     * @param attrName The attribute name.
     * @return The value of the attribute, if it exists, 0 otherwise.
     */
    public static int getAttrInt(Element root, String attrName) {
        if (root.hasAttribute(attrName))
            return Integer.valueOf(root.getAttribute(attrName)).intValue();
        return 0;
    }
}