Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 Linguine Maps Programmatic Visualization Library
 Copyright (C) 2005 Pavel Simakov
 http://www.softwaresecretweapons.com
    
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
    
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
    
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

import org.w3c.dom.Document;

public class Main {
    public static String qualifyName(Document doc, String name) {

        // parse name into local name and prefix pre:local
        int idx = name.indexOf(":");
        String localName = name;
        String pre = null;
        if (idx != -1 && idx > 0) {
            localName = name.substring(idx + 1);
            pre = name.substring(0, idx);
        }

        // if no prefix was specified we use document namespaceURI
        if (pre == null) {
            String ns = doc.getDocumentElement().getAttribute("targetNamespace");
            if (ns == null || "".equals(ns)) {
                return doc.getDocumentElement().getNamespaceURI() + ":" + localName;
            } else {
                return ns + ":" + localName;
            }
        }

        // resolve prefix into namespace URI
        String ns = doc.getDocumentElement().getAttribute("xmlns:" + pre);
        if (ns == null || "".equals(ns)) {
            throw new RuntimeException("Bad namespace specified in " + name);
        }

        return ns + ":" + localName;
    }
}