예제 #1
0
    /**
     * Create a Transferable to use as the source for a data transfer.
     *
     * @param c The component holding the data to be transfered. This argument is provided to enable
     *     sharing of TransferHandlers by multiple components.
     * @return The representation of the data to be transfered.
     */
    protected Transferable createTransferable(JComponent c) {
      Object[] values = null;
      if (c instanceof JList) {
        values = ((JList) c).getSelectedValues();
      } else if (c instanceof JTable) {
        JTable table = (JTable) c;
        int[] rows = table.getSelectedRows();
        if (rows != null) {
          values = new Object[rows.length];
          for (int i = 0; i < rows.length; i++) {
            values[i] = table.getValueAt(rows[i], 0);
          }
        }
      }
      if (values == null || values.length == 0) {
        return null;
      }

      StringBuffer plainBuf = new StringBuffer();
      StringBuffer htmlBuf = new StringBuffer();

      htmlBuf.append("<html>\n<body>\n<ul>\n");

      for (Object obj : values) {
        String val = ((obj == null) ? "" : obj.toString());
        plainBuf.append(val + "\n");
        htmlBuf.append("  <li>" + val + "\n");
      }

      // remove the last newline
      plainBuf.deleteCharAt(plainBuf.length() - 1);
      htmlBuf.append("</ul>\n</body>\n</html>");

      return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values);
    }
예제 #2
0
  void applyDirectives() {
    findRemoveDirectives(true);

    StringBuffer buffer = new StringBuffer();
    String head = "", toe = "; \n";

    if (crispBox.isSelected()) buffer.append(head + "crisp=true" + toe);
    if (!fontField.getText().trim().equals(""))
      buffer.append(head + "font=\"" + fontField.getText().trim() + "\"" + toe);
    if (globalKeyEventsBox.isSelected()) buffer.append(head + "globalKeyEvents=true" + toe);
    if (pauseOnBlurBox.isSelected()) buffer.append(head + "pauseOnBlur=true" + toe);
    if (!preloadField.getText().trim().equals(""))
      buffer.append(head + "preload=\"" + preloadField.getText().trim() + "\"" + toe);
    /*if ( transparentBox.isSelected() )
    buffer.append( head + "transparent=true" + toe );*/

    Sketch sketch = editor.getSketch();
    SketchCode code = sketch.getCode(0); // first tab
    if (buffer.length() > 0) {
      code.setProgram("/* @pjs " + buffer.toString() + " */\n\n" + code.getProgram());
      if (sketch.getCurrentCode() == code) // update textarea if on first tab
      {
        editor.setText(sketch.getCurrentCode().getProgram());
        editor.setSelection(0, 0);
      }

      sketch.setModified(false);
      sketch.setModified(true);
    }
  }
  public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append(super.toString());
    sb.append('\n');
    sb.append("String 1: " + string1Length + " String 2: " + string2Length);

    return sb.toString();
  }
예제 #4
0
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("(Union (" + unionTypes.size() + "): ");
   for (InferredType it : unionTypes) {
     buf.append(it.toString() + ", ");
   }
   buf.append(") ");
   return buf.toString();
 }
예제 #5
0
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("(Struct: ");
   for (InferredType it : structTypes) {
     buf.append(it.toString() + ", ");
   }
   buf.append(") ");
   return buf.toString();
 }
 /** Writes the body of the valid method to fileText. */
 private void writeValidBody() {
   if (vars.length > 0) {
     fileText.append("    return (" + vars[0].getFieldName() + " != null)");
     for (int i = 1; i < vars.length; i++) {
       fileText.append(" && (" + vars[0].getFieldName() + " != null)");
     }
     add(";");
   } else {
     add("    /* no variables were found */");
     add("    return false;");
   }
 }
