Ejemplo n.º 1
4
  protected String getRallyXML(String apiUrl) throws Exception {
    String responseXML = "";

    DefaultHttpClient httpClient = new DefaultHttpClient();

    Base64 base64 = new Base64();
    String encodeString =
        new String(base64.encode((rallyApiHttpUsername + ":" + rallyApiHttpPassword).getBytes()));

    HttpGet httpGet = new HttpGet(apiUrl);
    httpGet.addHeader("Authorization", "Basic " + encodeString);
    HttpResponse response = httpClient.execute(httpGet);
    HttpEntity entity = response.getEntity();

    if (entity != null) {

      InputStreamReader reader = new InputStreamReader(entity.getContent());
      BufferedReader br = new BufferedReader(reader);

      StringBuilder sb = new StringBuilder();
      String line = "";
      while ((line = br.readLine()) != null) {
        sb.append(line);
      }

      responseXML = sb.toString();
    }

    log.debug("responseXML=" + responseXML);

    return responseXML;
  }
Ejemplo n.º 2
2
  @Override
  protected Transferable createTransferable(JComponent c) {
    JTextPane aTextPane = (JTextPane) c;

    HTMLEditorKit kit = ((HTMLEditorKit) aTextPane.getEditorKit());
    StyledDocument sdoc = aTextPane.getStyledDocument();
    int sel_start = aTextPane.getSelectionStart();
    int sel_end = aTextPane.getSelectionEnd();

    int i = sel_start;
    StringBuilder output = new StringBuilder();
    while (i < sel_end) {
      Element e = sdoc.getCharacterElement(i);
      Object nameAttr = e.getAttributes().getAttribute(StyleConstants.NameAttribute);
      int start = e.getStartOffset(), end = e.getEndOffset();
      if (nameAttr == HTML.Tag.BR) {
        output.append("\n");
      } else if (nameAttr == HTML.Tag.CONTENT) {
        if (start < sel_start) {
          start = sel_start;
        }
        if (end > sel_end) {
          end = sel_end;
        }
        try {
          String str = sdoc.getText(start, end - start);
          output.append(str);
        } catch (BadLocationException ble) {
          Debug.error(me + "Copy-paste problem!\n%s", ble.getMessage());
        }
      }
      i = end;
    }
    return new StringSelection(output.toString());
  }
Ejemplo n.º 3
1
  /**
   * If the outbound level is BINARY, convert the string field to binary, then pad to the left with
   * the appropriate number of zero bits to reach a number of bits specified by the bitLength
   * attribute of the TDT definition file.
   */
  private void binaryPadding(Map<String, String> extraparams, Field tdtfield) {
    String fieldname = tdtfield.getName();
    int reqbitlength = tdtfield.getBitLength();
    String value;

    String binaryValue = fieldToBinary(tdtfield, extraparams);
    if (binaryValue.length() < reqbitlength) {
      int extraBitLength = reqbitlength - binaryValue.length();

      StringBuilder zeroPaddedBinaryValue = new StringBuilder("");
      for (int i = 0; i < extraBitLength; i++) {
        zeroPaddedBinaryValue.append("0");
      }
      zeroPaddedBinaryValue.append(binaryValue);
      value = zeroPaddedBinaryValue.toString();
    } else {
      if (binaryValue.length() > reqbitlength)
        throw new TDTException(
            "Binary value ["
                + binaryValue
                + "] for field "
                + fieldname
                + " exceeds maximum allowed "
                + reqbitlength
                + " bits.  Decimal value was "
                + extraparams.get(fieldname));

      value = binaryValue;
    }
    extraparams.put(fieldname, value);
  }
Ejemplo n.º 4
1
  public String getCoordinates(RevisionRef r) {
    StringBuilder sb = new StringBuilder(r.groupId).append(":").append(r.artifactId).append(":");
    if (r.classifier != null) sb.append(r.classifier).append("@");
    sb.append(r.version);

    return sb.toString();
  }
