Examples of Replacer


Examples of com.adito.boot.Replacer

    // 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);
View Full Code Here

Examples of com.adito.boot.Replacer

                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);
View Full Code Here

Examples of com.adito.boot.Replacer

      /* We may support replacement variables so
       * to validate we must replace with the minimum value
       */      
      if(properties != null && "true".equalsIgnoreCase(properties.getProperty("replacementVariables"))) {
        Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
          return replacementPattern;
        }       
        };
        ReplacementEngine re = new ReplacementEngine();
View Full Code Here

Examples of com.adito.boot.Replacer

      /* We may support replacement variables so
       * to validate we must replace with the minimum value
       */      
      if(properties != null && "true".equalsIgnoreCase(properties.getProperty("replacementVariables"))) {
        Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
          return replacementPattern;
        }       
        };
        ReplacementEngine re = new ReplacementEngine();
View Full Code Here

Examples of com.adito.boot.Replacer

   */
  public static void convertNetworkPlace(NetworkPlace networkPlace) throws Exception {
    if(Util.isNullOrTrimmedBlank(networkPlace.getScheme())) {
      String path = networkPlace.getPath();
     
      Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
 
              String match = matcher.group();
              String key = match.substring(2, 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 "_prototype_" + type + "_" + key + "_";
              }
              catch(Exception e) {
                NetworkPlaceInstall.log.error("Failed to replace.", e);
              }
              return "prototype";
        }
       
      };
     
      // 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("_");
View Full Code Here

Examples of com.adito.boot.Replacer

                    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")) {
View Full Code Here

Examples of jimm.util.Replacer

    assertEquals("a,xyzzy", StringUtils.join(list, ","));
    assertEquals("a-*-xyzzy", StringUtils.join(list, "-*-"));
}

public void testReplace() {
    Replacer r = new Replacer() {
  public Object replace(String s) { return "x"; }
  };

    assertNull(StringUtils.replaceDelimited("", "", null, null));
    assertNull(StringUtils.replaceDelimited(null, null, null, null));
View Full Code Here

Examples of jimm.util.Replacer

     StringUtils.replaceDelimited("{", "}", r,
          "{jobs.hourly rate}.nil? ? nil : {jobs.hourly rate} / 100.0"));
}

public void testReplaceNotAfter() {
    Replacer r = new Replacer() {
  public Object replace(String s) { return "x"; }
  };

    assertNull(StringUtils.replaceDelimited("#", "", "", null, null));
    assertNull(StringUtils.replaceDelimited("#", "#", "#", null, null));
View Full Code Here

Examples of jimm.util.Replacer

}

public void testAvoidInfiniteLoop() {
    final int[] count = new int[1];
    count[0] = 0;
    Replacer r = new Replacer() {
  public Object replace(String s) {
      if (++count[0] == 2)
    fail("caught in an infinite loop");
      return "{" + s + "}";
  }
View Full Code Here

Examples of jimm.util.Replacer

    // Here, we are using replacers so we can start observing things.
    // Usually, they are used to replace strings.

    // Formulas
    StringUtils.replaceDelimited(exceptAfter, "{@", "}", new Replacer() {
  public Object replace(String str) {
      Formula f = report.findFormula(str);
      observedContents.add(f);
      f.addObserver(Expression.this);
      return "";    // Avoid early bail-out
  }},
         expr);

    // Parameters
    StringUtils.replaceDelimited(exceptAfter, "{?", "}", new Replacer() {
  public Object replace(String str) {
      Parameter p = report.findParameter(str);
      observedContents.add(p);
      p.addObserver(Expression.this);
      return "";    // Avoid early bail-out
  }},
         expr);

    // User columns
    StringUtils.replaceDelimited(exceptAfter, "{!", "}", new Replacer() {
  public Object replace(String str) {
      UserColumn uc = report.findUserColumn(str);
      observedContents.add(uc);
      uc.addObserver(Expression.this);
      return "";    // Avoid early bail-out
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.