Package org.restlet.data

Examples of org.restlet.data.Parameter


     *         default value.
     */
    public String getFirstValue(String name, boolean ignoreCase,
            String defaultValue) {
        String result = defaultValue;
        Parameter param = getFirst(name, ignoreCase);

        if ((param != null) && (param.getValue() != null)) {
            result = param.getValue();
        }

        return result;
    }
View Full Code Here


     * @param domNode
     *            The DOM node to parse.
     * @return The {@link Parameter} instance.
     */
    private static Parameter parseParameter(Node domNode) {
        Parameter result = null;

        if (!isParameter(domNode)) {
            return null;
        }

        Node nameNode = domNode.getAttributes().getNamedItem("name");
        Node valueNode = domNode.getAttributes().getNamedItem("value");

        if ((nameNode != null) && (valueNode != null)) {
            result = new Parameter(nameNode.getNodeValue(),
                    valueNode.getNodeValue());
        }

        return result;
    }
View Full Code Here

                                    .getLength(); j++) {
                                final Node childNode2 = childNode
                                        .getChildNodes().item(j);

                                if (isParameter(childNode2)) {
                                    Parameter p = parseParameter(childNode2);
                                    if (p != null) {
                                        client.getContext().getParameters()
                                                .add(p);
                                    }
                                }
                            }
                        }
                    } else if ("server".equals(childNode.getNodeName())) {
                        Node item = childNode.getAttributes().getNamedItem(
                                "protocol");
                        final Node portNode = childNode.getAttributes()
                                .getNamedItem("port");
                        final Node addressNode = childNode.getAttributes()
                                .getNamedItem("address");
                        Server server = null;

                        if (item == null) {
                            item = childNode.getAttributes().getNamedItem(
                                    "protocols");

                            if (item != null) {
                                final String[] protocols = item.getNodeValue()
                                        .split(" ");
                                final List<Protocol> protocolsList = new ArrayList<Protocol>();

                                for (final String protocol : protocols) {
                                    protocolsList.add(getProtocol(protocol));
                                }

                                final int port = getInt(portNode,
                                        Protocol.UNKNOWN_PORT);

                                if (port == Protocol.UNKNOWN_PORT) {
                                    getLogger()
                                            .warning(
                                                    "Please specify a port when defining a list of protocols.");
                                } else {
                                    server = new Server(new Context(),
                                            protocolsList, getInt(portNode,
                                                    Protocol.UNKNOWN_PORT),
                                            getComponent().getServers()
                                                    .getNext());
                                }
                            }
                        } else {
                            final Protocol protocol = getProtocol(item
                                    .getNodeValue());
                            server = new Server(
                                    new Context(),
                                    protocol,
                                    getInt(portNode, protocol.getDefaultPort()),
                                    getComponent().getServers().getNext());
                        }

                        if (server != null) {
                            // Look for Restlet's attributes
                            parseRestlet(server, childNode);

                            if (addressNode != null) {
                                final String address = addressNode
                                        .getNodeValue();
                                if (address != null) {
                                    server.setAddress(address);
                                }
                            }

                            // Look for parameters
                            for (int j = 0; j < childNode.getChildNodes()
                                    .getLength(); j++) {
                                final Node childNode2 = childNode
                                        .getChildNodes().item(j);

                                if (isParameter(childNode2)) {
                                    Parameter p = parseParameter(childNode2);
                                    if (p != null) {
                                        server.getContext().getParameters()
                                                .add(p);
                                    }
                                }
                            }

                            getComponent().getServers().add(server);
                        }
                    } else if (isParameter(childNode)) {
                        Parameter p = parseParameter(childNode);

                        if (p != null) {
                            getComponent().getContext().getParameters().add(p);
                        }
                    } else if ("defaultHost".equals(childNode.getNodeName())) {
View Full Code Here

        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);

            if (isParameter(childNode)) {
                Parameter p = parseParameter(childNode);

                if (p != null) {
                    router.getContext().getParameters().add(p);
                }
            } else if ("attach".equals(childNode.getNodeName())
                    || "attachDefault".equals(childNode.getNodeName())) {
                String uriPattern = null;
                Node item = childNode.getAttributes()
                        .getNamedItem("uriPattern");

                if (item != null) {
                    uriPattern = item.getNodeValue();
                } else {
                    uriPattern = "";
                }

                item = childNode.getAttributes().getNamedItem("default");
                boolean bDefault = getBoolean(item, false)
                        || "attachDefault".equals(childNode.getNodeName());

                // Attaches a new route.
                TemplateRoute route = null;
                item = childNode.getAttributes().getNamedItem("targetClass");

                if (item != null) {
                    route = attach(router, item.getNodeValue(), uriPattern,
                            bDefault);
                } else {
                    item = childNode.getAttributes().getNamedItem(
                            "targetDescriptor");
                    if (item != null) {
                        route = attachWithDescriptor(router,
                                item.getNodeValue(), uriPattern, bDefault);
                    } else {
                        getLogger()
                                .log(Level.WARNING,
                                        "Both targetClass name and targetDescriptor are missing. Couldn't attach a new route.");
                    }
                }

                if (route != null) {
                    Template template = route.getTemplate();
                    item = childNode.getAttributes().getNamedItem(
                            "matchingMode");
                    template.setMatchingMode(getInt(item,
                            router.getDefaultMatchingMode()));
                    item = childNode.getAttributes().getNamedItem(
                            "defaultVariableType");
                    template.getDefaultVariable().setType(
                            getInt(item, Variable.TYPE_URI_SEGMENT));

                    // Parse possible parameters specific to this AttachType
                    final NodeList childNodes2 = childNode.getChildNodes();
                    for (int j = 0; j < childNodes2.getLength(); j++) {
                        Node aNode = childNodes2.item(j);
                        if (isParameter(aNode)) {
                            Parameter p = parseParameter(aNode);
                            if (p != null) {
                                route.getNext().getContext().getParameters()
                                        .add(p);
                            }
                        }
View Full Code Here

     *            Indicates if the name comparison is case insensitive.
     * @return True if the list changed.
     */
    public boolean removeAll(String name, boolean ignoreCase) {
        boolean changed = false;
        Parameter param = null;

        for (final Iterator<E> iter = iterator(); iter.hasNext();) {
            param = iter.next();
            if (equals(param.getName(), name, ignoreCase)) {
                iter.remove();
                changed = true;
            }
        }

View Full Code Here

     *            Indicates if the name comparison is case insensitive.
     * @return false if no entry has been removed, true otherwise.
     */
    public boolean removeFirst(String name, boolean ignoreCase) {
        boolean changed = false;
        Parameter param = null;

        for (final Iterator<E> iter = iterator(); iter.hasNext() && !changed;) {
            param = iter.next();
            if (equals(param.getName(), name, ignoreCase)) {
                iter.remove();
                changed = true;
            }
        }

View Full Code Here

     * @return The media parameters.
     */
    protected Series<Parameter> extractMediaParams(Series<Parameter> parameters) {
        Series<Parameter> result = null;
        boolean qualityFound = false;
        Parameter param = null;

        if (parameters != null) {
            result = new Form();

            for (final Iterator<Parameter> iter = parameters.iterator(); !qualityFound
                    && iter.hasNext();) {
                param = iter.next();

                if (param.getName().equals("q")) {
                    qualityFound = true;
                } else {
                    iter.remove();
                    result.add(param);
                }
View Full Code Here

    protected float extractQuality(Series<Parameter> parameters) {
        float result = 1F;
        boolean found = false;

        if (parameters != null) {
            Parameter param = null;
            for (final Iterator<Parameter> iter = parameters.iterator(); !found
                    && iter.hasNext();) {
                param = iter.next();
                if (param.getName().equals("q")) {
                    result = readQuality(param.getValue());
                    found = true;

                    // Remove the quality parameter as we will directly store it
                    // in the Preference object
                    iter.remove();
View Full Code Here

        if (type.length() > 0) {
            result = new Disposition();
            result.setType(type);

            if (skipParameterSeparator()) {
                Parameter param = readParameter();

                while (param != null) {
                    result.getParameters().add(param);

                    if (skipParameterSeparator()) {
View Full Code Here

            append(";q=");
            appendQuality(pref.getQuality());
        }

        if (pref.getParameters() != null) {
            Parameter param;

            for (Iterator<Parameter> iter = pref.getParameters().iterator(); iter
                    .hasNext();) {
                param = iter.next();

                if (param.getName() != null) {
                    append(';').append(param.getName());

                    if ((param.getValue() != null)
                            && (param.getValue().length() > 0)) {
                        append('=').append(param.getValue());
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.restlet.data.Parameter

Copyright © 2018 www.massapicom. 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.