Refine search
RenderletRendererImpl(IRI renderingSpecification, org.apache.clerezza.rdf.utils.graphnodeprovider.GraphNodeProvider graphNodeProvider, Renderlet renderlet, MediaType mediaType, RendererFactory rendererFactory, BundleContext bundleContext) { this.graphNodeProvider = graphNodeProvider; this.renderlet = renderlet; this.mediaType = mediaType; this.rendererFactory = rendererFactory; if (renderingSpecification != null) { try { renderSpecUri = new URI(renderingSpecification.getUnicodeString()); } catch (URISyntaxException ex) { throw new WebApplicationException(ex); } } this.bundleContext = bundleContext; }
@Override public boolean matches(Triple t) { return objectUri != null && t.getPredicate().equals(predicateUri) && t.getObject().equals(objectUri) ; } }
private <R extends RDFTerm> R toSourceRDFTerm(final R targetRDFTerm) { if (targetRDFTerm instanceof IRI) { final IRI sourceIRI = (IRI) targetRDFTerm; if (sourceIRI.getUnicodeString().startsWith(targetPrefix)) { final String uriRest = sourceIRI.getUnicodeString() .substring(targetPrefixLength); return (R) new IRI(sourcePrefix+uriRest); } } return targetRDFTerm; }
@Override public Iterator<Literal> getText(IRI field) { if(CO_MENTION_FIELD_HASH == field.hashCode() && //avoid calling equals CoMentionConstants.CO_MENTION_LABEL_FIELD.equals(field)){ return super.getText(nameField); } else if(CO_MENTION_TYPE_HASH == field.hashCode() && //avoid calling equals CoMentionConstants.CO_MENTION_TYPE_FIELD.equals(field)){ return super.getText(typeField); } else { return super.getText(field); } }
@Override public void computeEnhancements(ContentItem ci) throws EngineException { HtmlExtractor extractor = new HtmlExtractor(htmlExtractorRegistry, htmlParser); Graph model = new SimpleGraph(); ci.getLock().readLock().lock(); try { extractor.extract(ci.getUri().getUnicodeString(), ci.getStream(),null, ci.getMimeType(), model); } catch (ExtractorException e) { throw new EngineException("Error while processing ContentItem " + ci.getUri()+" with HtmlExtractor",e); } finally { ci.getLock().readLock().unlock(); } ClerezzaRDFUtils.urifyBlankNodes(model); // make the model single rooted if (singleRootRdf) { ClerezzaRDFUtils.makeConnected(model,ci.getUri(),new IRI(NIE_NS+"contains")); } //add the extracted triples to the metadata of the ContentItem ci.getLock().writeLock().lock(); try { LOG.info("Model: {}",model); ci.getMetadata().addAll(model); model = null; } finally { ci.getLock().writeLock().unlock(); } }
@Override public Object addPart(IRI uriRef, Object object) { writeLock.lock(); try { if(uriRef == null || object == null){ throw new IllegalArgumentException("The parsed content part ID and " + "object MUST NOT be NULL!"); } if(uriRef.equals(mainBlobUri)){ //avoid that this method is used to //reset the main content part throw new IllegalArgumentException("The parsed content part ID MUST " + "NOT be equals to the ID used by the main Content Part " + "( ContentItem.getUri()+\"_main\")"); } return parts.put(uriRef, object); } finally { writeLock.unlock(); } } @Override
/** * The activate method is called when SCR activates the component * configuration * * @param componentContext */ protected void activate(ComponentContext componentContext) throws Exception { URL template = getClass().getResource("exception-template.ssp"); renderletManager.registerRenderlet("org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesRenderlet", new IRI(template.toURI().toString()), TYPERENDERING.Exception, ".*", MediaType.APPLICATION_XHTML_XML_TYPE, true); } }
@Override public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException { if(name == null){ throw new IllegalArgumentException("The parsed ImmutableGraph IRI MUST NOT be NULL!"); } datasetLock.readLock().lock(); try { if (isExistingGraphName(name, Symbols.ImmutableGraph) || name.equals(defaultGraphName)){ return getModelGraph(name,false,false).getImmutableGraph(); } else { throw new NoSuchEntityException(name); } } finally { datasetLock.readLock().unlock(); } }
Lock readLock = systemGraph.getLock().readLock(); readLock.lock(); try { Iterator<Triple> triples = systemGraph.filter(null, FOAF.mbox, new IRI("mailto:" + email)); if (!triples.hasNext()) { return null; BlankNodeOrIRI user = triples.next().getSubject(); triples = systemGraph.filter(user, PLATFORM.userName, null); if (!triples.hasNext()) { throw new UserHasNoNameException("User with email address" + email + " does not have a name"); return ((Literal) triples.next().getObject()).getLexicalForm(); } finally { readLock.unlock();
IRI newValue) { Iterator<Triple> oldTriples = systemGraph.filter( (BlankNodeOrIRI) userNode.getNode(), predicate, null); Lock readLock = systemGraph.getLock().readLock(); readLock.lock(); try { while (oldTriples.hasNext()) { Triple triple = oldTriples.next(); RDFTerm oldValue = triple.getObject(); if (newValue.equals(oldValue)) { return; readLock.unlock(); systemGraph.removeAll(oldBuffer);
/** * Creates the RDF graph for the current Stanbol Enhancer configuration * * @return the graph with the configuration */ private Graph getEnhancerConfigGraph() { String rootUrl = getUriInfo().getBaseUriBuilder().path(getRootUrl()).build().toString(); IRI enhancerResource = new IRI(rootUrl + "enhancer"); Graph graph = new SimpleGraph(); graph.add(new TripleImpl(enhancerResource, RDF.type, Enhancer.ENHANCER)); addActiveEngines(engineManager, graph, rootUrl); addActiveChains(chainManager, graph, rootUrl); return graph; }
@SuppressWarnings("unchecked") @Override public T next() { RDFTerm value = results.next().getObject(); if (entity){ //type checks are done within the constructor return (T) factory.getProxy((BlankNodeOrIRI)value, (Class<? extends RdfEntity>)genericType); } else if(uri){ try { return (T)new URI(((IRI)value).getUnicodeString()); } catch (URISyntaxException e) { throw new IllegalStateException("Unable to parse "+URI.class+" for "+IRI.class+" value="+((IRI)value).getUnicodeString()); } } else if(url){ try { return (T)new URL(((IRI)value).getUnicodeString()); } catch (MalformedURLException e) { throw new IllegalStateException("Unable to parse "+URL.class+" for "+IRI.class+" value="+((IRI)value).getUnicodeString()); } } else if(uriRef){ return (T)value; } else { return literalFactory.createObject(genericType, (Literal)value); } }
public static void main(String[] args) throws Exception { int argv = 0; HtmlExtractor inst = new HtmlExtractor(); for (int i = argv; i < args.length; ++i) { File file = new File(args[i]); InputStream input = new FileInputStream(file); Charset charset = Charset.forName("UTF-8"); String mimeType = "text/html"; IRI uri = new IRI(file.toURI().toString()); Graph container = new SimpleGraph(); inst.extract(uri.getUnicodeString(), input, charset, mimeType, container); System.out.println("Model for " + args[i]); //TODO // container.writeTo(System.out); System.out.println(); } }
@Override public void computeEnhancements(ContentItem ci) throws EngineException { InputStream in = ci.getBlob().getStream(); XMPPacketScanner scanner = new XMPPacketScanner(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { scanner.parse(in, baos); } catch (IOException e) { throw new EngineException(e); } byte[] bytes = baos.toByteArray(); if (bytes.length > 0) { Graph model = new IndexedGraph(); parser.parse(model, new ByteArrayInputStream(bytes), "application/rdf+xml"); GraphNode gn = new GraphNode( new IRI("http://relative-uri.fake/"), model); gn.replaceWith(ci.getUri()); ci.getLock().writeLock().lock(); try { LOG.info("Model: {}",model); ci.getMetadata().addAll(model); } finally { ci.getLock().writeLock().unlock(); } } }
@Override public void deleteGraph(IRI name) throws UnsupportedOperationException, NoSuchEntityException, EntityUndeletableException { if(name == null){ throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!"); } datasetLock.writeLock().lock(); try { if(isExistingGraphName(name,Symbols.Graph)){ ModelGraph mg = getModelGraph(name, true, false); mg.delete(); removeFromIndex( name, Symbols.Graph ); } else if(isExistingGraphName(name,Symbols.ImmutableGraph)){ ModelGraph mg = getModelGraph(name, false, false); mg.delete(); removeFromIndex( name, Symbols.ImmutableGraph ); } else if (name.equals(defaultGraphName)){ throw new EntityUndeletableException(defaultGraphName); } //delete the graph from the initModels list syncModels.remove(name); } finally { datasetLock.writeLock().unlock(); } }
@Override public IRI run() { GraphNode platformInstance = getPlatformInstance(); Lock l = platformInstance.readLock(); l.lock(); try { Iterator<RDFTerm> triples = platformInstance.getObjects(PLATFORM.defaultBaseUri); if (triples.hasNext()) { return (IRI) triples.next(); } else { String port = context.getProperty("org.osgi.service.http.port"); if (port == null) { port = DEFAULT_PORT; } if (port.equals("80")) { return new IRI("http://localhost/"); } return new IRI("http://localhost:" + port + "/"); } } finally { l.unlock(); } } });
/** * Constructor that allows to parse the local name. if <code>null</code> * it uses <code>{@link #name()}{@link String#toLowerCase() .toLoverCase()} * </code> to generate the {@link #getLocalName() localName} * @param localName the local name or <code>null</code> to use * <code>{@link #name()}{@link String#toLowerCase() .toLoverCase()} * </code> */ private XSD(String localName){ this.localName = localName != null ? localName : name().toLowerCase(); this.uriString = namespace+this.localName; this.uri = URI.create(uriString); this.uriRef = new IRI(uriString); } public String getLocalName(){
FileGraph(IRI uri, Parser parser, Serializer serializer) { this(new File(URI.create(uri.getUnicodeString())), parser, serializer); }
@Override public void remove(String id) throws YardException, IllegalArgumentException { if(id == null) { throw new IllegalArgumentException("The parsed Representation id MUST NOT be NULL!"); } IRI resource = new IRI(id); final Lock writeLock = writeLockGraph(); try { Iterator<Triple> it = graph.filter(resource, null, null); while(it.hasNext()){ it.next(); it.remove(); } // if(isRepresentation(resource)){ // graph.removeAll(createRepresentationGraph(resource, graph)); // } //else not found -> nothing to do }finally { writeLock.unlock(); } } /**