/**
   * This function creates a directive record and adds it to the list, the value will be added later
   * after it is parsed.
   *
   * @param name Name
   * @param haveQuotedPair true if quoted pair is there else false
   */
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2014-09-03 15:02:38.406 -0400",
      hash_original_method = "266E87F8A828CDA30627CAA7433FF646",
      hash_generated_method = "CE03EAF7EDFB05F294B401E410CDC667")
  void addDirective(String name, boolean haveQuotedPair) {
    String value;
    int inputIndex;
    int valueIndex;
    char valueChar;
    int type;

    if (!haveQuotedPair) {
      value = m_directives.substring(m_scanStart, m_curPos);
    } else { // copy one character at a time skipping backslash excapes.
      StringBuffer valueBuf = new StringBuffer(m_curPos - m_scanStart);
      valueIndex = 0;
      inputIndex = m_scanStart;
      while (inputIndex < m_curPos) {
        if ('\\' == (valueChar = m_directives.charAt(inputIndex))) inputIndex++;
        valueBuf.setCharAt(valueIndex, m_directives.charAt(inputIndex));
        valueIndex++;
        inputIndex++;
      }
      value = new String(valueBuf);
    }

    if (m_state == STATE_SCANNING_QUOTED_STRING_VALUE) type = ParsedDirective.QUOTED_STRING_VALUE;
    else type = ParsedDirective.TOKEN_VALUE;
    m_directiveList.add(new ParsedDirective(name, value, type));
  }
  public static void decry() {
    try {
      BufferedReader bf = new BufferedReader(new FileReader("ciphertext.txt"));
      BufferedWriter wr = new BufferedWriter(new FileWriter("plaintext.txt"));
      char rkey[] = new char[26];
      for (char i = 'a'; i <= 'z'; i++) {
        if (key.charAt(i - 'a') > 'z' || key.charAt(i - 'a') < 'a') continue;
        rkey[key.charAt(i - 'a') - 'a'] = i;
      }
      System.out.println(rkey);
      StringBuffer strb;
      String str;
      while (((str = bf.readLine())) != null) {
        strb = new StringBuffer(str);
        // System.out.println(strb);
        // String ans;
        for (int i = 0; i < strb.length(); i++) {
          if (strb.charAt(i) >= 'a' && strb.charAt(i) <= 'z') {
            strb.setCharAt(i, rkey[strb.charAt(i) - 'a']);
          }
        }
        System.out.println(strb.toString());
        wr.write(strb.toString());
        wr.newLine();
      }
      // keyf.close();
      wr.close();
      bf.close();

    } catch (IOException e) {

    }
  }
  /**
   * Some String can be too long to be correctly displayed on the screen. Mainly when it is a path
   * to a file. This method truncate a String.
   *
   * @param longString The <code>String</code> to be truncated
   * @param maxLength The maximum length of the <code>String</code>
   * @return The truncated string
   */
  public static String getShortStringOf(String longString, int maxLength) {
    int len = longString.length();

    if (len <= maxLength) return longString;
    else if (longString.indexOf('\\') == -1 && longString.indexOf('/') == -1) {
      StringBuffer buff = new StringBuffer(longString.substring(longString.length() - maxLength));
      for (int i = 0; i < 3; i++) buff.setCharAt(i, '.');
      return buff.toString();
    } else {
      int first = len / 2;
      int second = first;

      for (int i = first - 1; i >= 0; i--) {
        if (longString.charAt(i) == '\\' || longString.charAt(i) == '/') {
          first = i;
          break;
        }
      }

      for (int i = second + 1; i < len; i++) {
        if (longString.charAt(i) == '\\' || longString.charAt(i) == '/') {
          second = i;
          break;
        }
      }

      loop:
      while ((len - (second - first)) > maxLength) {
        out:
        for (int i = first - 1; i >= 0; i--) {
          switch (longString.charAt(i)) {
            case '\\':
            case '/':
              first = i;
              break out;
          }
        }

        if ((len - (second - first)) < maxLength) break loop;

        out2:
        for (int i = second + 1; i < len; i++) {
          switch (longString.charAt(i)) {
            case '\\':
            case '/':
              second = i;
              break out2;
          }
        }
      }

      return longString.substring(0, first + 1) + "..." + longString.substring(second);

      // return longString.substring(0, maxLength / 2) + "..." +
      //       longString.substring(len - (maxLength / 2));
    }
  }
