Ejemplo n.º 1
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 String modifyFile(String str) throws IOException {
   String search = "<jndi-binding type=\"XAPooledDataSource\"";
   String last_search = "</jndi-binding>";
   String newDB = "newDB_" + OSProcess.getId();
   String jndi_str =
       "<jndi-binding type=\"XAPooledDataSource\" jndi-name=\"XAPooledDataSource\"          jdbc-driver-class=\"org.apache.derby.jdbc.EmbeddedDriver\" init-pool-size=\"5\" max-pool-size=\"5\" idle-timeout-seconds=\"600\" blocking-timeout-seconds=\"6\" login-timeout-seconds=\"2\" conn-pooled-datasource-class=\"org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource\" xa-datasource-class=\"org.apache.derby.jdbc.EmbeddedXADataSource\" user-name=\"mitul\" password=\"83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a\" connection-url=\"jdbc:derby:"
           + newDB
           + ";create=true\" >";
   String config_prop =
       "<config-property>"
           + "<config-property-name>description</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>hi</config-property-value>"
           + "</config-property>"
           + "<config-property>"
           + "<config-property-name>user</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>jeeves</config-property-value>"
           + "</config-property>"
           + "<config-property>"
           + "<config-property-name>password</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a</config-property-value>        "
           + "</config-property>"
           + "<config-property>"
           + "<config-property-name>databaseName</config-property-name>"
           + "<config-property-type>java.lang.String</config-property-type>"
           + "<config-property-value>"
           + newDB
           + "</config-property-value>"
           + "</config-property>\n";
   String new_str = jndi_str + config_prop;
   /*
    * String new_str = " <jndi-binding type=\"XAPooledDataSource\"
    * jndi-name=\"XAPooledDataSource\"
    * jdbc-driver-class=\"org.apache.derby.jdbc.EmbeddedDriver\"
    * init-pool-size=\"5\" max-pool-size=\"5\" idle-timeout-seconds=\"600\"
    * blocking-timeout-seconds=\"6\" login-timeout-seconds=\"2\"
    * conn-pooled-datasource-class=\"org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource\"
    * xa-datasource-class=\"org.apache.derby.jdbc.EmbeddedXADataSource\"
    * user-name=\"mitul\"
    * password=\"83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a\"
    * connection-url=\"jdbc:derby:"+newDB+";create=true\" > <property
    * key=\"description\" value=\"hi\"/> <property key=\"databaseName\"
    * value=\""+newDB+"\"/> <property key=\"user\" value=\"mitul\"/> <property
    * key=\"password\"
    * value=\"83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a\"/>";
    */
   int n1 = str.indexOf(search);
   getLogWriter().fine("Start Index = " + n1);
   int n2 = str.indexOf(last_search, n1);
   StringBuffer sbuff = new StringBuffer(str);
   getLogWriter().fine("END Index = " + n2);
   String modified_str = sbuff.replace(n1, n2, new_str).toString();
   return modified_str;
 }
Ejemplo n.º 3
0
 /**
  * Given a string, replace all occurraces of 'newStr' with 'oldStr'.
  *
  * @param originalStr the string to modify.
  * @param oldStr the string to replace.
  * @param newStr the string to insert in place of the old string.
  */
 public static String replaceText(String originalStr, String oldStr, String newStr) {
   if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
     return originalStr;
   }
   StringBuffer result = new StringBuffer(originalStr);
   int startIndex = 0;
   while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) {
     result = result.replace(startIndex, startIndex + oldStr.length(), newStr);
     startIndex += newStr.length();
   }
   return result.toString();
 }
Ejemplo n.º 4
0
 /**
  * This method removes a selector from the CSS file.
  *
  * @param selectorName
  * @return
  */
 public boolean removeSelector(String selectorName) {
   boolean retVal = false;
   String temp = getSelector(selectorName);
   if (temp != null && temp.length() > 0) {
     int beginPos = m_css.indexOf(selectorName);
     if (beginPos >= 0) {
       m_css.replace(beginPos, beginPos + temp.length(), "");
       retVal = true;
     }
   }
   return retVal;
 }
