private void traverseToLeaves(
     final PackageDependenciesNode treeNode,
     final StringBuffer denyRules,
     final StringBuffer allowRules) {
   final Enumeration enumeration = treeNode.breadthFirstEnumeration();
   while (enumeration.hasMoreElements()) {
     PsiElement childPsiElement =
         ((PackageDependenciesNode) enumeration.nextElement()).getPsiElement();
     if (myIllegalDependencies.containsKey(childPsiElement)) {
       final Map<DependencyRule, Set<PsiFile>> illegalDeps =
           myIllegalDependencies.get(childPsiElement);
       for (final DependencyRule rule : illegalDeps.keySet()) {
         if (rule.isDenyRule()) {
           if (denyRules.indexOf(rule.getDisplayText()) == -1) {
             denyRules.append(rule.getDisplayText());
             denyRules.append("\n");
           }
         } else {
           if (allowRules.indexOf(rule.getDisplayText()) == -1) {
             allowRules.append(rule.getDisplayText());
             allowRules.append("\n");
           }
         }
       }
     }
   }
 }
Exemplo n.º 2
0
 private void replaceAll(StringBuffer buffer, String search, String replace) {
   int index = buffer.indexOf(search);
   while (index >= 0) {
     buffer.replace(index, index + search.length(), replace);
     index = buffer.indexOf(search, index + search.length());
   }
 }
 public static String getDomain(HttpServletRequest request) {
   StringBuffer url = request.getRequestURL();
   int end = url.indexOf(".");
   if (end == -1) return "";
   int start = url.indexOf("//");
   return url.substring(start + 2, end);
 }
Exemplo n.º 4
0
  /*
   *  Replaces a template string throughout the entire file
   */
  public boolean replaceValue(String templateString, String newValue) {
    boolean retVal = false;
    if (templateString != null
        && templateString.length() > 0
        && newValue != null
        && newValue.length() > 0) {

      StringBuffer workTemplateString = new StringBuffer(templateString);

      if (!templateString.startsWith("[[") && !templateString.endsWith("]]")) {
        workTemplateString.insert(0, "[[");
        workTemplateString.append("]]");
      }

      boolean done = false;
      while (!done) {
        if (m_css.indexOf(workTemplateString.toString()) >= 0) {
          m_css.replace(
              m_css.indexOf(workTemplateString.toString()),
              m_css.indexOf(workTemplateString.toString()) + workTemplateString.length(),
              newValue);
          retVal = true;
        } else {
          done = true;
        }
      }
    }
    return retVal;
  }
 private static void updateShortcuts(StringBuffer text) {
   int lastIndex = 0;
   while (true) {
     lastIndex = text.indexOf(SHORTCUT_ENTITY, lastIndex);
     if (lastIndex < 0) return;
     final int actionIdStart = lastIndex + SHORTCUT_ENTITY.length();
     int actionIdEnd = text.indexOf(";", actionIdStart);
     if (actionIdEnd < 0) {
       return;
     }
     final String actionId = text.substring(actionIdStart, actionIdEnd);
     String shortcutText =
         getShortcutText(actionId, KeymapManager.getInstance().getActiveKeymap());
     if (shortcutText == null) {
       Keymap defKeymap =
           KeymapManager.getInstance()
               .getKeymap(DefaultKeymap.getInstance().getDefaultKeymapName());
       if (defKeymap != null) {
         shortcutText = getShortcutText(actionId, defKeymap);
         if (shortcutText != null) {
           shortcutText += " in default keymap";
         }
       }
     }
     if (shortcutText == null) {
       shortcutText = "<no shortcut for action " + actionId + ">";
     }
     text.replace(lastIndex, actionIdEnd + 1, shortcutText);
     lastIndex += shortcutText.length();
   }
 }
  protected Empresa getData(HtmlPage page) {

    StringBuffer sb = new StringBuffer();
    sb.append(page.asText());

    int posInit = 0;
    int posEnd = 0;

    Empresa empresa = new Empresa();

    posInit = sb.indexOf(EMPRESA[0]);
    posEnd = (posInit > -1) ? sb.indexOf(EMPRESA[1], posInit) : -1;
    // NOME EMPRESA
    if (posInit > -1 && posEnd > -1) {
      empresa.setNome(sb.substring(posInit + EMPRESA[0].length(), posEnd).trim());
    }

    posInit = sb.indexOf(CONTATO[0]);
    posEnd = (posInit > -1) ? sb.indexOf(CONTATO[1], posInit) : -1;
    if (posInit > -1 && posEnd > -1) {
      empresa.setContato(sb.substring(posInit + CONTATO[0].length(), posEnd).trim());
    }

    empresa.setSite(null);
    empresa.setEmail(null);
    empresa.setLocal("MX");

    System.out.println("\n### EMPRESA:" + empresa.getNome());
    System.out.println("### CONTATO:" + empresa.getContato() + "\n");

    return empresa;
  }
Exemplo n.º 7
0
  @Test
  public void urlDownload() throws IOException {
    URL url = new URL("http://news.sohu.com/20130531/n377586607.shtml");
    // url = new URL("http://www.baidu.com");
    // url = new URL("http://www.sohu.com");
    URLConnection conn = url.openConnection();
    conn.connect();
    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuffer content = new StringBuffer();
    String line = null;
    while ((line = reader.readLine()) != null) {
      content.append(line + System.getProperty("line.separator"));
      if (content.indexOf("</title>") != -1 && content.indexOf("charset") != -1) {
        break;
      }
    }

    Pattern p = Pattern.compile("charset=(.+)\"");
    Matcher m = p.matcher(content.toString());
    String encode = null;
    while (m.find()) {
      encode = m.group(1);
    }
    System.out.println(encode);
    System.out.println(new String(content.toString().getBytes(), encode));
    reader.close();
  }
Exemplo n.º 8
0
  /**
   * Redirects the user to the current url over HTTPS
   *
   * @param request a HttpServletRequest
   * @param response a HttpServletResponse
   * @param urlStr
   * @param nonSslPort the port Non-SSL requests should be forwarded to
   * @throws ServletException
   * @throws IOException
   */
  public static void redirectOverNonSSL(
      HttpServletRequest request, HttpServletResponse response, String urlStr, int nonSslPort)
      throws ServletException, IOException {

    StringBuffer url = new StringBuffer(urlStr);

    // Make sure we're on http
    if (url.charAt(4) == 's') url.deleteCharAt(4);

    // If there is a non-ssl port, make sure we're on it,
    // otherwise assume we're already on the right port
    if (nonSslPort > 0) {
      int portStart = url.indexOf(":", 8) + 1;
      int portEnd = url.indexOf("/", 8);

      if (portEnd == -1) // If their isn't a trailing slash, then the end is the last char
      portEnd = url.length() - 1;

      if (portStart > 0
          && portStart
              < portEnd) { // If we detected a : before the trailing slash or end of url, delete the
                           // port
        url.delete(portStart, portEnd);
      } else {
        url.insert(portEnd, ':'); // If the url didn't have a port, add in the :
        portStart = portEnd;
      }

      url.insert(portStart, nonSslPort); // Insert the right port where it should be
    }

    LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString());
    sendPermanentRedirect(response, url.toString());
  }
  public static void insertStyles(StringBuffer buffer, String[] styles) {
    if (styles == null || styles.length == 0) return;

    StringBuffer styleBuf = new StringBuffer(10 * styles.length);
    for (int i = 0; i < styles.length; i++) {
      styleBuf.append(" style=\""); // $NON-NLS-1$
      styleBuf.append(styles[i]);
      styleBuf.append('"');
    }

    // Find insertion index
    // a) within existing body tag with trailing space
    int index = buffer.indexOf("<body "); // $NON-NLS-1$
    if (index != -1) {
      buffer.insert(index + 5, styleBuf);
      return;
    }

    // b) within existing body tag without attributes
    index = buffer.indexOf("<body>"); // $NON-NLS-1$
    if (index != -1) {
      buffer.insert(index + 5, ' ');
      buffer.insert(index + 6, styleBuf);
      return;
    }
  }
  public String normalizePath(String path) {
    int column = path.indexOf(':');
    if (column > 0) {
      char driveLetter = path.charAt(column - 1);
      if (Character.isLowerCase(driveLetter)) {
        StringBuffer sb = new StringBuffer();
        if (column - 1 > 0) {
          sb.append(path.substring(0, column - 1));
        }
        sb.append(Character.toUpperCase(driveLetter));
        sb.append(path.substring(column));
        path = sb.toString();
      }
    }
    if (path.indexOf('.') == -1 || path.equals(".")) { // $NON-NLS-1$
      return (new Path(path)).toString(); // convert separators to '/'
    }
    // lose "./" segments since they confuse the Path normalization
    StringBuffer buf = new StringBuffer(path);
    int len = buf.length();
    StringBuffer newBuf = new StringBuffer(buf.length());
    int scp = 0; // starting copy point
    int ssp = 0; // starting search point
    int sdot;
    boolean validPrefix;
    while (ssp < len && (sdot = buf.indexOf(".", ssp)) != -1) { // $NON-NLS-1$
      validPrefix = false;
      int ddot = buf.indexOf("..", ssp); // $NON-NLS-1$
      if (sdot < ddot || ddot == -1) {
        newBuf.append(buf.substring(scp, sdot));
        scp = sdot;
        ssp = sdot + 1;
        if (ssp < len) {
          if (sdot == 0 || buf.charAt(sdot - 1) == '/' || buf.charAt(sdot - 1) == '\\') {
            validPrefix = true;
          }
          char nextChar = buf.charAt(ssp);
          if (validPrefix && nextChar == '/') {
            ++ssp;
            scp = ssp;
          } else if (validPrefix && nextChar == '\\') {
            ++ssp;
            if (ssp < len - 1 && buf.charAt(ssp) == '\\') {
              ++ssp;
            }
            scp = ssp;
          } else {
            // no path delimiter, must be '.' inside the path
            scp = ssp - 1;
          }
        }
      } else if (sdot == ddot) {
        ssp = sdot + 2;
      }
    }
    newBuf.append(buf.substring(scp, len));

    IPath orgPath = new Path(newBuf.toString());
    return orgPath.toString();
  }
