本文整理汇总了Java中org.apache.xerces.util.XMLChar.isValidNCName方法的典型用法代码示例。如果您正苦于以下问题:Java XMLChar.isValidNCName方法的具体用法?Java XMLChar.isValidNCName怎么用?Java XMLChar.isValidNCName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xerces.util.XMLChar
的用法示例。
在下文中一共展示了XMLChar.isValidNCName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidQName
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Checks if the given qualified name is legal with respect
* to the version of XML to which this document must conform.
*
* @param prefix prefix of qualified name
* @param local local part of qualified name
*/
public static final boolean isValidQName(String prefix, String local, boolean xml11Version) {
// check that both prefix and local part match NCName
if (local == null) return false;
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
&& XMLChar.isValidNCName(local);
}
else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
&& XML11Char.isXML11ValidNCName(local);
}
return validNCName;
}
示例2: validate
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Checks that "content" string is valid ID value.
* If invalid a Datatype validation exception is thrown.
*
* @param content the string value that needs to be validated
* @param context the validation context
* @throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @see InvalidDatatypeValueException
*/
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {
//Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
if(context.useNamespaces()) {
if (!XMLChar.isValidNCName(content)) {
throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
}
}
else {
if (!XMLChar.isValidName(content)) {
throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
}
}
if (context.isIdDeclared(content)) {
throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
}
context.addId(content);
}
示例3: validate
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Checks that "content" string is valid IDREF value.
* If invalid a Datatype validation exception is thrown.
*
* @param content the string value that needs to be validated
* @param context the validation context
* @throws InvalidDatatypeException if the content is
* invalid according to the rules for the validators
* @see InvalidDatatypeValueException
*/
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {
//Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
if(context.useNamespaces()) {
if (!XMLChar.isValidNCName(content)) {
throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content});
}
}
else {
if (!XMLChar.isValidName(content)) {
throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content});
}
}
context.addIdRef(content);
}
示例4: parseQName
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
private final ExpandedName parseQName(String qName) throws SAXException {
String prefix = "";
String uri = "";
String localName = qName;
int commaPos = qName.indexOf(':');
if (commaPos > 0 && commaPos < qName.length() - 1) {
prefix = qName.substring(0, commaPos);
if (!NAMESPACE_DECLARATION_PREFIX.equals(prefix)
&& !prefixMappings.containsKey(prefix))
throwException("undeclared namespace prefix " + prefix);
localName = qName.substring(commaPos + 1);
}
// check that localName is an NCName
if (localName.length() > 0 && !XMLChar.isValidNCName(localName))
throwException(localName + " local name is not a valid NCName");
Mapping mapping = prefixMappings.get(prefix);
if (mapping != null)
uri = mapping.uri;
return new ExpandedName(uri, localName);
}
示例5: isValidQName
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Checks if the given qualified name is legal with respect to the version of XML to which this document must
* conform.
*
* @param prefix prefix of qualified name
* @param local local part of qualified name
*/
public static final boolean isValidQName(String prefix, String local, boolean xml11Version) {
// check that both prefix and local part match NCName
if (local == null)
return false;
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix)) && XMLChar.isValidNCName(local);
} else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
&& XML11Char.isXML11ValidNCName(local);
}
return validNCName;
}
示例6: checkQName
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Checks if the given qualified name is legal with respect to the version of XML to which this document must
* conform.
*
* @param prefix prefix of qualified name
* @param local local part of qualified name
*/
protected final void checkQName(String prefix, String local) {
if (!errorChecking) {
return;
}
// check that both prefix and local part match NCName
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix)) && XMLChar.isValidNCName(local);
} else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
&& XML11Char.isXML11ValidNCName(local);
}
if (!validNCName) {
// REVISIT: add qname parameter to the message
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
示例7: setXLinkLabel
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* This method set the xlink:label
*
* @param label
* the xlink:label
*/
public final void setXLinkLabel(String label) {
if (label != null && !XMLChar.isValidNCName(label)) {
throw new MCRException("xlink:label is not a valid NCName: " + label);
}
this.label = label;
}
示例8: validate
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Validates this MCRMetaLink. This method throws an exception if:
* <ul>
* <li>the subtag is not null or empty</li>
* <li>the xlink:type not "locator" or "arc"</li>
* <li>the from or to are not valid</li>
* </ul>
*
* @throws MCRException the MCRMetaLink is invalid
*/
public void validate() throws MCRException {
super.validate();
if (label != null && label.length() > 0) {
if (!XMLChar.isValidNCName(label)) {
throw new MCRException(getSubTag() + ": label is no valid NCName:" + label);
}
}
if (linktype == null) {
throw new MCRException(getSubTag() + ": linktype is null");
}
if (!linktype.equals("locator") && !linktype.equals("arc")) {
throw new MCRException(getSubTag() + ": linktype is unsupported: " + linktype);
}
if (linktype.equals("arc")) {
if (from == null || from.length() == 0) {
throw new MCRException(getSubTag() + ": from is null or empty");
} else if (!XMLChar.isValidNCName(from)) {
throw new MCRException(getSubTag() + ": from is no valid NCName:" + from);
}
if (to == null || to.length() == 0) {
throw new MCRException(getSubTag() + ": to is null or empty");
} else if (!XMLChar.isValidNCName(to)) {
throw new MCRException(getSubTag() + ": to is no valid NCName:" + to);
}
}
if (linktype.equals("locator")) {
if (href == null || href.length() == 0) {
throw new MCRException(getSubTag() + ": href is null or empty");
}
}
}
示例9: checkQName
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Checks if the given qualified name is legal with respect
* to the version of XML to which this document must conform.
*
* @param prefix prefix of qualified name
* @param local local part of qualified name
*/
protected final void checkQName(String prefix, String local) {
if (!errorChecking) {
return;
}
// check that both prefix and local part match NCName
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
&& XMLChar.isValidNCName(local);
}
else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
&& XML11Char.isXML11ValidNCName(local);
}
if (!validNCName) {
// REVISIT: add qname parameter to the message
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
示例10: getActualValue
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
public Object getActualValue(String content, ValidationContext context)
throws InvalidDatatypeValueException {
// "prefix:localpart" or "localpart"
// get prefix and local part out of content
String prefix, localpart;
int colonptr = content.indexOf(":");
if (colonptr > 0) {
prefix = context.getSymbol(content.substring(0,colonptr));
localpart = content.substring(colonptr+1);
} else {
prefix = EMPTY_STRING;
localpart = content;
}
// both prefix (if any) a nd localpart must be valid NCName
if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});
if(!XMLChar.isValidNCName(localpart))
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});
// resove prefix to a uri, report an error if failed
String uri = context.getURI(prefix);
if (prefix.length() > 0 && uri == null)
throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object[]{content, prefix});
return new XQName(prefix, context.getSymbol(localpart), context.getSymbol(content), uri);
}
示例11: getActualValue
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
if (!XMLChar.isValidNCName(content)) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "NCName"});
}
return content;
}
示例12: validatePrefix
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
* Validates a user-defined prefix. A prefix is rejected if it meets any of the following conditions:
* <ul>
* <li>Is not a valid NCName according to the XML specification, or empty to represent the default namespace.</li>
* <li>Attempts to redefine one of the existing default prefixes (rdf, rdfs, owl, dc).</li>
* <li>Begins with the sequence "ns[0-9]" as this could conflict with a generated prefix.</li>
* </ul>
* @param prefix The prefix to validate.
* @return <code>true</code> if it is safe to include the prefix in the available namespace definitions.
*/
private boolean validatePrefix(String prefix) {
// Only accept prefixes that can be used in XML qnames.
if (!(XMLChar.isValidNCName(prefix) || prefix.equals(""))) return false;
// Don't allow existing prefixes to be redefined.
if (containsKey(prefix)) return false;
// Prefixes starting with "ns1", "ns2", etc. may conflict with generated prefixes.
if (prefix.matches("^ns\\d")) return false;
return true;
}
示例13: tag
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
String tag( String namespace, String local, int type, boolean localIsQname) {
if (dbg)
System.err.println(namespace + " - " + local);
String prefix = ns.get( namespace );
if (type != FAST && type != FASTATTR) {
if ((!localIsQname) && !XMLChar.isValidNCName(local))
return splitTag(namespace + local, type);
if (namespace.equals(RDFNS)) {
// Description, ID, nodeID, about, aboutEach, aboutEachPrefix, li
// bagID parseType resource datatype RDF
if (badRDF.contains(local)) {
logger.warn( "The URI rdf:" + local + " cannot be serialized in RDF/XML." );
throw new InvalidPropertyURIException( "rdf:" + local );
}
}
}
boolean cookUp = false;
if (prefix == null) {
checkURI( namespace );
logger.warn(
"Internal error: unexpected QName URI: <"
+ namespace
+ ">. Fixing up with j.cook.up code.",
new BrokenException( "unexpected QName URI " + namespace ));
cookUp = true;
} else if (prefix.length() == 0) {
if (type == ATTR || type == FASTATTR)
cookUp = true;
else
return local;
}
if (cookUp) return cookUpAttribution( type, namespace, local );
return prefix + ":" + local;
}
示例14: checkLegalPrefix
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
/**
Answer true iff prefix is a "legal" prefix to use, ie, is empty [for the default namespace]
or an NCName that does not start with "xml" and does not match the reserved-to-Jena
pattern.
*/
private boolean checkLegalPrefix( String prefix ) {
if (prefix.equals(""))
return true;
if (prefix.toLowerCase().startsWith( "xml" ))
logger.warn( "Namespace prefix '" + prefix + "' is reserved by XML." );
else if (!XMLChar.isValidNCName(prefix))
logger.warn( "'" + prefix + "' is not a legal namespace prefix." );
else if (jenaNamespace.matcher(prefix).matches())
logger.warn( "Namespace prefix '" + prefix + "' is reserved by Jena." );
else
return true;
return false;
}
示例15: getActualValue
import org.apache.xerces.util.XMLChar; //导入方法依赖的package包/类
@Override
public Object getActualValue(String content)
throws XSDBuiltinTypeFormatException {
// "prefix:localpart" or "localpart"
// get prefix and local part out of content
String prefix, localpart;
int colonptr = content.indexOf(":");
if (colonptr > 0) {
// replaced with ValidationState implementation
//prefix = context.getSymbol(content.substring(0,colonptr));
prefix = content.substring(0,colonptr).intern();
localpart = content.substring(colonptr+1);
} else {
prefix = EMPTY_STRING;
localpart = content;
}
// both prefix (if any) a nd localpart must be valid NCName
if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
throw new XSDBuiltinTypeFormatException(content, "invalid QName data: prefix is not a valid NCName");
if(!XMLChar.isValidNCName(localpart))
throw new XSDBuiltinTypeFormatException(content, "invalid QName data: local part is not a valid NCName");
//TODO maybe we should try to create a QName or validate prefix?
return content;
}