All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.windup.metadata.util.NamespaceMapContext Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2013 Red Hat, Inc. and/or its affiliates.
 *  
 *  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:
 *      Brad Davis - [email protected] - Initial API and implementation
*/
package org.jboss.windup.metadata.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.NamespaceContext;

public class NamespaceMapContext implements NamespaceContext {
	private final Map context = new HashMap();

	public NamespaceMapContext() {

	}

	public NamespaceMapContext(Map in) {
		if (in != null && in.size() > 0) {
			context.putAll(in);
		}
	}

	public String getNamespaceURI(String prefix) {
		return context.get(prefix);
	}

	public String getPrefix(String namespaceURI) {
		Iterator prefixIterator = getPrefixes(namespaceURI);

		if (prefixIterator.hasNext()) {
			return getPrefixes(namespaceURI).next();
		}
		return null;
	}

	public Iterator getPrefixes(String namespaceURI) {
		List prefixes = new LinkedList();

		for (String key : context.keySet()) {
			// slow but works.
			if (namespaceURI.equals(context.get(key))) {
				prefixes.add(key);
			}
		}

		return prefixes.iterator();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy