Skip to content

Commit

Permalink
Support for URL redirects in Orchard clients. This will be used for O…
Browse files Browse the repository at this point in the history
…Auth.
  • Loading branch information
aquark committed Jul 23, 2008
1 parent a64152f commit 9fad80e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Orchard/src/orc/inc/orchard.inc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
site Prompt = orc.lib.orchard.Prompt
site Prompt = orc.lib.orchard.Prompt
site Redirect = orc.lib.orchard.Redirect
42 changes: 42 additions & 0 deletions Orchard/src/orc/lib/orchard/Redirect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package orc.lib.orchard;

import java.net.MalformedURLException;
import java.net.URL;

import orc.error.JavaException;
import orc.error.SiteException;
import orc.error.TokenException;
import orc.runtime.Args;
import orc.runtime.OrcEngine;
import orc.runtime.Token;
import orc.runtime.sites.Site;

/**
* Redirect the user to a URL.
* @author quark
*/
public class Redirect extends Site {
/**
* Interface implemented by an engine which can handle
* this site.
* @author quark
*/
public interface Redirectable {
public void redirect(URL url);
}
@Override
public void callSite(Args args, final Token caller) throws TokenException {
OrcEngine engine = caller.getEngine();
final String url = args.stringArg(0);
if (!(engine instanceof Redirectable)) {
caller.error(new SiteException(
"This Orc engine does not support the Redirect site."));
}
try {
((Redirectable)engine).redirect(new URL(url));
caller.resume(signal());
} catch (MalformedURLException e) {
caller.error(new JavaException(e));
}
}
}
8 changes: 7 additions & 1 deletion Orchard/src/orc/orchard/Job.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package orc.orchard;

import java.net.URL;
import java.rmi.RemoteException;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -12,6 +13,7 @@
import orc.error.TokenException;
import orc.lib.orchard.Prompt.PromptCallback;
import orc.lib.orchard.Prompt.Promptable;
import orc.lib.orchard.Redirect.Redirectable;
import orc.orchard.errors.InvalidJobStateException;
import orc.orchard.errors.InvalidPromptException;
import orc.orchard.oil.ValueMarshaller;
Expand Down Expand Up @@ -136,7 +138,7 @@ public synchronized void close() {
*/
private JobConfiguration configuration;

private class JobEngine extends OrcEngine implements Promptable {
private class JobEngine extends OrcEngine implements Promptable, Redirectable {
private StringBuffer printBuffer = new StringBuffer();
/** Close the event stream when done running. */
@Override
Expand Down Expand Up @@ -183,6 +185,10 @@ public void prompt(String message, PromptCallback callback) {
}
events.add(new PromptEvent(promptID, message));
}

public void redirect(URL url) {
events.add(new RedirectEvent(url));
}
}
private int nextPromptID = 1;
private Map<Integer, PromptCallback> pendingPrompts =
Expand Down
6 changes: 5 additions & 1 deletion Orchard/src/orc/orchard/JobEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

import javax.xml.bind.annotation.XmlSeeAlso;

@XmlSeeAlso({PublicationEvent.class, TokenErrorEvent.class, PrintlnEvent.class, PromptEvent.class})
@XmlSeeAlso({PublicationEvent.class,
TokenErrorEvent.class,
PrintlnEvent.class,
PromptEvent.class,
RedirectEvent.class})
public abstract class JobEvent implements Serializable {
public int sequence;
public Date timestamp;
Expand Down
13 changes: 13 additions & 0 deletions Orchard/src/orc/orchard/RedirectEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package orc.orchard;

import java.net.URL;

public class RedirectEvent extends JobEvent {
public URL url;

public RedirectEvent() {}

public RedirectEvent(URL url) {
this.url = url;
}
}
11 changes: 11 additions & 0 deletions Orchard/web/orc-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ function escapeHtml(v) {
return v;
}

/**
* Despite the name this doesn't actually redirect,
* it justs opens a new window.
*/
function redirect(url) {
open(url);
}

/**
* Convert arbitrary JSON values to
* pretty-printed HTML
Expand Down Expand Up @@ -338,6 +346,9 @@ function OrcWidget(code) {
case "ns2:promptEvent":
onPrompt(v);
break;
case "ns2:redirectEvent":
redirect(v.url);
break;
}
});
job('purgeJobEvents', {}, function () {
Expand Down

0 comments on commit 9fad80e

Please sign in to comment.