Example usage for com.fasterxml.jackson.databind JsonNode textValue

List of usage examples for com.fasterxml.jackson.databind JsonNode textValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode textValue.

Prototype

public String textValue() 

Source Link

Usage

From source file:acromusashi.stream.example.spout.JsonExtractor.java

/**
 * {@inheritDoc}//  ww  w .ja v a2s .  c  om
 */
@Override
public String extractMessageKey(Object target) throws RabbitmqCommunicateException {
    // ObjectMapper???????????????
    if (this.mapper == null) {
        this.mapper = new ObjectMapper();
    }

    JsonNode rootJson;
    try {
        // JsonNode???JsonNode_A
        rootJson = this.mapper.readTree(target.toString());
    } catch (IOException ex) {
        throw new RabbitmqCommunicateException(ex);
    }

    // JsonNode_A?????JsonNode_B
    JsonNode parentJson = rootJson.get(PARENT_KEY);
    if (parentJson == null) {
        String message = "Parent Value is not exist.";
        throw new RabbitmqCommunicateException(message);
    }

    // JsonNode_B??????
    JsonNode childJson = parentJson.get(CHILD_KEY);
    if (childJson == null) {
        String message = "Child Value is not exist.";
        throw new RabbitmqCommunicateException(message);
    }

    return childJson.textValue();
}

From source file:com.digitalpebble.storm.crawler.filtering.regex.RegexURLFilterBase.java

@Override
public void configure(Map stormConf, JsonNode paramNode) {
    JsonNode node = paramNode.get("urlFilters");
    if (node != null && node.isArray()) {
        rules = readRules((ArrayNode) node);
    } else {/*from ww w.j a v  a 2 s .com*/
        JsonNode filenameNode = paramNode.get("regexFilterFile");
        String rulesFileName;
        if (filenameNode != null) {
            rulesFileName = filenameNode.textValue();
        } else {
            rulesFileName = "default-regex-filters.txt";
        }
        rules = readRules(rulesFileName);
    }
}

From source file:com.digitalpebble.stormcrawler.protocol.selenium.NavigationFilters.java

@SuppressWarnings("rawtypes")
@Override/*from   www. ja v  a 2s  .  com*/
public void configure(Map stormConf, JsonNode filtersConf) {
    // initialises the filters
    List<NavigationFilter> filterLists = new ArrayList<>();

    // get the filters part
    String name = getClass().getCanonicalName();
    filtersConf = filtersConf.get(name);

    if (filtersConf == null) {
        LOG.info("No field {} in JSON config. Skipping", name);
        filters = new NavigationFilter[0];
        return;
    }

    // conf node contains a list of objects
    Iterator<JsonNode> filterIter = filtersConf.elements();
    while (filterIter.hasNext()) {
        JsonNode afilterConf = filterIter.next();
        String filterName = "<unnamed>";
        JsonNode nameNode = afilterConf.get("name");
        if (nameNode != null) {
            filterName = nameNode.textValue();
        }
        JsonNode classNode = afilterConf.get("class");
        if (classNode == null) {
            LOG.error("Filter {} doesn't specified a 'class' attribute", filterName);
            continue;
        }
        String className = classNode.textValue().trim();
        filterName += '[' + className + ']';
        // check that it is available and implements the interface
        // NavigationFilter
        try {
            Class<?> filterClass = Class.forName(className);
            boolean subClassOK = NavigationFilter.class.isAssignableFrom(filterClass);
            if (!subClassOK) {
                LOG.error("Filter {} does not extend NavigationFilter", filterName);
                continue;
            }
            NavigationFilter filterInstance = (NavigationFilter) filterClass.newInstance();

            JsonNode paramNode = afilterConf.get("params");
            if (paramNode != null) {
                filterInstance.configure(stormConf, paramNode);
            } else {
                // Pass in a nullNode if missing
                filterInstance.configure(stormConf, NullNode.getInstance());
            }

            filterLists.add(filterInstance);
            LOG.info("Setup {}", filterName);
        } catch (Exception e) {
            LOG.error("Can't setup {}: {}", filterName, e);
            throw new RuntimeException("Can't setup " + filterName, e);
        }
    }

    filters = filterLists.toArray(new NavigationFilter[filterLists.size()]);
}

