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;
  }
Example #3
0
  /**
   * Validation of CitationStyle XML against 1) XML schema 2) Schematron schema
   *
   * @param xmlDocumentUrl is URI to XML to be validated
   * @throws IOException
   */
  public String validateCitationStyleXML(final String cs) throws IOException {
    String csFile = CitationUtil.getPathToCitationStyleXML(cs);
    logger.info("Document to be validated: " + csFile);

    // XML Schema validation
    logger.info("XML Schema validation...");
    String report =
        validateSchema(
            CitationUtil.getUriToResources()
                + CitationUtil.SCHEMAS_DIRECTORY
                + CITATIONSTYLE_XML_SCHEMA_FILE,
            csFile);
    if (report != null) {
      return report;
    }
    logger.info("OK");

    // Schematron validation
    logger.info("Schematron validation...");
    SchtrnValidator validator = new SchtrnValidator();
    validator.setEngineStylesheet(
        CitationUtil.getPathToSchemas() + SCHEMATRON_DIRECTORY + "schematron-diagnose.xsl");
    validator.setParams(new SchtrnParams());
    validator.setBaseXML(true);
    try {
      report = validator.validate(csFile, CitationUtil.getPathToSchemas() + SCHEMATRON_FILE);
    } catch (TransformerConfigurationException e1) {
      return "Schematron validation problem (TransformerConfigurationException): "
          + e1.getMessage();
    } catch (TransformerException e1) {
      return "Schematron validation problem (TransformerException): " + e1.getMessage();
    } catch (Exception e1) {
      return "Schematron validation problem: " + e1.getMessage();
    }
    if (report != null && report.contains("Report: ")) {
      return report;
    }
    logger.info("OK");

    return null;
  }
Example #4
0
 public static Document getExplainDocument() throws CitationStyleManagerException {
   Document doc = null;
   try {
     doc =
         parseDocumentForTraversing(
             new InputSource(
                 ResourceUtil.getResourceAsStream(
                     CitationUtil.getPathToSchemas() + CitationUtil.EXPLAIN_FILE,
                     XmlHelper.class.getClassLoader())));
   } catch (Exception e) {
     throw new CitationStyleManagerException("Cannot parse explain file", e);
   }
   return doc;
 }