Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a search form for text/html requests to field search without a qu…
…ery parameter
- Loading branch information
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
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
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
56 changes: 56 additions & 0 deletions
56
fcrepo-http-commons/src/main/java/org/fcrepo/responses/VelocityViewer.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,56 @@ | ||
package org.fcrepo.responses; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import java.io.StringWriter; | ||
import java.util.Properties; | ||
|
||
import org.apache.velocity.VelocityContext; | ||
import org.apache.velocity.app.VelocityEngine; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* Resolves the view to be used | ||
* @author Vincent Nguyen | ||
* | ||
*/ | ||
public class VelocityViewer { | ||
|
||
private VelocityEngine velocityEngine; | ||
|
||
private static final Logger logger = getLogger(VelocityViewer.class); | ||
|
||
public VelocityViewer() { | ||
try { | ||
// Load the velocity properties from the class path | ||
final Properties properties = new Properties(); | ||
properties.load(getClass().getClassLoader().getResourceAsStream("velocity.properties")); | ||
|
||
// Create and initialize the template engine | ||
velocityEngine = new VelocityEngine(properties); | ||
} catch (final Exception e) { | ||
logger.warn("Exception rendering Velocity template: {}", e); | ||
} | ||
} | ||
|
||
public String getSearchForm() { | ||
|
||
try { | ||
// Build a context to hold the model | ||
final VelocityContext velocityContext = new VelocityContext(); | ||
|
||
// Execute the template | ||
final StringWriter writer = new StringWriter(); | ||
velocityEngine.mergeTemplate("views/search.vsl", | ||
"utf-8", velocityContext, writer); | ||
|
||
// Return the result | ||
return writer.toString(); | ||
} catch (final Exception e) { | ||
logger.warn("Exception rendering Velocity template: {}", e); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
} |
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,24 @@ | ||
#parse("views/common.vsl") | ||
<html> | ||
<head> | ||
<title>Search</title> | ||
<script type="text/javascript"> | ||
#include("views/common.js") | ||
</script> | ||
<style type="text/css"> | ||
#include("views/common.css") | ||
</style> | ||
</head> | ||
<body> | ||
<h1>nt:file: $topic</h1> | ||
|
||
## output actions | ||
<div class="actions"> | ||
<form method="GET"> | ||
<input type="text" name="q" /> | ||
<input type="submit" value="search"/> | ||
</form> | ||
</div> | ||
|
||
</body> | ||
</html> |