Exemplo n.º 11
0
 protected String[] escapePaths(String srcPath, String dstPath) {
   srcPath = srcPath.trim();
   dstPath = dstPath.trim();
   String os = System.getProperty("os.name").toLowerCase();
   if (os != null && os.indexOf("windows") > -1) {
     srcPath = "\"" + srcPath + "\"";
     dstPath = "\"" + dstPath + "\"";
   } else {
     int lastidx = -1, curridx;
     StringBuffer buff = new StringBuffer(srcPath);
     while ((curridx = buff.indexOf(" ", lastidx)) > 0) {
       buff.insert(curridx, "\\");
       lastidx = curridx + 2;
     }
     srcPath = buff.toString();
     buff = new StringBuffer(dstPath);
     lastidx = -1;
     while ((curridx = buff.indexOf(" ", lastidx)) > 0) {
       buff.insert(curridx, "\\");
       lastidx = curridx + 2;
     }
     dstPath = buff.toString();
   }
   return new String[] {srcPath, dstPath};
 }
Exemplo n.º 12
0
 public static String removeParameter(String parameterString, String parameter) {
   StringBuffer sb = new StringBuffer(parameterString);
   int startPos = 0;
   if (parameterString.startsWith(parameter + "=")) {
     int pos = parameterString.indexOf('&');
     if (pos < 0) {
       sb.setLength(0);
     } else {
       sb.replace(0, pos, "");
     }
     startPos = 0;
   } else {
     int pos = parameterString.indexOf("&" + parameter + "=");
     if (pos >= 0) {
       int endPos = parameterString.indexOf("&", pos + 1);
       if (endPos < 0) {
         endPos = sb.length();
       }
       sb.replace(pos + 1, endPos, "");
       startPos = pos + 1;
     } else {
       startPos = sb.length();
     }
   }
   int pos = sb.indexOf("&" + parameter + "=", startPos);
   while (pos >= 0) {
     int endPos = sb.indexOf("&", pos + 1);
     if (endPos < 0) {
       endPos = sb.length();
     }
     sb.replace(pos, endPos, "");
     pos = sb.indexOf("&" + parameter + "=", pos);
   }
   return sb.toString();
 }
Exemplo n.º 13
0
 private static String internalReplaceDynamicParameters(
     String address, Map parameters, int index) {
   StringBuffer sb = new StringBuffer(address);
   int startPos = sb.indexOf("{");
   while (startPos >= 0) {
     int endPos = sb.indexOf("}", startPos + 1);
     if (endPos >= 0) {
       String attribute = sb.substring(startPos + 1, endPos);
       Object value = parameters.get(attribute);
       if (value != null) {
         if (value instanceof Object[]) {
           value = ((Object[]) value)[index];
         }
         sb.replace(startPos, endPos + 1, value.toString());
         endPos = startPos + value.toString().length();
       } else {
         sb.replace(startPos, endPos + 1, "");
         endPos = startPos;
       }
       startPos = sb.indexOf("{", endPos);
     } else {
       startPos = -1;
     }
   }
   return sb.toString();
 }
Exemplo n.º 14
0
 /**
  * 参数替换
  *
  * @param strVal
  * @param props
  * @param visitedPlaceholders
  * @return
  * @throws Exception
  */
 public static String parseStringValue(String strVal, Properties props) throws Exception {
   StringBuffer buf = new StringBuffer(strVal);
   int startIndex = strVal.indexOf(placeholderPrefix);
   while (startIndex != -1) {
     int endIndex = findPlaceholderEndIndex(buf, startIndex);
     if (endIndex != -1) {
       String placeholder = buf.substring(startIndex + placeholderPrefix.length(), endIndex);
       placeholder = parseStringValue(placeholder, props);
       String propVal = resolvePlaceholder(placeholder, props);
       if (propVal != null) {
         propVal = parseStringValue(propVal, props);
         buf.replace(startIndex, endIndex + placeholderSuffix.length(), propVal);
         if (log.isTraceEnabled()) {
           log.trace("已经替换占位符 '" + placeholder + "'");
         }
         startIndex = buf.indexOf(placeholderPrefix, startIndex + propVal.length());
       } else if (ignoreUnresolvablePlaceholders) {
         startIndex = buf.indexOf(placeholderPrefix, endIndex + placeholderSuffix.length());
       } else {
         throw new Exception("无法替换占位符 '" + placeholder + "'");
       }
     } else {
       startIndex = -1;
     }
   }
   return buf.toString();
 }
Exemplo n.º 15
0
 protected String cleanValue(String value) {
   LOG.debug("cleanValue value = " + value);
   int i = value.indexOf('\n');
   if (i == -1) {
     i = value.indexOf('\r');
   }
   if (i != -1) {
     LOG.debug("cleanValue removing newline");
     StringBuffer sb = new StringBuffer(value);
     i = sb.indexOf("\n");
     while (i != -1) {
       sb.deleteCharAt(i);
       i = sb.indexOf("\n");
     }
     i = sb.indexOf("\r");
     while (i != -1) {
       sb.deleteCharAt(i);
       i = sb.indexOf("\r");
     }
     LOG.debug("cleanValue value ut = " + sb.toString());
     return sb.toString();
   } else {
     LOG.debug("cleanValue not modified");
     return value;
   }
 }
Exemplo n.º 16
0
  /*
   * Clean any command line args from a vm display name before comparing it with expected values
   */
  private String cleanCommandLineArgs(String vmName) {

    vmName =
        vmName.replaceAll(
            "\"", ""); // Strip any quotes from the name (needed for running on Jenkins server)

    StringBuffer buff = new StringBuffer(vmName);
    int argIndex = -1;

    while ((argIndex = buff.indexOf("-D"))
        != -1) { // While there's a command line argument in the string

      int argEnd = -1;

      if ((argEnd = buff.indexOf(" ", argIndex))
          == -1) { // If this argument is at the end of the display name then clean to the end
                   // rather than to next white space
        argEnd = buff.length();
      }

      buff.replace(
          argIndex - 1,
          argEnd,
          ""); // remove contents of buffer between space before arg starts and the next white
               // space/end of buffer
    }

    return buff.toString();
  }
