results.add(valueFactory.createReference(value.toString())); } else if(value instanceof String[]){ if(((String[])value).length>0 && ((String[])value)[0] != null){ results.add(valueFactory.createText(((String[])value)[0], ((String[])value).length>1?((String[])value)[1]:null)); } else {
/** * Creates a {@link Representation} instance by using the parsed ID or * {@link RepresentationTest#DEFAULT_REPRESENTATION_ID} if <code>null</code> is parsed as ID. * * @param id * The ID or <code>null</code> to use the default ID * @return the Representation. */ protected Representation createRepresentation(String id) { if (id == null) { id = DEFAULT_REPRESENTATION_ID; } return getValueFactory().createRepresentation(id); }
/** * 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; } }
@Override public Text convert(Object value, ValueFactory valueFactory) { if (value == null) { return null; } if(value instanceof Text){ return (Text)value; } else if(value instanceof String){ return valueFactory.createText(value); } else { //do not convert other values return null; } } @Override
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 Text convert(Object value, ValueFactory valueFactory) { if (value == null) { return null; } if(value instanceof Text){ return (Text)value; } else if(value instanceof String){ return valueFactory.createText(value); } else { //do not convert other values return null; } } @Override
@Override public Representation process(Representation source) { if(mapper == null){ throw new IllegalStateException("The mapper is not initialised. One must call setConfiguration to configure the FieldMapper!"); } if(source == null){ return null; } else { return mapper.applyMappings(source, vf.createRepresentation(source.getId()), vf); } } /**
results.add(valueFactory.createReference(value.toString())); } else if(value instanceof String[]){ if(((String[])value).length>0 && ((String[])value)[0] != null){ results.add(valueFactory.createText(((String[])value)[0], ((String[])value).length>1?((String[])value)[1]:null)); } else {
@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 addNaturalText(String field, String text, String... languages) { if(text == null){ throw new IllegalArgumentException("NULL was parsed for the text! NULL values are not supported by Representations"); } if(languages == null || languages.length<1){ //if no language is parse add the default lanugage! add(field,valueFactory.createText(text, null)); } else { for(String lang : languages){ add(field,valueFactory.createText(text, lang)); } } }
@Override public Representation process(Representation source) { if(mapper == null){ throw new IllegalStateException("The mapper is not initialised. One must call setConfiguration to configure the FieldMapper!"); } if(source == null){ return null; } else { return mapper.applyMappings(source, vf.createRepresentation(source.getId()), vf); } } /**
if(siteConfiguration.getAttribution() != null){ siteMetadata.put(NamespaceEnum.cc.getNamespace()+"attributionName", vf.createText(siteConfiguration.getAttribution())); 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.createText(license.getText())); vf.createText(license.getName()));
@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 addNaturalText(String field, String text, String... languages) { if(text == null){ throw new IllegalArgumentException("NULL was parsed for the text! NULL values are not supported by Representations"); } if(languages == null || languages.length<1){ //if no language is parse add the default lanugage! add(field,valueFactory.createText(text, null)); } else { for(String lang : languages){ add(field,valueFactory.createText(text, lang)); } } }
protected Representation create(String id, boolean store) throws YardException { Representation r; if (store) { r = getYard().create(id); } else if (id != null && !id.isEmpty()) { r = getYard().getValueFactory().createRepresentation(id); } else { throw new IllegalArgumentException("If store is FALSE the id MUST NOT be NULL nor EMPTY!"); } representationIds.add(r.getId()); return r; }
if(siteConfiguration.getAttribution() != null){ siteMetadata.put(NamespaceEnum.cc.getNamespace()+"attributionName", vf.createText(siteConfiguration.getAttribution())); 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.createText(license.getText())); vf.createText(license.getName()));
@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 createLiteral(String content) { return getValueFactory().createText(content); }
/** * Used to create the Representation the first time * {@link #getRepresentation()} is called for the current entity. The * information for the Representation are already stored in {@link #data} */ private Representation createRepresentation() { final String uri; if(currentEntity.isBlank()){ //STANBOL-765: support bNodes StringBuilder sb = new StringBuilder(bnodePrefix); sb.append(currentEntity.getBlankNodeId().getLabelString()); uri = sb.toString(); } else { uri = currentEntity.getURI(); } Representation representation = vf.createRepresentation(uri); Iterator<Node> it = data.iterator(); while(it.hasNext()){ //data contains field,value pairs //because of that we call two times next for String field = it.next().getURI(); //the field Node value = it.next();//and the value processValue(value, representation, field); } return representation; } }
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; Double d = Math.PI;