Ejemplo n.º 5
1
Archivo: Macro.java Proyecto: bramk/bnd
 public static void verifyCommand(
     String args[],
     @SuppressWarnings("unused") String help,
     Pattern[] patterns,
     int low,
     int high) {
   String message = "";
   if (args.length > high) {
     message = "too many arguments";
   } else if (args.length < low) {
     message = "too few arguments";
   } else {
     for (int i = 0; patterns != null && i < patterns.length && i < args.length; i++) {
       if (patterns[i] != null) {
         Matcher m = patterns[i].matcher(args[i]);
         if (!m.matches())
           message +=
               String.format(
                   "Argument %s (%s) does not match %s%n", i, args[i], patterns[i].pattern());
       }
     }
   }
   if (message.length() != 0) {
     StringBuilder sb = new StringBuilder();
     String del = "${";
     for (String arg : args) {
       sb.append(del);
       sb.append(arg);
       del = ";";
     }
     sb.append("}, is not understood. ");
     sb.append(message);
     throw new IllegalArgumentException(sb.toString());
   }
 }
Ejemplo n.º 6
1
 private static String convert(List<List<Particle>> lists) {
   StringBuilder sb = new StringBuilder();
   for (List<Particle> list : lists) {
     if (list.isEmpty()) sb.append('.');
     else sb.append('X');
   }
   return sb.toString();
 }
  public synchronized void filter_input() {
    try {
      // grab data from shared buffer and move it the local one
      ourBuffer.append(sharedBuffer.take());
      // System.out.print(ourBuffer);
      // create a matcher to find an open tag in the buffer
      int endCloseTag;
      int startOpenTag;
      Matcher closeTagMatcher = closeTagPattern.matcher(ourBuffer);

      // look or a closing tag in our buffer
      if (closeTagMatcher.find()) {
        endCloseTag = closeTagMatcher.end();
        openTag = "<" + ourBuffer.charAt(closeTagMatcher.start() + 2) + ">";
        // find corresponding opening tag
        startOpenTag = ourBuffer.indexOf(openTag);
        // send the input string to the GUI for processing
        if (startOpenTag >= 0 && startOpenTag < endCloseTag) {
          gui.incoming(ourBuffer.substring(startOpenTag, endCloseTag));
          // clear our buffer
          ourBuffer.delete(startOpenTag, endCloseTag);
        }
      }
    } catch (Exception e) {
      System.out.print(e + "\n");
    }
  }
Ejemplo n.º 8
0
 static String outputOf(Reader r) throws IOException {
   final StringBuilder sb = new StringBuilder();
   final char[] buf = new char[1024];
   int n;
   while ((n = r.read(buf)) > 0) sb.append(buf, 0, n);
   return sb.toString();
 }
Ejemplo n.º 9
0
 public String toString() {
   StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()).append('{');
   for (TypedValues typed : _values) {
     sb.append(typed);
   }
   return sb.append('}').toString();
 }
Ejemplo n.º 10
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();
  }
Ejemplo n.º 11
0
  @SuppressWarnings("deprecation")
  public void testAllResolved() {
    assertNotNull("Expected a Bundle Context", context);
    StringBuilder sb = new StringBuilder();

    for (Bundle b : context.getBundles()) {
      if (b.getState() == Bundle.INSTALLED
          && b.getHeaders().get(aQute.bnd.osgi.Constants.FRAGMENT_HOST) == null) {
        try {
          b.start();
        } catch (BundleException e) {
          sb.append(b.getBundleId())
              .append(" ")
              .append(b.getSymbolicName())
              .append(";")
              .append(b.getVersion())
              .append("\n");
          sb.append("    ").append(e.getMessage()).append("\n\n");
          System.err.println(e.getMessage());
        }
      }
    }
    Matcher matcher = IP_P.matcher(sb);
    String out =
        matcher.replaceAll(
            "\n\n         " + aQute.bnd.osgi.Constants.IMPORT_PACKAGE + ": $1;version=[$2,$3)\n");
    assertTrue("Unresolved bundles\n" + out, sb.length() == 0);
  }
