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

net.sf.xolite.dom.DomPrefixResolver Maven / Gradle / Ivy

Go to download

This project provides a lightweight framework to serialize/deserialize (or marshall/unmarshall) java objects into XML. The implementation is based on standard SAX (Simple Api for Xml) but it follows a original approach based on the strong data encapsulation paradigm of Object Oriented (OO) programming.

The newest version!
/*-------------------------------------------------------------------------
 Copyright 2006 Olivier Berlanger

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -------------------------------------------------------------------------*/
package net.sf.xolite.dom;


import java.util.Iterator;

import javax.xml.namespace.NamespaceContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Node;


/**
 * Implementation of the NamespaceContext interface based on a DOM node. 
* You give it a DOM node and it creates the namespace context of this Node = all the namespaces declared in the path from this * node to the document root. */ public class DomPrefixResolver implements NamespaceContext { private static Log log = LogFactory.getLog(DomPrefixResolver.class); /** Node used to define the namespace context. */ private Node baseNode; public DomPrefixResolver(Node base) { if (base == null) throw new IllegalArgumentException("Base node cannot be null"); baseNode = base; } public void setNode(Node newBase) { if (newBase == null) throw new IllegalArgumentException("Base node cannot be null"); baseNode = newBase; } /** * Get namespace URI corresponding to the given prefix. * * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String) */ public String getNamespaceURI(String prefix) { if (log.isDebugEnabled()) log.debug("Prefix mapping:" + prefix + " --> " + DomUtils.getDefinedUri(baseNode, prefix)); return DomUtils.getDefinedUri(baseNode, prefix); } /** * Get the first perfix mapped to the given namespace. * * @see javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String) */ public String getPrefix(String namespaceURI) { return DomUtils.getDefinedPerfix(baseNode, namespaceURI); } /** * Get all the prefixs mapped to the given namespace. * * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) */ public Iterator getPrefixes(String namespaceURI) { return DomUtils.getDefinedPerfixes(baseNode, namespaceURI).iterator(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy