Examples of Vocabulary


Examples of org.apache.sis.util.resources.Vocabulary

     * @param validOptions The options to list.
     */
    void help(final boolean showHeader, final String[] commandNames, final EnumSet<Option> validOptions) {
        final ResourceBundle commands = ResourceBundle.getBundle("org.apache.sis.console.Commands", locale);
        final ResourceBundle options  = ResourceBundle.getBundle("org.apache.sis.console.Options",  locale);
        final Vocabulary vocabulary = Vocabulary.getResources(locale);
        if (showHeader) {
            out.print("Apache SIS, ");
            out.println(commands.getString("SIS"));
            out.println(commands.getString("Usage"));
            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Commands));
            out.println(':');
        }
        try {
            final TableAppender table = new TableAppender(out, "  ");
            for (final String command : commandNames) {
                if (showHeader) {
                    table.append("  ");
                }
                table.append(command);
                if (!showHeader) {
                    table.append(':');
                }
                table.nextColumn();
                table.append(commands.getString(command));
                table.nextLine();
            }
            table.flush();
            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Options));
            out.println(':');
            for (final Option option : validOptions) {
                final String name = option.name().toLowerCase(Locale.US);
                table.append("  ").append(Option.PREFIX).append(name);
                table.nextColumn();
View Full Code Here

Examples of org.apache.sis.util.resources.Vocabulary

        }
        /*
         * Finished to prepare information. Now begin the actual writing.
         * First, formats the table header (i.e. the column names).
         */
        final Vocabulary resources = Vocabulary.getResources(displayLocale);
        header.writeIdentifiers(out, true, colors, false, lineSeparator);
        out.append(lineSeparator);
        final char horizontalBorder = isBrief ? '─' : '═';
        final TableAppender table = (isBrief || !columnSeparator.equals(SEPARATOR)) ?
                new TableAppender(out, columnSeparator) : new TableAppender(out);
        table.setMultiLinesCells(true);
        table.nextLine(horizontalBorder);
        for (int i=0; ; i++) {
            boolean end = false;
            final short key;
            switch (i) {
                case 0: {
                    key = Vocabulary.Keys.Name;
                    break;
                }
                case 1: {
                    key = Vocabulary.Keys.Type;
                    break;
                }
                case 2: {
                    if (!showObligation) {
                       continue;
                    }
                    key = Vocabulary.Keys.Obligation;
                    break;
                }
                case 3: {
                    key = Vocabulary.Keys.ValueDomain;
                    break;
                }
                case 4: {
                    key = (values == null) ? Vocabulary.Keys.DefaultValue : Vocabulary.Keys.Value;
                    end = true;
                    break;
                }
                default: throw new AssertionError(i);
            }
            if (hasColors) table.append(X364.BOLD.sequence());
            table.append(resources.getString(key));
            if (hasColors) table.append(X364.NORMAL.sequence());
            if (!writeCodespaces && i == 0) {
                table.append(" (").append(groupCodespace).append(')');
            }
            if (end) break;
            nextColumn(table);
        }
        table.nextLine();
        /*
         * Now process to the formatting of (descriptor,value) pairs. Each descriptor's alias
         * will be formatted on its own line in a table row. If there is more than one value,
         * then each value will be formatted on its own line as well. Note that the values may
         * be null if there is none.
         */
        char horizontalLine = horizontalBorder;
        for (final Map.Entry<GeneralParameterDescriptor,ParameterTableRow> entry : descriptorValues.entrySet()) {
            if (horizontalLine != 0) {
                table.nextLine('─');
            }
            horizontalLine = isBrief ? 0 : '─';
            final ParameterTableRow row = entry.getValue();
            row.codespaceWidth = codespaceWidth;
            row.writeIdentifiers(table, writeCodespaces, null, hasColors, lineSeparator);
            nextColumn(table);
            final GeneralParameterDescriptor generalDescriptor = entry.getKey();
            if (generalDescriptor instanceof ParameterDescriptor<?>) {
                /*
                 * Writes value type.
                 */
                final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) generalDescriptor;
                final Class<?> valueClass = descriptor.getValueClass();
                table.append(getFormat(Class.class).format(valueClass, buffer, dummyFP).toString());
                nextColumn(table);
                buffer.setLength(0);
                /*
                 * Writes the obligation (mandatory or optional).
                 */
                if (showObligation) {
                    final int minimumOccurs = descriptor.getMinimumOccurs();
                    final int maximumOccurs = descriptor.getMaximumOccurs();
                    if (maximumOccurs == 1) {
                        table.append(resources.getString(minimumOccurs == 0 ?
                                Vocabulary.Keys.Optional : Vocabulary.Keys.Mandatory));
                    } else {
                        final Format f = getFormat(Integer.class);
                        table.append(f.format(minimumOccurs, buffer, dummyFP).toString()).append(" … ");
                        buffer.setLength(0);
View Full Code Here

Examples of org.apache.sis.util.resources.Vocabulary

        switch (borderWidth) {
            case 1: horizontalLine = '─'; separator += "│ "; break;
            case 2: horizontalLine = '═'; separator += "║ "; break;
        }
        final TableAppender table = new TableAppender(toAppendTo, separator);
        final Vocabulary resources = Vocabulary.getResources(headerLocale);
        /*
         * If there is a header for at least one statistics, write the full headers row.
         */
        if (horizontalLine != 0) {
            table.nextLine(horizontalLine);
        }
        if (showHeaders) {
            table.nextColumn();
            for (final String header : headers) {
                if (header != null) {
                    table.append(header);
                    table.setCellAlignment(TableAppender.ALIGN_CENTER);
                }
                table.nextColumn();
            }
            table.append(lineSeparator);
            if (horizontalLine != 0) {
                table.nextLine(horizontalLine);
            }
        }
        /*
         * Initialize the NumberFormat for formatting integers without scientific notation.
         * This is necessary since the format may have been modified by a previous execution
         * of this method.
         */
        final Format format = getFormat(Double.class);
        if (format instanceof DecimalFormat) {
            ((DecimalFormat) format).applyPattern("#0"); // Also disable scientific notation.
        } else if (format instanceof NumberFormat) {
            setFractionDigits((NumberFormat) format, 0);
        }
        /*
         * Iterates over the rows to format (count, minimum, maximum, mean, RMS, standard deviation),
         * then iterate over columns (statistics on sample values, on the first derivatives, etc.)
         * The NumberFormat configuration may be different for each column, but we can skip many
         * reconfiguration in the common case where there is only one column.
         */
        boolean needsConfigure = false;
        for (int i=0; i<KEYS.length; i++) {
            switch (i) {
                case 1: if (!showNaNCount) continue; else break;
                // Case 0 and 1 use the above configuration for integers.
                // Case 2 unconditionally needs a reconfiguration for floating point values.
                // Case 3 and others need reconfiguration only if there is more than one column.
                case 2: needsConfigure = true; break;
                case 3: needsConfigure = (stats[0].differences() != null); break;
            }
            table.setCellAlignment(TableAppender.ALIGN_LEFT);
            table.append(resources.getString(KEYS[i])).append(':');
            for (final Statistics s : stats) {
                final Number value;
                switch (i) {
                    case 0:  value = s.count();    break;
                    case 1:  value = s.countNaN(); break;
View Full Code Here

Examples of org.apache.sis.util.resources.Vocabulary

     * @param validOptions The options to list.
     */
    void help(final boolean showHeader, final String[] commandNames, final EnumSet<Option> validOptions) {
        final ResourceBundle commands = ResourceBundle.getBundle("org.apache.sis.console.Commands", locale);
        final ResourceBundle options  = ResourceBundle.getBundle("org.apache.sis.console.Options",  locale);
        final Vocabulary vocabulary = Vocabulary.getResources(locale);
        if (showHeader) {
            out.print("Apache SIS, ");
            out.println(commands.getString("SIS"));
            out.println(commands.getString("Usage"));
            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Commands));
            out.println(':');
        }
        try {
            final TableAppender table = new TableAppender(out, "  ");
            for (final String command : commandNames) {
                if (showHeader) {
                    table.append("  ");
                }
                table.append(command);
                if (!showHeader) {
                    table.append(':');
                }
                table.nextColumn();
                table.append(commands.getString(command));
                table.nextLine();
            }
            table.flush();
            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Options));
            out.println(':');
            for (final Option option : validOptions) {
                final String name = option.name().toLowerCase(Locale.US);
                table.append("  ").append(Option.PREFIX).append(name);
                table.nextColumn();
View Full Code Here

Examples of org.apache.sis.util.resources.Vocabulary

     * @param  objects The collection of objects to format.
     * @param  out The stream or buffer where to write the summary.
     * @throws IOException if an error occurred will writing to the given appendable.
     */
    private void formatSummary(final IdentifiedObject[] objects, final Appendable out) throws IOException {
        final Vocabulary resources = Vocabulary.getResources(displayLocale);
        /*
         * Prepares all rows before we write them to the output stream, because not all
         * identified objects may have names with the same scopes in the same order. We
         * also need to iterate over all rows in order to know the number of columns.
         *
         * The first column is reserved for the identifier. We put null as a sentinal key for
         * that column name, to be replaced later by "Identifier" in user locale. We can not
         * put the localized strings in the map right now because they could conflict with
         * the scope of some alias to be processed below.
         */
        boolean hasIdentifiers = false;
        final List<String[]> rows = new ArrayList<String[]>();
        final Map<String,Integer> columnIndices = new LinkedHashMap<String,Integer>();
        columnIndices.put(null, 0); // See above comment for the meaning of "null" here.
        if (preferredCodespaces != null) {
            for (final String codespace : preferredCodespaces) {
                columnIndices.put(codespace, columnIndices.size());
            }
        }
        for (final IdentifiedObject object : objects) {
            String[] row = new String[columnIndices.size()]; // Will growth later if needed.
            /*
             * Put the first identifier in the first column. If no identifier has a codespace in the list
             * supplied by the user, then we will use the first identifier (any codespace) as a fallback.
             */
            final Set<ReferenceIdentifier> identifiers = object.getIdentifiers();
            if (identifiers != null) { // Paranoiac check.
                ReferenceIdentifier identifier = null;
                for (final ReferenceIdentifier candidate : identifiers) {
                    if (candidate != null) { // Paranoiac check.
                        if (isPreferredCodespace(candidate.getCodeSpace())) {
                            identifier = candidate;
                            break; // Format now.
                        }
                        if (identifier == null) {
                            identifier = candidate; // To be used as a fallback if we find nothing better.
                        }
                    }
                }
                if (identifier != null) {
                    row[0] = IdentifiedObjects.toString(identifier);
                    hasIdentifiers = true;
                }
            }
            /*
             * If the name's codespace is in the list of codespaces asked by the user, add that name
             * in the current row and clear the 'name' locale variable. Otherwise, keep the 'name'
             * locale variable in case we found no alias to format.
             */
            ReferenceIdentifier name = object.getName();
            if (name != null) { // Paranoiac check.
                final String codespace = name.getCodeSpace();
                if (isPreferredCodespace(codespace)) {
                    row = putIfAbsent(resources, row, columnIndices, codespace, name.getCode());
                    name = null;
                }
            }
            /*
             * Put all aliases having a codespace in the list asked by the user.
             */
            final Collection<GenericName> aliases = object.getAlias();
            if (aliases != null) { // Paranoiac check.
                for (final GenericName alias : aliases) {
                    if (alias != null) { // Paranoiac check.
                        final String codespace = NameToIdentifier.getCodespaceOrAuthority(alias, displayLocale);
                        if (isPreferredCodespace(codespace)) {
                            row = putIfAbsent(resources, row, columnIndices, codespace,
                                    alias.tip().toInternationalString().toString(displayLocale));
                            name = null;
                        }
                    }
                }
            }
            /*
             * If no name and no alias have a codespace in the list of codespaces asked by the user,
             * force the addition of primary name regardless its codespace.
             */
            if (name != null) {
                row = putIfAbsent(resources, row, columnIndices, name.getCodeSpace(), name.getCode());
            }
            rows.add(row);
        }
        /*
         * Writes the table. The header will contain one column for each codespace in the order declared
         * by the user. If the user did not specified any codespace, or if we had to write codespace not
         * on the user list, then those codespaces will be written in the order we found them.
         */
        final boolean hasColors = (colors != null);
        final TableAppender table = new TableAppender(out, columnSeparator);
        table.setMultiLinesCells(true);
        table.appendHorizontalSeparator();
        for (String codespace : columnIndices.keySet()) {
            if (codespace == null) {
                if (!hasIdentifiers) continue; // Skip empty column.
                codespace = resources.getString(Vocabulary.Keys.Identifier);
            }
            if (hasColors) {
                codespace = X364.BOLD.sequence() + codespace + X364.NORMAL.sequence();
            }
            table.append(codespace);
View Full Code Here

Examples of org.deri.grefine.rdf.vocab.Vocabulary

      Map<String, Vocabulary> prefixesMap = new HashMap<String, Vocabulary>();
      JSONArray prefixesArr = ParsingUtilities.evaluateJsonStringToArray(request.getParameter("prefixes"));
      for(int i =0;i<prefixesArr.length();i++){
        JSONObject prefixObj = prefixesArr.getJSONObject(i);
        String name = prefixObj.getString("name");
        prefixesMap.put(name,new Vocabulary(name, prefixObj.getString("uri")));
      }
      getRdfSchema(request).setPrefixesMap(prefixesMap);
     
      String projectId = request.getParameter("project");
      getRdfContext().getVocabularySearcher().synchronize(projectId, prefixesMap.keySet());
View Full Code Here

Examples of org.deri.grefine.rdf.vocab.Vocabulary

        String name = tokenizer.nextToken();
        String uri = tokenizer.nextToken();
        String url = tokenizer.nextToken();
        //import and index
        this.applicationContext.getVocabularySearcher().importAndIndexVocabulary(name, uri,url, new VocabularyImporter());
        this.predefinedVocabulariesMap.put(name,new Vocabulary(name, uri));
      } catch (Exception e) {
        // predefined vocabularies are not defined properly
        // ignore the exception, just log it
        logger.warn("unable to add predefined vocabularies", e);
      }
View Full Code Here

Examples of org.deri.grefine.rdf.vocab.Vocabulary

            JSONArray prefixes = obj.getJSONArray("prefixes");
            for(int i=0;i<prefixes.length();i++){
              JSONObject p = prefixes.getJSONObject(i);
              String name = p.getString("name");
              String uri = p.getString("uri");
              this.predefinedVocabulariesMap.put(name,new Vocabulary(name,uri));
            }
        } finally {
            reader.close();
        }
View Full Code Here

Examples of org.deri.grefine.rdf.vocab.Vocabulary

    public void addPrefix(String name, String uri) throws PrefixExistException{
      synchronized(prefixesMap){
        if(this.prefixesMap.containsKey(name)){
          throw new PrefixExistException(name + " already defined");
        }
        this.prefixesMap.put(name, new Vocabulary(name, uri));
      }
    }
View Full Code Here

Examples of org.deri.grefine.rdf.vocab.Vocabulary

          prefixesArr = new JSONArray();
        }
        for (int i = 0; i < prefixesArr.length(); i++) {
          JSONObject prefixObj = prefixesArr.getJSONObject(i);
          String name = prefixObj.getString("name");
          s.prefixesMap.put(name,new Vocabulary(name, prefixObj.getString("uri")));
        }
       
        JSONArray rootNodes = o.getJSONArray("rootNodes");
        int count = rootNodes.length();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.