예제 #7
0
 /**
  * Converts the path back to the string representation.
  *
  * @return
  */
 public String toString(Path path) {
   StringBuffer buffer = new StringBuffer();
   boolean first = true;
   for (Part p : path.parts) {
     if (!first) {
       buffer.append(path_seperator);
     }
     buffer.append(p.toString(this));
     first = false;
   }
   return buffer.toString();
 }
예제 #8
0
 public String getDocString() {
   StringBuffer buf = new StringBuffer();
   buf.append("Example data: ");
   for (Iterator<String> it = sampleStrs.iterator(); it.hasNext(); ) {
     String tokStr = it.next();
     buf.append("'" + tokStr + "'");
     if (it.hasNext()) {
       buf.append(", ");
     }
   }
   return buf.toString();
 }
  /**
   * Strips all non-article links from the given markup; anything like [[this]] is removed unless it
   * goes to a wikipedia article, redirect, or disambiguation page.
   *
   * @param markup the text to be stripped
   * @return the stripped text
   */
  public static String stripIsolatedLinks(String markup) {

    Vector<Integer> linkStack = new Vector<Integer>();

    Pattern p = Pattern.compile("(\\[\\[|\\]\\])");
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {
      String tag = markup.substring(m.start(), m.end());

      if (tag.equals("[[")) linkStack.add(m.start());
      else {
        if (!linkStack.isEmpty()) {
          int linkStart = linkStack.lastElement();
          linkStack.remove(linkStack.size() - 1);

          if (linkStack.isEmpty()) {
            sb.append(markup.substring(lastIndex, linkStart));

            // we have the whole link, with other links nested inside if it's an image
            String linkMarkup = markup.substring(linkStart + 2, m.start());

            // System.out.println(" - " + linkStart + ", " + m.end() + ", " + markup.length()) ;

            if (markup.substring(Math.max(0, linkStart - 10), linkStart).matches("(?s).*(\\W*)\n")
                && (m.end() >= markup.length() - 1
                    || markup
                        .substring(m.end(), Math.min(markup.length() - 1, m.end() + 10))
                        .matches("(?s)(\\W*)(\n.*|$)"))) {
              // discarding link
            } else {
              sb.append("[[");
              sb.append(linkMarkup);
              sb.append("]]");
            }

            lastIndex = m.end();
          }
        }
      }
    }

    if (!linkStack.isEmpty())
      System.err.println(
          "MarkupStripper | Warning: links were not well formed, so we cannot guarantee that they were stripped out correctly. ");

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
 public void addFailure(Test test, AssertionFailedError t) {
   StringBuffer sb = new StringBuffer();
   sb.append(test.toString());
   sb.append("\n");
   StringWriter sw = new StringWriter();
   t.printStackTrace(new PrintWriter(sw, true));
   sb.append(sw.toString());
   Log.getLogWriter().severe("zzzzzFAILURE IN " + test, t);
   // reportFailure(test, sb.toString());
   lastFailClass = getClassName(test);
   lastFailMethod = getMethodName(test);
   lastThrowable = t;
 }
예제 #11
0
파일: kbSRU.java 프로젝트: STITCHplus/kbSRU
 public StringBuffer construct_lucene_solr(StringBuffer result, SolrDocument d) {
   for (String field : (d.getFieldNames())) {
     if ((!field.endsWith("_str")) && (!field.equalsIgnoreCase("fullrecord"))) {
       Iterator j = d.getFieldValues(field).iterator();
       while (j.hasNext()) {
         result.append("<" + field + ">");
         result.append(helpers.xmlEncode((String) j.next().toString()));
         field = field.split(" ")[0];
         result.append("</" + field + ">");
       }
     }
   }
   return (result);
 }
  /**
   * Removes all section headers.
   *
   * @param markup the text to be stripped
   * @return the stripped markup
   */
  public static String stripHeadings(String markup) {
    Pattern p = Pattern.compile("(={2,})([^=]+)(\\1)");
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {
      sb.append(markup.substring(lastIndex, m.start()));
      lastIndex = m.end();
    }

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
  public static void main(String[] args) throws IOException {
    // Get input html
    StringBuffer sb = new StringBuffer();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    for (String str = in.readLine(); str != null; str = in.readLine()) {
      sb.append("\n" + str);
    }
    String html = sb.toString();

    // Match all the questions
    Matcher matcher =
        Pattern.compile(
                "<\\s*div\\s+class\\s*=\\s*\"question-summary\"\\s*id\\s*=\\s*\"question-summary-(?<id>\\d+)\"\\s*>"
                    + ".*?<\\s*div\\s+class\\s*=\\s*\"summary\"\\s*>"
                    + ".*?<\\s*a\\s+.*?class\\s*=\\s*\"question-hyperlink\"\\s*>"
                    + "(?<title>.*?)"
                    + "</\\s*a\\s*>.*?<\\s*div\\s+class\\s*=\\s*\"user-action-time\"\\s*>"
                    + ".*?<\\s*span\\s+.*?>(?<time>.*?)</\\s*span\\s*>",
                Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(html);

    // Output the information
    while (matcher.find()) {
      String id = matcher.group("id");
      String title = matcher.group("title");
      String time = matcher.group("time");
      System.out.println(id + ";" + title + ";" + time);
    }
  }
예제 #14
0
 /** Receive notification of character data inside an element. */
 @Override
 public void characters(char ch[], int start, int len) {
   while (len > 0 && Character.isWhitespace(ch[start])) {
     ++start;
     --len;
   }
   while (len > 0 && Character.isWhitespace(ch[start + len - 1])) {
     --len;
   }
   if (len > 0) {
     if (_chars.length() > 0) {
       _chars.append(' ');
     }
     _chars.append(ch, start, len);
   }
 }
예제 #15
0
  private String blankSectionHeaders(String markup, StringBuffer context) {

    Pattern p = Pattern.compile("(={2,})([^=]+)\\1");
    Matcher m = p.matcher(markup);

    int lastPos = 0;
    StringBuilder sb = new StringBuilder();

    while (m.find()) {
      sb.append(markup.substring(lastPos, m.start()));
      sb.append(getSpaceString(m.group().length()));

      String title = m.group(2).trim();

      if (!title.equalsIgnoreCase("see also")
          && !title.equalsIgnoreCase("external links")
          && !title.equalsIgnoreCase("references")
          && !title.equalsIgnoreCase("further reading")) context.append("\n").append(title);

      lastPos = m.end();
    }

    sb.append(markup.substring(lastPos));
    return sb.toString();
  }
예제 #16
0
  public static String cleanText(String text) {
    StringBuffer string = new StringBuffer(text.length());
    char chars[] = text.toCharArray();
    for (int x = 0; x < chars.length; x++) {
      if (chars[x] != 1 && chars[x] != 2) string.append(chars[x]);
    }

    return string.toString();
  }
예제 #17
0
파일: App.java 프로젝트: natelong/qpp
 public static String MD5(String in) throws Throwable {
   MessageDigest md = MessageDigest.getInstance("MD5");
   byte[] array = md.digest(in.getBytes());
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < array.length; ++i) {
     sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
   }
   return sb.toString();
 }
예제 #18
0
  public static void main(String[] args) throws Exception {
    Reader trainingFile = null;

    // Process arguments
    int restArgs = commandOptions.processOptions(args);

    // Check arguments
    if (restArgs != args.length) {
      commandOptions.printUsage(true);
      throw new IllegalArgumentException("Unexpected arg " + args[restArgs]);
    }
    if (trainFileOption.value == null) {
      commandOptions.printUsage(true);
      throw new IllegalArgumentException("Expected --train-file FILE");
    }
    if (modelFileOption.value == null) {
      commandOptions.printUsage(true);
      throw new IllegalArgumentException("Expected --model-file FILE");
    }

    // Get the CRF structure specification.
    ZipFile zipFile = new ZipFile(modelFileOption.value);
    ZipEntry zipEntry = zipFile.getEntry("crf-info.xml");
    CRFInfo crfInfo = new CRFInfo(zipFile.getInputStream(zipEntry));

    StringBuffer crfInfoBuffer = new StringBuffer();
    BufferedReader reader =
        new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry)));
    String line;
    while ((line = reader.readLine()) != null) {
      crfInfoBuffer.append(line).append('\n');
    }
    reader.close();

    // Create the CRF, and train it.
    CRF4 crf = createCRF(trainFileOption.value, crfInfo);

    // Create a new zip file for our output.  This will overwrite
    // the file we used for input.
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(modelFileOption.value));

    // Copy the CRF info xml to the output zip file.
    zos.putNextEntry(new ZipEntry("crf-info.xml"));
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zos));
    writer.write(crfInfoBuffer.toString());
    writer.flush();
    zos.closeEntry();

    // Save the CRF classifier model to the output zip file.
    zos.putNextEntry(new ZipEntry("crf-model.ser"));
    ObjectOutputStream oos = new ObjectOutputStream(zos);
    oos.writeObject(crf);
    oos.flush();
    zos.closeEntry();
    zos.close();
  }
  /**
   * Strips all links from the given markup; anything like [[this]] is replaced. If it is a link to
   * a wikipedia article, then it is replaced with its anchor text. Only links to images are treated
   * differently: they are discarded entirely.
   *
   * <p>You may want to first strip non-article links, isolated links, category links etc before
   * calling this method.
   *
   * @param markup the text to be stripped
   * @return the stripped text
   */
  public static String stripLinks(String markup) {

    HashSet<String> discardPrefixes = new HashSet<String>();
    discardPrefixes.add("image");

    Vector<Integer> linkStack = new Vector<Integer>();

    Pattern p = Pattern.compile("(\\[\\[|\\]\\])");
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {
      String tag = markup.substring(m.start(), m.end());

      if (tag.equals("[[")) linkStack.add(m.start());
      else {
        if (!linkStack.isEmpty()) {
          int linkStart = linkStack.lastElement();
          linkStack.remove(linkStack.size() - 1);

          if (linkStack.isEmpty()) {
            sb.append(markup.substring(lastIndex, linkStart));

            // we have the whole link, with other links nested inside if it's an image
            String linkMarkup = markup.substring(linkStart + 2, m.start());
            sb.append(stripLink(linkMarkup, discardPrefixes, false));

            lastIndex = m.end();
          }
        }
      }
    }

    if (!linkStack.isEmpty()) {
      System.err.println(
          "MarkupStripper | Warning: links were not well formed, so we cannot guarantee that they were stripped out correctly. ");
    }

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
  /**
   * Removes all sections (both header and content) with the given sectionName
   *
   * @param sectionName the name of the section (case insensitive) to remove.
   * @param markup the markup to be stripped
   * @return the stripped markup
   */
  public static String stripSection(String markup, String sectionName) {

    Pattern p =
        Pattern.compile(
            "(={2,})\\s*" + sectionName + "\\s*\\1.*?([^=]\\1[^=])",
            Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {
      sb.append(markup.substring(lastIndex, m.start()));
      sb.append(m.group(2));
      lastIndex = m.end();
    }

    sb.append(markup.substring(lastIndex));
    markup = sb.toString();

    // if this was the last section in the doc, then it won't be discarded because we can't tell
    // where it ends.
    // best we can do is delete the title and the paragraph below it.

    p =
        Pattern.compile(
            "(={2,})\\s*" + sectionName + "\\s*\\1\\W*.*?\n\n",
            Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
    m = p.matcher(markup);

    sb = new StringBuffer();
    lastIndex = 0;

    while (m.find()) {
      sb.append(markup.substring(lastIndex, m.start()));
      lastIndex = m.end() - 2;
    }

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
예제 #21
0
  /** Returns the original argument types. */
  private String originalArguments(String obfuscatedArguments) {
    StringBuffer originalArguments = new StringBuffer();

    int startIndex = 0;
    while (true) {
      int endIndex = obfuscatedArguments.indexOf(',', startIndex);
      if (endIndex < 0) {
        break;
      }

      originalArguments
          .append(originalType(obfuscatedArguments.substring(startIndex, endIndex).trim()))
          .append(',');

      startIndex = endIndex + 1;
    }

    originalArguments.append(originalType(obfuscatedArguments.substring(startIndex).trim()));

    return originalArguments.toString();
  }
  /**
   * Strips all templates from the given markup; anything like {{this}}.
   *
   * @param markup the text to be stripped
   * @return the stripped text
   */
  public static String stripTemplates(String markup) {

    Vector<Integer> templateStack = new Vector<Integer>();

    Pattern p = Pattern.compile("(\\{\\{|\\}\\})");
    Matcher m = p.matcher(markup);

    StringBuffer sb = new StringBuffer();
    int lastIndex = 0;

    while (m.find()) {

      String tag = markup.substring(m.start(), m.end());

      if (tag.equals("{{")) templateStack.add(m.start());
      else {
        if (!templateStack.isEmpty()) {
          int templateStart = templateStack.lastElement();
          templateStack.remove(templateStack.size() - 1);

          if (templateStack.isEmpty()) {
            sb.append(markup.substring(lastIndex, templateStart));

            // TODO: here is where we would resolve a template, instead of just removing it.
            // sb.append(stripTemplate(markup.substring(templateStart+2, m.start()))) ;

            // we have the whole template, with other templates nested inside
            lastIndex = m.end();
          }
        }
      }
    }

    if (!templateStack.isEmpty())
      System.err.println(
          "MarkupStripper | Warning: templates were not well formed, so we cannot guarantee that they were stripped out correctly. ");

    sb.append(markup.substring(lastIndex));
    return sb.toString();
  }
 /** Writes the body of the instantiateDummy method to fileText. */
 private void writeInstantiateDummyBody() {
   if (vars.length >= 1 && vars.length <= 3) {
     for (int i = 0; i < vars.length; i++) {
       add(
           "    VarInfo "
               + vars[i].getVarName()
               + " = ppt.find_var_by_name(\""
               + vars[i].getNormalName()
               + "\");");
     }
     fileText.append("    if (");
     fileText.append(vars[0].getVarName() + " != null");
     for (int i = 1; i < vars.length; i++) {
       fileText.append(" && " + vars[i].getVarName() + " != null");
     }
     add(") {");
     fileText.append("      dummyInv = dummyInvFactory.instantiate(ppt, new VarInfo[] {");
     fileText.append(vars[0].getVarName());
     for (int i = 1; i < vars.length; i++) {
       fileText.append(", " + vars[i].getVarName());
     }
     add("});");
     add("    }");
   }
 }
  public JilterStatus header(String headerf, String headerv) {

    logger.debug("jilter header {name='" + headerf + "',value='" + headerv + "'}");
    StringBuffer header = new StringBuffer();
    header.append(headerf);
    header.append(": ");
    header.append(headerv);
    header.append("\n");
    try {
      bos.write(header.toString().getBytes());
    } catch (IOException io) {
      logger.error("jilter failed to write header field", io);
    }
    Matcher m = headerPattern1.matcher(headerf.toLowerCase(Locale.ENGLISH).trim());
    if (m.matches()) {
      logger.debug("jilter found to/bcc/cc header");
      String[] addresses = headerv.split(",");
      for (int i = 0; i < addresses.length; i++) {
        includeBCC = includeBCC | rcpts.remove(addresses[i].toLowerCase(Locale.ENGLISH).trim());
        logger.debug("jilter del recipient {recipient='" + addresses[i] + "'}");
        m = headerPattern2.matcher(addresses[i].toLowerCase(Locale.ENGLISH).trim());
        if (m.matches()) {
          String mailAddress = m.group(1);
          includeBCC = includeBCC | rcpts.remove(mailAddress);
          logger.debug("jilter del recipient {recipient='" + mailAddress + "'}");
        } else {
          m = headerPattern3.matcher(addresses[i].toLowerCase(Locale.ENGLISH).trim());
          if (m.matches()) {
            String mailAddress = m.group(1);
            includeBCC = includeBCC | rcpts.remove(mailAddress);
            logger.debug("jilter del recipient {recipient='" + mailAddress + "'}");
          }
        }
      }
    }
    return JilterStatus.SMFIS_CONTINUE;
  }
예제 #25
0
  /**
   * Finds the original field name(s), appending the first one to the out line, and any additional
   * alternatives to the extra lines.
   */
  private void originalFieldName(
      String className,
      String obfuscatedFieldName,
      String type,
      StringBuffer outLine,
      List extraOutLines) {
    int extraIndent = -1;

    // Class name -> obfuscated field names.
    Map fieldMap = (Map) classFieldMap.get(className);
    if (fieldMap != null) {
      // Obfuscated field names -> fields.
      Set fieldSet = (Set) fieldMap.get(obfuscatedFieldName);
      if (fieldSet != null) {
        // Find all matching fields.
        Iterator fieldInfoIterator = fieldSet.iterator();
        while (fieldInfoIterator.hasNext()) {
          FieldInfo fieldInfo = (FieldInfo) fieldInfoIterator.next();
          if (fieldInfo.matches(type)) {
            // Is this the first matching field?
            if (extraIndent < 0) {
              extraIndent = outLine.length();

              // Append the first original name.
              if (verbose) {
                outLine.append(fieldInfo.type).append(' ');
              }
              outLine.append(fieldInfo.originalName);
            } else {
              // Create an additional line with the proper
              // indentation.
              StringBuffer extraBuffer = new StringBuffer();
              for (int counter = 0; counter < extraIndent; counter++) {
                extraBuffer.append(' ');
              }

              // Append the alternative name.
              if (verbose) {
                extraBuffer.append(fieldInfo.type).append(' ');
              }
              extraBuffer.append(fieldInfo.originalName);

              // Store the additional line.
              extraOutLines.add(extraBuffer);
            }
          }
        }
      }
    }

    // Just append the obfuscated name if we haven't found any matching
    // fields.
    if (extraIndent < 0) {
      outLine.append(obfuscatedFieldName);
    }
  }
예제 #26
0
  /*
     String formatStringWordwrap(String output,int colWidth,char fillchar,String appendStr)
     {
        int beginIndex,endIndex;
        String valueStr;

        if (output == null)
        {
           return null;
        }

        // This is the case where the length of the value exceeds the
        // column width
        if ((appendStr !=null) && (appendStr.length()> colWidth-output.length()))
        {
           //print atleast five fill characters
           int labelWidth = output.length() + 5;
           StringBuffer blankOutput = new StringBuffer();
           for (int i=0;i<labelWidth;i++)
              blankOutput.append(' ');

           output=formatString(output,labelWidth,fillchar);

           //break the value into multiple strings to print
           //on separate lines
           colWidth = colWidth-labelWidth;
           for (beginIndex=0,endIndex=colWidth;
              endIndex<=appendStr.length();
              beginIndex=endIndex,endIndex+=colWidth)
           {
              valueStr = appendStr.substring(beginIndex,endIndex);
              if (beginIndex==0)
                 output+=valueStr;
              else
                 output = output + SessionDefaults.lineSeperator + blankOutput + valueStr ;

           }
           if (endIndex > appendStr.length())
              output = output + SessionDefaults.lineSeperator + blankOutput + appendStr.substring(beginIndex);

           return output;
        }

        if (appendStr != null)
        {
           colWidth=colWidth - appendStr.length();
        }

        output=formatString(output,colWidth,fillchar);

        if (appendStr != null && output != null)
        {
           output+=appendStr;
        }


        return output;

     }
  */
  String formatString(String output, int colWidth, char fillchar) {
    StringBuffer outBuffer = null;

    if (output == null) {
      return null;
    }

    outBuffer = new StringBuffer(output);

    if (outBuffer.length() <= colWidth) {
      for (int i = outBuffer.length(); i < colWidth; i++) outBuffer.append(fillchar);
    }

    return outBuffer.toString();
  }
예제 #27
0
파일: kbSRU.java 프로젝트: STITCHplus/kbSRU
 public StringBuffer construct_lucene_dc(StringBuffer result, SolrDocument d) {
   for (String field : (d.getFieldNames())) {
     StringTokenizer dcfields = new StringTokenizer(this.config.getProperty("dcfields", ","));
     while (dcfields.hasMoreTokens()) {
       String dcfield = dcfields.nextToken().trim().replaceAll(",", "");
       if (field.equalsIgnoreCase(dcfield)) {
         Iterator j = d.getFieldValues(field).iterator();
         String rename = this.config.getProperty("solr." + field);
         if (rename != null) {
           field = rename;
         } else {
           field = "dc:" + field;
         }
         while (j.hasNext()) {
           result.append("<" + field + ">");
           result.append(helpers.xmlEncode((String) j.next()));
           field = field.split(" ")[0];
           result.append("</" + field + ">");
         }
       }
     }
   }
   return (result);
 }
예제 #28
0
 static String combineDummy(String inv, String daikonStr, String esc, String simplify) {
   StringBuffer combined = new StringBuffer(inv);
   combined.append(lineSep + "\tDAIKON_FORMAT ");
   combined.append(daikonStr);
   combined.append(lineSep + "\tESC_FORMAT ");
   combined.append(esc);
   combined.append(lineSep + "\tSIMPLIFY_FORMAT ");
   combined.append(simplify);
   return combined.toString();
 }
예제 #29
0
  /*
   * Transform the hexadecimal long output into the equivalent
   * hexadecimal double value.
   */
  static String hexLongStringtoHexDoubleString(String transString) {
    transString = transString.toLowerCase();

    String zeros = "";
    StringBuffer result = new StringBuffer(24);

    for (int i = 0; i < (16 - transString.length()); i++, zeros += "0") ;
    transString = zeros + transString;

    // assert transString.length == 16;

    char topChar;
    // Extract sign
    if ((topChar = transString.charAt(0)) >= '8') { // 8, 9, a, A, b, B, ...
      result.append("-");
      // clear sign bit
      transString =
          Character.toString(Character.forDigit(Character.digit(topChar, 16) - 8, 16))
              + transString.substring(1, 16);
    }

    // check for NaN and infinity
    String signifString = transString.substring(3, 16);

    if (transString.substring(0, 3).equals("7ff")) {
      if (signifString.equals("0000000000000")) {
        result.append("Infinity");
      } else result.append("NaN");
    } else { // finite value
      // Extract exponent
      int exponent = Integer.parseInt(transString.substring(0, 3), 16) - DoubleConsts.EXP_BIAS;
      result.append("0x");

      if (exponent == DoubleConsts.MIN_EXPONENT - 1) { // zero or subnormal
        if (signifString.equals("0000000000000")) {
          result.append("0.0p0");
        } else {
          result.append(
              "0." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") + "p-1022");
        }
      } else { // normal value
        result.append(
            "1." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") + "p" + exponent);
      }
    }
    return result.toString();
  }
예제 #30
0
  /** Return a string representation of this expresssion. */
  public String toString() {
    StringBuffer buf = new StringBuffer();

    buf.append("(");
    buf.append(getImportance());
    buf.append(", ");
    buf.append(getName());
    buf.append(", ");
    buf.append(val);
    buf.append(")");

    return (buf.toString());
  }