Ejemplo n.º 12
0
  private static String expand(String str) {
    if (str == null) {
      return null;
    }

    StringBuilder result = new StringBuilder();
    Pattern re = Pattern.compile("^(.*?)\\$\\{([^}]*)\\}(.*)");
    while (true) {
      Matcher matcher = re.matcher(str);
      if (matcher.matches()) {
        result.append(matcher.group(1));
        String property = matcher.group(2);
        if (property.equals("/")) {
          property = "file.separator";
        }
        String value = System.getProperty(property);
        if (value != null) {
          result.append(value);
        }
        str = matcher.group(3);
      } else {
        result.append(str);
        break;
      }
    }
    return result.toString();
  }
Ejemplo n.º 13
0
 private void appendTestMethod(@Nonnull StackTraceElement current) {
   content.append("          <li>");
   content.append(current.getClassName()).append('#');
   content
       .append(LESS_THAN_CHAR.matcher(current.getMethodName()).replaceFirst("&lt;"))
       .append(": ");
   content.append(current.getLineNumber());
 }
Ejemplo n.º 14
0
 private String ns1() {
   int b = skip();
   StringBuilder sb = new StringBuilder();
   while (!(isSpaceChar(b) && b != ' ')) { // when nextLine,
     sb.appendCodePoint(b);
     b = readByte();
   }
   return sb.toString();
 }
 public String ns() {
   int b = skip();
   StringBuilder sb = new StringBuilder();
   while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != // ' ')
     sb.appendCodePoint(b);
     b = readByte();
   }
   return sb.toString();
 }
Ejemplo n.º 16
0
  public static String dropNonLetters(String s) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      if (Character.isLetter(c)) sb.append(c);
    }

    return sb.toString();
  }
  // todo: give options for document splitting. A line or the whole file or
  // sentence splitting as now
  public Iterator<List<IN>> getIterator(Reader r) {
    Tokenizer<IN> tokenizer = tokenizerFactory.getTokenizer(r);
    // PTBTokenizer.newPTBTokenizer(r, false, true);
    List<IN> words = new ArrayList<IN>();
    IN previous = tokenFactory.makeToken();
    StringBuilder prepend = new StringBuilder();

    /*
     * This changes SGML tags into whitespace -- it should maybe be moved
     * elsewhere
     */
    while (tokenizer.hasNext()) {
      IN w = tokenizer.next();
      String word = w.get(CoreAnnotations.TextAnnotation.class);
      Matcher m = sgml.matcher(word);
      if (m.matches()) {

        String before = StringUtils.getNotNullString(w.get(CoreAnnotations.BeforeAnnotation.class));
        String after = StringUtils.getNotNullString(w.get(CoreAnnotations.AfterAnnotation.class));
        prepend.append(before).append(word);
        String previousTokenAfter =
            StringUtils.getNotNullString(previous.get(CoreAnnotations.AfterAnnotation.class));
        previous.set(AfterAnnotation.class, previousTokenAfter + word + after);
        // previous.appendAfter(w.word() + w.after());
      } else {

        String before = StringUtils.getNotNullString(w.get(CoreAnnotations.BeforeAnnotation.class));
        if (prepend.length() > 0) {
          w.set(BeforeAnnotation.class, prepend.toString() + before);
          // w.prependBefore(prepend.toString());
          prepend = new StringBuilder();
        }
        words.add(w);
        previous = w;
      }
    }

    List<List<IN>> sentences = wts.process(words);
    String after = "";
    IN last = null;
    for (List<IN> sentence : sentences) {
      int pos = 0;
      for (IN w : sentence) {
        w.set(PositionAnnotation.class, Integer.toString(pos));
        after = StringUtils.getNotNullString(w.get(CoreAnnotations.AfterAnnotation.class));
        w.remove(AfterAnnotation.class);
        last = w;
      }
    }
    if (last != null) {
      last.set(AfterAnnotation.class, after);
    }

    return sentences.iterator();
  }
Ejemplo n.º 18
0
 protected void selected(CharPos start, CharPos end) {
   StringBuilder buf = new StringBuilder();
   synchronized (msgs) {
     boolean sel = false;
     for (Message msg : msgs) {
       if (!(msg.text() instanceof RichText)) continue;
       RichText rt = (RichText) msg.text();
       RichText.Part part = null;
       if (sel) {
         part = rt.parts;
       } else if (msg == start.msg) {
         sel = true;
         for (part = rt.parts; part != null; part = part.next) {
           if (part == start.part) break;
         }
       }
       if (sel) {
         for (; part != null; part = part.next) {
           if (!(part instanceof RichText.TextPart)) continue;
           RichText.TextPart tp = (RichText.TextPart) part;
           CharacterIterator iter = tp.ti();
           int sch;
           if (tp == start.part) sch = tp.start + start.ch.getInsertionIndex();
           else sch = tp.start;
           int ech;
           if (tp == end.part) ech = tp.start + end.ch.getInsertionIndex();
           else ech = tp.end;
           for (int i = sch; i < ech; i++) buf.append(iter.setIndex(i));
           if (part == end.part) {
             sel = false;
             break;
           }
           buf.append(' ');
         }
         if (sel) buf.append('\n');
       }
       if (msg == end.msg) break;
     }
   }
   Clipboard cl;
   if ((cl = java.awt.Toolkit.getDefaultToolkit().getSystemSelection()) == null)
     cl = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
   try {
     final CharPos ownsel = selstart;
     cl.setContents(
         new StringSelection(buf.toString()),
         new ClipboardOwner() {
           public void lostOwnership(Clipboard cl, Transferable tr) {
             if (selstart == ownsel) selstart = selend = null;
           }
         });
   } catch (IllegalStateException e) {
   }
 }
Ejemplo n.º 19
0
 /**
  * Converts a binary string input into an ASCII string output, assuming that 7-bit compaction was
  * used
  */
 private String bin2asciiseven(String binary) {
   String asciiseven;
   StringBuilder buffer = new StringBuilder("");
   int len = binary.length();
   for (int i = 0; i < len; i += 7) {
     int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 7), 8)));
     buffer.append((char) j);
   }
   asciiseven = buffer.toString();
   return asciiseven;
 }
Ejemplo n.º 20
0
 /**
  * Converts an alphanumeric string input into a binary string, using 6-bit compaction of each
  * ASCII byte
  */
 private String alphanumsix2bin(String alphanumsix) {
   String binary;
   StringBuilder buffer = new StringBuilder("");
   int len = alphanumsix.length();
   byte[] bytes = alphanumsix.getBytes();
   for (int i = 0; i < len; i++) {
     buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 64)), 8).substring(2, 8));
   }
   binary = buffer.toString();
   return binary;
 }
Ejemplo n.º 21
0
  private void end(StringBuilder ans, Pretty pretty, String indent) {
    if (endEncloser == null) return;
    if (!pretty.pretty) ans.append(endEncloser);
    else {
      Utilities.assureEndsWithNewLine(ans);
      ans.append(indent + endEncloser);
      if (pretty.comments && endComment.length() > 0) ans.append("#" + endComment);

      Utilities.assureEndsWithNewLine(ans);
    }
  }
Ejemplo n.º 22
0
 /**
  * Converts an upper case character string input into a binary string, using 5-bit compaction of
  * each ASCII byte
  */
 private String uppercasefive2bin(String uppercasefive) {
   String binary;
   StringBuilder buffer = new StringBuilder("");
   int len = uppercasefive.length();
   byte[] bytes = uppercasefive.getBytes();
   for (int i = 0; i < len; i++) {
     buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 32)), 8).substring(3, 8));
   }
   binary = buffer.toString();
   return binary;
 }
