private void check(String string) { IRI iri = factory.create(string); if (iri.hasViolation(true)) { System.out.println("n: " + string); Iterator<Violation> it = iri.violations(true); while (it.hasNext()) { Violation v = it.next(); System.out.println(v.getLongMessage()); } } else { System.out.println("y: " + string); } }
private void check(String string) { IRI iri = factory.create(string); if (iri.hasViolation(true)) { System.out.println("n: " + string); Iterator<Violation> it = iri.violations(true); while (it.hasNext()) { Violation v = it.next(); System.out.println(v.getLongMessage()); } } else { System.out.println("y: " + string); } }
protected IRI throwAnyErrors(IRI rslt) throws IRIException { if (rslt.hasViolation(false)) { throw new IRIImplException(rslt.violations(false).next()); // Iterator it = rslt.exceptions(); // while (it.hasNext()){ // Violation v = (Violation)it.next(); // if (v.isError()) // throw new IRIImplException(v); // } } return rslt; }
protected IRI throwAnyErrors(IRI rslt) throws IRIException { if (rslt.hasViolation(false)) { throw new IRIImplException(rslt.violations(false).next()); // Iterator it = rslt.exceptions(); // while (it.hasNext()){ // Violation v = (Violation)it.next(); // if (v.isError()) // throw new IRIImplException(v); // } } return rslt; }
private void check(String string) { IRI iri = factory.create(string); if (iri.hasViolation(true)) { System.out.println("n: " + string); Iterator<Violation> it = iri.violations(true); while (it.hasNext()) { Violation v = it.next(); System.out.println(v.getLongMessage()); } } else { System.out.println("y: " + string); } }
protected IRI throwAnyErrors(IRI rslt) throws IRIException { if (rslt.hasViolation(false)) { throw new IRIImplException(rslt.violations(false).next()); // Iterator it = rslt.exceptions(); // while (it.hasNext()){ // Violation v = (Violation)it.next(); // if (v.isError()) // throw new IRIImplException(v); // } } return rslt; } // public IRI create(IRI i) {
private boolean checkURI( String uri ) { IRIFactory factory = IRIFactory.jenaImplementation(); IRI iri = factory.create( uri ); if (iri.hasViolation(false) ) { log.error("Bad URI: "+uri); log.error( "Only well-formed absolute URIrefs can be included in RDF/XML output: " + iri.violations(false).next().getShortMessage()); return true; } else { return false; } }
public static void main(String... args) { //IRIFactory iriFactory = IRIFactory.iriImplementation() ; IRIFactory iriFactory = IRIResolver.iriFactory() ; boolean first = true ; for ( String iriStr : args ) { if ( iriStr.startsWith("<") && iriStr.endsWith(">") ) iriStr = iriStr.substring(1, iriStr.length()-1) ; if ( ! first ) System.out.println() ; first = false ; IRI iri = iriFactory.create(iriStr) ; System.out.println(iriStr + " ==> "+iri) ; if ( iri.isRelative() ) System.out.println("Relative: "+iri.isRelative()) ; Iterator<Violation> vIter = iri.violations(true) ; for ( ; vIter.hasNext() ; ) { System.out.println(vIter.next().getShortMessage()) ; } } }
/** * Throw any exceptions resulting from IRI. * * @param iri * @return iri */ private static IRI exceptions(IRI iri) { if (!showExceptions) return iri; if (!iri.hasViolation(false)) return iri; String msg = iri.violations(false).next().getShortMessage(); throw new RiotException(msg); }
/** * Throw any exceptions resulting from IRI. * * @param iri * @return iri */ private static IRI exceptions(IRI iri) { if (!showExceptions) return iri ; if (!iri.hasViolation(false)) return iri ; String msg = iri.violations(false).next().getShortMessage() ; throw new RiotException(msg) ; }
public static void main(String[] args) { IRIFactory iriFactory = IRIFactory.iriImplementation() ; iriFactory = IRIResolver.iriFactory ; boolean first = true ; for ( String iriStr : args ) { if ( ! first ) System.out.println() ; first = false ; IRI iri = iriFactory.create(iriStr) ; System.out.println(iriStr + " ==> "+iri) ; if ( iri.isRelative() ) System.out.println("Relative: "+iri.isRelative()) ; Iterator<Violation> vIter = iri.violations(true) ; for ( ; vIter.hasNext() ; ) { System.out.println(vIter.next().getShortMessage()) ; } } }
/** Answer the argument URI, but if we demandGoodURIs and it isn't good, throw a JenaException that encapsulates a MalformedURIException. There doesn't appear to be a convenient URI.checkGood() kind of method, alas. */ private String checkURI( String uri ) { if (demandGoodURIs) { IRI iri = factory.create( uri ); if (iri.hasViolation(false) ) throw new BadURIException( "Only well-formed absolute URIrefs can be included in RDF/XML output: " + (iri.violations(false).next()).getShortMessage()); } return uri; }
/** Answer the argument URI, but if we demandGoodURIs and it isn't good, throw a JenaException that encapsulates a MalformedURIException. There doesn't appear to be a convenient URI.checkGood() kind of method, alas. */ private String checkURI( String uri ) { if (demandGoodURIs) { IRI iri = factory.create( uri ); if (iri.hasViolation(false) ) throw new BadURIException( "Only well-formed absolute URIrefs can be included in RDF/XML output: " + (iri.violations(false).next()).getShortMessage()); } return uri; }
/** Answer the argument URI, but if we demandGoodURIs and it isn't good, throw a JenaException that encapsulates a MalformedURIException. There doesn't appear to be a convenient URI.checkGood() kind of method, alas. */ private String checkURI( String uri ) { if (demandGoodURIs) { IRI iri = factory.create( uri ); if (iri.hasViolation(false) ) throw new BadURIException( "Only well-formed absolute URIrefs can be included in RDF/XML output: " + (iri.violations(false).next()).getShortMessage()); } return uri; }
/** * Checks a URI for validity. Jena models can store invalid URIs, but this causes RDF/XML output serialization to fail. * @param uri URI * @return null if URI is good, otherwise an error message String */ protected String checkURI( String uri ) { IRIFactory factory = IRIFactory.jenaImplementation(); IRI iri = factory.create( uri ); if (iri.hasViolation(false) ) { String errorStr = ("Bad URI: "+ uri + "\nOnly well-formed absolute URIrefs can be included in RDF/XML output: " + (iri.violations(false).next()).getShortMessage()); return errorStr; } else { return null; } }
private String checkURIForValidity(String uriStr) { uriStr = (uriStr == null) ? " " : uriStr; IRI iri = IRIFactory.jenaImplementation().create(uriStr); if (iri.hasViolation(false)) { return (iri.violations(false).next()).getShortMessage() + " "; } try { Resource res = ResourceFactory.createResource(uriStr); if (res.getLocalName().matches("\\d+")) { return "Localname must contain at least one non-numeric " + "character. Please enter another URI. "; } } catch (Exception e) { return "Not a valid URI. Please enter another URI. "; } return null; }
protected static void checkURI(XMLHandler forErrors, Taint taintMe, IRI rslt) throws SAXParseException { if (rslt.hasViolation(false)) { Iterator<Violation> it = rslt.violations(false); while (it.hasNext()) { Violation irie = it.next(); // if (irie.getViolationCode() == // ViolationCodes.REQUIRED_COMPONENT_MISSING) String msg = irie.getShortMessage(); if (irie.getViolationCode() == ViolationCodes.REQUIRED_COMPONENT_MISSING && irie.getComponent() == IRIComponents.SCHEME) { if (!forErrors.allowRelativeURIs()) forErrors.warning(taintMe, WARN_RELATIVE_URI, "Relative URIs are not permitted in RDF: specifically <"+rslt.toString()+">"); } else forErrors.warning(taintMe, WARN_MALFORMED_URI, "Bad URI: " + msg); } } }
protected static void checkURI(XMLHandler forErrors, Taint taintMe, IRI rslt) throws SAXParseException { if (rslt.hasViolation(false)) { Iterator<Violation> it = rslt.violations(false); while (it.hasNext()) { Violation irie = it.next(); // if (irie.getViolationCode() == // ViolationCodes.REQUIRED_COMPONENT_MISSING) String msg = irie.getShortMessage(); if (irie.getViolationCode() == ViolationCodes.REQUIRED_COMPONENT_MISSING && irie.getComponent() == IRIComponents.SCHEME) { if (!forErrors.allowRelativeURIs()) forErrors.warning(taintMe, WARN_RELATIVE_URI, "Relative URIs are not permitted in RDF: specifically <"+rslt.toString()+">"); } else forErrors.warning(taintMe, WARN_MALFORMED_URI, "Bad URI: " + msg); } } }
public void testURI(String uri, boolean ok) { IRI ref = factory.create(uri); if (ok && ref.hasViolation(false)) { Violation v = ref.violations(false).next(); fail("<" + uri + "> is expected to be a URI, but: "+v.getLongMessage()); } assertEquals("<" + uri + "> is"+(ok?" ":" not ")+"a URI", ok, !ref.hasViolation(false)); } public void testNoDomain() {
public void testURI(String uri, boolean ok) { IRI ref = factory.create(uri); if (ok && ref.hasViolation(false)) { Violation v = ref.violations(false).next(); fail("<" + uri + "> is expected to be a URI, but: "+v.getLongMessage()); } assertEquals("<" + uri + "> is"+(ok?" ":" not ")+"a URI", ok, !ref.hasViolation(false)); } public void testNoDomain() {