+ @SuppressWarnings("unchecked")
+ @Override
+ public <C extends Closeable> C open(Class<C> clss) throws IOException, IllegalArgumentException {
+ if (InputStream.class.isAssignableFrom(clss)) {
+ PipedOutputStream out = new PipedOutputStream();
+ ForkJoinPool.commonPool().execute(() -> {
+ try {
+ Source source = new DOMSource(element);
+ Result result = new StreamResult(out);
+ provider.getTransformerFactory().newTransformer().transform(source, result);
+ out.flush();
+ out.close();
+ } catch (TransformerException | IOException e) {
+ throw new RuntimeException("Cannot read " + getPath(), e);
+ }
+ });
+ return (C) new PipedInputStream(out);
+ }
+ return super.open(clss);
+ }
+
+ @Override
+ public int getSiblingIndex() {
+ Node curr = element.getPreviousSibling();
+ int count = 1;
+ while (curr != null) {
+ if (curr instanceof Element) {
+ if (Objects.equals(curr.getNamespaceURI(), element.getNamespaceURI())
+ && Objects.equals(curr.getLocalName(), element.getLocalName())) {
+ count++;
+ }
+ }
+ curr = curr.getPreviousSibling();
+ }
+ return count;
+ }
+
+ /*
+ * TYPING
+ */
+ @Override
+ public List<QName> getContentClasses() {
+ List<QName> res = new ArrayList<>();
+ if (isLocalRoot()) {
+ String mountPath = provider.getMountPath();
+ if (Content.ROOT_PATH.equals(mountPath)) {// repository root
+ res.add(CrName.root.qName());
+ } else {
+ Content mountPoint = getSession().getMountPoint(mountPath);
+ res.addAll(mountPoint.getContentClasses());
+ }
+ } else {
+ res.add(getName());
+ }
+ return res;
+ }
+
+ @Override
+ public void addContentClasses(QName... contentClass) {
+ if (isLocalRoot()) {
+ String mountPath = provider.getMountPath();
+ if (Content.ROOT_PATH.equals(mountPath)) {// repository root
+ throw new IllegalArgumentException("Cannot add content classes to repository root");
+ } else {
+ Content mountPoint = getSession().getMountPoint(mountPath);
+ mountPoint.addContentClasses(contentClass);
+ }
+ } else {
+ super.addContentClasses(contentClass);
+ }
+ }
+