Ejemplo n.º 23
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < urls.size(); i++) {
     if (i > 0) {
       sb.append("|");
     }
     sb.append(
         String.format("%d,%d=\"%s\"", locations.get(i)[0], locations.get(i)[1], urls.get(i)));
   }
   return sb.toString();
 }
Ejemplo n.º 24
0
 /**
  * Converts an ASCII string input into a binary string, using 7-bit compaction of each ASCII byte
  */
 private String asciiseven2bin(String asciiseven) {
   String binary;
   StringBuilder buffer = new StringBuilder("");
   int len = asciiseven.length();
   byte[] bytes = asciiseven.getBytes();
   for (int i = 0; i < len; i++) {
     buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 128)), 8).substring(1, 8));
   }
   binary = buffer.toString();
   return binary;
 }
Ejemplo n.º 25
0
 /**
  * Return a string that describes the statistics for the top n entries, sorted by descending
  * order of total time spent dealing with the query. This will always include the totals entry
  * in the first position.
  *
  * @param n the desired number of entries to describe
  * @return a string describing the statistics for the top n entries
  */
 public synchronized String toStringTop(int n) {
   StringBuilder out = new StringBuilder();
   List<Entry> list = entries();
   if (list.isEmpty()) return "<no queries executed>";
   Collections.sort(list, TOTAL_TIME_DESCENDING);
   int maxCountLength = COUNT_FORMAT.format(list.get(0).numQueries).length();
   double totalDuration = list.get(0).queryTime;
   for (Entry entry : list.subList(0, Math.min(n, list.size())))
     out.append(entry.toString(maxCountLength, totalDuration)).append('\n');
   return out.toString();
 }
Ejemplo n.º 26
0
  @Nonnull
  private static String getRelativeSubPathToOutputDir(@Nonnull String filePath) {
    StringBuilder cssRelPath = new StringBuilder();
    int n = PATH_SEPARATOR.split(filePath).length;

    for (int i = 1; i < n; i++) {
      cssRelPath.append("../");
    }

    return cssRelPath.toString();
  }
Ejemplo n.º 27
0
 /** Converts a binary string input into a byte string, using 8-bits per character byte */
 private String bytestring2bin(String bytestring) {
   String binary;
   StringBuilder buffer = new StringBuilder("");
   int len = bytestring.length();
   byte[] bytes = bytestring.getBytes();
   for (int i = 0; i < len; i++) {
     buffer.append(padBinary(dec2bin(Integer.toString(bytes[i])), 8));
   }
   binary = buffer.toString();
   return binary;
 }
Ejemplo n.º 28
0
 /**
  * Converts a binary string input into a character string output, assuming that 5-bit compaction
  * was used
  */
 private String bin2uppercasefive(String binary) {
   String uppercasefive;
   StringBuilder buffer = new StringBuilder("");
   int len = binary.length();
   for (int i = 0; i < len; i += 5) {
     int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 5), 8)));
     buffer.append((char) (j + 64));
   }
   uppercasefive = buffer.toString();
   return uppercasefive;
 }
Ejemplo n.º 29
0
 /** Converts a byte string input into a binary string, using 8-bits per character byte */
 private String bin2bytestring(String binary) {
   String bytestring;
   StringBuilder buffer = new StringBuilder("");
   int len = binary.length();
   for (int i = 0; i < len; i += 8) {
     int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 8), 8)));
     buffer.append((char) j);
   }
   bytestring = buffer.toString();
   return bytestring;
 }
Ejemplo n.º 30
0
 private void start(StringBuilder ans, Pretty pretty, String indent) {
   if (startEncloser == null) return;
   if (!pretty.pretty) {
     ans.append(startEncloser);
   } else {
     String comment;
     if (pretty.comments && startComment.length() > 0) comment = " #" + startComment;
     else comment = "";
     ans.append(indent + startEncloser + comment);
     Utilities.assureEndsWithNewLine(ans);
   }
 }