Changeset 1890


Ignore:
Timestamp:
04/17/12 19:30:27 (12 years ago)
Author:
oschonef
Message:
  • fix parsing of /indexInfo/index/map settings
  • sanity check for existing set
Location:
SRUServer/trunk/src/main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServerConfig.java

    r1889 r1890  
    636636            List<SchemaInfo> schemaInfo = buildSchemaInfo(xpath, doc);
    637637
    638 
    639638            String transport = params.get(SRU_TRANSPORT);
    640639            if ((transport == null) || transport.isEmpty()) {
     
    755754                String identifier = e.getAttribute("identifier");
    756755                String name       = e.getAttribute("name");
     756                if (identifier.isEmpty()) {
     757                    throw new SRUConfigException("attribute 'identifier' may "+
     758                            "on element '/indexInfo/set' may not be empty");
     759                }
     760                if (name.isEmpty()) {
     761                    throw new SRUConfigException("attribute 'name' may on " +
     762                            "element '/indexInfo/set' may not be empty");
     763                }
    757764                List<LocalizedString> title =
    758765                        fromNodeList(e.getElementsByTagName("title"));
     
    788795                            foundPrimary = true;
    789796                        }
    790                         String set = e2.getAttribute("set");
    791                         String name = e2.getTextContent();
     797                        String set  = null;
     798                        String name = null;
     799                        NodeList result3 = e2.getElementsByTagName("name");
     800                        if ((result3 != null) && (result3.getLength() > 0)) {
     801                            Element e3 = (Element) result3.item(0);
     802                            set  = e3.getAttribute("set");
     803                            name = e3.getTextContent();
     804                            if (set.isEmpty()) {
     805                                throw new SRUConfigException("attribute 'set'" +
     806                                        " on element '/indexInfo/index/map/" +
     807                                        "name' may not be empty");
     808                            }
     809                            if ((name == null) || name.isEmpty()) {
     810                                throw new SRUConfigException("element " +
     811                                        "'/indexInfo/index/map/name' may not " +
     812                                        "be empty");
     813                            }
     814                        }
    792815                        maps.add(new IndexInfo.Index.Map(primary, set, name));
    793816                    }
    794817                }
    795                 indexes.add(new IndexInfo.Index(title, can_search, can_scan, can_sort, maps));
     818                indexes.add(new IndexInfo.Index(title, can_search, can_scan,
     819                        can_sort, maps));
    796820            } // for
     821           
     822            // sanity check (/index/map/name/@set exists in any set/@name)
     823            if (sets != null) {
     824                for (IndexInfo.Index index : indexes) {
     825                    if (index.getMaps() != null) {
     826                        for (IndexInfo.Index.Map maps : index.getMaps()) {
     827                            if (findSetByName(sets, maps.getSet()) == null) {
     828                                throw new SRUConfigException("/index/map/" +
     829                                        "name refers to nonexitsing set (" +
     830                                        maps.getSet() + ")");
     831                            }
     832                        }
     833                    }
     834                }
     835            }
    797836        } // if
    798837        return new IndexInfo(sets, indexes);
     
    828867
    829868
     869    private static IndexInfo.Set findSetByName(List<IndexInfo.Set> sets,
     870            String name) {
     871        for (IndexInfo.Set set : sets) {
     872            if (set.getName().equals(name)) {
     873                return set;
     874            }
     875        }
     876        return null;
     877    }
     878
     879   
    830880    private static List<LocalizedString> buildList(XPath xpath, Document doc,
    831881            String expression) throws SRUConfigException,
  • SRUServer/trunk/src/main/resources/META-INF/sru-server-config.xsd

    r1889 r1890  
    7474            <xsd:simpleContent>
    7575              <xsd:extension base="xsd:string">
    76                 <xsd:attribute name="set" type="xsd:string" />
     76                <xsd:attribute name="set" type="xsd:string" use="required" />
    7777              </xsd:extension>
    7878            </xsd:simpleContent>
Note: See TracChangeset for help on using the changeset viewer.