1 61 62 63 package org.jaxen; 64 65 import java.io.Serializable ; 66 import java.util.HashMap ; 67 import java.util.Iterator ; 68 import java.util.Map ; 69 70 74 public class SimpleNamespaceContext implements NamespaceContext, Serializable 75 { 76 77 private Map namespaces; 79 80 83 public SimpleNamespaceContext() 84 { 85 this.namespaces = new HashMap (); 86 } 87 88 97 public SimpleNamespaceContext(Map namespaces) 98 { 99 this.namespaces = new HashMap (namespaces); 102 } 103 104 116 public void addElementNamespaces( Navigator nav, Object element ) 117 throws UnsupportedAxisException 118 { 119 Iterator namespaceAxis = nav.getNamespaceAxisIterator( element ); 120 121 while ( namespaceAxis.hasNext() ) { 122 Object namespace = namespaceAxis.next(); 123 String prefix = nav.getNamespacePrefix( namespace ); 124 String uri = nav.getNamespaceStringValue( namespace ); 125 if ( translateNamespacePrefixToUri(prefix) == null ) { 126 addNamespace( prefix, uri ); 127 } 128 } 129 } 130 131 138 public void addNamespace(String prefix, String URI) 139 { 140 this.namespaces.put( prefix, URI ); 141 } 142 143 public String translateNamespacePrefixToUri(String prefix) 144 { 145 if ( this.namespaces.containsKey( prefix ) ) 146 { 147 return (String ) this.namespaces.get( prefix ); 148 } 149 150 return null; 151 } 152 } 153 | Popular Tags |