Ejemplo n.º 1
0
  /**
   * Process a single session element node.
   *
   * @param session
   * @param element
   */
  private void process(Session session, Node element, HashMap additionalInformation) {

    if ((element == null) || (session == null)) {
      return;
    }

    String nodeName = element.getNodeName();

    if (nodeName.equalsIgnoreCase(SessionElement.RESOURCES.getText())
        || nodeName.equalsIgnoreCase(SessionElement.FILES.getText())) {
      processResources(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.RESOURCE.getText())
        || nodeName.equalsIgnoreCase(SessionElement.DATA_FILE.getText())) {
      processResource(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.REGIONS.getText())) {
      processRegions(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.REGION.getText())) {
      processRegion(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.GENE_LIST.getText())) {
      processGeneList(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.FILTER.getText())) {
      processFilter(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.FILTER_ELEMENT.getText())) {
      processFilterElement(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.COLOR_SCALES.getText())) {
      processColorScales(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.COLOR_SCALE.getText())) {
      processColorScale(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.PREFERENCES.getText())) {
      processPreferences(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.DATA_TRACKS.getText())
        || nodeName.equalsIgnoreCase(SessionElement.FEATURE_TRACKS.getText())
        || nodeName.equalsIgnoreCase(SessionElement.PANEL.getText())) {
      processPanel(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.PANEL_LAYOUT.getText())) {
      processPanelLayout(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.HIDDEN_ATTRIBUTES.getText())) {
      processHiddenAttributes(session, (Element) element, additionalInformation);
    } else if (nodeName.equalsIgnoreCase(SessionElement.VISIBLE_ATTRIBUTES.getText())) {
      processVisibleAttributes(session, (Element) element, additionalInformation);
    }
  }
Ejemplo n.º 2
0
  private void processResource(Session session, Element element, HashMap additionalInformation) {

    String nodeName = element.getNodeName();
    boolean oldSession = nodeName.equals(SessionElement.DATA_FILE.getText());

    String label = getAttribute(element, SessionAttribute.LABEL.getText());
    String name = getAttribute(element, SessionAttribute.NAME.getText());
    String sampleId = getAttribute(element, SessionAttribute.SAMPLE_ID.getText());
    String description = getAttribute(element, SessionAttribute.DESCRIPTION.getText());
    String type = getAttribute(element, SessionAttribute.TYPE.getText());
    String coverage = getAttribute(element, SessionAttribute.COVERAGE.getText());
    String trackLine = getAttribute(element, SessionAttribute.TRACK_LINE.getText());
    String colorString = getAttribute(element, SessionAttribute.COLOR.getText());

    String relPathValue = getAttribute(element, SessionAttribute.RELATIVE_PATH.getText());
    boolean isRelativePath = ((relPathValue != null) && relPathValue.equalsIgnoreCase("true"));
    String serverURL = getAttribute(element, SessionAttribute.SERVER_URL.getText());

    // Older sessions used the "name" attribute for the path.
    String path = getAttribute(element, SessionAttribute.PATH.getText());

    if (oldSession && name != null) {
      path = name;
      int idx = name.lastIndexOf("/");
      if (idx > 0 && idx + 1 < name.length()) {
        name = name.substring(idx + 1);
      }
    }

    ResourceLocator resourceLocator;
    if (isRelativePath) {
      final String sessionPath = session.getPath();

      String absolutePath;
      if (sessionPath == null) {
        log.error("Null session path -- this is not expected");
        MessageUtils.showMessage("Unexpected error loading session: null session path");
        return;
      }
      absolutePath = FileUtils.getAbsolutePath(path, sessionPath);
      fullToRelPathMap.put(absolutePath, path);
      resourceLocator = new ResourceLocator(serverURL, absolutePath);

      // If the resourceLocator is relative, we assume coverage is as well
      if (coverage != null) {
        String absoluteCoveragePath = FileUtils.getAbsolutePath(coverage, sessionPath);
        resourceLocator.setCoverage(absoluteCoveragePath);
      }
    } else {
      resourceLocator = new ResourceLocator(serverURL, path);
      resourceLocator.setCoverage(coverage);
    }

    String url = getAttribute(element, SessionAttribute.URL.getText());
    if (url == null) {
      url = getAttribute(element, SessionAttribute.FEATURE_URL.getText());
    }
    resourceLocator.setUrl(url);

    String infolink = getAttribute(element, SessionAttribute.HYPERLINK.getText());
    if (infolink == null) {
      infolink = getAttribute(element, SessionAttribute.INFOLINK.getText());
    }
    resourceLocator.setInfolink(infolink);

    // Label is deprecated in favor of name.
    if (name != null) {
      resourceLocator.setName(name);
    } else {
      resourceLocator.setName(label);
    }

    resourceLocator.setSampleId(sampleId);

    resourceLocator.setDescription(description);
    // This test added to get around earlier bug in the writer
    if (type != null && !type.equals("local")) {
      resourceLocator.setType(type);
    }
    resourceLocator.setCoverage(coverage);
    resourceLocator.setTrackLine(trackLine);

    if (colorString != null) {
      try {
        Color c = ColorUtilities.stringToColor(colorString);
        resourceLocator.setColor(c);
      } catch (Exception e) {
        log.error("Error setting color: ", e);
      }
    }

    dataFiles.add(resourceLocator);

    NodeList elements = element.getChildNodes();
    process(session, elements, additionalInformation);
  }