Java Code Examples for org.apache.xerces.util.XMLChar#isValidName()
The following examples show how to use
org.apache.xerces.util.XMLChar#isValidName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultAdxDataService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Map<String, Category> getCodeCategoryMap( CategoryCombo categoryCombo ) throws AdxException { Map<String, Category> categoryMap = new HashMap<>(); List<Category> categories = categoryCombo.getCategories(); for ( Category category : categories ) { String categoryCode = category.getCode(); if ( categoryCode == null || !XMLChar.isValidName( categoryCode ) ) { throw new AdxException( "Category code for " + category.getName() + " is missing or invalid: " + categoryCode ); } categoryMap.put( category.getCode(), category ); } return categoryMap; }
Example 2
Source File: AdxDataSetMetadata.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void addExplodedCategoryAttributes( CategoryOptionCombo coc ) throws AdxException { Map<String, String> categoryAttributes = new HashMap<>(); if ( !coc.isDefault() ) { for ( Category category : coc.getCategoryCombo().getCategories() ) { String categoryCode = category.getCode(); if ( categoryCode == null || !XMLChar.isValidName( categoryCode ) ) { throw new AdxException( "Category code for " + category.getName() + " is missing or invalid: " + categoryCode ); } String catOptCode = category.getCategoryOption( coc ).getCode(); if ( catOptCode == null || catOptCode.isEmpty() ) { throw new AdxException( "CategoryOption code for " + category.getCategoryOption( coc ).getName() + " is missing" ); } categoryAttributes.put( categoryCode, catOptCode ); } } categoryOptionMap.put( coc.getId(), categoryAttributes ); }
Example 3
Source File: ISO9075.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
/** * Encode a string according to ISO 9075 * * @param toEncode String * @return String */ public static String encode(String toEncode) { if ((toEncode == null) || (toEncode.length() == 0)) { return toEncode; } else if (XMLChar.isValidName(toEncode) && (toEncode.indexOf("_x") == -1) && (toEncode.indexOf(':') == -1)) { return toEncode; } else { StringBuilder builder = new StringBuilder(toEncode.length()); for (int i = 0; i < toEncode.length(); i++) { char c = toEncode.charAt(i); // First requires special test if (i == 0) { if (XMLChar.isNCNameStart(c)) { // The first character may be the _ at the start of an // encoding pattern if (matchesEncodedPattern(toEncode, i)) { // Encode the first _ encode('_', builder); } else { // Just append builder.append(c); } } else { // Encode an invalid start character for an XML element // name. encode(c, builder); } } else if (!XMLChar.isNCName(c)) { encode(c, builder); } else { if (matchesEncodedPattern(toEncode, i)) { // '_' must be encoded encode('_', builder); } else { builder.append(c); } } } return builder.toString(); } }