Example usage for org.apache.commons.lang StringUtils substring

List of usage examples for org.apache.commons.lang StringUtils substring

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substring.

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:au.org.ala.delta.key.Key.java

private void printTabularKey(TabularKey key, PrintFile printFile) {
    ItemFormatter itemFormatter = new ItemFormatter(false, CommentStrippingMode.STRIP_ALL,
            AngleBracketHandlingMode.REMOVE, true, false, false);

    // Do a first pass of the data structure to get the counts for the
    // number of times a taxon appears in the key, and to work out how wide
    // the cells need to be
    Map<Item, Integer> itemOccurrences = new HashMap<Item, Integer>();
    int cellWidth = 0;

    for (TabularKeyRow row : key.getRows()) {
        Item it = row.getItem();/*from  w ww.j a  v a 2  s.c  om*/

        if (itemOccurrences.containsKey(it)) {
            int currentItemCount = itemOccurrences.get(it);
            itemOccurrences.put(it, currentItemCount + 1);
        } else {
            itemOccurrences.put(it, 1);
        }

        // If TRUNCATE TABULAR KEY AT directive has been used, only
        // traverse up to the relevant column.
        int columnLimit = row.getNumberOfColumns();
        if (_context.getTruncateTabularKeyAtColumnNumber() != -1) {
            columnLimit = _context.getTruncateTabularKeyAtColumnNumber();
        }

        for (int i = 0; i < columnLimit; i++) {
            int columnNumber = i + 1;

            for (MultiStateAttribute attr : row.getAllAttributesForColumn(columnNumber)) {
                int characterNumber = attr.getCharacter().getCharacterId();
                int numberOfDigits = Integer.toString(characterNumber).length();

                // Cell width needs to be at least as wide as the number of
                // digits, plus one extra character for the state value
                // associated with the attribute
                if (cellWidth < numberOfDigits + 1) {
                    cellWidth = numberOfDigits + 1;
                }
            }
        }
    }

    // Highest number of item occurrences in the key
    int maxItemOccurrences = Collections.max(itemOccurrences.values());

    // Determine the maximum allowable length for a formatted taxon name in
    // the tabulated key. This will be the length
    // of the name cell, less the length of the largest number of item
    // occurrences (these are printed right-justified) in the cell, with a
    // space between the name and the item occurrence count.
    int maxFormattedItemNameLength = TABULATED_KEY_NAME_CELL_WIDTH
            - Integer.toString(maxItemOccurrences).length() - 1;

    StringBuilder builder = new StringBuilder();

    // Second pass - output the key
    for (int i = 0; i < key.getNumberOfRows(); i++) {
        TabularKeyRow row = key.getRowAt(i);
        Item it = row.getItem();

        List<MultiStateAttribute> rowAttributes;
        List<MultiStateAttribute> previousRowAttributes = null;

        // If TRUNCATE TABULAR KEY AT directive has been used, only
        // traverse up to the relevant column.
        int columnLimit = row.getNumberOfColumns();

        if (_context.getTruncateTabularKeyAtColumnNumber() == -1) {
            rowAttributes = row.getAllAttributes();
            if (i > 0) {
                previousRowAttributes = key.getRowAt(i - 1).getAllAttributes();
            }
        } else {
            columnLimit = _context.getTruncateTabularKeyAtColumnNumber();
            rowAttributes = row.getAllCharacterValuesUpToColumn(columnLimit);
            if (i > 0) {
                previousRowAttributes = key.getRowAt(i - 1).getAllCharacterValuesUpToColumn(columnLimit);
            }
        }

        // Output the dividing line between the previous row and the current
        // row
        builder.append("+---------------------------+");

        for (int j = 0; j < rowAttributes.size(); j++) {
            Attribute currentRowAttribute = rowAttributes.get(j);

            if (previousRowAttributes != null && previousRowAttributes.size() >= j + 1) {
                Attribute previousRowAttribute = previousRowAttributes.get(j);
                if (currentRowAttribute.equals(previousRowAttribute)) {
                    builder.append(StringUtils.repeat(" ", cellWidth));
                    builder.append("|");
                } else {
                    builder.append(StringUtils.repeat("-", cellWidth));
                    builder.append("+");
                }

            } else {
                builder.append(StringUtils.repeat("-", cellWidth));
                builder.append("+");
            }
        }

        if (previousRowAttributes != null) {
            int diffPrevRowAttributes = previousRowAttributes.size() - rowAttributes.size();
            for (int k = 0; k < diffPrevRowAttributes; k++) {
                builder.append(StringUtils.repeat("-", cellWidth));
                builder.append("+");
            }
        }

        builder.append("\n");

        // Output the item name and the number of occurences of the item in
        // the key, if it appears more than once
        builder.append("|");
        String formattedItemName = itemFormatter.formatItemDescription(it);
        formattedItemName = StringUtils.substring(formattedItemName, 0, maxFormattedItemNameLength);
        builder.append(formattedItemName);

        int numItemOccurrences = itemOccurrences.get(it);

        if (numItemOccurrences > 1) {
            builder.append(StringUtils.repeat(" ", TABULATED_KEY_NAME_CELL_WIDTH - formattedItemName.length()
                    - Integer.toString(numItemOccurrences).length()));
            builder.append(numItemOccurrences);
        } else {
            builder.append(StringUtils.repeat(" ", TABULATED_KEY_NAME_CELL_WIDTH - formattedItemName.length()));
        }

        builder.append("|");

        // Output the values character values used in the. Include values
        // for confirmatory characters if they are present
        for (int j = 0; j < columnLimit; j++) {
            int columnNumber = j + 1;
            List<MultiStateAttribute> cellCharacterValues = row.getAllAttributesForColumn(columnNumber);
            for (int k = 0; k < cellCharacterValues.size(); k++) {
                MultiStateAttribute cellCharacterValue = cellCharacterValues.get(k);
                int characterId = cellCharacterValue.getCharacter().getCharacterId();

                // Insert spaces to pad out the cell if the character id +
                // state
                // value are not as wide as the cell width
                builder.append(
                        StringUtils.repeat(" ", cellWidth - (Integer.toString(characterId).length() + 1)));

                builder.append(characterId);

                // Only 1 state will be ever set - the key generation
                // algorithm
                // only sets
                // Individual states for characters
                int stateNumber = cellCharacterValue.getPresentStates().iterator().next();
                // Convert state numbers to "A", "B", "C" etc
                builder.append((char) (64 + stateNumber));

                if (cellCharacterValues.size() > 1 && k < cellCharacterValues.size() - 1) {
                    builder.append(" ");
                }
            }

            builder.append("|");
        }

        builder.append("\n");

        // If this is the last row, need to print the bottom edge of the
        // table
        if (i == key.getNumberOfRows() - 1) {
            builder.append("+---------------------------+");
            for (int l = 0; l < rowAttributes.size(); l++) {
                builder.append(StringUtils.repeat("-", cellWidth));
                builder.append("+");
            }
        }
    }

    printPagedTabularKey(builder.toString(), cellWidth, printFile);
}

