/** Checks that a prefix is "legal" - it must be a valid XML NCName. */ private void checkLegal( String prefix ) { if (prefix.length() > 0 && !XMLChar.isValidNCName( prefix )) throw new PrefixMapping.IllegalPrefixException( prefix ); }
@Override public PrefixMapping setNsPrefix(String prefix, String uri) { checkUnlocked(); // TODO support an empty prefix for the default namespace if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix)) // required by AbstractTestPrefixMapping#testCheckNames() { throw new PrefixMapping.IllegalPrefixException(prefix); } if (uri == null) // required by AbstractTestPrefixMapping#testNullURITrapped() // TODO: why not an IllegalArgumentException? { throw new NullPointerException("null URIs are prohibited as arguments to setNsPrefix"); } try { getGraph().getConnection().setNamespace(prefix, uri); } catch (RepositoryException e) { throw new RuntimeException(e); } return this; }
/** * Checks that a prefix is "legal" - it must be a valid XML NCName or "". XML rules * for RDF/XML output. * <p> * This is a recurring user question - why does {@code Resource.getNamespace}, * {@code Resource.getLocalname} not abbreviate when it is legal Turtle. * <p> * Answer - legacy for RDF/XML. * <p> * See also {@link #qnameFor}. */ public static void checkLegalPrefix(String prefix) { if ( prefix == null ) throw new PrefixMapping.IllegalPrefixException("null for prefix"); if ( prefix.length() > 0 && !XMLChar.isValidNCName(prefix) ) throw new PrefixMapping.IllegalPrefixException(prefix); }
/** Checks that a prefix is "legal" - it must be a valid XML NCName. */ private void checkLegal( String prefix ) { if (prefix.length() > 0 && !XMLChar.isValidNCName( prefix )) throw new PrefixMapping.IllegalPrefixException( prefix ); }