707 vc = VALID_NAMES[c]; |
708 vc = VALID_NAMES[c]; |
708 }else{ |
709 }else{ |
709 vc = XMLChar.isName(c); |
710 vc = XMLChar.isName(c); |
710 } |
711 } |
711 if(!vc)break; |
712 if(!vc)break; |
712 if (++fCurrentEntity.position == fCurrentEntity.count) { |
713 if ((length = checkBeforeLoad(fCurrentEntity, offset, offset)) > 0) { |
713 int length = fCurrentEntity.position - offset; |
|
714 invokeListeners(length); |
|
715 if (length == fCurrentEntity.fBufferSize) { |
|
716 // bad luck we have to resize our buffer |
|
717 char[] tmp = new char[fCurrentEntity.fBufferSize * 2]; |
|
718 System.arraycopy(fCurrentEntity.ch, offset, |
|
719 tmp, 0, length); |
|
720 fCurrentEntity.ch = tmp; |
|
721 fCurrentEntity.fBufferSize *= 2; |
|
722 } else { |
|
723 System.arraycopy(fCurrentEntity.ch, offset, |
|
724 fCurrentEntity.ch, 0, length); |
|
725 } |
|
726 offset = 0; |
714 offset = 0; |
727 if (load(length, false, false)) { |
715 if (load(length, false, false)) { |
728 break; |
716 break; |
729 } |
717 } |
730 } |
718 } |
731 } |
719 } |
732 } |
720 } |
733 int length = fCurrentEntity.position - offset; |
721 length = fCurrentEntity.position - offset; |
734 fCurrentEntity.columnNumber += length; |
722 fCurrentEntity.columnNumber += length; |
735 |
723 |
736 // return name |
724 // return name |
737 String symbol; |
725 String symbol; |
738 if (length > 0) { |
726 if (length > 0) { |
|
727 checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length); |
739 symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length); |
728 symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length); |
740 } else |
729 } else |
741 symbol = null; |
730 symbol = null; |
742 if (DEBUG_BUFFER) { |
731 if (DEBUG_BUFFER) { |
743 System.out.print(")scanName: "); |
732 System.out.print(")scanName: "); |
827 } |
817 } |
828 index = fCurrentEntity.position; |
818 index = fCurrentEntity.position; |
829 //check prefix before further read |
819 //check prefix before further read |
830 checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, index - offset); |
820 checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, index - offset); |
831 } |
821 } |
832 if (++fCurrentEntity.position == fCurrentEntity.count) { |
822 if ((length = checkBeforeLoad(fCurrentEntity, offset, index)) > 0) { |
833 int length = fCurrentEntity.position - offset; |
|
834 //check localpart before loading more data |
|
835 checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length - index - 1); |
|
836 invokeListeners(length); |
|
837 if (length == fCurrentEntity.fBufferSize) { |
|
838 // bad luck we have to resize our buffer |
|
839 char[] tmp = new char[fCurrentEntity.fBufferSize * 2]; |
|
840 System.arraycopy(fCurrentEntity.ch, offset, |
|
841 tmp, 0, length); |
|
842 fCurrentEntity.ch = tmp; |
|
843 fCurrentEntity.fBufferSize *= 2; |
|
844 } else { |
|
845 System.arraycopy(fCurrentEntity.ch, offset, |
|
846 fCurrentEntity.ch, 0, length); |
|
847 } |
|
848 if (index != -1) { |
823 if (index != -1) { |
849 index = index - offset; |
824 index = index - offset; |
850 } |
825 } |
851 offset = 0; |
826 offset = 0; |
852 if (load(length, false, false)) { |
827 if (load(length, false, false)) { |
853 break; |
828 break; |
854 } |
829 } |
855 } |
830 } |
856 } |
831 } |
857 int length = fCurrentEntity.position - offset; |
832 length = fCurrentEntity.position - offset; |
858 fCurrentEntity.columnNumber += length; |
833 fCurrentEntity.columnNumber += length; |
859 if (length > 0) { |
834 if (length > 0) { |
860 String prefix = null; |
835 String prefix = null; |
861 String localpart = null; |
836 String localpart = null; |
862 String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch, |
837 String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch, |
896 System.out.println(" -> false"); |
871 System.out.println(" -> false"); |
897 } |
872 } |
898 return false; |
873 return false; |
899 |
874 |
900 } // scanQName(QName):boolean |
875 } // scanQName(QName):boolean |
|
876 |
|
877 /** |
|
878 * Checks whether the end of the entity buffer has been reached. If yes, |
|
879 * checks against the limit and buffer size before loading more characters. |
|
880 * |
|
881 * @param entity the current entity |
|
882 * @param offset the offset from which the current read was started |
|
883 * @param nameOffset the offset from which the current name starts |
|
884 * @return the length of characters scanned before the end of the buffer, |
|
885 * zero if there is more to be read in the buffer |
|
886 */ |
|
887 protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset, |
|
888 int nameOffset) throws IOException { |
|
889 int length = 0; |
|
890 if (++entity.position == entity.count) { |
|
891 length = entity.position - offset; |
|
892 int nameLength = length; |
|
893 if (nameOffset != -1) { |
|
894 nameOffset = nameOffset - offset; |
|
895 nameLength = length - nameOffset - 1; |
|
896 } else { |
|
897 nameOffset = offset; |
|
898 } |
|
899 //check limit before loading more data |
|
900 checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength); |
|
901 invokeListeners(length); |
|
902 if (length == entity.ch.length) { |
|
903 // bad luck we have to resize our buffer |
|
904 char[] tmp = new char[entity.fBufferSize * 2]; |
|
905 System.arraycopy(entity.ch, offset, tmp, 0, length); |
|
906 entity.ch = tmp; |
|
907 entity.fBufferSize *= 2; |
|
908 } |
|
909 else { |
|
910 System.arraycopy(entity.ch, offset, entity.ch, 0, length); |
|
911 } |
|
912 } |
|
913 return length; |
|
914 } |
901 |
915 |
902 /** |
916 /** |
903 * Checks whether the value of the specified Limit exceeds its limit |
917 * Checks whether the value of the specified Limit exceeds its limit |
904 * |
918 * |
905 * @param limit The Limit to be checked. |
919 * @param limit The Limit to be checked. |
1084 * the character data. |
1098 * the character data. |
1085 * |
1099 * |
1086 * @param quote The quote character that signifies the end of the |
1100 * @param quote The quote character that signifies the end of the |
1087 * attribute value data. |
1101 * attribute value data. |
1088 * @param content The content structure to fill. |
1102 * @param content The content structure to fill. |
|
1103 * @param isNSURI a flag indicating whether the content is a Namespace URI |
1089 * |
1104 * |
1090 * @return Returns the next character on the input, if known. This |
1105 * @return Returns the next character on the input, if known. This |
1091 * value may be -1 but this does <em>note</em> designate |
1106 * value may be -1 but this does <em>note</em> designate |
1092 * end of file. |
1107 * end of file. |
1093 * |
1108 * |
1094 * @throws IOException Thrown if i/o error occurs. |
1109 * @throws IOException Thrown if i/o error occurs. |
1095 * @throws EOFException Thrown on end of file. |
1110 * @throws EOFException Thrown on end of file. |
1096 */ |
1111 */ |
1097 public int scanLiteral(int quote, XMLString content) |
1112 public int scanLiteral(int quote, XMLString content, boolean isNSURI) |
1098 throws IOException { |
1113 throws IOException { |
1099 if (DEBUG_BUFFER) { |
1114 if (DEBUG_BUFFER) { |
1100 System.out.print("(scanLiteral, '"+(char)quote+"': "); |
1115 System.out.print("(scanLiteral, '"+(char)quote+"': "); |
1101 print(); |
1116 print(); |
1102 System.out.println(); |
1117 System.out.println(); |
1205 } |
1220 } |
1206 int length = fCurrentEntity.position - offset; |
1221 int length = fCurrentEntity.position - offset; |
1207 fCurrentEntity.columnNumber += length - newlines; |
1222 fCurrentEntity.columnNumber += length - newlines; |
1208 if (fCurrentEntity.isGE) { |
1223 if (fCurrentEntity.isGE) { |
1209 checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length); |
1224 checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length); |
|
1225 } |
|
1226 if (isNSURI) { |
|
1227 checkLimit(Limit.MAX_NAME_LIMIT, fCurrentEntity, offset, length); |
1210 } |
1228 } |
1211 content.setValues(fCurrentEntity.ch, offset, length); |
1229 content.setValues(fCurrentEntity.ch, offset, length); |
1212 |
1230 |
1213 // return next character |
1231 // return next character |
1214 if (fCurrentEntity.position != fCurrentEntity.count) { |
1232 if (fCurrentEntity.position != fCurrentEntity.count) { |