Exemple #4
0
 public String getPropertyName(String name) {
   // Set the first letter of the property name to lower-case
   StringBuffer propertyName = new StringBuffer(name);
   char c = propertyName.charAt(0);
   if (c >= 'A' && c <= 'Z') {
     c -= 'A' - 'a';
     propertyName.setCharAt(0, c);
   }
   return propertyName.toString();
 }
  boolean updateToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.setCharAt(x - 1, ch);
      // setLine
      vectorLines.setElementAt(currentLine, y);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in updateToLine()");
      return false;
    }
  }
Exemple #6
0
 private String formatName(String name) {
   StringBuffer propertyName = new StringBuffer();
   if (lowerCase) propertyName.append(name.toLowerCase());
   else propertyName.append(name);
   char c = propertyName.charAt(0);
   if (firstLetterUpperCase) {
     if (c >= 'a' && c <= 'z') {
       c += 'A' - 'a';
     }
   } else {
     if (c >= 'A' && c <= 'Z') {
       c -= 'A' - 'a';
     }
   }
   propertyName.setCharAt(0, c);
   return propertyName.toString();
 }
 /**
  * Getters/Setters are supposed to be kept with their associated property. Search the list of
  * entries to find the property and attach the setter.
  *
  * @param entries list of all items (methods, fields) in the class.
  */
 private void hookGetterToProperty(List<ClassContentsEntry> entries) {
   ListIterator<ClassContentsEntry> li = entries.listIterator();
   String property = MethodUtil.getPropertyName((PsiMethod) myEnd);
   while (li.hasNext()) {
     Object o = li.next();
     if (o instanceof FieldEntry) {
       FieldEntry fe = (FieldEntry) o;
       StringBuffer sb = new StringBuffer(fe.getName());
       sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
       if (fe.getGetterMethod() == null && property.equals(sb.toString())) {
         fe.setGetterMethod(this);
         myKeptWithProperty = true;
         break;
       }
     }
   }
 }
Exemple #8
0
  /** Thanks to Teodor Danciu for this method (c) 2003 Teodor Danciu */
  public static String replaceTabWithBlank(String source) {
    String result = source;

    if (source != null && source.length() > 0) {
      StringBuffer sbuffer = new StringBuffer(source);

      int offset = 0;
      int pos = source.indexOf("\t", offset);
      while (pos >= 0) {
        sbuffer.setCharAt(pos, ' ');
        offset = pos + 1;
        pos = source.indexOf("\t", offset);
      }

      result = sbuffer.toString();
    }

    return result;
  }
  private static String toLowerCase(String text) {
    CodeInsightSettings settings = CodeInsightSettings.getInstance();
    switch (settings.COMPLETION_CASE_SENSITIVE) {
      case CodeInsightSettings.NONE:
        return text.toLowerCase();

      case CodeInsightSettings.FIRST_LETTER:
        {
          StringBuffer buffer = new StringBuffer();
          buffer.append(text.toLowerCase());
          if (buffer.length() > 0) {
            buffer.setCharAt(0, text.charAt(0));
          }
          return buffer.toString();
        }

      default:
        return text;
    }
  }
 /**
  * Creates a default class name including package prefix. Uses the schema attribute to determine a
  * default name, prepends a default package name based on the project and appends the counter if
  * more than one such class exists.
  *
  * @param project project that the class name is being generated for
  * @param attInfo the schema attribute describing the new class
  * @param counter used to make each generated name unique
  */
 public static String createDefaultClassName(
     IProject project, ISchemaAttribute attInfo, int counter) {
   String tag = attInfo.getParent().getName();
   String expectedType = attInfo.getBasedOn();
   String className = ""; // $NON-NLS-1$
   if (expectedType == null) {
     StringBuffer buf = new StringBuffer(tag);
     buf.setCharAt(0, Character.toUpperCase(tag.charAt(0)));
     className = buf.toString();
   } else {
     className = expectedType;
     int dotLoc = className.lastIndexOf('.');
     if (dotLoc != -1) className = className.substring(dotLoc + 1);
     if (className.length() > 2
         && className.charAt(0) == 'I'
         && Character.isUpperCase(className.charAt(1))) className = className.substring(1);
   }
   String packageName = createDefaultPackageName(project, className);
   className += counter;
   return packageName + "." + className; // $NON-NLS-1$
 }