Ejemplo n.º 5
0
 /**
  * Given a string, replace all tabs with the appropriate number of spaces.
  *
  * @param tabLength the length of each tab.
  * @param s the String to scan.
  */
 public static void replaceTabs(int tabLength, StringBuffer s) {
   int index, col;
   StringBuffer whitespace;
   while ((index = s.indexOf("\t")) != -1) {
     whitespace = new StringBuffer();
     col = index;
     do {
       whitespace.append(" ");
       col++;
     } while ((col % tabLength) != 0);
     s.replace(index, index + 1, whitespace.toString());
   }
 }
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      System.exit(-1);
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      System.exit(-1);
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      System.exit(-1);
    }
    // do the replacement.

    for (i = 0; i < COMPONENTS; i++) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "$$$" + (i + 1);
      // get the position of the search string in the content string.
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(str1);
      strBuf.replace(posFound, posFound + str1.length(), sliderValue);
      strContent = new String(strBuf);
    }
    textPane.setText(strContent);
  }
Ejemplo n.º 8
0
  /**
   * Removes a CSS item from the CSS file.
   *
   * @param selectorName Name of selector.
   * @param name Name of item to remove.
   */
  public void removeValueFromSelector(String selectorName, String name) {
    if (selectorName != null && name != null) {
      if (m_css.indexOf(selectorName) >= 0) {
        boolean done = false;
        int pos = 0;
        while (!done) {
          int beginPos = m_css.indexOf(selectorName, pos);

          if (beginPos >= 0) {
            int endPos = m_css.indexOf("{", beginPos);

            if (endPos >= 0) {
              String workSelectorName = m_css.substring(beginPos, endPos).trim();

              if (workSelectorName.equals(selectorName)) {

                // ArrayList lines = readLines(m_css.substring(endPos, m_css.indexOf("}")));
                // String work = m_css.substring(endPos, m_css.indexOf("}"));
                // int removeStartPos = m_css.substring(endPos, m_css.indexOf("}")).indexOf(name);
                int removeStartPos = m_css.indexOf(name, endPos);
                int removeEndPos = m_css.indexOf(";", removeStartPos);

                if (removeStartPos < removeEndPos) {
                  // logger.info("REMOVING:::::::" + m_css.substring(removeStartPos,
                  // removeEndPos+1));
                  m_css.replace(removeStartPos, removeEndPos + 1, " ");
                }
                done = true;
              }

              pos = endPos;
              if (pos >= m_css.length()) {
                done = true;
              }
            } else {
              done = true;
            }
          } else {
            done = true;
          }
        }
      } else {
        logger.error("Error processing CSS removeValueFromSelector: " + selectorName);
      }
    }
  }
Ejemplo n.º 9
0
  /** This method sets the Data Source the component should be bound to. */
  public void setDataSource(String dataSource) {
    _dataSource = dataSource;
    if (_dataSource == null) return;

    // search and replace &QUOT; with a single quote. For Engines that have trouble with single
    // quotes inside a tag
    String test = _dataSource.toUpperCase();
    int pos = test.indexOf("&QUOT;");
    if (pos == -1) return;

    StringBuffer work = new StringBuffer(_dataSource);
    while (pos > -1) {
      work.replace(pos, pos + 6, "'");
      test = work.toString().toUpperCase();
      pos = test.indexOf("&QUOT;");
    }
    _dataSource = work.toString();
  }
Ejemplo n.º 10
0
 /**
  * Scans the html string and checks for <A HREF= > tags, then adds them to a ArrayList and returns
  * the modified html string.
  */
 private String checkForLinks(String htmlStr, ArrayList urlList) {
   String STARTTAG = "<A HREF=\"";
   String ENDTAG = "\">";
   String urlString;
   int startTag = 0;
   int endTag = 0;
   while ((startTag != -1) && (endTag != -1)) {
     startTag = htmlStr.toUpperCase().indexOf(STARTTAG, endTag);
     endTag = htmlStr.indexOf(ENDTAG, startTag);
     if ((startTag != -1) && (endTag != -1)) {
       urlString = htmlStr.substring(startTag + STARTTAG.length(), endTag);
       urlList.add(urlString);
       // now nicify this link
       StringBuffer htmlStrBuffer = new StringBuffer(htmlStr);
       htmlStrBuffer.replace(startTag + STARTTAG.length(), endTag, niceifyLink(urlString));
       htmlStr = htmlStrBuffer.toString();
       endTag = htmlStr.indexOf(ENDTAG, startTag) + ENDTAG.length();
     }
   }
   return htmlStr;
 }
