71 lines
2 KiB
Java
71 lines
2 KiB
Java
/*
|
|
* 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.vizirdb;
|
|
|
|
/**
|
|
* Factory class capturing all methods for generating URL to reference resources
|
|
* served by the Web API.
|
|
*
|
|
* @author Heiko Mueller
|
|
*/
|
|
public class URLFactory {
|
|
|
|
private final String _baseUrl;
|
|
|
|
public URLFactory(String baseUrl) {
|
|
|
|
if (baseUrl.endsWith("/")) {
|
|
_baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
|
|
} else {
|
|
_baseUrl = baseUrl;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* URL for existing notebook resource.
|
|
*
|
|
* @param notebookIdentifier Notebook id
|
|
* @return
|
|
*/
|
|
public String getNotebookURL(int notebookIdentifier) {
|
|
|
|
return _baseUrl + "/notebooks/" + notebookIdentifier;
|
|
}
|
|
|
|
/**
|
|
* URL referencing script resource for an existing notebook.
|
|
*
|
|
* @param notebookIdentifier Notebook id
|
|
* @return
|
|
*/
|
|
public String getNotebookScriptURL(int notebookIdentifier) {
|
|
|
|
return this.getNotebookURL(notebookIdentifier) + "/script";
|
|
}
|
|
|
|
/**
|
|
* URL referencing snapshot of an existing notebook.
|
|
*
|
|
* @param notebookIdentifier Notebook id
|
|
* @param snapshotIndex Snapshot index corresponding to operation in
|
|
* the notebook script that generated the
|
|
* snapshot
|
|
* @return
|
|
*/
|
|
public String getNotebookSnapshotURL(int notebookIdentifier, int snapshotIndex) {
|
|
|
|
return this.getNotebookURL(notebookIdentifier) + "/snapshots/" + snapshotIndex;
|
|
}
|
|
}
|