Commit 6e51c543 authored by Ard Schrijvers's avatar Ard Schrijvers

CMS7-8219 new api: a webresource bundle is the entry point for getting hold of...

CMS7-8219 new api: a webresource bundle is the entry point for getting hold of all resources for a channel, and also the entry point for versioning (tagging)
parent c5649661
......@@ -7,6 +7,5 @@ src/main/java/org/onehippo/cms7/services/eventbus/HippoEventListener.java -text
src/main/java/org/onehippo/cms7/services/eventbus/Subscribe.java -text
src/main/java/org/onehippo/cms7/services/googleanalytics/GoogleAnalyticsService.java -text
src/main/java/org/onehippo/cms7/services/jaxrs/JaxrsService.java -text
src/main/java/org/onehippo/cms7/services/webresources/Content.java -text
src/main/java/org/onehippo/cms7/services/webresources/WebResource.java -text
src/main/java/org/onehippo/cms7/services/webresources/WebResourcesService.java -text
......@@ -33,24 +33,6 @@ public interface Binary {
*/
InputStream getStream();
/**
* Reads successive bytes from the specified <code>position</code>
* in this binary into the passed byte array until either the byte
* array is full or the end of the <code>Binary</code> is encountered.
*
* @param buffer the buffer into which the data is read.
* @param position the position in this binary from which to start reading bytes.
*
* @return the number of bytes read into the buffer, or -1 if there is no
* more data because the end of the Binary has been reached.
*
* @throws java.io.IOException if an I/O error occurs.
* @throws java.lang.NullPointerException if b is null.
* @throws java.lang.IllegalArgumentException if offset is negative or {@link #dispose()} has already been called.
* @throws WebResourceException if another error occurs.
*/
int read(byte[] buffer, long position) throws java.io.IOException;
/**
* @return the size of this binary in bytes.
* @throws java.lang.IllegalStateException if {@link #dispose()} has already been called.
......
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.cms7.services.webresources;
import java.util.Calendar;
/**
* The content of a web resource.
*/
public interface Content {
/**
* @return the revision ID of this content, or <code>null</code> when this content is not revisioned.
*/
String getRevisionId();
/**
* @return the encoding of this content.
*/
String getEncoding();
/**
* @return the last time this content has changed.
*/
Calendar getLastModified();
/**
* @return the MIME type of this content.
*/
String getMimeType();
/**
* @return a unique hash value of this content based on its binary data. Content with the same binary data will
* always return the same hash. It is extremely unlikely that content with different binary data returns the same
* hash.
*/
String getHash();
/**
* @return the binary data of this content.
*/
Binary getBinary();
}
......@@ -16,7 +16,7 @@
package org.onehippo.cms7.services.webresources;
import java.util.List;
import java.util.Calendar;
/**
* A web resource contains binary data that can be revisioned. There is always a current working version of the content.
......@@ -37,52 +37,25 @@ public interface WebResource {
String getName();
/**
* @return the current content of this web resource. Use {@link #createRevision()} to create a revision
* of the content.
* @return the encoding of this content.
*/
Content getContent();
String getEncoding();
/**
* Updates the content of this web resource.
* @param binary the binary data to store.
* @return whether the content actually changed (e.g. the new binary data differs from the existing
* binary data)
* @throws java.lang.IllegalArgumentException if the given binary is <code>null</code>.
* @return the last time this content has changed.
*/
boolean setContent(Binary binary);
Calendar getLastModified();
/**
* Creates a new revision of this web resource's content. Afterwards the current content will have been added to the
* revision history, and the latest revision and the current content will be identical.
* @return the ID of the created revision.
* @throws WebResourceException when an error occurs.
* @return the MIME type of this content.
*/
String createRevision();
String getMimeType();
/**
* @return all revision IDs of this web resource's content. If no revisions exist yet, an empty list will be returned.
* Revision IDs are unique within the revision history of a web resource.
* @return the binary data of this content.
*/
List<String> getRevisionIds();
Binary getBinary();
/**
* @return the ID of the most recently created revision, or <code>null</code> if no revision has been created yet.
*/
String getLatestRevisionId();
/**
* @param revisionId the ID of the revision to return. When the revision ID is <code>null</code>, this call is
* identical to {@link #getContent()}.
* @return a revision of the content of this web resource, or the current working version of the content when the
* revision ID is null.
*/
Content getContent(String revisionId) throws RevisionNotFoundException;
/**
* Removes this web resource.
* @throws WebResourceException in case the delete did not occur, for example because the resource is not there any more,
* insufficient authorization, locking, etc
*/
void delete() throws WebResourceException;
String getChecksum();
}
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onehippo.cms7.services.webresources;
/**
* TODO: write Javadoc
*/
public class WebResourceAlreadyExistsException extends WebResourceException {
public WebResourceAlreadyExistsException() {
super();
}
public WebResourceAlreadyExistsException(final String message) {
super(message);
}
public WebResourceAlreadyExistsException(final String message, final Throwable cause) {
super(message, cause);
}
public WebResourceAlreadyExistsException(final Throwable cause) {
super(cause);
}
}
......@@ -15,12 +15,14 @@
*/
package org.onehippo.cms7.services.webresources;
import java.util.List;
/**
* A collection of web resources, i.e. binary data objects. Each web resource is identified by an absolute path
* starting at the web resources root. Paths start with a slash and consist of elements separated by slashes
* (e.g. "/css/style.css").
*/
public interface WebResources {
public interface WebResourceBundle {
/**
* @param absPath the absolute path to the web resource, starting at the web resources root. The path must start with a slash.
......@@ -29,19 +31,72 @@ public interface WebResources {
boolean exists(String absPath);
/**
* @param absPath the absolute path to the web resource, starting at the web resources root. The path must start with a slash.
* @return the web resource located at the given path.
* @param absPath the absolute path starting with a slash to the web resource, relative to this {@link WebResourceBundle}
* @return the web resource <b>head</b> located at the given path.
* @throws WebResourceNotFoundException if no web resource exists at the given path.
*/
WebResource get(String absPath) throws WebResourceNotFoundException;
/**
* Creates a new web resource at the given location.
* @param absPath the absolute path to the web resource, starting at the web resources root. The path must start with a slash.
* @param absPath the absolute path starting with a slash to the web resource, relative to this {@link WebResourceBundle}
* @param content the content of the new web resource.
* @return the created web resource.
* @throws WebResourceAlreadyExistsException if another web resource already exists at the given location.
* @throws WebResourceException if another (web) resource already exists at the given location.
* @throws java.lang.IllegalArgumentException if the given binary is <code>null</code>.
* @throws WebResourceException in case of insufficient authorization
*/
WebResource create(String absPath, Binary content) throws WebResourceException, IllegalArgumentException;
/**
* Updates the content of this web resource.
* @param absPath the absolute path starting with a slash to the web resource, relative to this {@link WebResourceBundle}
* @param content the binary data to store.
* @return the updated {@link WebResource}
* @throws WebResourceNotFoundException if no web resource exists at the given path.
* @throws java.lang.IllegalArgumentException if the given binary is <code>null</code>.
* @throws WebResourceException in case of insufficient authorization
*/
WebResource update(String absPath, Binary content) throws WebResourceNotFoundException, IllegalArgumentException;
/**
* Removes the web resource at absPath
* @param absPath the absolute path starting with a slash to the web resource, relative to this {@link WebResourceBundle}
* @throws WebResourceException in case the delete did not occur, for example because the resource is not there any more,
* insufficient authorization, locking, etc
*/
void delete(String absPath) throws WebResourceException;
/**e
* @param absPath the absolute path to the web resource, starting at the web resources root. The path must start with a slash.
* @return the latest tagged {@link WebResourceBundle} or in case not yet tagged or tagging is not supported, return
* <code>null</code>
*/
WebResource create(String absPath, Binary content) throws WebResourceAlreadyExistsException;
WebResource getLatestTag(String absPath);
/**
* @return The immutable {@link java.util.List} ordered list of tag names for this {@link WebResourceBundle} or empty List in case
* there are no tags for this {@link WebResourceBundle} or tagging is not supported (for this {@link WebResourceBundle})
*/
List<String> getTagNames();
/**
* @param absPath the absolute path to the web resource, starting at the web resources root. The path must start with a slash.
* @param tagName the {@link WebResource} for tagName
* @return the web resource <b>tag</b> located at the given path for <code>tag</code>.
* @throws WebResourceNotFoundException if no web resource exists at the given path for <code>tag</code>.
*/
WebResource get(String absPath, String tagName) throws WebResourceNotFoundException, WebResourceTagNotFoundException;
/**
* Creates a new tag for this entire {@link WebResourceBundle}
* @return the name of the newly created tag
* @throws WebResourceException
*/
String createTag() throws WebResourceException;
/**
* @return the checksum of this {@link WebResourceBundle}
*/
String getChecksum();
}
......@@ -18,21 +18,21 @@ package org.onehippo.cms7.services.webresources;
/**
* TODO: write Javadoc
*/
public class RevisionNotFoundException extends WebResourceException {
public class WebResourceTagNotFoundException extends WebResourceException {
public RevisionNotFoundException() {
public WebResourceTagNotFoundException() {
super();
}
public RevisionNotFoundException(final String message) {
public WebResourceTagNotFoundException(final String message) {
super(message);
}
public RevisionNotFoundException(final String message, final Throwable cause) {
public WebResourceTagNotFoundException(final String message, final Throwable cause) {
super(message, cause);
}
public RevisionNotFoundException(final Throwable cause) {
public WebResourceTagNotFoundException(final Throwable cause) {
super(cause);
}
}
......@@ -29,8 +29,10 @@ public interface WebResourcesService {
/**
* Creates a web resources implementation based on JCR.
* @param session the JCR session used to access web resources.
* @return a JCR-based web resources implementation.
* @param bundleName the name of the web resources bundle.
* @return a JCR-based web resources implementation for <code>bundleName</code>.
* @throw WebResourceException if the {@link WebResourceBundle} for <code>bundleName</code> cannot be found
*/
WebResources getJcrWebResources(Session session);
WebResourceBundle getJcrWebResourceBundle(Session session, String bundleName);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment