Changeset 2995 for SRUClient


Ignore:
Timestamp:
06/05/13 14:30:15 (11 years ago)
Author:
oschonef
Message:
  • add support for parsing schemaInfo within ZeeRex? (explain) record data
Location:
SRUClient/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordData.java

    r2989 r2995  
    403403    } // class IndexInfo
    404404
     405    public static class Schema {
     406        private final String identifier;
     407        private final String name;
     408        private final String location;
     409        private final boolean sort;
     410        private final boolean retrieve;
     411        private final List<LocalizedString> title;
     412
     413
     414        Schema(String identifier, String name, String location, boolean sort,
     415                boolean retrieve, List<LocalizedString> title) {
     416            this.identifier = identifier;
     417            this.name       = name;
     418            this.location   = location;
     419            this.sort       = sort;
     420            this.retrieve   = retrieve;
     421            if ((title != null) && !title.isEmpty()) {
     422                this.title = Collections.unmodifiableList(title);
     423            } else {
     424                this.title = null;
     425            }
     426        }
     427
     428
     429        public String getIdentifier() {
     430            return identifier;
     431        }
     432
     433
     434        public String getName() {
     435            return name;
     436        }
     437
     438
     439        public String getLocation() {
     440            return location;
     441        }
     442
     443
     444        public boolean getSort() {
     445            return sort;
     446        }
     447
     448
     449        public boolean getRetrieve() {
     450            return retrieve;
     451        }
     452
     453
     454        public List<LocalizedString> getTitle() {
     455            return title;
     456        }
     457    } // class SchemaInfo
     458
    405459    public static class ConfigInfo {
    406460        private final Map<String, String> defaults;
     
    447501    private final DatabaseInfo databaseInfo;
    448502    private final IndexInfo indexInfo;
     503    private final List<Schema> schemaInfo;
    449504    private final ConfigInfo configInfo;
    450505
    451506
    452507    SRUExplainRecordData(ServerInfo serverInfo, DatabaseInfo databaseInfo,
    453             IndexInfo indexInfo, ConfigInfo configInfo) {
     508            IndexInfo indexInfo, List<Schema> schemaInfo,
     509            ConfigInfo configInfo) {
    454510        this.serverInfo   = serverInfo;
    455511        this.databaseInfo = databaseInfo;
    456512        this.indexInfo    = indexInfo;
     513        if ((schemaInfo != null) && !schemaInfo.isEmpty()) {
     514            this.schemaInfo = Collections.unmodifiableList(schemaInfo);
     515        } else {
     516            this.schemaInfo = null;
     517        }
    457518        this.configInfo   = configInfo;
    458519    }
     
    481542
    482543
     544    public List<Schema> getSchemaInfo() {
     545        return schemaInfo;
     546    }
     547
     548
    483549    public IndexInfo getIndexInfo() {
    484550        return indexInfo;
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordDataParser.java

    r2994 r2995  
    3535import eu.clarin.sru.client.SRUExplainRecordData.IndexInfo;
    3636import eu.clarin.sru.client.SRUExplainRecordData.LocalizedString;
     37import eu.clarin.sru.client.SRUExplainRecordData.Schema;
    3738import eu.clarin.sru.client.SRUExplainRecordData.ServerInfo;
    3839
     
    134135
    135136        // explain/recordInfo or explain/schemaInfo
     137        List<Schema> schemaInfo = null;
    136138        if (XmlStreamReaderUtils.peekStart(reader, ns, "recordInfo") ||
    137139            XmlStreamReaderUtils.peekStart(reader, ns, "schemaInfo")) {
    138140            if (XmlStreamReaderUtils.readStart(reader,
    139141                    ns, "recordInfo", false)) {
    140                 logger.debug("recordInfo");
     142                logger.debug("skipping 'recordInfo'");
    141143                XmlStreamReaderUtils.readEnd(reader, ns, "recordInfo", true);
    142144            } else if (XmlStreamReaderUtils.readStart(reader,
    143145                    ns, "schemaInfo", false)) {
    144                 logger.debug("schemaInfo");
    145                 XmlStreamReaderUtils.readEnd(reader, ns, "schemaInfo", true);
     146                schemaInfo = parseSchemaInfo(reader, strict, ns);
     147                XmlStreamReaderUtils.readEnd(reader, ns, "schemaInfo");
    146148            } else {
    147149                throw new XMLStreamException("unexpected start element '" +
     
    159161        XmlStreamReaderUtils.readEnd(reader, ns, "explain", true);
    160162        return new SRUExplainRecordData(serverInfo, databaseInfo, indexInfo,
    161                 configInfo);
     163                schemaInfo, configInfo);
    162164    }
    163165
     
    448450                final String id =
    449451                        XmlStreamReaderUtils.readAttributeValue(reader, null, "id");
    450                 final boolean can_search =
    451                         parseBooleanAttribute(reader, strict,null, "search");
    452                 final boolean can_scan =
    453                         parseBooleanAttribute(reader, strict,null, "search");
    454                 final boolean can_sort =
    455                         parseBooleanAttribute(reader, strict,null, "search");
     452                final boolean can_search = parseBooleanAttribute(reader,
     453                        strict, null, "search", false);
     454                final boolean can_scan = parseBooleanAttribute(reader,
     455                        strict, null, "scan", false);
     456                final boolean can_sort = parseBooleanAttribute(reader,
     457                        strict, null, "sort", false);
    456458                XmlStreamReaderUtils.consumeStart(reader);
    457459
     
    476478                        first_map, true)) {
    477479                    final boolean primary = parseBooleanAttribute(reader,
    478                             strict, null, "primary");
     480                            strict, null, "primary", false);
    479481                    XmlStreamReaderUtils.consumeStart(reader);
    480482
     
    599601        }
    600602        final boolean primary =
    601                 parseBooleanAttribute(reader, strict, null, "primary");
     603                parseBooleanAttribute(reader, strict, null, "primary", false);
    602604        XmlStreamReaderUtils.consumeStart(reader);
    603605        String value = XmlStreamReaderUtils.readString(reader, false);
     
    608610
    609611    private static boolean parseBooleanAttribute(XMLStreamReader reader,
    610             boolean strict, String ns, String localName)
     612            boolean strict, String ns, String localName, boolean defaultValue)
    611613            throws XMLStreamException {
    612         boolean result = false;
     614        boolean result = defaultValue;
    613615        final String s = XmlStreamReaderUtils.readAttributeValue(reader,
    614616                ns, localName, false);
     
    643645
    644646
     647    private static List<Schema> parseSchemaInfo(XMLStreamReader reader,
     648            boolean strict, String ns) throws XMLStreamException {
     649        /*
     650         * schemaInfo (schema+)
     651         * schema (title*)
     652         */
     653        List<Schema> schemaInfo = null;
     654        boolean first_schema = true;
     655        while (XmlStreamReaderUtils.readStart(reader, ns, "schema",
     656                first_schema, true)) {
     657            final String identifier =
     658                    XmlStreamReaderUtils.readAttributeValue(reader,
     659                            null, "identifier", true);
     660            final String name = XmlStreamReaderUtils.readAttributeValue(reader,
     661                    null, "name", true);
     662            final String location =
     663                    XmlStreamReaderUtils.readAttributeValue(reader,
     664                            null, "location");
     665            final boolean sort = parseBooleanAttribute(reader, strict,
     666                    null, "sort", false);
     667            final boolean retrieve = parseBooleanAttribute(reader, strict,
     668                    null, "retrieve", true);
     669            XmlStreamReaderUtils.consumeStart(reader);
     670
     671            List<LocalizedString> titles = null;
     672            for (;;) {
     673                LocalizedString title =
     674                        parseStringI18N(reader, strict, ns, "title", false);
     675                if (title == null) {
     676                    break;
     677                }
     678                if (titles == null) {
     679                    titles = new ArrayList<LocalizedString>();
     680                }
     681                titles.add(title);
     682            } // for
     683            XmlStreamReaderUtils.readEnd(reader, ns, "schema");
     684
     685            if (schemaInfo == null) {
     686                schemaInfo = new ArrayList<Schema>();
     687            }
     688            schemaInfo.add(new Schema(identifier, name, location, sort,
     689                    retrieve, titles));
     690            first_schema = false;
     691        }
     692        return schemaInfo;
     693    }
     694
     695
    645696    private static Map<String, String> parseConfigInfoItem(
    646697            XMLStreamReader reader, boolean strict, String ns,
  • SRUClient/trunk/src/test/java/eu/clarin/sru/client/TestUtils.java

    r2989 r2995  
    2525
    2626import eu.clarin.sru.client.SRUExplainRecordData.ConfigInfo;
     27import eu.clarin.sru.client.SRUExplainRecordData.Schema;
    2728import eu.clarin.sru.client.fcs.ClarinFCSRecordData;
    2829import eu.clarin.sru.client.fcs.DataView;
     
    155156                    data.getServerInfo().getPort(),
    156157                    data.getServerInfo().getDatabase());
     158            List<Schema> schemaInfo = data.getSchemaInfo();
     159            if (schemaInfo != null) {
     160                for (Schema schema : schemaInfo) {
     161                    logger.debug("schema: identifier={}, name={}, " +
     162                            "location={}, sort={}, retrieve={}",
     163                            schema.getIdentifier(),
     164                            schema.getName(),
     165                            schema.getLocation(),
     166                            schema.getSort(),
     167                            schema.getRetrieve());
     168                }
     169            }
    157170            ConfigInfo configInfo = data.getConfigInfo();
    158171            if (configInfo != null) {
Note: See TracChangeset for help on using the changeset viewer.