From source file:ca.sqlpower.matchmaker.address.AddressPool.java

private String adjustSize(String source, Integer size) {
    if (size == null) {
        return source; // we couldn't obtain the column size, so do nothing.
    }//from   w  w  w .  j  a  v a 2  s. c om

    if (StringUtils.length(source) > size) {
        return StringUtils.substring(source, 0, size);
    }

    return source;
}

From source file:net.triptech.metahive.model.KeyValue.java

/**
 * Gets the formatted value.//from   w w w .j a  va2 s. com
 *
 * @param includeUnits the include units flag
 * @return the value
 */
private String getValue(final boolean includeUnits) {

    if (this.getDefinition() == null) {
        throw new NullPointerException("A valid definition is required");
    }
    if (this.getContext() == null) {
        throw new NullPointerException("A valid application context is required");
    }

    // The default value is authorisation required
    String value = context.getMessage("label_net_triptech_metahive_model_keyvalue_access_restricted", null,
            LocaleContextHolder.getLocale());

    if (UserRole.allowAccess(this.getUserRole(), definition.getKeyValueAccess())) {
        value = context.getMessage("label_net_triptech_metahive_model_keyvalue_no_data", null,
                LocaleContextHolder.getLocale());

        if (this.getDefinition().getDataType() == DataType.TYPE_STRING) {
            if (this.getStringValue() != null) {
                value = this.getStringValue();
                if (includeUnits) {
                    value += appendUnitOfMeasure();
                }
            }
        }
        if (this.getDefinition().getDataType() == DataType.TYPE_BOOLEAN) {
            if (this.getBooleanValue() != null && this.getContext() != null) {
                value = context.getMessage(this.getBooleanValue().getMessageKey(), null,
                        LocaleContextHolder.getLocale());
            }
        }
        if (this.getDefinition().getDataType() == DataType.TYPE_NUMBER
                || this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) {
            if (this.getDoubleValue() != null) {
                DecimalFormat df = new DecimalFormat("#.######");
                value = df.format(this.getDoubleValue());
                if (StringUtils.endsWithIgnoreCase(value, ".000000")) {
                    value = StringUtils.substring(value, 0, value.length() - 6);
                }
                if (this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) {
                    value += "%";
                }
                if (includeUnits) {
                    value += appendUnitOfMeasure();
                }
            }
        }
        if (this.getDefinition().getDataType() == DataType.TYPE_CURRENCY) {
            if (this.getDoubleValue() != null) {
                DecimalFormat df = new DecimalFormat("$###,###,###,##0.00");
                value = df.format(this.getDoubleValue()) + appendUnitOfMeasure();
            }
        }
    }
    return value;
}

