/*
   * 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();
  }
  /**
   * Check a DicomObject and record any failing lookups in the database.
   *
   * @param fileObject the object to process.
   * @return the same FileObject if the result is true; otherwise null.
   */
  public FileObject process(FileObject fileObject) {
    String cmd;

    lastFileIn = new File(fileObject.getFile().getAbsolutePath());
    lastTimeIn = System.currentTimeMillis();

    if (fileObject instanceof DicomObject) {
      DicomObject dob = (DicomObject) fileObject;
      if (dcmScriptFile != null) {
        DAScript daScript = DAScript.getInstance(dcmScriptFile);
        scriptTable = new ScriptTable(daScript);
        lutProps = LookupTable.getProperties(lutFile);
        synchronized (this) {
          Dataset ds = dob.getDataset();
          charset = ds.getSpecificCharacterSet();
          boolean ok = checkDataset(ds);
          if (!ok) {
            try {
              recman.commit();
            } catch (Exception unable) {
            }
            ;
            if (quarantine != null) quarantine.insert(fileObject);
            return null;
          }
        }
      }
    }
    lastFileOut = new File(fileObject.getFile().getAbsolutePath());
    lastTimeOut = System.currentTimeMillis();
    return fileObject;
  }
    public PrivateGroupsIndex(Dataset ds) {
      this.ds = ds;
      cs = ds.getSpecificCharacterSet();
      index = new Hashtable<Integer, PrivateGroupIndex>();

      for (Iterator it = ds.iterator(); it.hasNext(); ) {
        DcmElement el = (DcmElement) it.next();
        int tag = el.tag();
        int group = (tag >> 16) & 0xFFFF;
        int element = tag & 0xFFFF;
        if (((group & 1) != 0) && (element < 0x100)) {

          // This is a private group element that claims a block.
          try {
            String blockOwnerID = el.getString(cs);
            if ((blockOwnerID != null) && !(blockOwnerID = blockOwnerID.trim()).equals("")) {

              // Get the index of this group
              Integer gpInteger = new Integer(group);
              PrivateGroupIndex idx = index.get(gpInteger);
              if (idx == null) {
                idx = new PrivateGroupIndex();
                index.put(gpInteger, idx);
              }

              // Store the mapping for this block.
              // Note: this implementation requires that all blocks
              // within a single private group be claimed with unique IDs.
              // The standard doesn't seem to require this constraint, but
              // objects in practice seem to observe it. There is a CP
              // inprocess to require it.
              idx.put(blockOwnerID, new Integer(tag));
            }
          } catch (Exception skip) {
          }
        }
      }
    }
 /*
  * Get the SpecificCharacterSet of the input dataset.
  * @return the SpecificCharacterSet of the input dataset.
  */
 public SpecificCharacterSet getSpecificCharacterSet() {
   return inDS.getSpecificCharacterSet();
 }