public void write(int ch) { out.write(ch); if (ch == 10) { reporter.printNotice(out.toString()); out.reset(); } }
public static boolean validOptions(String options[][], DocErrorReporter reporter) { boolean foundDirOption = false; for (int i = 0; i < options.length; i++) { String[] opt = options[i]; if (opt[0].equals("-d")) { if (foundDirOption) { reporter.printError("Only one -d option allowed."); return false; } else { foundDirOption = true; } } else if (opt[0].equals("-overwrite")) { } } if (!foundDirOption) { reporter.printError( "Usage: javadoc -d outputDir " + "-doclet in.kp.doclet.sample.ListClass " + "... "); } return foundDirOption; }
/** * This checks for the validity of the options used by the user. This works exactly like {@link * bluej.doclet.Doclet#validOptions(String[][], DocErrorReporter)}. This will validate the options * which are shared by our doclets. For example, this method will flag an error using the * DocErrorReporter if user has used "-nohelp" and "-helpfile" option together. * * @param options options used on the command line. * @param reporter used to report errors. * @return true if all the options are valid. */ public boolean generalValidOptions(String options[][], DocErrorReporter reporter) { boolean docencodingfound = false; String encoding = ""; for (int oi = 0; oi < options.length; oi++) { String[] os = options[oi]; String opt = os[0].toLowerCase(); if (opt.equals("-d")) { String destdirname = addTrailingFileSep(os[1]); File destDir = new File(destdirname); if (!destDir.exists()) { // Create the output directory (in case it doesn't exist yet) reporter.printNotice(getText("doclet.dest_dir_create", destdirname)); (new File(destdirname)).mkdirs(); } else if (!destDir.isDirectory()) { reporter.printError( getText("doclet.destination_directory_not_directory_0", destDir.getPath())); return false; } else if (!destDir.canWrite()) { reporter.printError( getText("doclet.destination_directory_not_writable_0", destDir.getPath())); return false; } } else if (opt.equals("-docencoding")) { docencodingfound = true; if (!checkOutputFileEncoding(os[1], reporter)) { return false; } } else if (opt.equals("-encoding")) { encoding = os[1]; } } if (!docencodingfound && encoding.length() > 0) { if (!checkOutputFileEncoding(encoding, reporter)) { return false; } } return true; }
public static boolean validOptions(String[][] options, DocErrorReporter r) { for (String[] a : options) { if (a[0].equals("-error") || a[0].equals("-warning") || a[0].equals("-hide")) { try { Integer.parseInt(a[1]); } catch (NumberFormatException e) { r.printError("bad -" + a[0] + " value must be a number: " + a[1]); return false; } } } return true; }
/** * Check the validity of the given Source or Output File encoding on this platform. * * @param docencoding output file encoding. * @param reporter used to report errors. */ private boolean checkOutputFileEncoding(String docencoding, DocErrorReporter reporter) { OutputStream ost = new ByteArrayOutputStream(); OutputStreamWriter osw = null; try { osw = new OutputStreamWriter(ost, docencoding); } catch (UnsupportedEncodingException exc) { reporter.printError(getText("doclet.Encoding_not_supported", docencoding)); return false; } finally { try { if (osw != null) { osw.close(); } } catch (IOException exc) { } } return true; }
public void apply(File xmlSourceDirectory, File targetDirectory, DocErrorReporter reporter) throws DocTransletException { PrintStream err = System.err; try { URL mainResourceURL = classLoader == null ? ClassLoader.getSystemResource(mainResourceFilename) : classLoader.getResource(mainResourceFilename); if (null == mainResourceURL) { throw new DocTransletException("Cannot find resource '" + mainResourceFilename + "'"); } Map parameters = new HashMap(); parameters.put("gjdoc.xmldoclet.version", Driver.XMLDOCLET_VERSION); parameters.put("gjdoc.option.nonavbar", xsltBoolean(options.nonavbar)); parameters.put("gjdoc.option.noindex", xsltBoolean(options.noindex)); parameters.put("gjdoc.option.notree", xsltBoolean(options.notree)); parameters.put("gjdoc.option.nocomment", xsltBoolean(options.nocomment)); parameters.put("gjdoc.option.nohelp", xsltBoolean(options.nohelp)); parameters.put("gjdoc.option.splitindex", xsltBoolean(options.splitindex)); parameters.put("gjdoc.option.linksource", xsltBoolean(options.linksource)); parameters.put("gjdoc.option.nodeprecatedlist", xsltBoolean(options.nodeprecatedlist)); parameters.put("gjdoc.option.uses", xsltBoolean(options.uses)); parameters.put("gjdoc.option.windowtitle", options.windowtitle); parameters.put("gjdoc.option.helpfile", options.helpfile); parameters.put("gjdoc.option.stylesheetfile", options.stylesheetfile); parameters.put("gjdoc.option.header", options.header); parameters.put("gjdoc.option.footer", options.footer); parameters.put("gjdoc.option.bottom", options.bottom); parameters.put("gjdoc.option.doctitle", options.doctitle); List outputFileList = getOutputFileList(mainResourceURL, xmlSourceDirectory, parameters); reporter.printNotice("Running DocTranslet..."); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setErrorListener(this); boolean isLibxmlJ = transformerFactory .getClass() .getName() .equals("gnu.xml.libxmlj.transform.TransformerFactoryImpl"); for (Iterator it = outputFileList.iterator(); it.hasNext(); ) { if (isLibxmlJ) { System.gc(); Runtime.getRuntime().runFinalization(); } OutputFileInfo fileInfo = (OutputFileInfo) it.next(); File targetFile = new File(targetDirectory, fileInfo.getName()); File packageTargetDir = getParentFile(targetFile); if (!packageTargetDir.exists() && !packageTargetDir.mkdirs()) { throw new DocTransletException( "Target directory " + packageTargetDir + " does not exist and cannot be created."); } if (options.linksource) { File sourceTargetDirectory = new File(targetDirectory, "src-html"); File sourceTargetFile = new File(sourceTargetDirectory, fileInfo.getName()); File sourcePackageTargetDir = getParentFile(sourceTargetFile); if (!sourcePackageTargetDir.exists() && !sourcePackageTargetDir.mkdirs()) { throw new DocTransletException( "Target directory " + packageTargetDir + " does not exist and cannot be created."); } } if (options.uses) { File usesTargetDirectory = new File(targetDirectory, "class-use"); File usesTargetFile = new File(usesTargetDirectory, fileInfo.getName()); File usesPackageTargetDir = getParentFile(usesTargetFile); if (!usesPackageTargetDir.exists() && !usesPackageTargetDir.mkdirs()) { throw new DocTransletException( "Target directory " + packageTargetDir + " does not exist and cannot be created."); } } if (null != fileInfo.getSource()) { reporter.printNotice("Copying " + fileInfo.getComment() + "..."); InputStream in = new URL(mainResourceURL, fileInfo.getSource()).openStream(); FileOutputStream out = new FileOutputStream(targetFile.getAbsolutePath()); IOToolkit.copyStream(in, out); in.close(); out.close(); } else { reporter.printNotice("Generating " + fileInfo.getComment() + "..."); String pathToRoot = ""; for (File file = getParentFile(targetFile); !equalsFile(file, targetDirectory); file = getParentFile(file)) { pathToRoot += "../"; } StreamResult out = new StreamResult(targetFile.getAbsolutePath()); StreamSource in = new StreamSource(new File(xmlSourceDirectory, "index.xml").getAbsolutePath()); URL resource = new URL(mainResourceURL, fileInfo.getSheet()); StreamSource xsltSource = new StreamSource(resource.toExternalForm()); if (null != fileInfo.getInfo()) { parameters.put("gjdoc.outputfile.info", fileInfo.getInfo()); } parameters.put("gjdoc.pathtoroot", pathToRoot); Transformer transformer; transformer = (Transformer) transformerMap.get(xsltSource.getSystemId()); if (null == transformer) { transformer = transformerFactory.newTransformer(xsltSource); if (cacheXSLTSheets) { transformerMap.put(xsltSource.getSystemId(), transformer); } } transformer.clearParameters(); for (Iterator pit = parameters.keySet().iterator(); pit.hasNext(); ) { String key = (String) pit.next(); String value = (String) parameters.get(key); transformer.setParameter(key, value); } transformer.setErrorListener(this); DocErrorReporterOutputStream errorReporterOut = new DocErrorReporterOutputStream(reporter); System.setErr(new PrintStream(errorReporterOut)); transformer.transform(in, out); errorReporterOut.flush(); } } } catch (MalformedURLException e) { throw new DocTransletException(e); } catch (TransformerFactoryConfigurationError e) { throw new DocTransletException(e); } catch (TransformerException e) { throw new DocTransletException(e.getMessageAndLocation(), e); } catch (IOException e) { throw new DocTransletException(e); } finally { System.setErr(err); } }