From source file:net.triptech.metahive.model.Person.java

/**
 * Build the option map if any search options exist.
 *//*from  w  w  w  .ja  va 2  s  .  co  m*/
@PostLoad
public final void postLoad() {
    this.searchOptionsMap = new HashMap<String, Boolean>();

    if (StringUtils.isNotBlank(this.searchOptions)) {
        // Parse the search options
        StringTokenizer st = new StringTokenizer(this.searchOptions, "|");
        while (st.hasMoreTokens()) {
            String t = st.nextToken();
            String key = StringUtils.substring(t, 0, StringUtils.indexOf(t, "="));
            String vl = StringUtils.substring(t, StringUtils.indexOf(t, "=") + 1);

            // Parse the value to a boolean
            try {
                boolean bl = Boolean.parseBoolean(vl);
                this.searchOptionsMap.put(key, bl);
            } catch (Exception e) {
                // Error casting string to boolean
            }
        }
    }
}

From source file:net.triptech.metahive.model.SubmittedField.java

/**
 * Gets the formatted value.// w  w w.j a v  a  2s.  c  o  m
 *
 * @return the formatted value
 */
public final String getFormattedValue() {
    String unformattedValue = "";
    String formattedValue = "";

    if (this.getDefinition() == null) {
        throw new NullPointerException("A valid definition is required");
    }

    if (StringUtils.isNotBlank(this.getValue())) {
        unformattedValue = this.getValue();
    }

    if (this.getDefinition().getDataType() == DataType.TYPE_STRING) {
        formattedValue = unformattedValue + appendUnitOfMeasure();
    }
    if (this.getDefinition().getDataType() == DataType.TYPE_BOOLEAN) {
        formattedValue = unformattedValue;
    }
    if (this.getDefinition().getDataType() == DataType.TYPE_NUMBER
            || this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) {
        double dblValue = 0;
        try {
            dblValue = Double.parseDouble(unformattedValue);
        } catch (NumberFormatException nfe) {
            // Error parsing double
        }

        DecimalFormat df = new DecimalFormat("#.######");
        formattedValue = df.format(dblValue);
        if (StringUtils.endsWithIgnoreCase(formattedValue, ".000000")) {
            formattedValue = StringUtils.substring(formattedValue, 0, formattedValue.length() - 6);
        }

        if (this.getDefinition().getDataType() == DataType.TYPE_PERCENTAGE) {
            formattedValue += "%";
        }
        formattedValue += appendUnitOfMeasure();
    }
    if (this.getDefinition().getDataType() == DataType.TYPE_CURRENCY) {
        double dblValue = 0;
        try {
            dblValue = Double.parseDouble(unformattedValue);
        } catch (NumberFormatException nfe) {
            // Error parsing double
        }

        DecimalFormat df = new DecimalFormat("$###,###,###,##0.00");
        formattedValue = df.format(dblValue) + appendUnitOfMeasure();
    }
    return formattedValue;
}

From source file:net.ymate.platform.webmvc.impl.DefaultModuleCfg.java

public DefaultModuleCfg(YMP owner) throws Exception {
    Map<String, String> _moduleCfgs = owner.getConfig().getModuleConfigs(IWebMvc.MODULE_NAME);
    //// w  w w  .j  av a 2s .  c  om
    String _reqProcessorClass = StringUtils.defaultIfBlank(_moduleCfgs.get("request_processor_class"),
            "default");
    Class<? extends IRequestProcessor> _requestProcessorClass = Type.REQUEST_PROCESSORS.get(_reqProcessorClass);
    if (_requestProcessorClass == null && StringUtils.isNotBlank(_reqProcessorClass)) {
        __requestProcessor = ClassUtils.impl(_reqProcessorClass, IRequestProcessor.class, this.getClass());
    } else if (_requestProcessorClass != null) {
        __requestProcessor = _requestProcessorClass.newInstance();
    }
    if (__requestProcessor == null) {
        __requestProcessor = new DefaultRequestProcessor();
    }
    //
    String _errorProcessorClass = _moduleCfgs.get("error_processor_class");
    if (StringUtils.isNotBlank(_errorProcessorClass)) {
        __errorProcessor = ClassUtils.impl(_errorProcessorClass, IWebErrorProcessor.class, this.getClass());
    }
    //
    String _cacheProcessorClass = _moduleCfgs.get("cache_processor_class");
    if (StringUtils.isNotBlank(_errorProcessorClass)) {
        __cacheProcessor = ClassUtils.impl(_cacheProcessorClass, IWebCacheProcessor.class, this.getClass());
    }
    //
    __charsetEncoding = StringUtils.defaultIfBlank(_moduleCfgs.get("default_charset_encoding"), "UTF-8");
    __requestIgnoreRegex = StringUtils.defaultIfBlank(_moduleCfgs.get("request_ignore_regex"), __IGNORE);
    __requestMethodParam = StringUtils.defaultIfBlank(_moduleCfgs.get("request_method_param"), "_method");
    __requestPrefix = StringUtils.trimToEmpty(_moduleCfgs.get("request_prefix"));
    //
    __parameterEscapeMode = BlurObject.bind(_moduleCfgs.get("parameter_escape_mode")).toBooleanValue();
    __parameterEscapeOrder = Type.EscapeOrder.valueOf(
            StringUtils.defaultIfBlank(_moduleCfgs.get("parameter_escape_order"), "after").toUpperCase());
    //
    __baseViewPath = RuntimeUtils.replaceEnvVariable(
            StringUtils.defaultIfBlank(_moduleCfgs.get("base_view_path"), "/WEB-INF/templates/"));
    __abstractBaseViewPath = __baseViewPath;
    if (__abstractBaseViewPath.startsWith("/WEB-INF")) {
        __abstractBaseViewPath = new File(RuntimeUtils.getRootPath(false), __abstractBaseViewPath).getPath();
    }
    //
    __cookiePrefix = StringUtils.trimToEmpty(_moduleCfgs.get("cookie_prefix"));
    __cookieDomain = StringUtils.trimToEmpty(_moduleCfgs.get("cookie_domain"));
    __cookiePath = StringUtils.defaultIfBlank(_moduleCfgs.get("cookie_path"), "/");
    __cookieAuthKey = StringUtils.trimToEmpty(_moduleCfgs.get("cookie_auth_key"));
    __defaultEnabledCookieAuth = BlurObject.bind(_moduleCfgs.get("default_enabled_cookie_auth"))
            .toBooleanValue();
    //
    __uploadTempDir = RuntimeUtils
            .replaceEnvVariable(StringUtils.trimToEmpty(_moduleCfgs.get("upload_temp_dir")));
    __uploadFileSizeMax = Integer
            .parseInt(StringUtils.defaultIfBlank(_moduleCfgs.get("upload_file_size_max"), "10485760"));
    __uploadTotalSizeMax = Integer
            .parseInt(StringUtils.defaultIfBlank(_moduleCfgs.get("upload_total_size_max"), "10485760"));
    __uploadSizeThreshold = Integer
            .parseInt(StringUtils.defaultIfBlank(_moduleCfgs.get("upload_size_threshold"), "10240"));
    __uploadFileListener = ClassUtils.impl(_moduleCfgs.get("upload_file_listener_class"),
            ProgressListener.class, this.getClass());
    //
    __conventionMode = BlurObject.bind(_moduleCfgs.get("convention_mode")).toBooleanValue();
    __conventionUrlrewriteMode = BlurObject.bind(_moduleCfgs.get("convention_urlrewrite_mode"))
            .toBooleanValue();
    __conventionInterceptorMode = BlurObject.bind(_moduleCfgs.get("convention_interceptor_mode"))
            .toBooleanValue();
    //
    __conventionViewAllowPaths = new HashSet<String>();
    __conventionViewNotAllowPaths = new HashSet<String>();
    //
    String[] _cViewPaths = StringUtils
            .split(StringUtils.defaultIfBlank(_moduleCfgs.get("convention_view_paths"), ""), "|");
    if (_cViewPaths != null) {
        for (String _cvPath : _cViewPaths) {
            _cvPath = StringUtils.trimToNull(_cvPath);
            if (_cvPath != null) {
                boolean _flag = true;
                if (_cvPath.length() > 1) {
                    char _c = _cvPath.charAt(_cvPath.length() - 1);
                    if (_c == '+') {
                        _cvPath = StringUtils.substring(_cvPath, 0, _cvPath.length() - 1);
                    } else if (_c == '-') {
                        _cvPath = StringUtils.substring(_cvPath, 0, _cvPath.length() - 1);
                        _flag = false;
                    }
                }
                if (_cvPath.charAt(0) != '/') {
                    _cvPath = "/" + _cvPath;
                }
                if (_flag) {
                    __conventionViewAllowPaths.add(_cvPath);
                } else {
                    __conventionViewNotAllowPaths.add(_cvPath);
                }
            }
        }
    }
}

