protected NameClass getNameClass( String maybeQName, boolean handleAsAttribute ) {
String[] s = splitQName(maybeQName);
if(s[0].length()==0 && handleAsAttribute )
// if this is an attribute and unprefixed, it is local to the element.
return new SimpleNameClass(s[0],s[1]);
Set vec = (Set)namespaces.get(s[0]/*uri*/);
if(vec==null) {
if(s[0].equals(""))
// this DTD does not attempt to use namespace.
// this is OK and we assume anonymous namespace.
return new SimpleNameClass("",s[1]);
// we found element name like "html:p" but
// we haven't see any "xmlns:html" attribute declaration.
// this is considered as an error for MSV.
controller.error( new Locator[]{locator},
Localizer.localize( ERR_UNDECLARED_PREFIX, s[0] ), null );
// recover by returning something
return new LocalNameClass( s[1]/*local*/ );
}
if( vec.contains(ABANDON_URI_SNIFFING) ) {
// System.out.println("sniffing abandoned for "+s[0]);
// possibly multiple URI can be assigned.
// so fall back to use LocalNameClass to at least check local part.
return new LocalNameClass( s[1] );
}
// create choice of all possible namespace, and
// return it.
String[] candidates = (String[])vec.toArray(new String[vec.size()]);
NameClass nc = new SimpleNameClass( candidates[0], s[1] );
// System.out.println("candidate for "+s[0]+" is "+ candidates[0] );
for( int i=1; i<vec.size(); i++ ) {
nc = new ChoiceNameClass( nc,
new SimpleNameClass( candidates[i], s[1] ) );
// System.out.println("candidate for "+s[0]+" is "+ candidates[i] );
}
return nc;
}