Commit 39af5206 authored by Mathijs den Burger's avatar Mathijs den Burger

CMS7-8188: improve web resources API

parent 6901689b
......@@ -7,5 +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/webresources/Content.java -text
src/main/java/org/onehippo/cms7/services/webresources/File.java -text
src/main/java/org/onehippo/cms7/services/webresources/WebResource.java -text
src/main/java/org/onehippo/cms7/services/webresources/WebResourcesService.java -text
/*.iml
/.classpath
/.idea
/.project
/.settings
/target
/*
* 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.io.InputStream;
/**
* TODO: write Javadoc
*/
public interface Binary {
InputStream getStream();
int read(byte[] bytes, long l) throws java.io.IOException;
long getSize();
void dispose();
}
......@@ -17,15 +17,12 @@ package org.onehippo.cms7.services.webresources;
import java.util.Calendar;
import javax.jcr.Binary;
public interface Content {
/**
* @return the specific version or <code>null</code> in case of workspace content node
*/
String getVersion();
String getRevisionId();
String getEncoding();
......
/*
* 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 RevisionNotFoundException extends WebResourceException {
public RevisionNotFoundException() {
super();
}
public RevisionNotFoundException(final String message) {
super(message);
}
public RevisionNotFoundException(final String message, final Throwable cause) {
super(message, cause);
}
public RevisionNotFoundException(final Throwable cause) {
super(cause);
}
}
......@@ -16,39 +16,70 @@
package org.onehippo.cms7.services.webresources;
import java.util.List;
import java.util.Map;
public interface File {
public interface WebResource {
/**
* @return the path to the nt:file node
* @return the path to this web resource, relative to to web resources root location.
* The path always starts with a slash, and the path elements are also separated by slashes.
*/
String getPath();
String getFileName();
/**
* @return the name of this web resource, i.e. the last element of the path.
*/
String getName();
/**
*
* @return
*/
List<String> getRevisionIds();
/**
* @return the jcr workspace (trunk) version of the content
*/
Content getTrunk();
Content getCurrent();
/**
* @return the most recent checked in version, or if never checked in yet or in case the node is not versionable,
* the workspace content {@link #getTrunk()} is returned
*/
Content getTag();
Content getLatestRevision();
/**
* @param versionName the name of the version (tag) to fetch
* @return the <code>WebResource</code> for <code>versionName</code> and <code>null</code> if no such version present or
* if the content is not versionable
*/
Content getTag(String versionName);
Content getRevision(String revisionId) throws RevisionNotFoundException;
/**
* @return all versions and empty map in case the content is not versionable
* Creates a new revision of this web resource.
* @return the ID of the created revision.
*/
Map<String, Content> getAll();
String createRevision();
/**
* @param binary the binary to store
* @return true when the content of the nt:file node got changed as a result of this method. This might not be needed
* in case for example the MD5 of the <code>binary</code> is the same as the already present binary
*/
boolean update(Binary binary);
/**
*
* @param session
* @param absPath
* @return
*/
boolean delete();
/**
* @param revisionId the ID of the revision to restore.
*/
void restore(String revisionId);
}
/*
* 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);
}
}
/*
* 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 WebResourceException extends RuntimeException {
public WebResourceException() {
super();
}
public WebResourceException(final String message) {
super(message);
}
public WebResourceException(final String message, final Throwable cause) {
super(message, cause);
}
public WebResourceException(final Throwable cause) {
super(cause);
}
}
/*
* 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 WebResourceNotFoundException extends WebResourceException {
public WebResourceNotFoundException() {
super();
}
public WebResourceNotFoundException(final String message) {
super(message);
}
public WebResourceNotFoundException(final String message, final Throwable cause) {
super(message, cause);
}
public WebResourceNotFoundException(final Throwable cause) {
super(cause);
}
}
/*
* 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 javax.jcr.Binary;
import javax.jcr.Session;
/**
*
*/
public interface WebResources {
/**
* @param path
* @return
*/
boolean exists(String path);
/**
* @param path the path to the resource absolute path to the nt:file node
* @return the jcr workspace (trunk) version
*/
WebResource get(String path);
WebResource create(String path, Binary content);
}
......@@ -16,49 +16,19 @@
package org.onehippo.cms7.services.webresources;
import java.util.List;
import javax.jcr.Binary;
import javax.jcr.Session;
import org.onehippo.cms7.services.SingletonService;
import org.onehippo.cms7.services.WhiteboardService;
@SingletonService
@WhiteboardService
@SuppressWarnings("UnusedDeclaration")
public interface WebResourcesService {
/**
* @param absPath the absolute path to the nt:file node
* @return the jcr workspace (trunk) version
*/
File get(Session session, String absPath);
// TODO checkin method
// TODO how should create work?
// boolean create(Session session, String absPath, Binary binary);
/**
* @param absPath to a jcr node of type jcr:content
* @param binary the binary to store
* @return true when the content of the nt:file node got changed as a result of this method. This might not be needed
* in case for example the MD5 of the <code>binary</code> is the same as the already present binary
*/
boolean update(Session session, String absPath, Binary binary);
/**
*
* @param session
* @param absPath
* @return
*/
boolean delete(Session session, String absPath);
/**
* @param absPath to a jcr node of type nt:file
*/
void restore(Session session, String absPath, String versionName);
WebResources get(Session session);
}
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