From source file:nl.strohalm.cyclos.entities.sms.SmsLog.java

private static String ensureArgLength(final String arg) {
    return StringUtils.substring(arg, 0, MAX_ARG_LEN);
}

From source file:org.adl.validator.contentpackage.CPValidator.java

/**
 * This method checks that if the &lt;resource&gt; is local to the content
 * package, then a &lt;file&gt; element is required that represents the
 * &lt;resource&gt; itself. The href attribute of the &lt;file&gt; element
 * shall be identical to the href attribute of the &lt;resource&gt;
 * /*  w  ww.  j  ava 2  s. co m*/
 * @param iResourceNode
 *            - The &lt;resource&gt; element
 * @return boolean - Result of the overall check. True if the checks passed,
 *         false otherwise.
 */
private boolean checkResourceFileHref(Node iResourceNode) {
    boolean result = true;
    String msgText = "";

    // retrive the href and apply xml:base
    String resourceHref = DOMTreeUtility.getAttributeValue(iResourceNode, "href");

    // only continue check if the resourceHref exists
    if (!resourceHref.equals("")) {
        // remove all parameters from the end of the href, if they exist

        // first deal with ?
        int questionMarkIndex = StringUtils.indexOf(resourceHref, '?');
        if (questionMarkIndex > 0) {
            resourceHref = StringUtils.substring(resourceHref, 0, questionMarkIndex);
        }

        // also deal with #
        int poundIndex = StringUtils.indexOf(resourceHref, '#');
        if (poundIndex > 0) {
            resourceHref = StringUtils.substring(resourceHref, 0, poundIndex);
        }

        // we must manually retrieve the resource xml:base attribute value
        // the applyXMLBase is not aware of it at this time of processing
        String resourceXMLBase = DOMTreeUtility.getAttributeValue(iResourceNode, "base");

        // resourceID used for logging error messages
        String resourceID = DOMTreeUtility.getAttributeValue(iResourceNode, "identifier");
        mLogger.debug("Checking for this resource now " + resourceID);

        // apply XML Base to the href if it exists
        resourceHref = mXMLBase[0][1] + mXMLBase[1][1] + resourceXMLBase + resourceHref;

        // only need to perform this check on local resource
        if (!StringUtils.startsWith(resourceHref, "http:") && !StringUtils.startsWith(resourceHref, "https:")
                && !StringUtils.startsWith(resourceHref, "ftp:")
                && !StringUtils.startsWith(resourceHref, "ftps:")) {
            // we have a resource that is local to the package, must have a
            // file
            // href that is identifical to it

            List<String> files = mResourceTable.get(resourceID);

            if (files != null) {
                if (!files.contains(resourceHref)) {
                    // the resourceHref does not contain a matching file
                    // href when
                    // it should
                    result = false;

                    msgText = Messages.getString("CPValidator.628", resourceID);
                    mLogger.debug("FAILED: " + msgText);
                    DetailedLogMessageCollection.getInstance()
                            .addMessage(new LogMessage(MessageType.FAILED, msgText));
                }
            } else {
                // there are no files that exist for the local resource
                result = false;

                msgText = Messages.getString("CPValidator.628", resourceID);
                mLogger.debug("FAILED: " + msgText);
                DetailedLogMessageCollection.getInstance()
                        .addMessage(new LogMessage(MessageType.FAILED, msgText));
            }
        }
    }
    return result;
}