Exemple #11
0
 private Object createObject(
     Node node, String name, String classPackage, String type, String value, boolean setProperty) {
   Bean parentBean = null;
   if (beansStack.size() > 0) parentBean = (Bean) beansStack.peek();
   Object object = null;
   // param is either an XSD type or a bean,
   // check if it can be converted to an XSD type
   XSDatatype dt = null;
   try {
     dt = DatatypeFactory.getTypeByName(type);
   } catch (DatatypeException dte) {
     // the type is not a valid XSD data type
   }
   // convert null value to default
   if ((dt != null) && (value == null)) {
     Class objType = dt.getJavaObjectType();
     if (objType == String.class) value = "";
     else if ((objType == java.math.BigInteger.class)
         || (objType == Long.class)
         || (objType == Integer.class)
         || (objType == Short.class)
         || (objType == Byte.class)) value = "0";
     else if ((objType == java.math.BigDecimal.class)
         || (objType == Double.class)
         || (objType == Float.class)) value = "0.0";
     else if (objType == Boolean.class) value = "false";
     else if (objType == java.util.Date.class) value = DateUtils.getCurrentDate();
     else if (objType == java.util.Calendar.class) value = DateUtils.getCurrentDateTime();
   }
   //  check whether the type was converted to an XSD datatype
   if ((dt != null) && dt.isValid(value, null)) {
     // create and return an XSD Java object (e.g. String, Integer, Boolean, etc)
     object = dt.createJavaObject(value, null);
     if (object instanceof java.util.Calendar) {
       // check that the object is truly a Calendar
       // because DatatypeFactory converts xsd:date
       // types to GregorianCalendar instead of Date.
       if (type.equals("date")) {
         java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
         try {
           object = df.parse(value);
         } catch (java.text.ParseException pe) {
           object = new java.util.Date();
         }
       }
     }
   } else {
     // Create a bean object
     if (topLevelBean == null) topLevelBean = parentBean;
     object = pushBeanOnStack(classPackage, type);
     // Check fields to see if this property is the 'value' for the object
     Field[] fields = object.getClass().getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(ObjectXmlAsValue.class)) {
         try {
           StringBuffer fieldName = new StringBuffer(fields[i].getName());
           char c = fieldName.charAt(0);
           if (c >= 'a' && c <= 'z') {
             c += 'A' - 'a';
           }
           fieldName.setCharAt(0, c);
           fieldName.insert(0, "set");
           Method method =
               object
                   .getClass()
                   .getMethod(fieldName.toString(), new Class[] {fields[i].getType()});
           method.invoke(object, value);
           break;
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
     NamedNodeMap nodeAttrs = node.getAttributes();
     // iterate attributes and set field values for property attributes
     for (int i = 0; i < nodeAttrs.getLength(); i++) {
       String nodePrefix = nodeAttrs.item(i).getPrefix();
       if (nodePrefix.equals(nsPrefix)) {
         String nodeName = nodeAttrs.item(i).getLocalName();
         String nodeValue = nodeAttrs.item(i).getNodeValue();
         try {
           Field field = object.getClass().getDeclaredField(nodeName);
           if (field.isAnnotationPresent(ObjectXmlAsAttribute.class)) {
             StringBuffer fieldName = new StringBuffer(field.getName());
             char c = fieldName.charAt(0);
             if (c >= 'a' && c <= 'z') {
               c += 'A' - 'a';
             }
             fieldName.setCharAt(0, c);
             fieldName.insert(0, "set");
             Method method =
                 object.getClass().getMethod(fieldName.toString(), new Class[] {field.getType()});
             if (field.getType() == String.class) method.invoke(object, nodeValue);
             else if (field.getType() == Boolean.TYPE)
               method.invoke(object, StringUtils.strToBool(nodeValue, "true"));
             else if (field.getType() == Byte.TYPE)
               method.invoke(object, Byte.valueOf(nodeValue).byteValue());
             else if (field.getType() == Character.TYPE)
               method.invoke(object, Character.valueOf(nodeValue.charAt(0)));
             else if (field.getType() == Double.TYPE)
               method.invoke(object, Double.valueOf(nodeValue).doubleValue());
             else if (field.getType() == Float.TYPE)
               method.invoke(object, Float.valueOf(nodeValue).floatValue());
             else if (field.getType() == Integer.TYPE)
               method.invoke(object, Integer.valueOf(nodeValue).intValue());
             else if (field.getType() == Long.TYPE)
               method.invoke(object, Long.valueOf(nodeValue).longValue());
             else if (field.getType() == Short.TYPE)
               method.invoke(object, Short.valueOf(nodeValue).shortValue());
           }
         } catch (Exception e) {
           System.err.println(e.getMessage());
         }
       }
     }
   }
   if ((parentBean != null) && (setProperty)) {
     parentBean.setProperty(name, object);
   }
   return object;
 }