public synchronized void connect()

in src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java [292:359]


    public synchronized void connect() throws IOException {
        if (!connected) {

            // Get hold of the data
            Session session = null;
            try {
                session = this.handler.getClassLoaderWriter().createSession();
                final Node node = (Node)session.getItem(this.getPath());
                // resolve the URLs item to a property
                final Property property = Util.getProperty(node);
                if (property == null) {
                    throw failure("connect",
                        "Multivalue property not supported", null);
                }

                final byte[] contents = Util.getBytes(node);

                // values to set later
                String contentType;
                String contentEncoding = null; // no defined content encoding
                long lastModified;

                Node parent = property.getParent();
                if (parent.hasProperty("jcr:lastModified")) {
                    lastModified = parent.getProperty("jcr:lastModified").getLong();
                } else {
                    lastModified = 0;
                }

                if (parent.hasProperty("jcr:mimeType")) {
                    contentType = parent.getProperty("jcr:mimeType").getString();
                } else {
                    contentType = guessContentTypeFromName(node.getName());
                    if (contentType == null) {
                        contentType = (property.getType() == PropertyType.BINARY)
                                ? APPLICATION_OCTET
                                : TEXT_PLAIN;
                    }
                }

                if (parent.hasProperty("jcr:encoding")) {
                    contentEncoding = parent.getProperty("jcr:encoding").getString();
                }

                log.debug(
                    "connect: Using property '{}' with content type '{}' for {} bytes",
                    new Object[] { property.getPath(), contentType,
                        new Integer(contentLength) });

                // set the fields
                this.contents = contents;
                this.contentType = contentType;
                this.contentEncoding = contentEncoding;
                this.contentLength = contents.length;
                this.lastModified = lastModified;

                // mark connection open
                connected = true;

            } catch (final RepositoryException re) {
                throw failure("connect", re.toString(), re);
            } finally {
                if ( session != null ) {
                    session.logout();
                }
            }
        }
    }