Ejemplo n.º 11
0
  /**
   * @param context - ServletContext
   * @param contextPath - context path or custom configured context path
   * @param cssFilePath - css file path
   * @param line - one single line in a css file
   * @return processed string with appropriate replacement of image URLs if any
   */
  private String processCSSLine(
      ServletContext context, String contextPath, String cssFilePath, StringBuffer line) {
    Matcher matcher = CSS_IMG_URL_PATTERN.matcher(line);
    String cssRealPath = context.getRealPath(cssFilePath);
    while (matcher.find()) {
      String refImgPath = matcher.group(1);
      if (!Utils.isProtocolURL(refImgPath)) { // ignore absolute protocol paths
        String resolvedImgPath = refImgPath;
        if (!refImgPath.startsWith("/")) {
          resolvedImgPath = Utils.buildProperPath(Utils.getParentPath(cssFilePath), refImgPath);
        }
        String imgRealPath = context.getRealPath(resolvedImgPath);
        String fingerPrint = Utils.buildETagForResource(resolvedImgPath, context);
        int offset = line.indexOf(refImgPath);
        line.replace(
            offset, // from
            offset + refImgPath.length(), // to
            contextPath + Utils.addFingerPrint(fingerPrint, resolvedImgPath));

        Utils.updateReferenceMap(cssRealPath, imgRealPath);
      }
    }
    return line.toString();
  }
Ejemplo n.º 12
0
  void doSourceFileUpdate() {
    BufferedReader bufferIn = null;
    String str1 = new String();
    String strContent = new String();
    String sliderValue = new String();
    String newLine = System.getProperty("line.separator");
    StringBuffer strBuf = new StringBuffer();
    RandomAccessFile access = null;
    String tempFile = "temp" + round + ".html";
    File fp = new File(tempFile);
    boolean firstChoice = true;
    int posFound = 0;
    int i = 0;
    PSlider slider;

    // round += 1;
    // Read the original source file to input buffer
    try {
      bufferIn = new BufferedReader(new FileReader(exampleSource));
    } catch (FileNotFoundException fe) {
      System.err.println("Example Source File not found " + fe);
      // System.exit(-1);;
    }
    // get the first line of the buffer.
    try {
      str1 = bufferIn.readLine();
    } catch (IOException ie) {
      System.err.println("Error reading line from the buffer " + ie);
      // System.exit(-1);;
    }
    // Transfer the whole content of the input buffer to the string
    try {
      do strContent += str1 + newLine;
      while ((str1 = bufferIn.readLine()) != null);
    } catch (IOException ie) {
      System.err.println("Error readding content of the input buffer " + ie);
      // System.exit(-1);;
    }
    // do the replacement.
    // First having to update the code part that is active in this section before
    // doing variables updated. Look at the current active radiobutton to make decision
    if (secondBox.isSelected() == true) firstChoice = false;
    if (firstChoice == true) {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr2);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr2.length(), tempStr);
      strContent = new String(strBuf);
    } else {
      String tempStr = new String();
      strBuf = new StringBuffer(strContent);
      posFound = strContent.indexOf(textStr1);
      tempStr =
          "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>";
      strBuf.replace(posFound, posFound + textStr1.length(), tempStr);
      strContent = new String(strBuf);
    }
    for (i = COMPONENTS; i > 0; i--) {
      // get the current value of slider
      slider = (PSlider) vSlider.elementAt(i - 1);
      sliderValue = slider.getValue();
      // construct the search string
      str1 = "JPOT$" + i;
      // get the position of the search string in the content string.
      while ((posFound = strContent.indexOf(str1)) != -1) {
        strBuf = new StringBuffer(strContent);
        strBuf.replace(posFound, posFound + str1.length(), sliderValue);
        strContent = new String(strBuf);
      }
    }

    boolean delete = fp.delete();

    try {
      fp.createNewFile();
    } catch (IOException ie) {
      System.err.println("Couldn't create the new file " + ie);
      // System.exit(-1);;
    }

    try {
      access = new RandomAccessFile(fp, "rw");
    } catch (IOException ie) {
      System.err.println("Error in accessing the file " + ie);
      // System.exit(-1);;
    }

    try {
      access.writeBytes(strContent);
      access.close();
    } catch (IOException ie) {
      System.err.println("Error in writing to file " + ie);
      // System.exit(-1);;
    }
    try {
      textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null);
      URL url = new URL("file:" + tempFile + "#gohere");
      textPane.setPage(url);
      delete = fp.delete();
    } catch (IOException ie) {
      System.err.println("Can not get the example html file " + ie);
      // System.exit(-1);;
    }
  }