public static String escapeName(String str) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if ((c & 0xFC00) == 0xD800) { char next = str.charAt(++i); appendUHexTo(sb, (c << 10) + next + SURROGATE_OFFSET); } else if (i == 0 && !isNCNameStart(c)) { appendUHexTo(sb, c); } else if (i != 0 && !isNCNameTrail(c)) { appendUHexTo(sb, c); } else { sb.append(c); } } return sb.toString().intern(); } // ]NOCPP]
/** * @see nu.validator.htmlparser.sax.XmlSerializer#checkNCName() */ @Override protected void checkNCName(String name) throws SAXException { if (!NCName.isNCName(name)) { throw new SAXException("Not an XML 1.0 4th ed. NCName: " + name); } }
public static boolean isNCName(String str) { if (str == null) { return false; } else { int len = str.length(); switch (len) { case 0: return false; case 1: return NCName.isNCNameStart(str.charAt(0)); default: if (!NCName.isNCNameStart(str.charAt(0))) { return false; } for (int i = 1; i < len; i++) { if (!NCName.isNCNameTrail(str.charAt(i))) { return false; } } } return true; } }
private String checkPopName(@Local String name) throws SAXException { if (NCName.isNCName(name)) { return name; } else { switch (namePolicy) { case ALLOW: warn("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); return name; case ALTER_INFOSET: warn("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); return NCName.escapeName(name); case FATAL: fatal("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); } } return null; // keep compiler happy }
private void checkDataName(String local) throws SAXException { for (int i = 5; i < local.length(); i++) { char c = local.charAt(i); if (c >= 'A' && c <= 'Z') { errorHandler.error(new SAXParseException("\u201Cdata-*\u201D attributes must not have characters from the range \u201CA\u201D\u2026\u201CZ\u201D in the name.", locator)); } else if (!NCName.isNCNameTrail(c)) { errorHandler.error(new SAXParseException("\u201Cdata-*\u201D attribute names must be XML 1.0 4th ed. plus Namespaces NCNames.", locator)); } } }
void processNonNcNames(TreeBuilder<?> treeBuilder, XmlViolationPolicy namePolicy) throws SAXException { for (int i = 0; i < length; i++) { AttributeName attName = names[i]; if (!attName.isNcName(mode)) { String name = attName.getLocal(mode); switch (namePolicy) { case ALTER_INFOSET: names[i] = AttributeName.create(NCName.escapeName(name)); // fall through case ALLOW: if (attName != AttributeName.XML_LANG) { treeBuilder.warn("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0."); } break; case FATAL: treeBuilder.fatal("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0."); break; } } } }
public static boolean isNCName(String str) { if (str == null) { return false; } else { int len = str.length(); switch (len) { case 0: return false; case 1: return NCName.isNCNameStart(str.charAt(0)); default: if (!NCName.isNCNameStart(str.charAt(0))) { return false; } for (int i = 1; i < len; i++) { if (!NCName.isNCNameTrail(str.charAt(i))) { return false; } } } return true; } }
private String checkPopName(@Local String name) throws SAXException { if (NCName.isNCName(name)) { return name; } else { switch (namePolicy) { case ALLOW: warn("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); return name; case ALTER_INFOSET: warn("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); return NCName.escapeName(name); case FATAL: fatal("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); } } return null; // keep compiler happy }
private void checkDataName(String local) throws SAXException { for (int i = 5; i < local.length(); i++) { char c = local.charAt(i); if (c >= 'A' && c <= 'Z') { errorHandler.error(new SAXParseException( "\u201Cdata-*\u201D attributes must not have" + " characters from the range" + " \u201CA\u201D\u2026\u201CZ\u201D in the name.", locator)); } else if (!NCName.isNCNameTrail(c)) { errorHandler.error(new SAXParseException( "\u201Cdata-*\u201D attribute names must be" + " XML 1.0 4th ed. plus Namespaces NCNames.", locator)); } } }
void processNonNcNames(TreeBuilder<?> treeBuilder, XmlViolationPolicy namePolicy) throws SAXException { for (int i = 0; i < length; i++) { AttributeName attName = names[i]; if (!attName.isNcName(mode)) { String name = attName.getLocal(mode); switch (namePolicy) { case ALTER_INFOSET: names[i] = AttributeName.create(NCName.escapeName(name)); // fall through case ALLOW: if (attName != AttributeName.XML_LANG) { treeBuilder.warn("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0."); } break; case FATAL: treeBuilder.fatal("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0."); break; } } } }
public static String escapeName(String str) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if ((c & 0xFC00) == 0xD800) { char next = str.charAt(++i); appendUHexTo(sb, (c << 10) + next + SURROGATE_OFFSET); } else if (i == 0 && !isNCNameStart(c)) { appendUHexTo(sb, c); } else if (i != 0 && !isNCNameTrail(c)) { appendUHexTo(sb, c); } else { sb.append(c); } } return sb.toString().intern(); } // ]NOCPP]
public static boolean isNCName(String str) { if (str == null) { return false; } else { int len = str.length(); switch (len) { case 0: return false; case 1: return NCName.isNCNameStart(str.charAt(0)); default: if (!NCName.isNCNameStart(str.charAt(0))) { return false; } for (int i = 1; i < len; i++) { if (!NCName.isNCNameTrail(str.charAt(i))) { return false; } } } return true; } }
private String checkPopName(@Local String name) throws SAXException { if (NCName.isNCName(name)) { return name; } else { switch (namePolicy) { case ALLOW: warn("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); return name; case ALTER_INFOSET: warn("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); return NCName.escapeName(name); case FATAL: fatal("Element name \u201C" + name + "\u201D cannot be represented as XML 1.0."); } } return null; // keep compiler happy }
/** * @see nu.validator.htmlparser.sax.XmlSerializer#checkNCName() */ @Override protected void checkNCName(String name) throws SAXException { if (!NCName.isNCName(name)) { throw new SAXException("Not an XML 1.0 4th ed. NCName: " + name); } }
void processNonNcNames(TreeBuilder<?> treeBuilder, XmlViolationPolicy namePolicy) throws SAXException { for (int i = 0; i < length; i++) { AttributeName attName = names[i]; if (!attName.isNcName(mode)) { String name = attName.getLocal(mode); switch (namePolicy) { case ALTER_INFOSET: names[i] = AttributeName.create(NCName.escapeName(name)); // fall through case ALLOW: if (attName != AttributeName.XML_LANG) { treeBuilder.warn("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0."); } break; case FATAL: treeBuilder.fatal("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0."); break; } } } }
public static String escapeName(String str) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if ((c & 0xFC00) == 0xD800) { char next = str.charAt(++i); appendUHexTo(sb, (c << 10) + next + SURROGATE_OFFSET); } else if (i == 0 && !isNCNameStart(c)) { appendUHexTo(sb, c); } else if (i != 0 && !isNCNameTrail(c)) { appendUHexTo(sb, c); } else { sb.append(c); } } return sb.toString().intern(); } // ]NOCPP]
default: if (isName && (nameBufferPos == 0) && (!(NCName.isNCNameStart(c)))) { fatal("Not a name start character, U+" + Integer.toHexString(c)); } else if (!(NCName.isNCNameTrail(c) || c == ':')) { fatal("Not a name character, U+" + Integer.toHexString(c));
/** * @see nu.validator.htmlparser.sax.XmlSerializer#checkNCName() */ @Override protected void checkNCName(String name) throws SAXException { if (!NCName.isNCName(name)) { throw new SAXException("Not an XML 1.0 4th ed. NCName: " + name); } }
/** * Creates an <code>AttributeName</code> for a local name. * * @param name * the name * @param checkNcName * whether to check ncnameness * @return an <code>AttributeName</code> */ private static AttributeName createAttributeName(@Local String name // [NOCPP[ , boolean checkNcName // ]NOCPP] ) { // [NOCPP[ int flags = NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG; if (name.startsWith("xmlns:")) { flags = IS_XMLNS; } else if (checkNcName && !NCName.isNCName(name)) { flags = 0; } // ]NOCPP] return new AttributeName(AttributeName.ALL_NO_NS, AttributeName.SAME_LOCAL(name), ALL_NO_PREFIX, flags); }
/** * Creates an <code>AttributeName</code> for a local name. * * @param name * the name * @param checkNcName * whether to check ncnameness * @return an <code>AttributeName</code> */ static AttributeName createAttributeName(@Local String name // [NOCPP[ , boolean checkNcName // ]NOCPP] ) { // [NOCPP[ int flags = NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG; if (name.startsWith("xmlns:")) { flags = IS_XMLNS; } else if (checkNcName && !NCName.isNCName(name)) { flags = 0; } // ]NOCPP] return new AttributeName(AttributeName.ALL_NO_NS, AttributeName.SAME_LOCAL(name), ALL_NO_PREFIX, flags); }