Exemplo n.º 17
0
 /**
  * formate le nom afin d'enlever les "%20" dans le pseudo
  *
  * @deprecated utiliser la méthode getFormattedFriendlyName
  * @param str String
  * @return String
  */
 public static String formatFriendlyName(String str) {
   StringBuffer strbuff = new StringBuffer(str);
   while (strbuff.indexOf("%20") != -1) {
     strbuff.insert(strbuff.indexOf("%20"), " ");
     strbuff.delete(strbuff.indexOf("%20"), strbuff.indexOf("%20") + 3);
   }
   return strbuff.toString();
 }
  /**
   * an Arduino does not need to know about a shield but a shield must know about a Arduino Arduino
   * owns the script, but a Shield needs additional support Shields are specific - but plug into a
   * generalized Arduino Arduino shields can not be plugged into other uCs
   *
   * <p>TODO - Program Version & Type injection - with feedback + query to load
   */
  @Override
  public boolean attach(Arduino inArduino) {

    if (inArduino == null) {
      error("can't attach - arduino is invalid");
      return false;
    }

    this.arduino = inArduino;

    // arduinoName; FIXME - get clear on diction Program Script or Sketch
    StringBuffer newProgram = new StringBuffer();
    newProgram.append(arduino.getSketch());

    // modify the program
    int insertPoint = newProgram.indexOf(Arduino.VENDOR_DEFINES_BEGIN);

    if (insertPoint > 0) {
      newProgram.insert(Arduino.VENDOR_DEFINES_BEGIN.length() + insertPoint, ADAFRUIT_DEFINES);
    } else {
      error("could not find insert point in MRLComm.ino");
      // get info back to user
      return false;
    }

    insertPoint = newProgram.indexOf(Arduino.VENDOR_SETUP_BEGIN);

    if (insertPoint > 0) {
      newProgram.insert(Arduino.VENDOR_SETUP_BEGIN.length() + insertPoint, ADAFRUIT_SETUP);
    } else {
      error("could not find insert point in MRLComm.ino");
      // get info back to user
      return false;
    }

    insertPoint = newProgram.indexOf(Arduino.VENDOR_CODE_BEGIN);

    if (insertPoint > 0) {
      newProgram.insert(Arduino.VENDOR_CODE_BEGIN.length() + insertPoint, ADAFRUIT_CODE);
    } else {
      error("could not find insert point in MRLComm.ino");
      // get info back to user
      return false;
    }

    // set the program
    Sketch sketch = new Sketch("AdafruitMotorShield", newProgram.toString());
    arduino.setSketch(sketch);
    // broadcast the arduino state - ArduinoGUI should subscribe to
    // setProgram
    broadcastState(); // state has changed let everyone know

    // servo9.attach(arduinoName, 9); // FIXME ??? - createServo(Integer i)
    // servo10.attach(arduinoName, 10);

    // error(String.format("couldn't find %s", arduinoName));
    return true;
  }
  public void replaceSqlBlock(
      File versionFile, String fileName, String moduleName, String queryString)
      throws PhrescoException, IOException {
    BufferedReader buff = null;
    try {
      File scriptFile = new File(versionFile + File.separator + fileName);
      StringBuffer sb = new StringBuffer();
      if (scriptFile.isFile()) {
        // if script file is available need to replace the content
        buff = new BufferedReader(new FileReader(scriptFile));
        String readBuff = buff.readLine();
        String sectionStarts = MODULE_START_TAG + moduleName + START_MODULE_END_TAG;
        String sectionEnds = MODULE_START_TAG + moduleName + END_MODULE_END_TAG;

        while (readBuff != null) {
          sb.append(readBuff);
          sb.append(LINE_BREAK);
          readBuff = buff.readLine();
        }

        int cnt1 = sb.indexOf(sectionStarts);
        int cnt2 = sb.indexOf(sectionEnds);
        if (cnt1 != -1 || cnt2 != -1) {
          sb.replace(cnt1 + sectionStarts.length(), cnt2, LINE_BREAK + queryString + LINE_BREAK);
        } else {
          // if this module is not added already in the file and need to add this config alone
          sb.append(LINE_BREAK + DOUBLE_HYPHEN + LINE_BREAK);
          sb.append(MODULE_START_TAG + moduleName + START_MODULE_END_TAG + LINE_BREAK);
          sb.append(queryString);
          sb.append(LINE_BREAK);
          sb.append(MODULE_START_TAG + moduleName + END_MODULE_END_TAG + LINE_BREAK);
          sb.append(DOUBLE_HYPHEN + LINE_BREAK);
        }

      } else {
        // else construct the format and write
        // query string buffer
        sb.append(
            "CREATE TABLE IF NOT EXISTS `variable` (`name` varchar(128) NOT NULL DEFAULT '' COMMENT 'The name of the variable.', `value` longblob NOT NULL COMMENT 'The value of the variable.', PRIMARY KEY (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Named variable/value pairs created by Drupal core or any...';"
                + LINE_BREAK);
        sb.append(DOUBLE_HYPHEN + LINE_BREAK);
        sb.append(MODULE_START_TAG + moduleName + START_MODULE_END_TAG + LINE_BREAK);
        sb.append(queryString);
        sb.append(LINE_BREAK);
        sb.append(MODULE_START_TAG + moduleName + END_MODULE_END_TAG + LINE_BREAK);
        sb.append(DOUBLE_HYPHEN + LINE_BREAK);
      }

      FileUtils.writeStringToFile(scriptFile, sb.toString());
    } catch (Exception e) {
      throw new PhrescoException(e);
    } finally {
      if (buff != null) {
        buff.close();
      }
    }
  }
 /**
  * Abbreviate name.
  *
  * @param buf buffer to append abbreviation.
  * @param nameStart start of name to abbreviate.
  */
 public void abbreviate(final int nameStart, final StringBuffer buf) {
   int i = count;
   for (int pos = buf.indexOf(".", nameStart); pos != -1; pos = buf.indexOf(".", pos + 1)) {
     if (--i == 0) {
       buf.delete(nameStart, pos + 1);
       break;
     }
   }
 }