From source file:org.aksw.xoperator.Controller.java

/**
 * Processes a Message received through the P2P facilities. Defines that only the built in store should be asked.
 *
 * @param query the incoming query//ww w .ja  v a 2  s. c  o  m
 *
 * @return the SPARQL Result, serialized as a String
 */
public String processIncomingSparqlQuery(SPARQLQueryOverXmpp incomingQuery) {
    SparqlQuery query = incomingQuery.getSparqlQuery();
    p2pLog.info("received " + query.getQueryString());
    query.setAgentsToAsk(new ArrayList<SparqlEndpointIdentifier>());
    query.setStoresToAsk(new ArrayList<SparqlEndpointIdentifier>());
    query.setAskLocal(true);
    endpointFacade.process(query);

    List<String> results = new ArrayList<String>();

    for (SparqlResult sresult : query.getResults().values()) {
        results.add(sresult.getAnswer());
    }

    String result = uglySparqlResultCombiner(results);
    p2pLog.info("answered: " + StringUtils.substring(result, 0, 200));

    return result;
}

From source file:org.ala.lucene.CreateWordPressIndex.java

/**
 * Index the WP pages by parsing with Jsoup and indexing into SOLR
 *
 * @return/*  w  ww . j  av a2 s . co  m*/
 * @throws IOException
 */
protected int indexPages() throws Exception {
    int documentCount = 0;
    // Initialise SOLR
    SolrServer solrServer = solrUtils.getSolrServer();
    logger.info("Deleting all WordPress documents in SOLR index...");
    solrServer.deleteByQuery("idxtype:" + IndexedTypes.WORDPRESS); // delete WP pages
    solrServer.commit();

    for (String pageUrl : this.pageUrls) {
        try {
            // Crawl and extract text from WP pages
            Document document = Jsoup.connect(pageUrl + CONTENT_ONLY_PARAM).get();
            String title = document.select("head > title").text();
            String id = document.select("head > meta[name=id]").attr("content");
            String bodyText = document.body().text();
            Elements postCategories = document.select("ul[class=post-categories]");
            List<String> categoriesOut = new ArrayList<String>();
            Boolean excludePost = false;

            if (!postCategories.isEmpty()) {
                // Is a WP post (not page)
                Elements categoriesIn = postCategories.select("li > a"); // get list of li elements

                for (Element cat : categoriesIn) {
                    String thisCat = cat.text();

                    if (thisCat != null && excludedCategories.contains(thisCat)) { // "button".equals(thisCat)
                        // exclude category "button" posts
                        excludePost = true;
                    }
                    if (thisCat != null) {
                        // add category to list
                        categoriesOut.add(thisCat.replaceAll(" ", "_"));
                    }
                }
            }

            if (excludePost) {
                logger.debug("Excluding post (id: " + id + ") with category: "
                        + StringUtils.join(categoriesOut, "|"));
                continue;
            }

            documentCount++;
            // Index with SOLR
            logger.debug(documentCount + ". Indexing WP page - id: " + id + " | title: " + title + " | text: "
                    + StringUtils.substring(bodyText, 0, 100) + "... ");
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("idxtype", IndexedTypes.WORDPRESS);
            doc.addField("guid", WP_BASE_URI + id); // use page_id based URI instead of permalink in case permalink is too long for id field
            doc.addField("id", "wp" + id); // probably not needed but safer to leave in
            doc.addField("name", title, 1.2f);
            doc.addField("content", bodyText);
            doc.addField("australian_s", "recorded"); // so they appear in default QF search
            doc.addField("categories", categoriesOut);
            // add to index
            solrServer.add(doc);

            if (documentCount % 100 == 0) {
                logger.info("Committing to SOLR (count = " + documentCount + ")...");
                solrServer.commit();
            }
        } catch (IOException ex) {
            // catch it so we don't stop indexing other pages
            logger.warn("Problem accessing/reading WP page: " + ex.getMessage(), ex);
        }
    }

    logger.info("Final Committing to SOLR...");
    solrServer.commit();
    //logger.info("Optimising SOLR index...");
    //solrServer.optimize(); // throws errors on my machine??
    logger.info("Committed to SOLR. Final document count: " + documentCount);
    return documentCount;
}