示例#1
0
  /**
   * Gets the validation report from the validator.
   *
   * @param source the source text
   * @param path the source path
   * @return the report
   */
  private static String getReport(String source, URI path) {
    StyleSheetParser parser = new StyleSheetParser();
    ApplContext ac = new ApplContext("en"); // $NON-NLS-1$
    ac.setProfile(APTANA_PROFILE);
    try {
      parser.parseStyleElement(
          ac, new ByteArrayInputStream(source.getBytes(IOUtil.UTF_8)), null, null, path.toURL(), 0);
    } catch (MalformedURLException e) {
      IdeLog.logError(
          CSSCorePlugin.getDefault(),
          MessageFormat.format(Messages.CSSValidator_ERR_InvalidPath, path),
          e);
    } catch (UnsupportedEncodingException e) {
      IdeLog.logError(CSSCorePlugin.getDefault(), e);
    }

    StyleSheet stylesheet = parser.getStyleSheet();
    stylesheet.findConflicts(ac);
    StyleReport report =
        StyleReportFactory.getStyleReport(
            ac, "Title", stylesheet, "soap12", 2); // $NON-NLS-1$ //$NON-NLS-2$
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    report.print(new PrintWriter(out));
    return out.toString().replaceAll("m:", ""); // $NON-NLS-1$ //$NON-NLS-2$
  }
示例#2
0
  /**
   * Loads our CSS profile.
   *
   * @throws IOException if profile loading fails
   */
  private static void loadAptanaCSSProfile() {
    InputStream configStream = CSSValidator.class.getResourceAsStream(CONFIG_FILE);
    InputStream profilesStream = CSSValidator.class.getResourceAsStream(PROFILES_CONFIG_FILE);

    try {
      // loads our config
      PropertiesLoader.config.load(configStream);

      // loads our profile
      Utf8Properties profiles = new Utf8Properties();
      profiles.load(profilesStream);
      // a hack, but no other way since PropertiesLoader provides no public access to stored
      // profiles
      Field field = PropertiesLoader.class.getDeclaredField("profiles"); // $NON-NLS-1$
      field.setAccessible(true);
      field.set(null, profiles);
    } catch (Exception e) {
      IdeLog.logError(CSSCorePlugin.getDefault(), Messages.CSSValidator_ERR_FailToLoadProfile, e);
    } finally {
      try {
        configStream.close();
      } catch (IOException e) {
      }
      try {
        profilesStream.close();
      } catch (IOException e) {
      }
    }
  }