Package loci.common

Examples of loci.common.Location


  }

  /* @see loci.formats.IFormatReader#fileGroupOption(String) */
  public int fileGroupOption(String id) throws FormatException, IOException {
    return checkSuffix(id, MDB_SUFFIX) ||
      !new Location(id).getName().startsWith("spim_") ? FormatTools.MUST_GROUP :
      FormatTools.CAN_GROUP;
  }
View Full Code Here


  }

  // -- Helper methods --

  private String getMDBFile(String id) throws FormatException, IOException {
    Location parentFile = new Location(id).getAbsoluteFile().getParentFile();
    String[] fileList = parentFile.list();
    for (int i=0; i<fileList.length; i++) {
      if (fileList[i].startsWith(".")) continue;
      if (checkSuffix(fileList[i], MDB_SUFFIX)) {
        Location file =
          new Location(parentFile, fileList[i]).getAbsoluteFile();
        if (file.isDirectory()) continue;
        // make sure that the .mdb references this .lsm
        String[] lsms = parseMDB(file.getAbsolutePath());
        if (lsms == null) return null;
        for (String lsm : lsms) {
          if (id.endsWith(lsm) || lsm.endsWith(id)) {
            return file.getAbsolutePath();
          }
        }
      }
    }
    return null;
View Full Code Here

  }

  /** Parse a .mdb file and return a list of referenced .lsm files. */
  private String[] parseMDB(String mdbFile) throws FormatException, IOException
  {
    Location mdb = new Location(mdbFile).getAbsoluteFile();
    Location parent = mdb.getParentFile();

    MDBService mdbService = null;
    try {
      ServiceFactory factory = new ServiceFactory();
      mdbService = factory.getInstance(MDBService.class);
    }
    catch (DependencyException de) {
      throw new FormatException("MDB Tools Java library not found", de);
    }

    try {
      mdbService.initialize(mdbFile);
    }
    catch (Exception e) {
      return null;
    }
    Vector<Vector<String[]>> tables = mdbService.parseDatabase();
    mdbService.close();
    Vector<String> referencedLSMs = new Vector<String>();

    int referenceCount = 0;

    for (Vector<String[]> table : tables) {
      String[] columnNames = table.get(0);
      String tableName = columnNames[0];

      for (int row=1; row<table.size(); row++) {
        String[] tableRow = table.get(row);
        for (int col=0; col<tableRow.length; col++) {
          String key = tableName + " " + columnNames[col + 1];
          if (currentId != null) {
            addGlobalMetaList(key, tableRow[col]);
          }

          if (tableName.equals("Recordings") && columnNames[col + 1] != null &&
            columnNames[col + 1].equals("SampleData"))
          {
            String filename = tableRow[col].trim();
            filename = filename.replace('\\', File.separatorChar);
            filename = filename.replace('/', File.separatorChar);
            filename =
              filename.substring(filename.lastIndexOf(File.separator) + 1);
            if (filename.length() > 0) {
              Location file = new Location(parent, filename);
              if (file.exists()) {
                referencedLSMs.add(file.getAbsolutePath());
              }
            }
            referenceCount++;
          }
        }
      }
    }

    if (referencedLSMs.size() == referenceCount) {
      return referencedLSMs.toArray(new String[0]);
    }

    String[] fileList = parent.list(true);
    Arrays.sort(fileList);
    for (int i=0; i<fileList.length; i++) {
      String absolutePath = new Location(parent, fileList[i]).getAbsolutePath();
      if (checkSuffix(fileList[i], "mdb") &&
        (!absolutePath.equals(mdbFile) && !fileList[i].equals(mdbFile)))
      {
        if (referencedLSMs.size() > 0) {
          return referencedLSMs.toArray(new String[0]);
        }
        break;
      }
    }

    referencedLSMs.clear();

    int mdbCount = 0;
    for (int i=0; i<fileList.length; i++) {
      String absolutePath = new Location(parent, fileList[i]).getAbsolutePath();
      if (checkSuffix(fileList[i], "lsm")) {
        referencedLSMs.add(absolutePath);
      }
      else if (checkSuffix(fileList[i], "mdb")) {
        mdbCount++;
      }
    }

    if (mdbCount > 1 || ((referencedLSMs.size() > referenceCount) &&
      mdbCount > 1))
    {
      for (int i=0; i<fileList.length; i++) {
        String absolutePath =
          new Location(parent, fileList[i]).getAbsolutePath();
        if (checkSuffix(fileList[i], "mdb") && !absolutePath.endsWith(mdbFile))
        {
          String[] files = parseMDB(absolutePath);
          for (String f : files) {
            referencedLSMs.remove(f);
View Full Code Here

TOP

Related Classes of loci.common.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.