Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,21 @@ public interface BookmarkManager {
* @throws WebloggerException If there is a problem.
*/
WeblogBookmarkFolder getFolder(String id) throws WebloggerException;



/**
* Get a folder by id, restricted to the given weblog.
*
* <p>Named differently from {@link #getFolder(Weblog, String)}, which
* looks a folder up by name, because the two would otherwise have the
* same erasure.
*
* @return the folder, or null if no folder with that id belongs to the
* given weblog. A folder that exists but belongs to another weblog
* is reported the same way as one that does not exist.
*/
WeblogBookmarkFolder getFolderById(Weblog weblog, String id) throws WebloggerException;


/**
* Get all folders for a weblog.
*
Expand Down Expand Up @@ -123,8 +136,18 @@ WeblogBookmarkFolder getFolder(Weblog weblog, String name)
* @throws WebloggerException If there is a problem.
*/
WeblogBookmark getBookmark(String id) throws WebloggerException;



/**
* Get a bookmark by id, restricted to the given weblog.
*
* @return the bookmark, or null if no bookmark with that id belongs to a
* folder of the given weblog. A bookmark that exists but belongs
* to another weblog is reported the same way as one that does not
* exist.
*/
WeblogBookmark getBookmark(Weblog weblog, String id) throws WebloggerException;


/**
* Lookup all Bookmarks in a folder, optionally search recursively.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ void updateMediaFile(Weblog website, MediaFile mf, InputStream fis)
*/
MediaFile getMediaFile(String id) throws WebloggerException;

/**
* Get media file metadata by file id, restricted to the given weblog.
*
* @return the media file, or null if no media file with that id belongs to
* the given weblog. A media file that exists but belongs to another
* weblog is reported the same way as one that does not exist.
*/
MediaFile getMediaFile(Weblog weblog, String id) throws WebloggerException;

/**
* Get media file metadata optionally including the actual content
*/
Expand Down Expand Up @@ -118,6 +127,16 @@ MediaFileDirectory createMediaFileDirectory(Weblog weblog,
MediaFileDirectory getMediaFileDirectory(String id)
throws WebloggerException;

/**
* Get media file directory by id, restricted to the given weblog.
*
* @return the directory, or null if no directory with that id belongs to
* the given weblog. A directory that exists but belongs to another
* weblog is reported the same way as one that does not exist.
*/
MediaFileDirectory getMediaFileDirectory(Weblog weblog, String id)
throws WebloggerException;

/**
* Get media file directory by its path
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ public interface WeblogEntryManager {
* Get weblog entry by id.
*/
WeblogEntry getWeblogEntry(String id) throws WebloggerException;

/**
* Get weblog entry by anchor.

/**
* Get weblog entry by id, restricted to the given weblog.
*
* @return the entry, or null if no entry with that id belongs to the given
* weblog. An entry that exists but belongs to another weblog is
* reported the same way as one that does not exist.
*/
WeblogEntry getWeblogEntry(Weblog weblog, String id) throws WebloggerException;

/**
* Get weblog entry by anchor.
*/
WeblogEntry getWeblogEntryByAnchor(Weblog website, String anchor)
throws WebloggerException;
Expand Down Expand Up @@ -154,8 +163,17 @@ void removeWeblogEntryAttribute(String name,WeblogEntry entry)
* Get category by id.
*/
WeblogCategory getWeblogCategory(String id) throws WebloggerException;



/**
* Get category by id, restricted to the given weblog.
*
* @return the category, or null if no category with that id belongs to the
* given weblog. A category that exists but belongs to another
* weblog is reported the same way as one that does not exist.
*/
WeblogCategory getWeblogCategory(Weblog weblog, String id) throws WebloggerException;


/**
* Recategorize all entries with one category to another.
*/
Expand Down Expand Up @@ -190,7 +208,18 @@ List<WeblogCategory> getWeblogCategories(Weblog website)
* Get comment by id.
*/
WeblogEntryComment getComment(String id) throws WebloggerException;


/**
* Get comment by id, restricted to the given weblog.
*
* @return the comment, or null if no comment with that id belongs to an
* entry of the given weblog. A comment that exists but belongs to
* another weblog is reported the same way as one that does not
* exist.
*/
WeblogEntryComment getComment(Weblog weblog, String id) throws WebloggerException;


/**
* Generic comments query method.
* @param csc CommentSearchCriteria object with fields indicating search criteria
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,28 @@ List<Weblog> getWeblogsByLetter(char letter, int offset, int length)


/**
* Get a custom template by its id.
* Get a custom template by its id, without restricting the result to any
* weblog.
*
* <p>Callers that act on behalf of a single weblog must use
* {@link #getTemplate(Weblog, String)} instead, so that a template id
* belonging to another weblog cannot resolve. This unscoped form is for
* callers that legitimately have no weblog in context, such as the
* Velocity resource loader.
*/
WeblogTemplate getTemplate(String id) throws WebloggerException;




/**
* Get a custom template by its id, restricted to the given weblog.
*
* @return the template, or null if no template with that id belongs to
* the given weblog. A template that exists but belongs to another
* weblog is reported the same way as one that does not exist.
*/
WeblogTemplate getTemplate(Weblog weblog, String id) throws WebloggerException;


/**
* Get a custom template by the action it supports.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,50 @@ public WeblogBookmark getBookmark(String id) throws WebloggerException {
return (WeblogBookmark) strategy.load(WeblogBookmark.class, id);
}

@Override
public WeblogBookmark getBookmark(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<WeblogBookmark> q = strategy.getNamedQuery(
"WeblogBookmark.getByWebsite&Id", WeblogBookmark.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

@Override
public WeblogBookmarkFolder getFolderById(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<WeblogBookmarkFolder> q = strategy.getNamedQuery(
"WeblogBookmarkFolder.getByWebsite&Id", WeblogBookmarkFolder.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

@Override
public void removeBookmark(WeblogBookmark bookmark) throws WebloggerException {
Weblog weblog = bookmark.getWebsite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,51 @@ public MediaFile getMediaFile(String id) throws WebloggerException {
return getMediaFile(id, false);
}

@Override
public MediaFile getMediaFile(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<MediaFile> q = strategy.getNamedQuery(
"MediaFile.getByWeblogAndId", MediaFile.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

@Override
public MediaFileDirectory getMediaFileDirectory(Weblog weblog, String id)
throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<MediaFileDirectory> q = strategy.getNamedQuery(
"MediaFileDirectory.getByWeblogAndId", MediaFileDirectory.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,82 @@ public WeblogEntryComment getComment(String id) throws WebloggerException {
public WeblogEntry getWeblogEntry(String id) throws WebloggerException {
return (WeblogEntry)strategy.load(WeblogEntry.class, id);
}


/**
* @inheritDoc
*/
@Override
public WeblogEntry getWeblogEntry(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<WeblogEntry> q = strategy.getNamedQuery(
"WeblogEntry.getByWebsite&Id", WeblogEntry.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

/**
* @inheritDoc
*/
@Override
public WeblogCategory getWeblogCategory(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<WeblogCategory> q = strategy.getNamedQuery(
"WeblogCategory.getByWeblog&Id", WeblogCategory.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

/**
* @inheritDoc
*/
@Override
public WeblogEntryComment getComment(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

if (id == null) {
return null;
}

TypedQuery<WeblogEntryComment> q = strategy.getNamedQuery(
"WeblogEntryComment.getByWebsite&Id", WeblogEntryComment.class);
q.setParameter(1, weblog);
q.setParameter(2, id);
try {
return q.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

/**
* @inheritDoc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,32 @@ public WeblogTemplate getTemplate(String id) throws WebloggerException {
if (id != null && id.endsWith(".vm")) {
return null;
}

return (WeblogTemplate)this.strategy.load(WeblogTemplate.class,id);
}

@Override
public WeblogTemplate getTemplate(Weblog weblog, String id) throws WebloggerException {

if (weblog == null) {
throw new WebloggerException("weblog is null");
}

// Don't hit database for templates stored on disk
if (id == null || id.endsWith(".vm")) {
return null;
}

TypedQuery<WeblogTemplate> query = strategy.getNamedQuery("WeblogTemplate.getByWeblog&Id",
WeblogTemplate.class);
query.setParameter(1, weblog);
query.setParameter(2, id);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}

/**
* Use JPA directly because Weblogger's Query API does too much allocation.
Expand Down
Loading
Loading