Ejemplo n.º 1
0
  /**
   * Sort the <code>faces-config</code> documents found on the classpath and those specified by the
   * <code>javax.faces.CONFIG_FILES</code> context init parameter.
   *
   * @param facesDocuments an array of <em>all</em> <code>faces-config</code> documents
   * @param webInfFacesConfig FacesConfigInfo representing the WEB-INF/faces-config.xml for this app
   * @return the sorted documents
   */
  private DocumentInfo[] sortDocuments(
      DocumentInfo[] facesDocuments, FacesConfigInfo webInfFacesConfig) {

    int len =
        (webInfFacesConfig.isWebInfFacesConfig()
            ? facesDocuments.length - 1
            : facesDocuments.length);

    List<String> absoluteOrdering = webInfFacesConfig.getAbsoluteOrdering();

    if (len > 1) {
      List<DocumentOrderingWrapper> list = new ArrayList<DocumentOrderingWrapper>();
      for (int i = 1; i < len; i++) {
        list.add(new DocumentOrderingWrapper(facesDocuments[i]));
      }
      DocumentOrderingWrapper[] ordering = list.toArray(new DocumentOrderingWrapper[list.size()]);
      if (absoluteOrdering == null) {
        DocumentOrderingWrapper.sort(ordering);
        // sorting complete, now update the appropriate locations within
        // the original array with the sorted documentation.
        for (int i = 1; i < len; i++) {
          facesDocuments[i] = ordering[i - 1].getDocument();
        }
        return facesDocuments;
      } else {
        DocumentOrderingWrapper[] result = DocumentOrderingWrapper.sort(ordering, absoluteOrdering);
        DocumentInfo[] ret =
            new DocumentInfo
                [((webInfFacesConfig.isWebInfFacesConfig())
                    ? (result.length + 2)
                    : (result.length + 1))];
        for (int i = 1; i < len; i++) {
          ret[i] = result[i - 1].getDocument();
        }
        // add the impl specific config file
        ret[0] = facesDocuments[0];
        // add the WEB-INF if necessary
        if (webInfFacesConfig.isWebInfFacesConfig()) {
          ret[ret.length - 1] = facesDocuments[facesDocuments.length - 1];
        }
        return ret;
      }
    }

    return facesDocuments;
  }