use of net.sourceforge.processdash.ui.snippet.SnippetDefinition in project processdash by dtuma.
the class EditedPageDataParser method parseSnippet.
private SnippetInstanceTO parseSnippet(String ns) {
if (StringUtils.hasValue(getParameter(SNIPPET_DISCARDED_ + ns)))
return null;
SnippetInstanceTO snip = new SnippetInstanceTO();
snip.setSnippetID(getParameter(SNIPPET_ID_ + ns));
snip.setSnippetVersion(getParameter(SNIPPET_VERSION_ + ns));
snip.setPageRegion(getIntParameter(SNIPPET_PAGE_REGION_ + ns));
String instId = getParameter(SNIPPET_INSTANCE_ID_ + ns);
if (AbstractPageAssembler.AUTO_HEADER_INSTANCE_ID.equals(instId))
return null;
else if (XMLUtils.hasValue(instId))
try {
nextInstanceID = Math.max(nextInstanceID, Integer.parseInt(instId) + 1);
} catch (NumberFormatException nfe) {
}
snip.setInstanceID(instId);
if (parameters.containsKey(SNIPPET_VERBATIM_TEXT_ + ns)) {
snip.setPersistedText(getParameter(SNIPPET_VERBATIM_TEXT_ + ns));
snip.setPersisterID(getParameter(SNIPPET_VERBATIM_PERSISTER_ + ns));
} else {
SnippetDefinition defn = SnippetDefinitionManager.getSnippet(snip.getSnippetID());
if (defn == null)
return snip;
snip.setDefinition(defn);
if (defn.shouldParsePersistedText())
parseParameters(snip, ns);
else
invokeSnippet(snip, ns);
}
return snip;
}
use of net.sourceforge.processdash.ui.snippet.SnippetDefinition in project processdash by dtuma.
the class AddNewSnippet method getSortedSnippets.
private TreeSet getSortedSnippets() {
DataContext ctx = getDataContext();
String[] deny = (String[]) parameters.get("deny_ALL");
Set allSnippets = SnippetDefinitionManager.getAllSnippets();
TreeSet snippets = new TreeSet();
for (Iterator i = allSnippets.iterator(); i.hasNext(); ) {
SnippetDefinition d = (SnippetDefinition) i.next();
if (!d.shouldHide() && !denied(d, deny) && d.matchesContext(ctx))
snippets.add(new SnipData(d));
}
return snippets;
}
use of net.sourceforge.processdash.ui.snippet.SnippetDefinition in project processdash by dtuma.
the class SnippetInvoker method test.
/** Check to see if the given snippet is valid for the current context and
* the current user.
*
* @param snippet a snippet to test.
* @return true if the definition for this snippet matches the context
* of this invoker, and if the user has permission. If false is
* returned, the snippet's status will be set to indicate the problem.
*/
public boolean test(SnippetInstanceTO snippet) {
SnippetDefinition defn = snippet.getDefinition();
if (defn == null) {
snippet.setStatus(SnippetInvoker.STATUS_NO_DEFINITION);
return false;
} else if (!defn.matchesContext(dataContext)) {
snippet.setStatus(SnippetInvoker.STATUS_CONTEXT_MISMATCH);
return false;
}
String permID = defn.getPermission();
if (permID != null && (!XMLUtils.hasValue(mode) || "view".equalsIgnoreCase(mode) || "toc".equalsIgnoreCase(mode)) && !PermissionsManager.getInstance().hasPermission(permID)) {
snippet.setStatus(SnippetInvoker.NO_PERMISSION);
return false;
}
return true;
}
use of net.sourceforge.processdash.ui.snippet.SnippetDefinition in project processdash by dtuma.
the class ProcessAdvisor method getAdvisorSnippets.
/**
* @param pageRegion
* @return a list of all snippets in the "advice" category
*/
private static List getAdvisorSnippets(int pageRegion) {
List result = new ArrayList();
Set snippets = SnippetDefinitionManager.getAllSnippets();
for (Iterator i = snippets.iterator(); i.hasNext(); ) {
SnippetDefinition snipDef = (SnippetDefinition) i.next();
if (snipDef.matchesCategory(ADVISOR_SNIPPET_CATEGORY)) {
SnippetInstanceTO snip = new SnippetInstanceTO();
snip.setSnippetID(snipDef.getId());
snip.setDefinition(snipDef);
snip.setPageRegion(pageRegion);
result.add(snip);
}
}
return result;
}
use of net.sourceforge.processdash.ui.snippet.SnippetDefinition in project processdash by dtuma.
the class SnippetInvoker method invoke.
/** Invoke a single snippet.
*
* @param snippet the snippet to run
* @return the content generated by the snippet
* @throws IOException if an error was encountered
*/
public String invoke(SnippetInstanceTO snippet) throws IOException {
if (!test(snippet))
return null;
SnippetDefinition defn = snippet.getDefinition();
if (XMLUtils.hasValue(mode) && !"view".equalsIgnoreCase(mode) && !defn.getModes().contains(mode)) {
snippet.setStatus(SnippetInvoker.UNSUPPORTED_MODE);
return null;
}
String uri = defn.getUri(mode, action);
if (uri == null) {
snippet.setStatus(SnippetInvoker.UNSUPPORTED_MODE);
return null;
}
String namespace = snippet.getNamespace();
Map extraEnvironment = new HashMap();
extraEnvironment.put(SNIPPET_ID, snippet.getSnippetID());
extraEnvironment.put(SNIPPET_VERSION, snippet.getSnippetVersion());
extraEnvironment.put(PERSISTED_TEXT, snippet.getPersistedText());
extraEnvironment.put(RESOURCES, defn.getResources());
extraEnvironment.put(HTMLPreprocessor.REPLACEMENTS_PARAM, Collections.singletonMap("$$$_", namespace));
for (int i = 0; i < PROPAGATE_TO_ENV.length; i++) extraEnvironment.put(PROPAGATE_TO_ENV[i], parentParameters.get(PROPAGATE_TO_ENV[i]));
StringBuffer queryString = new StringBuffer(this.queryString);
addNamespacedParameters(parentParameters, namespace, queryString);
if (defn.shouldParsePersistedText())
addParsedParameters(snippet.getPersistedText(), queryString);
StringBuffer fullUri = new StringBuffer();
fullUri.append(WebServer.urlEncodePath(prefix)).append("/").append(uri);
HTMLUtils.appendQuery(fullUri, queryString.toString());
WebServer webServer = (WebServer) parentEnv.get(TinyCGI.TINY_WEB_SERVER);
try {
String results = webServer.getRequestAsString(fullUri.toString(), extraEnvironment);
snippet.setStatus(SnippetInvoker.STATUS_OK);
snippet.setUri(fullUri.toString());
return results;
} catch (IOException ioe) {
snippet.setStatus(SnippetInvoker.STATUS_INTERNAL_ERROR);
snippet.setInvocationException(ioe);
throw ioe;
}
}
Aggregations