From source file:org.apache.taverna.activities.interaction.InteractionActivity.java

InteractionActivityType getInteractionActivityType() {
    JsonNode subNode = json.get("interactivityActivityType");
    if (subNode == null) {
        return InteractionActivityType.LocallyPresentedHtml;
    }//from w w w  . ja  v a2  s  .co m
    String textValue = subNode.textValue();
    if (textValue == null) {
        return InteractionActivityType.LocallyPresentedHtml;
    }
    if ("VelocityTemplate".equals(textValue)) {
        return InteractionActivityType.VelocityTemplate;
    }
    return InteractionActivityType.LocallyPresentedHtml;
}

From source file:org.eel.kitchen.jsonschema.format.HostnameFormatAttribute.java

@Override
public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report,
        final JsonNode value) {
    final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid hostname").addInfo("value",
            value);/*  w  w w  . j a v a2s. c  o  m*/

    final InternetDomainName hostname;
    try {
        hostname = InternetDomainName.from(value.textValue());
    } catch (IllegalArgumentException ignored) {
        report.addMessage(msg.build());
        return;
    }

    if (ctx.hasFeature(ValidationFeature.STRICT_RFC_CONFORMANCE))
        return;

    if (!hostname.hasParent())
        report.addMessage(msg.build());
}

From source file:com.digitalpebble.storm.crawler.parse.ParseFilters.java

@SuppressWarnings("rawtypes")
@Override/*  w  w w. j a v  a2s  . c  o  m*/
public void configure(Map stormConf, JsonNode filtersConf) {
    // initialises the filters
    List<ParseFilter> filterLists = new ArrayList<>();

    // get the filters part
    String name = getClass().getCanonicalName();
    filtersConf = filtersConf.get(name);

    if (filtersConf == null) {
        LOG.info("No field {} in JSON config. Skipping", name);
        filters = new ParseFilter[0];
        return;
    }

    // conf node contains a list of objects
    Iterator<JsonNode> filterIter = filtersConf.elements();
    while (filterIter.hasNext()) {
        JsonNode afilterConf = filterIter.next();
        String filterName = "<unnamed>";
        JsonNode nameNode = afilterConf.get("name");
        if (nameNode != null) {
            filterName = nameNode.textValue();
        }
        JsonNode classNode = afilterConf.get("class");
        if (classNode == null) {
            LOG.error("Filter {} doesn't specified a 'class' attribute", filterName);
            continue;
        }
        String className = classNode.textValue().trim();
        filterName += '[' + className + ']';
        // check that it is available and implements the interface
        // ParseFilter
        try {
            Class<?> filterClass = Class.forName(className);
            boolean subClassOK = ParseFilter.class.isAssignableFrom(filterClass);
            if (!subClassOK) {
                LOG.error("Filter {} does not extend ParseFilter", filterName);
                continue;
            }
            ParseFilter filterInstance = (ParseFilter) filterClass.newInstance();

            JsonNode paramNode = afilterConf.get("params");
            if (paramNode != null) {
                filterInstance.configure(stormConf, paramNode);
            } else {
                // Pass in a nullNode if missing
                filterInstance.configure(stormConf, NullNode.getInstance());
            }

            filterLists.add(filterInstance);
            LOG.info("Setup {}", filterName);
        } catch (Exception e) {
            LOG.error("Can't setup {}: {}", filterName, e);
            throw new RuntimeException("Can't setup " + filterName, e);
        }
    }

    filters = filterLists.toArray(new ParseFilter[filterLists.size()]);
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.hyperschema.MediaSyntaxChecker.java

@Override
protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle,
        final ProcessingReport report, final SchemaTree tree) throws ProcessingException {
    final JsonNode node = getNode(tree);
    JsonNode subNode;
    NodeType type;/*from   w w  w . ja  v a 2  s . c o  m*/
    String value;

    subNode = node.path(BINARY_ENCODING_FIELDNAME);
    if (!subNode.isMissingNode()) {
        type = NodeType.getNodeType(subNode);
        value = subNode.textValue();
        if (value == null)
            report.error(newMsg(tree, bundle, "draftv4.media.binaryEncoding.incorrectType")
                    .put("expected", NodeType.STRING).putArgument("found", type));
        else if (!BINARY_ENCODINGS.contains(value.toLowerCase()))
            report.error(newMsg(tree, bundle, "draftv4.media.binaryEncoding.invalid")
                    .putArgument("value", value).putArgument("valid", BINARY_ENCODINGS));
    }

    subNode = node.path(TYPE_FIELDNAME);
    if (subNode.isMissingNode())
        return;
    type = NodeType.getNodeType(subNode);
    if (type != NodeType.STRING) {
        report.error(newMsg(tree, bundle, "draftv4.media.type.incorrectType").put("expected", NodeType.STRING)
                .putArgument("found", type));
        return;
    }
    value = subNode.textValue();
    try {
        MediaType.parse(value);
    } catch (IllegalArgumentException ignored) {
        report.error(newMsg(tree, bundle, "draftv4.media.type.notMediaType").putArgument("value", value));
    }
}

From source file:com.github.fge.uritemplate.ExtendedTestsTest.java

@Test(dataProvider = "getData")
public void illegalTemplatesAreMarkedAsSuch(final String tmpl, final VariableMap vars,
        final JsonNode resultNode) throws URITemplateException {
    final URITemplate template = new URITemplate(tmpl);
    final String actual = template.toString(vars);

    if (resultNode.isTextual()) {
        assertEquals(actual, resultNode.textValue());
        return;//from   w  ww . j  a  v  a  2s  . com
    }

    if (!resultNode.isArray())
        throw new RuntimeException("Didn't expect that");

    boolean found = false;
    for (final JsonNode node : resultNode)
        if (node.textValue().equals(actual))
            found = true;

    assertTrue(found, "no value matched expansion");
}

From source file:org.apache.streams.rss.serializer.SyndEntryActivitySerializer.java

/**
 * Given an RSS object, build the ActivityObject
 *
 * @param entry/* w  w w .  j  ava 2  s. c  o  m*/
 * @return
 */
private ActivityObject buildActivityObject(ObjectNode entry) {
    ActivityObject activityObject = new ActivityObject();

    JsonNode summary = entry.get("description");
    if (summary != null)
        activityObject.setSummary(summary.textValue());
    else if ((summary = entry.get("title")) != null) {
        activityObject.setSummary(summary.textValue());
    }

    return activityObject;
}

From source file:com.rusticisoftware.tincan.internal.StatementBase.java

public StatementBase(JsonNode jsonNode) throws URISyntaxException, MalformedURLException {
    this();/*  ww  w . ja va  2 s .  co m*/

    JsonNode actorNode = jsonNode.path("actor");
    if (!actorNode.isMissingNode()) {
        this.setActor(Agent.fromJson(actorNode));
    }

    JsonNode verbNode = jsonNode.path("verb");
    if (!verbNode.isMissingNode()) {
        this.setVerb(new Verb(verbNode));
    }

    JsonNode objectNode = jsonNode.path("object");
    if (!objectNode.isMissingNode()) {
        String objectType = objectNode.path("objectType").textValue();
        if ("Group".equals(objectType) || "Agent".equals(objectType)) {
            this.setObject(Agent.fromJson(objectNode));
        } else if ("StatementRef".equals(objectType)) {
            this.setObject(new StatementRef(objectNode));
        } else if ("SubStatement".equals(objectType)) {
            this.setObject(new SubStatement(objectNode));
        } else {
            this.setObject(new Activity(objectNode));
        }
    }

    JsonNode resultNode = jsonNode.path("result");
    if (!resultNode.isMissingNode()) {
        this.setResult(new Result(resultNode));
    }

    JsonNode contextNode = jsonNode.path("context");
    if (!contextNode.isMissingNode()) {
        this.setContext(new Context(contextNode));
    }

    JsonNode timestampNode = jsonNode.path("timestamp");
    if (!timestampNode.isMissingNode()) {
        this.setTimestamp(new DateTime(timestampNode.textValue()));
    }

    JsonNode voidedNode = jsonNode.path("voided");
    if (!voidedNode.isMissingNode()) {
        this.setVoided(voidedNode.asBoolean());
    }

    JsonNode attachmentsNode = jsonNode.path("attachments");
    if (!attachmentsNode.isMissingNode()) {
        this.attachments = new ArrayList<Attachment>();
        for (JsonNode element : attachmentsNode) {
            this.attachments.add(new Attachment(element));
        }
    }
}