Exemplo n.º 21
0
  public DeviceResponse sendCommand(DeviceCommand command) {
    if (socket == null || socket.isClosed()) {
      try {
        socket = new Socket(device.getInetAddress(), device.getPort());
      } catch (IOException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
      }
    }

    try {
      BufferedReader deviceInput =
          new BufferedReader(new InputStreamReader(socket.getInputStream()));
      BufferedWriter deviceOutput =
          new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

      String commandString = command.getCommandString();
      deviceOutput.write(commandString + "\n");
      deviceOutput.flush();

      StringBuffer fullResponse = new StringBuffer();
      String partialResponse;
      while (!(partialResponse = deviceInput.readLine().trim()).equals("")) {
        fullResponse.append(partialResponse);
        fullResponse.append("\n");
      }

      int contentLength = 0;
      if (fullResponse.indexOf("Content-Length:") != -1) {
        String cls = "Content-Length:";
        int si = fullResponse.indexOf(cls);
        int ei = fullResponse.indexOf("\n", si + cls.length());
        contentLength = Integer.parseInt(fullResponse.substring(si + cls.length(), ei).trim());
      }

      StringBuffer content = null;
      if (contentLength > 0) {
        content = new StringBuffer(contentLength);
        char buffer[] = new char[1024];
        int read, totalRead = 0;
        do {
          read = deviceInput.read(buffer);
          totalRead += read;
          content.append(buffer, 0, read);
        } while (read != -1 && totalRead < contentLength);
      }

      return new DeviceResponse(
          fullResponse.toString(), content == null ? null : content.toString());
    } catch (IOException e) {
      logger.log(Level.SEVERE, e.getMessage(), e);
      throw new RuntimeException(e.getMessage(), e);
    }
  }
