< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java

Print this page


   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl.xs.traversers;
  23 


1590             if (sGrammar == null) {
1591                 continue;
1592             }
1593             // and get the datatype validator, if there is one
1594             attrDecl = sGrammar.getGlobalAttributeDecl(attrLocal);
1595             if (attrDecl == null) {
1596                 continue;
1597             }
1598             XSSimpleType dv = (XSSimpleType)attrDecl.getTypeDefinition();
1599             if (dv == null) {
1600                 continue;
1601             }
1602 
1603             // get all values appeared with this attribute name
1604             List<String> values = entry.getValue();
1605             String elName;
1606             String attrName = values.get(0);
1607             // for each of the values
1608             int count = values.size();
1609             for (int i = 1; i < count; i += 2) {
1610                 elName = (String)values.get(i);
1611                 try {
1612                     // and validate it using the XSSimpleType
1613                     // REVISIT: what would be the proper validation context?
1614                     //          guess we need to save that in the vectors too.
1615                     dv.validate(values.get(i+1), null, null);
1616                 } catch(InvalidDatatypeValueException ide) {
1617                     reportSchemaError ("s4s-att-invalid-value",
1618                                        new Object[] {elName, attrName, ide.getMessage()},
1619                                        null);
1620                 }
1621             }
1622         }
1623     }
1624 
1625     // normalize the string according to the whiteSpace facet
1626     public static String normalize(String content, short ws) {
1627         int len = content == null ? 0 : content.length();
1628         if (len == 0 || ws == XSSimpleType.WS_PRESERVE)
1629             return content;
1630 


1807         for (int i = 0; i < pos; i++) {
1808             if (keys[i].equals(key)) {
1809                 return values[i];
1810             }
1811         }
1812         return null;
1813     }
1814 }
1815 
1816 class LargeContainer extends Container {
1817     Map<String, OneAttr> items;
1818     LargeContainer(int size) {
1819         items = new HashMap<>(size*2+1);
1820         values = new OneAttr[size];
1821     }
1822     void put(String key, OneAttr value) {
1823         items.put(key, value);
1824         values[pos++] = value;
1825     }
1826     OneAttr get(String key) {
1827         OneAttr ret = (OneAttr)items.get(key);
1828         return ret;
1829     }
1830 }
   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl.xs.traversers;
  23 


1590             if (sGrammar == null) {
1591                 continue;
1592             }
1593             // and get the datatype validator, if there is one
1594             attrDecl = sGrammar.getGlobalAttributeDecl(attrLocal);
1595             if (attrDecl == null) {
1596                 continue;
1597             }
1598             XSSimpleType dv = (XSSimpleType)attrDecl.getTypeDefinition();
1599             if (dv == null) {
1600                 continue;
1601             }
1602 
1603             // get all values appeared with this attribute name
1604             List<String> values = entry.getValue();
1605             String elName;
1606             String attrName = values.get(0);
1607             // for each of the values
1608             int count = values.size();
1609             for (int i = 1; i < count; i += 2) {
1610                 elName = values.get(i);
1611                 try {
1612                     // and validate it using the XSSimpleType
1613                     // REVISIT: what would be the proper validation context?
1614                     //          guess we need to save that in the vectors too.
1615                     dv.validate(values.get(i+1), null, null);
1616                 } catch(InvalidDatatypeValueException ide) {
1617                     reportSchemaError ("s4s-att-invalid-value",
1618                                        new Object[] {elName, attrName, ide.getMessage()},
1619                                        null);
1620                 }
1621             }
1622         }
1623     }
1624 
1625     // normalize the string according to the whiteSpace facet
1626     public static String normalize(String content, short ws) {
1627         int len = content == null ? 0 : content.length();
1628         if (len == 0 || ws == XSSimpleType.WS_PRESERVE)
1629             return content;
1630 


1807         for (int i = 0; i < pos; i++) {
1808             if (keys[i].equals(key)) {
1809                 return values[i];
1810             }
1811         }
1812         return null;
1813     }
1814 }
1815 
1816 class LargeContainer extends Container {
1817     Map<String, OneAttr> items;
1818     LargeContainer(int size) {
1819         items = new HashMap<>(size*2+1);
1820         values = new OneAttr[size];
1821     }
1822     void put(String key, OneAttr value) {
1823         items.put(key, value);
1824         values[pos++] = value;
1825     }
1826     OneAttr get(String key) {
1827         OneAttr ret = items.get(key);
1828         return ret;
1829     }
1830 }
< prev index next >