Package com.adito.boot

Examples of com.adito.boot.ReplacementEngine$ReplaceOp


   
    // Create the javascript to execute to launch the HTML application window
   
    String windowParsed = null;
        if (window != null) {
            ReplacementEngine engine = new ReplacementEngine();
            engine.addPattern("\\$\\{shortcut:[^}]*\\}", new Replacer() {
                public String getReplacement(Pattern pattern, Matcher matcher, String sequence) {
                    String match = matcher.group();
                    try {
                        String param = match.substring(11, match.length() - 1);
                        String val = shortcut.getParameters().get(param);
                        val = val == null ? "" : val;
                        return val;
                    } catch (Throwable t) {
                    }
                    return "";
                }
            }, null);
            windowParsed = engine.replace(window);
        }

        String script = "";
        if (aditoAware) {
            script = "myRef = window.open('" + "/getHTMLApplication.do?" 
View Full Code Here


                            requestProcessor.getRequestParameters().getProxiedURIDetails().getProxiedURL().toExternalForm());
            if (replacements.size() > 0) {
                // The default replacer
              if (log.isDebugEnabled())
                log.debug("Found " + replacements.size() + ", processing");
                ReplacementEngine replace = new ReplacementEngine();
               
                if(!requestProcessor.getWebForward().getEncoding().equals(WebForwardTypes.DEFAULT_ENCODING))
                    replace.setEncoding(requestProcessor.getWebForward().getEncoding());
                else
                    replace.setEncoding(responseProcessor.getCharset());
               
                replace.setCaseSensitive(false);
                replace.setDotAll(false);
                final BaseSearch baseSearch = new BaseSearch();
                replace.addPattern("(<base*\\s+(?:href)\\=['\\\"]*)([^\\s'>\\\"]*)([^>]*)(>)", baseSearch, "");

                Replacer replacer = new ProxyReplacer(requestProcessor, baseSearch);

                for (Iterator i = replacements.iterator(); i.hasNext();) {
                    Replacement r = (Replacement) i.next();
                    if (log.isDebugEnabled())
                      log.debug("Adding replacement pattern '" + r.getMatchPattern() + "' = '" + r.getReplacePattern() + "'");
                    if (r.getReplacePattern().startsWith("#")) {
                        String cn = r.getReplacePattern().substring(1);
                        try {
                            Class clazz = Class.forName(cn);
                            Constructor c = clazz.getConstructor(new Class[] { URL.class, String.class });
                            Replacer re = (Replacer) (c.newInstance(new Object[] { requestProcessor.getRequestParameters().getProxiedURIDetails().getProxiedURLBase(), requestProcessor.getLaunchId() }));
                            if (log.isDebugEnabled())
                              log.debug("Loaded custom replacer " + cn + ".");
                            replace.addPattern(r.getMatchPattern(), re, null);
                        } catch (Throwable t) {
                            log.error("Could not load custom replacer " + cn + ".", t);
                        }
                    } else {
                        replace.addPattern(r.getMatchPattern(), replacer, r.getReplacePattern());
                    }
                }

                OutputStream monitorOut = responseOut;
                int origLen = responseProcessor.getContentLength();
                int len = origLen == -1 ? 1024 : responseProcessor.getContentLength();
                if (log.isDebugEnabled())
                  log.debug("Reading response from target and processing into memory (" + len + " bytes buffer)");
                monitorOut = new ByteArrayOutputStream(len);
                long length = replace.replace(serverIn, monitorOut);
                if (log.isDebugEnabled())
                  log.debug("Replacement complete");
                               

                /* Tack some javascript on to the end of the page for JavaScript based automatic
View Full Code Here

        Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
          return replacementPattern;
        }       
        };
        ReplacementEngine re = new ReplacementEngine();
        re.addPattern(VariableReplacement.VARIABLE_PATTERN, r, String.valueOf(min));
        value = re.replace(value);
      }
       
        // Validate
        try {
            int i  = Integer.parseInt(value);
View Full Code Here

        Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
          return replacementPattern;
        }       
        };
        ReplacementEngine re = new ReplacementEngine();
        re.addPattern(VariableReplacement.VARIABLE_PATTERN, r, String.valueOf(min));
        value = re.replace(value);
      }
       
        // Validate
        try {
            int i  = Integer.parseInt(value);
View Full Code Here

        out.write(b);
        return b.length;
    }

    public String replace(String input) {
        ReplacementEngine engine = new ReplacementEngine();
        if (encoder != null) {
            engine.setEncoder(encoder);
        }
       
        // User attributes and policy attributes can nest replacement variables so these must
        // be done first
        if (session != null) {
            engine.addPattern(VARIABLE_PATTERN, new UserAttributesReplacer(session.getUser().getPrincipalName(), session.getUser()
                            .getRealm().getResourceId()), null);
        } else {
            if (username != null) {
                engine.addPattern(VARIABLE_PATTERN, new UserAttributesReplacer(username, realm), null);
            }
        }
       
        if (policy != null) {
            engine.addPattern(VARIABLE_PATTERN, new PolicyAttributesReplacer(policy), null);
        }
       
        // Now do the variable patterns that may be nested in attributes
       
        engine.addPattern(VARIABLE_PATTERN, GLOBAL_REPLACER, null);
        if (extensionBundle != null)
            engine.addPattern(VARIABLE_PATTERN, new ExtensionBundleReplacer(extensionBundle), null);
        if (extensionDescriptor != null) {
            engine.addPattern(VARIABLE_PATTERN, new ExtensionDescriptorReplacer(extensionDescriptor, parameters), null);
        }
        if (request != null) {
            engine.addPattern(VARIABLE_PATTERN, new RequestHandlerRequestReplacer(request), null);
        }
        if (servletRequest != null) {
            engine.addPattern(VARIABLE_PATTERN, new ServletRequestReplacer(servletRequest), null);
        }
        if (session != null) {
            engine.addPattern(VARIABLE_PATTERN, new SessionInfoReplacer(session), null);
        }
        return engine.replace(input);
    }
View Full Code Here

        }
       
      };
     
      // Replace all replacement variables with prototype values
          ReplacementEngine engine = new ReplacementEngine();
          engine.addPattern(NetworkPlaceInstall.VARIABLE_PATTERN, r, null);
          path = engine.replace(path);
         
          //
          URI newUri = null;
     
      // Is it a UNC path
      if(path.startsWith("\\\\")) {
        try {
          newUri = new URI("smb:" + path.replace('\\', '/'));
        }
        catch(MalformedURIException murie) {
          murie.printStackTrace();
        }
      }
     
      // Is this a supported RI?
      if(newUri == null) {
        int idx = path.indexOf(':');
        if(idx > 1) { // index of 1 would mean a windows absolute path           
          // Is it an non windows absolute file URI?
          String rpath = path.substring(idx + 1);
          String scheme = path.substring(0, idx);
          if(scheme.equals("file")) {
            if(rpath.startsWith("//") && !rpath.startsWith("///") &&
                    ( rpath.length() < 4 || rpath.charAt(3) != ':' ) ) {
              path = scheme + ":/" + rpath;
            }
          }
         
          newUri = new URI(path);         
        }
      }
     
      // Is it a local file? (wont work for replacements)
      boolean switchSlash = false;
      if(newUri == null) {   
          if(path.contains("\\")) {
            switchSlash = true;
          }
          try {
                    String scheme;
                    if(path.toLowerCase().endsWith(".jar")) {
                        scheme = "jar";
                    } else if(path.toLowerCase().endsWith(".zip")) {
                        scheme = "zip";
                    } else {
                        scheme = "file";
                    }
          newUri = new URI(scheme + ":///" + DAVUtilities.stripLeadingSlash(path.replace('\\', '/')));
        } catch (MalformedURIException e) {
          e.printStackTrace();
        }
      }
     
      // Convert the network place if required
      if(newUri != null) {
            engine = new ReplacementEngine();
 
       
        r = new Replacer() {
          public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
                String match = matcher.group();
                String key = match.substring(11, match.length() - 1);
                try {
                    int idx = key.indexOf("_");
                    if (idx == -1) {
                        throw new Exception("String replacement pattern is in incorrect format for " + key
                            + ". Must be <TYPE>:<key>");
                    }
                    String type = key.substring(0, idx);
                    key = key.substring(idx + 1);
                    return "${" + type + ":" + key + "}";
                }
                catch(Exception e) {
                  NetworkPlaceInstall.log.error("Failed to replace.", e);
                }
                return "prototype";
          }
         
        };
            engine.addPattern(NetworkPlaceInstall.PROTOTYPE_PATTERN, r, null);
            String newScheme = newUri.getScheme();
            String newHost = newUri.getHost();
            if(!Util.isNullOrTrimmedBlank(newHost)) {
              newHost = engine.replace(newHost);
            }
            int newPort = Math.max(newUri.getPort(), 0);
            String newPath = newUri.getPath();
            if(!Util.isNullOrTrimmedBlank(newPath)) {
              newPath = Util.urlDecode(engine.replace(newPath));
            }
            if(newPath.startsWith("/") && newPath.length() > 2 && newPath.charAt(2) == ':') {
              newPath = newPath.substring(1);
            }
            if(switchSlash) {
              newPath = newPath.replace('/', '\\');
            }
            String newFragment = newUri.getFragment();
            if(!Util.isNullOrTrimmedBlank(newFragment)) {
              newFragment = engine.replace(newFragment);
            }
            String newUserinfo = newUri.getUserinfo();
        int idx = newUserinfo == null ? -1 : newUserinfo.indexOf(':');
        String newUsername = newUserinfo;
        String newPassword = "";
        if(idx != -1) {
          newPassword = newUsername.substring(idx + 1);
          newUsername = newUsername.substring(0, idx);
        }
            if(!Util.isNullOrTrimmedBlank(newUsername)) {
              newUsername = Util.urlDecode(engine.replace(newUsername));
            }
            if(!Util.isNullOrTrimmedBlank(newPassword)) {
              newPassword = Util.urlDecode(engine.replace(newPassword));
            }
       
        networkPlace.setScheme(Util.emptyWhenNull(newScheme));
        networkPlace.setHost(Util.emptyWhenNull(newHost));
        networkPlace.setPort(newPort);
View Full Code Here

        r.setApplicationShortcut(app, shortcut.getParameters());
        r.setServletRequest(request);
        r.setLaunchSession(launchSession);       
        String templateText = r.replace(template.toString());

        ReplacementEngine engine = new ReplacementEngine();

        String tunnels = request.getParameter("tunnels");
        if (tunnels != null && !tunnels.equals("")) {
            StringTokenizer t = new StringTokenizer(tunnels, ",");
            while (t.hasMoreTokens()) {
                String name = null;
                String hostname = null;
                int port = -1;
                try {
                    String tunnel = t.nextToken();
                    StringTokenizer t2 = new StringTokenizer(tunnel, ":");
                    name = t2.nextToken();
                    hostname = t2.nextToken();
                    port = Integer.parseInt(t2.nextToken());
                } catch (Exception e) {
                    throw new Exception("Failed to parse tunnels parameter '" + tunnels + "'.", e);
                }
                final ExtensionDescriptor.TunnelDescriptor tunnelDescriptor = app.getTunnel(name);
                if (tunnelDescriptor == null) {
                    throw new Exception("No tunnel named " + name);
                }
                final String fHostname = hostname;
                final int fPort = port;
                String pattern = "\\$\\{tunnel:" + name + "\\.[^\\}]*\\}";
                engine.addPattern(pattern, new Replacer() {
                    public String getReplacement(Pattern pattern, Matcher matcher, String sequence) {
                        String match = matcher.group();
                        if (match.equals("${tunnel:" + tunnelDescriptor.getName() + ".hostname}")) {
                            return fHostname;
                        } else if (match.equals("${tunnel:" + tunnelDescriptor.getName() + ".port}")) {
                            return String.valueOf(fPort);
                        } else {
                            return "";
                        }
                    }
                }, null);

            }
        }

        // Get the location of Adito as the client sees it
        String url = request.getParameter("adito");
        if (url != null) {
            String host = request.getHeader(HttpConstants.HDR_HOST);
            if (host != null) {
                url = (request.isSecure() ? "https" : "http") + "://" + host;
            } else {

                throw new Exception("No adito parameter supplied.");
            }
        }
        final URL aditoUrl = new URL(url);
        engine.addPattern("\\$\\{adito:[^\\}]*\\}", new Replacer() {
            public String getReplacement(Pattern pattern, Matcher matcher, String sequence) {
                String match = matcher.group();
                try {
                    String param = match.substring(14, match.length() - 1);
                    if (param.equals("host")) {
                        return aditoUrl.getHost();
                    } else if (param.equals("port")) {
                        return String.valueOf(aditoUrl.getPort() == -1 ? (aditoUrl.getProtocol().equals("https") ? 443
                                        : 80) : aditoUrl.getPort());
                    } else if (param.equals("protocol")) {
                        return aditoUrl.getProtocol();
                    } else {
                        throw new Exception("Unknow variable.");
                    }
                } catch (Throwable t) {
                    log.error("Failed to replace " + match + ".", t);
                }
                return "";
            }
        }, null);

        String processed = engine.replace(templateText);
        if (log.isDebugEnabled())
          log.debug("Returning " + processed);

        Util.noCache(response);

View Full Code Here

TOP

Related Classes of com.adito.boot.ReplacementEngine$ReplaceOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.