⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsltc.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public void setXMLReader(XMLReader reader) {	_reader = reader;    }    /**     * Get the XMLReader to use for parsing the next input stylesheet     */    public XMLReader getXMLReader() {	return _reader ;    }    /**     * Get a Vector containing all compile error messages     * @return A Vector containing all compile error messages     */    public Vector getErrors() {	return _parser.getErrors();    }    /**     * Get a Vector containing all compile warning messages     * @return A Vector containing all compile error messages     */    public Vector getWarnings() {	return _parser.getWarnings();    }    /**     * Print all compile error messages to standard output     */    public void printErrors() {	_parser.printErrors();    }    /**     * Print all compile warning messages to standard output     */    public void printWarnings() {	_parser.printWarnings();    }    /**     * This method is called by the XPathParser when it encounters a call     * to the document() function. Affects the DOM used by the translet.     */    protected void setMultiDocument(boolean flag) {	_multiDocument = flag;    }    public boolean isMultiDocument() {	return _multiDocument;    }    /**     * This method is called by the XPathParser when it encounters a call     * to the nodeset() extension function. Implies multi document.     */    protected void setCallsNodeset(boolean flag) {	if (flag) setMultiDocument(flag);	_callsNodeset = flag;    }    public boolean callsNodeset() {	return _callsNodeset;    }    protected void setHasIdCall(boolean flag) {    	_hasIdCall = flag;    }    public boolean hasIdCall() {    	return _hasIdCall;    }    /**     * Set the class name for the generated translet. This class name is     * overridden if multiple stylesheets are compiled in one go using the     * compile(Vector urls) method.     * @param className The name to assign to the translet class     */    public void setClassName(String className) {	final String base  = Util.baseName(className);	final String noext = Util.noExtName(base);	String name  = Util.toJavaName(noext);	if (_packageName == null)	    _className = name;	else	    _className = _packageName + '.' + name;    }    /**     * Get the class name for the generated translet.     */    public String getClassName() {	return _className;    }    /**     * Convert for Java class name of local system file name.     * (Replace '.' with '/' on UNIX and replace '.' by '\' on Windows/DOS.)     */    private String classFileName(final String className) {	return className.replace('.', File.separatorChar) + ".class";    }    /**     * Generate an output File object to send the translet to     */    private File getOutputFile(String className) {	if (_destDir != null)	    return new File(_destDir, classFileName(className));	else	    return new File(classFileName(className));    }    /**     * Set the destination directory for the translet.     * The current working directory will be used by default.     */    public boolean setDestDirectory(String dstDirName) {	final File dir = new File(dstDirName);	if (dir.exists() || dir.mkdirs()) {	    _destDir = dir;	    return true;	}	else {	    _destDir = null;	    return false;	}    }    /**     * Set an optional package name for the translet and auxiliary classes     */    public void setPackageName(String packageName) {	_packageName = packageName;	if (_className != null) setClassName(_className);    }    /**     * Set the name of an optional JAR-file to dump the translet and     * auxiliary classes to     */    public void setJarFileName(String jarFileName) {	final String JAR_EXT = ".jar";	if (jarFileName.endsWith(JAR_EXT))	    _jarFileName = jarFileName;	else	    _jarFileName = jarFileName + JAR_EXT;	_outputType = JAR_OUTPUT;    }    public String getJarFileName() {	return _jarFileName;    }    /**     * Set the top-level stylesheet     */    public void setStylesheet(Stylesheet stylesheet) {	if (_stylesheet == null) _stylesheet = stylesheet;    }    /**     * Returns the top-level stylesheet     */    public Stylesheet getStylesheet() {	return _stylesheet;    }    /**     * Registers an attribute and gives it a type so that it can be mapped to     * DOM attribute types at run-time.     */    public int registerAttribute(QName name) {	Integer code = (Integer)_attributes.get(name.toString());	if (code == null) {	    code = new Integer(_nextGType++);	    _attributes.put(name.toString(), code);	    final String uri = name.getNamespace();	    final String local = "@"+name.getLocalPart();	    if ((uri != null) && (!uri.equals("")))		_namesIndex.addElement(uri+":"+local);	    else		_namesIndex.addElement(local);	    if (name.getLocalPart().equals("*")) {		registerNamespace(name.getNamespace());	    }	}	return code.intValue();    }    /**     * Registers an element and gives it a type so that it can be mapped to     * DOM element types at run-time.     */    public int registerElement(QName name) {	// Register element (full QName)	Integer code = (Integer)_elements.get(name.toString());	if (code == null) {	    _elements.put(name.toString(), code = new Integer(_nextGType++));	    _namesIndex.addElement(name.toString());	}	if (name.getLocalPart().equals("*")) {	    registerNamespace(name.getNamespace());	}	return code.intValue();    }     /**       * Registers a namespace prefix and gives it a type so that it can be mapped to      * DOM namespace types at run-time.      */      public int registerNamespacePrefix(QName name) {        Integer code = (Integer)_namespacePrefixes.get(name.toString());    if (code == null) {           code = new Integer(_nextGType++);        _namespacePrefixes.put(name.toString(), code);         final String uri = name.getNamespace();        if ((uri != null) && (!uri.equals(""))){            // namespace::ext2:ped2 will be made empty in TypedNamespaceIterator            _namesIndex.addElement("?");         } else{                   _namesIndex.addElement("?"+name.getLocalPart());                }    }       return code.intValue();    }    /**     * Registers a namespace and gives it a type so that it can be mapped to     * DOM namespace types at run-time.     */    public int registerNamespace(String namespaceURI) {	Integer code = (Integer)_namespaces.get(namespaceURI);	if (code == null) {	    code = new Integer(_nextNSType++);	    _namespaces.put(namespaceURI,code);	    _namespaceIndex.addElement(namespaceURI);	}	return code.intValue();    }    public int nextModeSerial() {	return _modeSerial++;    }    public int nextStylesheetSerial() {	return _stylesheetSerial++;    }    public int nextStepPatternSerial() {	return _stepPatternSerial++;    }    public int[] getNumberFieldIndexes() {	return _numberFieldIndexes;    }    public int nextHelperClassSerial() {	return _helperClassSerial++;    }    public int nextAttributeSetSerial() {	return _attributeSetSerial++;    }    public Vector getNamesIndex() {	return _namesIndex;    }    public Vector getNamespaceIndex() {	return _namespaceIndex;    }    /**     * Returns a unique name for every helper class needed to     * execute a translet.     */    public String getHelperClassName() {	return getClassName() + '$' + _helperClassSerial++;    }    public void dumpClass(JavaClass clazz) {	if (_outputType == FILE_OUTPUT ||	    _outputType == BYTEARRAY_AND_FILE_OUTPUT)	{	    File outFile = getOutputFile(clazz.getClassName());	    String parentDir = outFile.getParent();	    if (parentDir != null) {	      	File parentFile = new File(parentDir);	      	if (!parentFile.exists())	            parentFile.mkdirs();	    }	}	try {	    switch (_outputType) {	    case FILE_OUTPUT:		clazz.dump(		    new BufferedOutputStream(			new FileOutputStream(			    getOutputFile(clazz.getClassName()))));		break;	    case JAR_OUTPUT:		_bcelClasses.addElement(clazz);		break;	    case BYTEARRAY_OUTPUT:	    case BYTEARRAY_AND_FILE_OUTPUT:	    case BYTEARRAY_AND_JAR_OUTPUT:	    case CLASSLOADER_OUTPUT:		ByteArrayOutputStream out = new ByteArrayOutputStream(2048);		clazz.dump(out);		_classes.addElement(out.toByteArray());		if (_outputType == BYTEARRAY_AND_FILE_OUTPUT)		  clazz.dump(new BufferedOutputStream(			new FileOutputStream(getOutputFile(clazz.getClassName()))));		else if (_outputType == BYTEARRAY_AND_JAR_OUTPUT)		  _bcelClasses.addElement(clazz);		break;	    }	}	catch (Exception e) {	    e.printStackTrace();	}    }    /**     * File separators are converted to forward slashes for ZIP files.     */    private String entryName(File f) throws IOException {	return f.getName().replace(File.separatorChar, '/');    }    /**     * Generate output JAR-file and packages     */    public void outputToJar() throws IOException {	// create the manifest	final Manifest manifest = new Manifest();	final java.util.jar.Attributes atrs = manifest.getMainAttributes();	atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION,"1.2");	final Map map = manifest.getEntries();	// create manifest	Enumeration classes = _bcelClasses.elements();	final String now = (new Date()).toString();	final java.util.jar.Attributes.Name dateAttr =	    new java.util.jar.Attributes.Name("Date");	while (classes.hasMoreElements()) {	    final JavaClass clazz = (JavaClass)classes.nextElement();	    final String className = clazz.getClassName().replace('.','/');	    final java.util.jar.Attributes attr = new java.util.jar.Attributes();	    attr.put(dateAttr, now);	    map.put(className+".class", attr);	}	final File jarFile = new File(_destDir, _jarFileName);	final JarOutputStream jos =	    new JarOutputStream(new FileOutputStream(jarFile), manifest);	classes = _bcelClasses.elements();	while (classes.hasMoreElements()) {	    final JavaClass clazz = (JavaClass)classes.nextElement();	    final String className = clazz.getClassName().replace('.','/');	    jos.putNextEntry(new JarEntry(className+".class"));	    final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);	    clazz.dump(out); // dump() closes it's output stream	    out.writeTo(jos);	}	jos.close();    }    /**     * Turn debugging messages on/off     */    public void setDebug(boolean debug) {	_debug = debug;    }    /**     * Get current debugging message setting     */    public boolean debug() {	return _debug;    }    /**     * Retrieve a string representation of the character data to be stored     * in the translet as a <code>char[]</code>.  There may be more than     * one such array required.     * @param index The index of the <code>char[]</code>.  Zero-based.     * @return String The character data to be stored in the corresponding     *               <code>char[]</code>.     */    public String getCharacterData(int index) {        return ((StringBuffer) m_characterData.elementAt(index)).toString();    }    /**     * Get the number of char[] arrays, thus far, that will be created to     * store literal text in the stylesheet.     */    public int getCharacterDataCount() {        return (m_characterData != null) ? m_characterData.size() : 0;    }    /**     * Add literal text to char arrays that will be used to store character     * data in the stylesheet.     * @param newData String data to be added to char arrays.     *                Pre-condition:  <code>newData.length() &le; 21845</code>     * @return int offset at which character data will be stored     */    public int addCharacterData(String newData) {        StringBuffer currData;        if (m_characterData == null) {            m_characterData = new Vector();            currData = new StringBuffer();            m_characterData.addElement(currData);        } else {            currData = (StringBuffer) m_characterData                                           .elementAt(m_characterData.size()-1);        }        // Character data could take up to three-times as much space when        // written to the class file as UTF-8.  The maximum size for a        // constant is 65535/3.  If we exceed that,        // (We really should use some "bin packing".)        if (newData.length() + currData.length() > 21845) {            currData = new StringBuffer();            m_characterData.addElement(currData);        }        int newDataOffset = currData.length();        currData.append(newData);        return newDataOffset;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -