-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial specification of the asset system (#13)
Signed-off-by: Clement Escoffier <[email protected]>
- Loading branch information
1 parent
db39bcf
commit ed53f9c
Showing
4 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
core/wisdom-api/src/main/java/org/wisdom/api/asset/Asset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* #%L | ||
* Wisdom-Framework | ||
* %% | ||
* Copyright (C) 2013 - 2014 Wisdom Framework | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package org.wisdom.api.asset; | ||
|
||
import java.net.URL; | ||
|
||
/** | ||
* A structure representing assets. | ||
*/ | ||
public interface Asset<T> { | ||
|
||
/** | ||
* @return the path to retrieve the asset. The result of this method can be use in HREF or Routes to retrieve the | ||
* asset itself. | ||
*/ | ||
public String getPath(); | ||
|
||
/** | ||
* @return the asset content. Can be an url or a file. | ||
*/ | ||
public T getContent(); | ||
|
||
/** | ||
* @return an identifier of the source. | ||
*/ | ||
public String getSource(); | ||
|
||
|
||
/** | ||
* @return the last modified date. | ||
*/ | ||
public long getLastModified(); | ||
|
||
|
||
/** | ||
* @return the asset ETAG. | ||
*/ | ||
public String getEtag(); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
core/wisdom-api/src/main/java/org/wisdom/api/asset/AssetProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* #%L | ||
* Wisdom-Framework | ||
* %% | ||
* Copyright (C) 2013 - 2014 Wisdom Framework | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package org.wisdom.api.asset; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* An interface used by {@link org.wisdom.api.asset.Assets} implementation to retrieve the set of assets. | ||
*/ | ||
public interface AssetProvider { | ||
|
||
/** | ||
* @return the list of provided assets. | ||
*/ | ||
Collection<Asset<?>> assets(); | ||
|
||
/** | ||
* Retrieves an asset. | ||
* | ||
* @param path the asset path | ||
* @return the Asset object, or {@literal null} if the current provider can't serve this asset. | ||
*/ | ||
Asset assetAt(String path); | ||
} |
54 changes: 54 additions & 0 deletions
54
core/wisdom-api/src/main/java/org/wisdom/api/asset/Assets.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* #%L | ||
* Wisdom-Framework | ||
* %% | ||
* Copyright (C) 2013 - 2014 Wisdom Framework | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package org.wisdom.api.asset; | ||
|
||
import java.net.URL; | ||
import java.util.Collection; | ||
|
||
/** | ||
* Assets defines a layer to manipulate and retrieve asset currently available in the system. | ||
*/ | ||
public interface Assets { | ||
|
||
/** | ||
* Gets the path to retrieve the asset identified by its file name. | ||
* | ||
* @param path the path | ||
* @return the path to retrieve the asset or {@literal null} if not found. If there are several matches, | ||
* return the first one. | ||
*/ | ||
Asset assetAt(String path); | ||
|
||
/** | ||
* @return the list of all assets currently available. This lookup is done on demand, | ||
* ignoring cached value. So it can be very expensive. | ||
*/ | ||
Collection<Asset<?>> assets(); | ||
|
||
/** | ||
* Retrieve the list of all asset currently available on the platform. | ||
* | ||
* @param useCache whether or not we can returned a cached version of the result. This cache may contain | ||
* invalidated data or may not contain all available assets. | ||
* @return the list of assets | ||
*/ | ||
Collection<Asset<?>> assets(boolean useCache); | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
core/wisdom-api/src/main/java/org/wisdom/api/asset/DefaultAsset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* #%L | ||
* Wisdom-Framework | ||
* %% | ||
* Copyright (C) 2013 - 2014 Wisdom Framework | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package org.wisdom.api.asset; | ||
|
||
/** | ||
* a default implementation of asset. | ||
*/ | ||
public class DefaultAsset<T> implements Asset<T> { | ||
|
||
private final String path; | ||
|
||
private final T content; | ||
|
||
private final String source; | ||
|
||
private final String etag; | ||
|
||
private final long lastModified; | ||
|
||
|
||
public DefaultAsset(String path, T content, String source) { | ||
this(path, content, source, -1, null); | ||
} | ||
|
||
public DefaultAsset(String path, T content, String source, long lastModified, String etag) { | ||
this.path = path; | ||
this.content = content; | ||
this.source = source; | ||
this.etag = etag; | ||
this.lastModified = lastModified; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public T getContent() { | ||
return content; | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
||
public String getEtag() { | ||
return etag; | ||
} | ||
|
||
public long getLastModified() { | ||
return lastModified; | ||
} | ||
} |