Exemplo n.º 22
0
  protected void addPlugins() {
    ContainerBase container = new ContainerBase("Plugins");
    container.initProperties();
    addChild(container);

    ComponentDescription[] desc = ComponentConnector.parseFile(filename);
    if (desc == null) {
      if (log.isWarnEnabled()) {
        log.warn("No data found in file " + filename);
      }
      return;
    }
    for (int i = 0; i < desc.length; i++) {
      StringBuffer name = new StringBuffer(desc[i].getName());
      StringBuffer className = new StringBuffer(desc[i].getClassname());
      String insertionPoint = desc[i].getInsertionPoint();
      String priority = desc[i].priorityToString(desc[i].getPriority());
      //       if(log.isDebugEnabled()) {
      //         log.debug("Insertion Point: " + insertionPoint);
      //       }

      if (insertionPoint.endsWith("Plugin")) {
        int start = 0;
        if ((start = name.indexOf("OrgRTData")) != -1) {
          name.delete(start, start + 2);
          start = className.indexOf("RT");
          className.delete(start, start + 2);
        }

        // HACK!
        // When dumping INIs we add an extra parameter to the GLSInitServlet,
        // so strip it off here
        boolean isGLS = false;
        if (className.indexOf("GLSInitServlet") != -1) {
          isGLS = true;
        }

        int index = name.lastIndexOf(".");
        if (index != -1) name.delete(0, index + 1);
        PluginBase plugin = new PluginBase(name.substring(0), className.substring(0), priority);
        plugin.initProperties();
        Iterator iter = ComponentConnector.getPluginProps(desc[i]);
        while (iter.hasNext()) {
          if (isGLS) {
            String param = (String) iter.next();
            if (param.startsWith("exptid=")) continue;
            else plugin.addParameter(param);
          } else plugin.addParameter((String) iter.next());
        }
        container.addChild(plugin);
      }
    }
  }
Exemplo n.º 23
0
 public static String removeJavascript(String s) {
   StringBuffer buf = new StringBuffer(s);
   int scriptStart = buf.indexOf("<script");
   while (scriptStart > 0) {
     int scriptEnd = buf.indexOf("</script>", scriptStart) + 9;
     if (scriptEnd > 0) {
       buf.replace(scriptStart, scriptEnd, "");
     }
     scriptStart = buf.indexOf("<script", scriptStart);
   }
   return buf.toString();
 }
Exemplo n.º 24
0
  /*
   * Returns the CSS for the selector name passed in.  Allows you to return one
   * selector from the entire file.
   */
  public String getSelector(String selectorName) {
    String retVal = "";
    if (selectorName != null) {
      if (m_css.indexOf(selectorName) >= 0) {
        int beginPos = m_css.indexOf(selectorName);
        int endPos = m_css.indexOf("}", beginPos);

        retVal = m_css.substring(beginPos, endPos + 1);
      }
    }
    return retVal;
  }
 public static String transform(String token) {
   StringBuffer tmp = new StringBuffer(token);
   String firstChar = ("" + tmp.charAt(0)).toUpperCase();
   tmp.replace(0, 1, firstChar);
   int _idx_ = tmp.indexOf("_");
   String transform = null;
   while (_idx_ != -1) {
     transform = tmp.substring(_idx_ + 1, _idx_ + 2).toUpperCase();
     tmp.replace(_idx_, _idx_ + 2, transform);
     _idx_ = tmp.indexOf("_");
   }
   return tmp.toString();
 }
Exemplo n.º 26
0
 private String buildEmailBody(CSVRecord record) {
   StringBuffer sb = new StringBuffer(messageTemplate);
   for (int i = 0; i < record.size(); i += 1) {
     String from = "@" + i + "@";
     String to = record.get(i);
     int j = sb.indexOf(from);
     while (j != -1) {
       sb.replace(j, j + from.length(), to);
       j += to.length();
       j = sb.indexOf(from, j);
     }
   }
   return sb.toString();
 }
Exemplo n.º 27
0
  public Font toFont() {
    StringBuffer stringBuffer = new StringBuffer(getFont());
    String fontName = stringBuffer.substring(0, stringBuffer.indexOf("-"));
    stringBuffer = stringBuffer.delete(0, stringBuffer.indexOf("-") + 1);
    String dataStyle = stringBuffer.substring(0, stringBuffer.indexOf("-"));
    if (dataStyle.equalsIgnoreCase("PLAIN")) fontStyle = Font.PLAIN;
    else if (dataStyle.equalsIgnoreCase("BOLD")) fontStyle = Font.BOLD;
    else if (dataStyle.equalsIgnoreCase("")) fontStyle = Font.ITALIC;

    stringBuffer = stringBuffer.delete(0, stringBuffer.indexOf("-") + 1);
    int fontSize = Integer.parseInt(stringBuffer.toString());

    Font font = new Font(fontName, fontStyle, fontSize);
    return font;
  }
Exemplo n.º 28
0
  private static String combineEnv(String value) {

    StringBuffer sb = new StringBuffer(value);
    int index1 = sb.indexOf("${") + 2;
    int index2 = sb.indexOf("}");
    String envParam = sb.substring(index1, index2);
    String envValue = System.getProperty(envParam);

    if (envValue == null || "".equals(envValue)) {
      return "";
    }

    StringBuffer sb2 = sb.replace(index1 - 2, index2 + 1, envValue);
    return sb2.toString();
  }
Exemplo n.º 29
0
    String replaceTimestamp(String strLine) {
      if (timestamp == null) return strLine; // no timestamp was specified at constructor.

      if (strLine.contains(TIMESTAMP_TAG)
          && tsIndex < ts.size()) { // ts is timestamp array, each next timestamp gets next value
        StringBuffer sb = new StringBuffer(strLine);
        String tsStr = ts.get(tsIndex++);
        int p1 = sb.indexOf("value=\"") + 7;
        int p2 = sb.indexOf("\"", p1);
        String strLine2 = sb.replace(p1, p2, "0x" + tsStr).toString();
        System.out.println(">>> replaced Event-Timestamp :  " + strLine + " => " + strLine2);
        return strLine2;
      }
      return strLine; // default
    }
Exemplo n.º 30
0
  public void searchFiles(String queryStr) throws Exception {
    String indexDir = "Folder_Index";
    String[] field = {
      "contents",
      "title",
      "Exacttitle",
      "Bold",
      "BoldAndItalic",
      "Summary",
      "Italic",
      "Category_Links"
    };

    IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexDir)));
    IndexSearcher searcher = new IndexSearcher(reader);

    // Analyzer analyzer = new SnowballAnalyzer(Version.LUCENE_35,"English");
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35);
    // Analyzer analyzer = new PatternAnalyzer(Version.LUCENE_35);
    // QueryParser parser = new QueryParser(Version.LUCENE_35, field, analyzer);

    MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_35, field, analyzer);
    // System.out.println("Query being searched : "+queryStr);
    StringBuffer query_text = new StringBuffer(queryStr);

    int posn = query_text.indexOf(" ");

    if (posn > 0) {
      query_text.insert(posn, "^6 ");
      int posn2 = query_text.indexOf(" ", posn + 4);
      if (posn2 > 0) {
        query_text.insert(posn2, "^4 ");
        int posn3 = query_text.indexOf(" ", posn2 + 4);
        if (posn3 > 0) query_text.insert(posn3, "^2 ");
      }
    }
    Query query = parser.parse(query_text.toString());
    TopDocs hits = searcher.search(query, 30);

    // System.out.println("\nFound "+hits.totalHits +" documents :\n");

    ScoreDoc results[] = hits.scoreDocs;

    for (int i = 0; i < results.length; i++) {
      Document doc = searcher.doc(results[i].doc);
      System.out.println(doc.get("Exacttitle"));
    }
  }