443 * @param input An InputSource that will pass in the stylesheet contents
444 * @param name The name of the translet class to generate - can be null
445 * @return 'true' if the compilation was successful
446 */
447 public boolean compile(InputSource input, String name) {
448 try {
449 // Reset globals in case we're called by compile(ArrayList v);
450 reset();
451
452 // The systemId may not be set, so we'll have to check the URL
453 String systemId = null;
454 if (input != null) {
455 systemId = input.getSystemId();
456 }
457
458 // Set the translet class name if not already set
459 if (_className == null) {
460 if (name != null) {
461 setClassName(name);
462 }
463 else if (systemId != null && !systemId.equals("")) {
464 setClassName(Util.baseName(systemId));
465 }
466
467 // Ensure we have a non-empty class name at this point
468 if (_className == null || _className.length() == 0) {
469 setClassName("GregorSamsa"); // default translet name
470 }
471 }
472
473 // Get the root node of the abstract syntax tree
474 SyntaxTreeNode element = null;
475 if (_reader == null) {
476 element = _parser.parse(input);
477 }
478 else {
479 element = _parser.parse(_reader, input);
480 }
481
482 // Compile the translet - this is where the work is done!
483 if ((!_parser.errorsFound()) && (element != null)) {
753 }
754
755 /**
756 * Returns the top-level stylesheet
757 */
758 public Stylesheet getStylesheet() {
759 return _stylesheet;
760 }
761
762 /**
763 * Registers an attribute and gives it a type so that it can be mapped to
764 * DOM attribute types at run-time.
765 */
766 public int registerAttribute(QName name) {
767 Integer code = _attributes.get(name.toString());
768 if (code == null) {
769 code = _nextGType++;
770 _attributes.put(name.toString(), code);
771 final String uri = name.getNamespace();
772 final String local = "@"+name.getLocalPart();
773 if ((uri != null) && (!uri.equals("")))
774 _namesIndex.add(uri+":"+local);
775 else
776 _namesIndex.add(local);
777 if (name.getLocalPart().equals("*")) {
778 registerNamespace(name.getNamespace());
779 }
780 }
781 return code.intValue();
782 }
783
784 /**
785 * Registers an element and gives it a type so that it can be mapped to
786 * DOM element types at run-time.
787 */
788 public int registerElement(QName name) {
789 // Register element (full QName)
790 Integer code = _elements.get(name.toString());
791 if (code == null) {
792 _elements.put(name.toString(), code = _nextGType++);
793 _namesIndex.add(name.toString());
794 }
795 if (name.getLocalPart().equals("*")) {
796 registerNamespace(name.getNamespace());
797 }
798 return code.intValue();
799 }
800
801 /**
802 * Registers a namespace prefix and gives it a type so that it can be mapped to
803 * DOM namespace types at run-time.
804 */
805
806 public int registerNamespacePrefix(QName name) {
807
808 Integer code = _namespacePrefixes.get(name.toString());
809 if (code == null) {
810 code = _nextGType++;
811 _namespacePrefixes.put(name.toString(), code);
812 final String uri = name.getNamespace();
813 if ((uri != null) && (!uri.equals(""))){
814 // namespace::ext2:ped2 will be made empty in TypedNamespaceIterator
815 _namesIndex.add("?");
816 } else{
817 _namesIndex.add("?"+name.getLocalPart());
818 }
819 }
820 return code.intValue();
821 }
822
823 /**
824 * Registers a namespace and gives it a type so that it can be mapped to
825 * DOM namespace types at run-time.
826 */
827 public int registerNamespace(String namespaceURI) {
828 Integer code = _namespaces.get(namespaceURI);
829 if (code == null) {
830 code = _nextNSType++;
831 _namespaces.put(namespaceURI,code);
832 _namespaceIndex.add(namespaceURI);
833 }
|
443 * @param input An InputSource that will pass in the stylesheet contents
444 * @param name The name of the translet class to generate - can be null
445 * @return 'true' if the compilation was successful
446 */
447 public boolean compile(InputSource input, String name) {
448 try {
449 // Reset globals in case we're called by compile(ArrayList v);
450 reset();
451
452 // The systemId may not be set, so we'll have to check the URL
453 String systemId = null;
454 if (input != null) {
455 systemId = input.getSystemId();
456 }
457
458 // Set the translet class name if not already set
459 if (_className == null) {
460 if (name != null) {
461 setClassName(name);
462 }
463 else if (systemId != null && !systemId.isEmpty()) {
464 setClassName(Util.baseName(systemId));
465 }
466
467 // Ensure we have a non-empty class name at this point
468 if (_className == null || _className.length() == 0) {
469 setClassName("GregorSamsa"); // default translet name
470 }
471 }
472
473 // Get the root node of the abstract syntax tree
474 SyntaxTreeNode element = null;
475 if (_reader == null) {
476 element = _parser.parse(input);
477 }
478 else {
479 element = _parser.parse(_reader, input);
480 }
481
482 // Compile the translet - this is where the work is done!
483 if ((!_parser.errorsFound()) && (element != null)) {
753 }
754
755 /**
756 * Returns the top-level stylesheet
757 */
758 public Stylesheet getStylesheet() {
759 return _stylesheet;
760 }
761
762 /**
763 * Registers an attribute and gives it a type so that it can be mapped to
764 * DOM attribute types at run-time.
765 */
766 public int registerAttribute(QName name) {
767 Integer code = _attributes.get(name.toString());
768 if (code == null) {
769 code = _nextGType++;
770 _attributes.put(name.toString(), code);
771 final String uri = name.getNamespace();
772 final String local = "@"+name.getLocalPart();
773 if ((uri != null) && (!uri.isEmpty()))
774 _namesIndex.add(uri+":"+local);
775 else
776 _namesIndex.add(local);
777 if (name.getLocalPart().equals("*")) {
778 registerNamespace(name.getNamespace());
779 }
780 }
781 return code.intValue();
782 }
783
784 /**
785 * Registers an element and gives it a type so that it can be mapped to
786 * DOM element types at run-time.
787 */
788 public int registerElement(QName name) {
789 // Register element (full QName)
790 Integer code = _elements.get(name.toString());
791 if (code == null) {
792 _elements.put(name.toString(), code = _nextGType++);
793 _namesIndex.add(name.toString());
794 }
795 if (name.getLocalPart().equals("*")) {
796 registerNamespace(name.getNamespace());
797 }
798 return code.intValue();
799 }
800
801 /**
802 * Registers a namespace prefix and gives it a type so that it can be mapped to
803 * DOM namespace types at run-time.
804 */
805
806 public int registerNamespacePrefix(QName name) {
807
808 Integer code = _namespacePrefixes.get(name.toString());
809 if (code == null) {
810 code = _nextGType++;
811 _namespacePrefixes.put(name.toString(), code);
812 final String uri = name.getNamespace();
813 if ((uri != null) && (!uri.isEmpty())){
814 // namespace::ext2:ped2 will be made empty in TypedNamespaceIterator
815 _namesIndex.add("?");
816 } else{
817 _namesIndex.add("?"+name.getLocalPart());
818 }
819 }
820 return code.intValue();
821 }
822
823 /**
824 * Registers a namespace and gives it a type so that it can be mapped to
825 * DOM namespace types at run-time.
826 */
827 public int registerNamespace(String namespaceURI) {
828 Integer code = _namespaces.get(namespaceURI);
829 if (code == null) {
830 code = _nextNSType++;
831 _namespaces.put(namespaceURI,code);
832 _namespaceIndex.add(namespaceURI);
833 }
|