@Override public <T extends Resource> T getSpecificResource(final String uri, final Class<T> specificClass) throws WebLabCheckedException { final Resource res = this.getResource(uri); if (specificClass.isInstance(res)) { return specificClass.cast(res); } throw new WebLabCheckedException("Cannot retrieve Resource '" + uri + "'", new ClassCastException("Unable to cast resource: " + res.getUri() + " into a " + specificClass.getName() + " since its a " + res.getClass().getName())); }
@Override protected void addResource(final Resource res) { for (final Annotation a : res.getAnnotation()) { final String rdf = PoKUtil.getPoKData(a); if (!rdf.trim().equals("")) { this.loadFromRdfXml(rdf, true); } } } }
/** * Create an instance of {@link Resource } * */ public Resource createResource() { return new Resource(); }
if (res.isSetAnnotation()) { subResources.addAll(res.getAnnotation()); if (res.isSetDescriptor()) { subResources.addAll(res.getDescriptor());
protected synchronized static void addDescriptor(final LowLevelDescriptor descriptor, final Resource parent, final Resource root) { parent.getDescriptor().add(descriptor); AbstractFactory.listUri(root).add(descriptor.getUri()); }
throw new WebLabRISyntaxException(wri.toString()); resource.setUri(wri.toString()); AbstractFactory.cleanMapping(wri.toString()); } catch (final WebLabRISyntaxException wlrise) {
final Set<String> buffered_uris = AbstractFactory.listUri(resource.getUri()); if (!force && !buffered_uris.isEmpty()) { return buffered_uris; set.add(resource.getUri()); if (resource instanceof Document) { final Document doc = (Document) resource; if (resource.isSetAnnotation()) { for (final Annotation a : resource.getAnnotation()) { set.addAll(AbstractFactory.listUri(a)); if (resource.isSetDescriptor()) { for (final LowLevelDescriptor lld : resource.getDescriptor()) { set.addAll(AbstractFactory.listUri(lld)); AbstractFactory.setUris(resource.getUri(), set);
/** * Method recursively called to add every resources in the model and in the map. * * @param res * The resource to add. */ protected void addResource(final Resource res) { this.resourcesMap.put(res.getUri(), res); for (final Resource subRes : ResourceUtil.getSubResources(res)) { this.resourcesMap.put(subRes.getUri(), subRes); if (subRes instanceof PieceOfKnowledge) { this.addPieceOfKnowledge((PieceOfKnowledge) subRes); } } }
@Override protected void addResource(final Resource res) { for (final Annotation a : res.getAnnotation()) { final String rdf = PoKUtil.getPoKData(a); if (!rdf.trim().isEmpty()) { this.loadFromRdfXml(rdf, true); } } }
/** * @param res * The <code>Resource</code> to be printed. * @param writer * The <code>PrintWriter</code> to write into. * @param gap * The space to be added at the beginning of the lines. */ private static void printTree(final Resource res, final PrintWriter writer, final String gap) { writer.println(gap + res.getUri() + " " + res.getClass().getSimpleName()); for (final Resource subResource : ResourceUtil.getDirectSubResources(res)) { ResourceUtil.printTree(subResource, writer, gap + " "); } }
protected synchronized static void addAnnotation(final Annotation annotation, final Resource resource, final Resource root) { resource.getAnnotation().add(annotation); AbstractFactory.listUri(root).add(annotation.getUri()); }
/** * Create a URI checking it does not already exist in the resource. * * @param resource a top container resource * @param isChild if true, the uri will describe a child or subchild of this resource * @param isAnnotation if true, the uri will describe a annotation on this resource * @return an URI unique among all URI in the resource and its sub resources */ protected synchronized static String createUniqueURIFrom(final Resource resource, final boolean isChild, final boolean isAnnotation) { return AbstractFactory.createUniqueURIin(AbstractFactory.listUri(resource), isChild, isAnnotation, resource.getUri()); }
/** * Read annotation on the input resource and get access to its normalised content through a JAVA file. Only read access are guaranteed on the returned File * * @param res * a standard WebLab Resource * @return a java File object with read rights * @throws WebLabCheckedException */ public File readNormalisedContent(final Resource res) throws WebLabCheckedException { final WProcessingAnnotator wpa = new WProcessingAnnotator(res); final Value<URI> values = wpa.readNormalisedContent(); if ((values == null) || (!values.hasValue())) { throw new WebLabCheckedException("There is no normalised content defined on this resource [" + res.getUri() + "]"); } if (values.size() > 1) { this.logger.warn("There are multiple normalised content defined on this resource [" + res.getUri() + "]:" + values); } final URI uri = values.firstTypedValue(); return this.readContent(uri, res); }
/** * Read annotation on the input resource and get access to its native content through a JAVA file. Only read access are guaranteed on the returned File * * @param res * a standard WebLab Resource * @return a java File object with read rights * @throws WebLabCheckedException */ public File readNativeContent(final Resource res) throws WebLabCheckedException { final WProcessingAnnotator wpa = new WProcessingAnnotator(res); final Value<URI> values = wpa.readNativeContent(); if ((values == null) || (!values.hasValue())) { throw new WebLabCheckedException("There is no native content defined on this resource [" + res.getUri() + "]"); } if (values.size() > 1) { throw new WebLabCheckedException("There are multiple native content defined on this resource [" + res.getUri() + "]:" + values); } final URI uri = values.getValues().get(0); return this.readContent(uri, res); }
protected synchronized static String createSegmentURIFor(final Object segmentContainer) { if (segmentContainer instanceof Segment){ final Segment segment = (Segment)segmentContainer; return AbstractFactory.createUniqueURIin(AbstractFactory.listUri(segment), true, false, segment.getUri()); }else if (segmentContainer instanceof Resource){ final Resource resource = (Resource)segmentContainer; return AbstractFactory.createUniqueURIin(AbstractFactory.listUri(resource), true, false, resource.getUri()); }else{ throw new WebLabUncheckedException("Object of type "+segmentContainer.getClass()+" can not contain Segment."); } }