Java URI Encode encodeUriWithPrefix(String uri)

Here you can find the source of encodeUriWithPrefix(String uri)

Description

Elements (identifiers) used in MDX need to follow certain rules in order to be parseable from and to MDX.

License

Apache License

Parameter

Parameter Description
baseuri The pure uri string to be encoded for MDX

Return

encoded string

Declaration

static String encodeUriWithPrefix(String uri) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    /**//w w  w. j  a  v a 2s.  c  o  m
     * Elements (identifiers) used in MDX need to follow certain rules in order
     * to be parseable from and to MDX. In fact, having it URL encoded is not
     * enough, also, % and . need to be replaced.
     * 
     * @param baseuri
     *            The pure uri string to be encoded for MDX
     * @return encoded string
     */
    static String encodeUriWithPrefix(String uri) {

        // Since we do not manage prefixes, we have to come up with one
        // ourselves
        // (which if possible should be always the same):
        return encodeSpecialMdxCharactersInNames(uri);
    }

    /**
     * We need to make sure that names of multidimensional elements do not carry
     * any MDX special characters.
     * 
     * Note: You can use a bash command for translating a URI into an MDX
     * applicable form:
     * 
     * echo "http://lod.gesis.org/lodpilot/ALLBUS/geo.rdf#list" | sed
     * 's/\./YYY/g' | sed 's/-/ZZZ/g' | sed 's/%/XXX/g'
     * 
     * @param name
     * @return
     */
    public static String encodeSpecialMdxCharactersInNames(String name) {
        try {
            name = URLEncoder.encode(name, "UTF-8");
            name = name.replace("%", "XXX");
            name = name.replace(".", "YYY");
            name = name.replace("-", "ZZZ");
            return name;
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. encodeURIComponent(String uriComp)
  2. encodeUriComponent(String value)
  3. encodeURIComponentForJavaScript(String str)
  4. encodeURIParam(String s)
  5. encodeURIString(Writer out, String text, String encoding, int start)
  6. uriEncode(Object o)
  7. uriEncode(String decoded)
  8. uriEncode(String input)
  9. uriEncodePath(String path)