Example #1
0
 private static String errorMessage(String msg, int tag, int... sqTags) {
   StringBuffer sb = new StringBuffer(msg);
   if (sqTags != null && sqTags.length != 0)
     for (int sqTag : sqTags) Tags.toString(sb, sqTag).append('/');
   Tags.toString(sb, tag);
   return sb.toString();
 }
  /*
   * Get the contents of an input dataset element by tag,
   * handling CTP elements specially.
   * @param tag the element tag
   * @return the value of the specified element in the current dataset,
   * @throws Exception if the element is missing.
   */
  public String contents(int tag) throws Exception {
    SpecificCharacterSet cs = inDS.getSpecificCharacterSet();

    // Handle FileMetaInfo references
    if ((inFMI != null) && ((tag & 0x7FFFFFFF) < 0x80000)) {
      DcmElement el = inFMI.get(tag);
      if (el == null) throw new Exception(Tags.toString(tag) + " missing");
      return el.getString(cs);
    }

    // Not FMI, handle DataSet references
    boolean ctp = false;
    if (((tag & 0x00010000) != 0) && ((tag & 0x0000ff00) != 0)) {
      int blk = (tag & 0xffff0000) | ((tag & 0x0000ff00) >> 8);
      try {
        ctp = inDS.getString(blk).equals("CTP");
      } catch (Exception notCTP) {
        ctp = false;
      }
    }
    DcmElement el = inDS.get(tag);
    if (el == null) throw new Exception(Tags.toString(tag) + " missing");

    if (ctp) return new String(inDS.getByteBuffer(tag).array());

    String[] s = el.getStrings(cs);
    if (s.length == 1) return s[0];
    if (s.length == 0) return "";
    StringBuffer sb = new StringBuffer(s[0]);
    for (int i = 1; i < s.length; i++) {
      sb.append("\\" + s[i]);
    }
    return sb.toString();
  }
 /**
  * Add the query keys found in the configuration properties to the Dataset "keys" used bei the
  * cFIND method.
  *
  * @param cfg the configuration properties for this class.
  * @throws ParseException if a given properties for the keys was not found.
  */
 private void addQueryKeys(ConfigProperties cfg) throws ParseException {
   // Add/replace keys found in the configuration file. Syntax key.<element name> = <element value>
   for (Enumeration it = cfg.keys(); it.hasMoreElements(); ) {
     String key = (String) it.nextElement();
     if (key.startsWith("key.")) {
       try {
         keys.putXX(Tags.forName(key.substring(4)), cfg.getProperty(key));
       } catch (Exception e) {
         throw new ParseException(
             "Illegal entry in configuration filr: " + key + "=" + cfg.getProperty(key), 0);
       }
     }
   }
 }