All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tinkerpop.rexster.extension.ExtensionAllowed Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package com.tinkerpop.rexster.extension;

/**
 * Holds namespaces that define which extensions are allowed for a specific graph.
 *
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public class ExtensionAllowed {
    private final String namespace;

    /**
     * Initializes a new ExtensionAllowed object as taken from rexster.xml.
     * The namespace may be wildcarded to be one of the follows: *:*, namespace:*, namespace:extension
     */
    public ExtensionAllowed(final String namespace) {
        // must match this format *:*, namespace:*, namespace:extension
        if (!(namespace.matches("([\\w-]+|\\*):([\\w-]+|\\*)")
                && !(namespace.startsWith("*") && namespace.equals("*.*")))) {
            throw new IllegalArgumentException("The namespace must match the format of *:*, namespace:*, namespace:extension");
        }

        this.namespace = namespace;
    }

    /**
     * Determines if the namespace and extension are allowed given the configuration of the graph in rexster.xml.
     */
    public boolean isExtensionAllowed(final ExtensionSegmentSet extensionSegmentSet) {
        boolean allowed = false;

        if (this.namespace.equals("*:*")) {
            allowed = true;
        } else if (this.namespace.equals(extensionSegmentSet.getNamespace() + ":*")) {
            allowed = true;
        } else if (this.namespace.equals(extensionSegmentSet.getNamespace() + ":" + extensionSegmentSet.getExtension())) {
            allowed = true;
        }

        return allowed;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy