Example #1
1
  /**
   * Load Default FontStylesCollection, singleton 1) if no citation style is given, return default
   * {@link FontStylesCollection} 2) if citation style is given, check citation style directory. If
   * there is a citation style specific {@link FontStylesCollection} in the citation style directory
   * FontStylesCollection, get it; if not - get default FontStylesCollection
   *
   * @param cs - citation style
   * @return {@link FontStylesCollection}
   * @throws CitationStyleManagerException
   */
  public static FontStylesCollection loadFontStylesCollection(String cs) {
    // get default FontStyleCollection from __Default__ element for empty cs
    if (cs == null || "".equals(cs.trim())) return loadFontStylesCollection("__Default__");

    if (fsc.containsKey(cs)) return fsc.get(cs);

    try {
      // load __Default__ collection
      if ("__Default__".equalsIgnoreCase(cs)) {
        fsc.put(
            cs,
            FontStylesCollection.loadFromXml(
                CitationUtil.getPathToCitationStyles() + FONT_STYLES_COLLECTION_FILE));
      } else {
        InputStream inputStream =
            ResourceUtil.getResourceAsStream(
                CitationUtil.getPathToCitationStyle(cs) + FONT_STYLES_COLLECTION_FILE,
                XmlHelper.class.getClassLoader());
        // get specific FontStyleCollection for citation style if exists
        if (inputStream != null) {
          fsc.put(cs, FontStylesCollection.loadFromXml(inputStream));
        }
        // otherwise: get __Default_ one
        else {
          fsc.put(cs, loadFontStylesCollection());
        }
      }
      return fsc.get(cs);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      throw new RuntimeException("Cannot loadFontStylesCollection: ", e);
    }
  }
Example #2
0
  public static JasperReport tryJasperCache(String cs)
      throws CitationStyleManagerException, IOException, JRException {
    Utils.checkName(cs, "Empty style name.");

    JasperReport jr = XmlHelper.jasperCache.get(cs);

    if (jr == null) {

      // get default JasperDesign

      String path = CitationUtil.getPathToCitationStyles() + "citation-style.jrxml";
      JasperDesign jd =
          JRXmlLoader.load(
              ResourceUtil.getResourceAsStream(path, XmlHelper.class.getClassLoader()));

      // populate page header
      // setPageHeader(jd, cs);

      // set default Report Style
      setDefaultReportStyle(jd, cs);

      // compile to the JasperReport
      jr = JasperCompileManager.compileReport(jd);

      XmlHelper.jasperCache.put(cs, jr);
    }

    return jr;
  }