/** * Caches references for parsed strings. Intended to be used for * Entiries of the geonames ontology. * @param refString the string reference * @return the {@link Reference} for the parsed String */ public static Reference getReference(String refString){ Reference ref = indexDocRefs.get(refString); if(ref == null){ ref = valueFactory.createReference(refString); indexDocRefs.put(refString, ref); } return ref; } }
private Collection<Reference> getFeatureReferences(Collection<Integer> ids){ List<Reference> refs = new ArrayList<Reference>(ids.size()); for(Integer id : ids){ if(id != null){ refs.add(vf.createReference( new StringBuilder(GeonamesConstants.GEONAMES_RESOURCE_NS) .append(id).append('/').toString())); } } return refs; }
@Override public Reference convert(Object value, ValueFactory valueFactory) { if (value == null) { return null; } if(value instanceof Reference){ return (Reference)value; } else if(value instanceof URI || value instanceof URL){ return valueFactory.createReference(value); } else { try { //For converting we only accept absolute URIs if(new URI(value.toString()).isAbsolute()){; return valueFactory.createReference(value); } else { return null; } } catch (URISyntaxException e){ return null;} } } @Override
@Override public Reference convert(Object value, ValueFactory valueFactory) { if (value == null) { return null; } if(value instanceof Reference){ return (Reference)value; } else if(value instanceof URI || value instanceof URL){ return valueFactory.createReference(value); } else { try { //For converting we only accept absolute URIs if(new URI(value.toString()).isAbsolute()){; return valueFactory.createReference(value); } else { return null; } } catch (URISyntaxException e){ return null;} } } @Override
@Override public void addReference(String field, String reference) { if(reference == null){ throw new IllegalArgumentException("NULL values are not supported by Representations"); } add(field, valueFactory.createReference(reference)); } /**
@Override public void addReference(String field, String reference) { if(reference == null){ throw new IllegalArgumentException("NULL values are not supported by Representations"); } add(field, valueFactory.createReference(reference)); } /**
@Override public Object createURI(String uri) { return getValueFactory().createReference(uri); }
@Override public Reference createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException { if (type == null) { throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null"); } if (type.equals(INDEX_TYPE)) { if (value == null) { return null; } return valueFactory.createReference(value.toString()); } else { throw new UnsupportedIndexTypeException(this, type); } } }
@Override public Reference createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException, NullPointerException { if (type == null) { throw new IllegalArgumentException("The parsed IndexDataType MUST NOT be null"); } if (type.equals(INDEX_TYPE)) { if (value == null) { return null; } return valueFactory.createReference(value.toString()); } else { throw new UnsupportedIndexTypeException(this, type); } } }
results.add(valueFactory.createReference(value.toString())); } else if(value instanceof String[]){ if(((String[])value).length>0 && ((String[])value)[0] != null){
private void addParents(Representation doc,Integer id,String[] adminCodes){ Integer[] adminIds = new Integer[5]; //now process the admin Codes (including the country at index 0) for(int i=0;i<adminCodes.length;i++){ if(adminCodes[i] != null && !adminCodes[i].equals("00")){ //00 is used to indicate not known adminIds[i] =adminCode2featureId.get(adminCodes[i]); //might also add null! } } //now get the direct parents Map<Integer,Collection<Integer>> parents = new HashMap<Integer, Collection<Integer>>(); getParents(id,parents); //add all parents (NOW done by the field mappings configuration) //doc.add(GeonamesPropertyEnum.gn_parentFeature.toString(), getFeatureReferences(parents.keySet())); //get admin hierarchy Set<Integer> parentLevel; //add country if(adminIds[0] != null){ doc.add(GeonamesPropertyEnum.gn_parentCountry.toString(), vf.createReference( new StringBuilder(GeonamesConstants.GEONAMES_RESOURCE_NS).append(adminIds[0]).append('/').toString())); parentLevel = Collections.singleton(adminIds[0]); } else { parentLevel = Collections.emptySet(); } //add the admin codes for the 4 levels parentLevel = addAdminLevel(doc, GeonamesPropertyEnum.gn_parentADM1, parents, parentLevel, adminIds[1]); parentLevel = addAdminLevel(doc, GeonamesPropertyEnum.gn_parentADM2, parents, parentLevel, adminIds[2]); parentLevel = addAdminLevel(doc, GeonamesPropertyEnum.gn_parentADM3, parents, parentLevel, adminIds[3]); parentLevel = addAdminLevel(doc, GeonamesPropertyEnum.gn_parentADM4, parents, parentLevel, adminIds[4]); } /**
Representation rep = resultIt.next(); Representation transformed = ldPath.execute(vf.createReference(rep.getId()), program);
@Override public Representation process(Representation source) { if(source == null){ return null; } backend.setRepresentation(source); Representation result = ldPath.execute(vf.createReference(source.getId()), program); if(appendMode){ Iterator<String> fields = result.getFieldNames(); while(fields.hasNext()){ String field = fields.next(); source.add(field, result.get(field)); } return source; } else { return result; } }
@Override public Representation process(Representation source) { if(source == null){ return null; } backend.setRepresentation(source); Representation result = ldPath.execute(vf.createReference(source.getId()), program); if(appendMode){ Iterator<String> fields = result.getFieldNames(); while(fields.hasNext()){ String field = fields.next(); source.add(field, result.get(field)); } return source; } else { return result; } }
/** * Internally used to create and test {@link Reference}s for the different tests * * @param refObject * the object representing the reference * @return the created {@link Reference} that can be used to perform further tests. */ private Reference testRef(Object refObject) { ValueFactory vf = getValueFactory(); Reference ref = vf.createReference(refObject); // check not null assertNotNull(ref); // check reference is not null assertNotNull(ref.getReference()); return ref; }
/** * Tests if {@link Reference} instances are correctly generated for {@link URI}. This test also depends on * the correct implementation of the {@link Reference#equals(Object)} method * * @throws URISyntaxException */ @Test public void testURIToReferenceConversion() throws URISyntaxException { String field = "urn:the.field:used.for.this.Test"; URI uri = new URI("http://www.test.org/uriTest"); ValueFactory vf = getValueFactory(); Representation rep = createRepresentation(null); // test conversion rep.add(field, uri); Iterator<Reference> refs = rep.getReferences(field); assertTrue(refs.hasNext()); assertEquals(refs.next().getReference(), uri.toString()); assertFalse(refs.hasNext()); // test multiple adds do not generate duplicate References rep.add(field, uri); assertTrue(asCollection(rep.get(field)).size() == 1); // test adding a equivalent reference rep.add(field, vf.createReference(uri.toString())); assertTrue(asCollection(rep.get(field)).size() == 1); // test removing rep.remove(field, uri); assertFalse(rep.get(field).hasNext()); }
assertTrue(asCollection(rep.get(field)).size() == 1); rep.add(field, vf.createReference(url.toString())); assertTrue(asCollection(rep.get(field)).size() == 1);
vf.createReference(siteConfiguration.getAttributionUrl())); if(license.getUrl() != null){ siteMetadata.put(NamespaceEnum.cc.getNamespace()+"license", vf.createReference(license.getUrl())); } else if(license.getText() != null){ siteMetadata.put(NamespaceEnum.cc.getNamespace()+"license",
vf.createReference(siteConfiguration.getAttributionUrl())); if(license.getUrl() != null){ siteMetadata.put(NamespaceEnum.cc.getNamespace()+"license", vf.createReference(license.getUrl())); } else if(license.getText() != null){ siteMetadata.put(NamespaceEnum.cc.getNamespace()+"license",
ValueFactory vf = getValueFactory(); Representation rep = createRepresentation(null); Reference ref = vf.createReference("http://www.test.org/test"); Text text = vf.createText("test", "en"); Integer i = 42;