Example usage for java.net URI getFragment

List of usage examples for java.net URI getFragment

Introduction

In this page you can find the example usage for java.net URI getFragment.

Prototype

public String getFragment() 

Source Link

Document

Returns the decoded fragment component of this URI.

Usage

From source file:org.xdi.oxauth.ws.rs.UserInfoRestWebServiceEmbeddedTest.java

@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestUserInfoAdditionalClaims(final String authorizePath, final String userId,
        final String userSecret, final String redirectUri) throws Exception {

    final String state = UUID.randomUUID().toString();

    new ResourceRequestEnvironment.ResourceRequest(new ResourceRequestEnvironment(this), Method.GET,
            authorizePath) {/* ww  w  . ja  v a 2 s  .c o m*/

        @Override
        protected void prepareRequest(EnhancedMockHttpServletRequest request) {
            super.prepareRequest(request);

            List<ResponseType> responseTypes = new ArrayList<ResponseType>();
            responseTypes.add(ResponseType.TOKEN);
            List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
            String nonce = UUID.randomUUID().toString();

            AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId,
                    scopes, redirectUri, nonce);
            authorizationRequest.setState(state);
            authorizationRequest.getPrompts().add(Prompt.NONE);
            authorizationRequest.setAuthUsername(userId);
            authorizationRequest.setAuthPassword(userSecret);

            JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest,
                    SignatureAlgorithm.HS256, clientSecret);
            jwtAuthorizationRequest.addUserInfoClaim(new Claim("invalid", ClaimValue.createEssential(false)));
            jwtAuthorizationRequest.addUserInfoClaim(new Claim("iname", ClaimValue.createNull()));
            jwtAuthorizationRequest.addUserInfoClaim(new Claim("o", ClaimValue.createEssential(true)));

            String authJwt = jwtAuthorizationRequest.getEncodedJwt();
            authorizationRequest.setRequest(authJwt);
            System.out.println("Request JWT: " + authJwt);

            request.addHeader("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
            request.addHeader("Accept", MediaType.TEXT_PLAIN);
            request.setQueryString(authorizationRequest.getQueryString());
        }

        @Override
        protected void onResponse(EnhancedMockHttpServletResponse response) {
            super.onResponse(response);
            showResponse("requestUserInfoAdditionalClaims step 1", response);

            assertEquals(response.getStatus(), 302, "Unexpected response code.");
            assertNotNull(response.getHeader("Location"),
                    "Unexpected result: " + response.getHeader("Location"));

            if (response.getHeader("Location") != null) {
                try {
                    URI uri = new URI(response.getHeader("Location").toString());
                    assertNotNull(uri.getFragment(), "Fragment is null");

                    Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());

                    assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
                    assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
                    assertNotNull(params.get(AuthorizeResponseParam.EXPIRES_IN),
                            "The expires in value is null");
                    assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope must be null");
                    assertNull(params.get("refresh_token"), "The refresh_token must be null");
                    assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
                    assertEquals(params.get(AuthorizeResponseParam.STATE), state);

                    accessToken3 = params.get(AuthorizeResponseParam.ACCESS_TOKEN);
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                    fail("Response URI is not well formed");
                } catch (Exception e) {
                    e.printStackTrace();
                    fail(e.getMessage());
                }
            }
        }
    }.run();
}

From source file:org.dita.dost.module.reader.AbstractReaderModule.java

/**
 * Categorize current file type//  ww w. j av  a2  s  .c  om
 *
 * @param ref file path
 */
void categorizeCurrentFile(final Reference ref) {
    final URI currentFile = ref.filename;
    if (listFilter.hasConaction()) {
        conrefpushSet.add(currentFile);
    }

    if (listFilter.hasConRef()) {
        conrefSet.add(currentFile);
    }

    if (listFilter.hasKeyRef()) {
        keyrefSet.add(currentFile);
    }

    if (listFilter.hasCodeRef()) {
        coderefSet.add(currentFile);
    }

    if (listFilter.isDitaTopic()) {
        if (ref.format != null && !ref.format.equals(ATTR_FORMAT_VALUE_DITA)) {
            assert currentFile.getFragment() == null;
            final URI f = currentFile.normalize();
            if (!fileinfos.containsKey(f)) {
                final FileInfo i = new FileInfo.Builder()
                        .uri(tempFileNameScheme.generateTempFileName(currentFile)).src(currentFile)
                        .format(ref.format).build();
                fileinfos.put(i.src, i);
            }
        }
        fullTopicSet.add(currentFile);
        hrefTargetSet.add(currentFile);
        if (listFilter.hasHref()) {
            hrefTopicSet.add(currentFile);
        }
    } else if (listFilter.isDitaMap()) {
        fullMapSet.add(currentFile);
    }
}

From source file:com.amazonservices.mws.client.MwsConnection.java

/**
 * Sets service endpoint property./*from   w w w  .  jav a 2 s .  c  o m*/
 * 
 * @param endpoint
 *            The service end point URI.
 * 
 */
public synchronized void setEndpoint(URI endpoint) {
    checkUpdatable();
    int port = endpoint.getPort();
    if (port == 80 || port == 443) {
        if (MwsUtl.usesStandardPort(endpoint)) {
            try {
                //some versions of apache http client cause signature errors when
                //standard port is explicitly used, so remove that case.
                endpoint = new URI(endpoint.getScheme(), endpoint.getHost(), endpoint.getPath(),
                        endpoint.getFragment());
            } catch (URISyntaxException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
    this.endpoint = endpoint;
}

From source file:org.apache.hive.jdbc.Utils.java

/**
 * Parse JDBC connection URL/*  w  ww.j a v  a2 s.  co  m*/
 * The new format of the URL is:
 * jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?hive_conf_list#hive_var_list
 * where the optional sess, conf and var lists are semicolon separated <key>=<val> pairs.
 * For utilizing dynamic service discovery with HiveServer2 multiple comma separated host:port pairs can
 * be specified as shown above.
 * The JDBC driver resolves the list of uris and picks a specific server instance to connect to.
 * Currently, dynamic service discovery using ZooKeeper is supported, in which case the host:port pairs represent a ZooKeeper ensemble.
 *
 * As before, if the host/port is not specified, it the driver runs an embedded hive.
 * examples -
 *  jdbc:hive2://ubuntu:11000/db2?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID
 *  jdbc:hive2://?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID
 *  jdbc:hive2://ubuntu:11000/db2;user=foo;password=bar
 *
 *  Connect to http://server:10001/hs2, with specified basicAuth credentials and initial database:
 *  jdbc:hive2://server:10001/db;user=foo;password=bar?hive.server2.transport.mode=http;hive.server2.thrift.http.path=hs2
 *
 * @param uri
 * @return
 * @throws SQLException
 */
public static JdbcConnectionParams parseURL(String uri)
        throws JdbcUriParseException, SQLException, ZooKeeperHiveClientException {
    JdbcConnectionParams connParams = new JdbcConnectionParams();

    if (!uri.startsWith(URL_PREFIX)) {
        throw new JdbcUriParseException("Bad URL format: Missing prefix " + URL_PREFIX);
    }

    // For URLs with no other configuration
    // Don't parse them, but set embedded mode as true
    if (uri.equalsIgnoreCase(URL_PREFIX)) {
        connParams.setEmbeddedMode(true);
        return connParams;
    }

    // The JDBC URI now supports specifying multiple host:port if dynamic service discovery is
    // configured on HiveServer2 (like: host1:port1,host2:port2,host3:port3)
    // We'll extract the authorities (host:port combo) from the URI, extract session vars, hive
    // confs & hive vars by parsing it as a Java URI.
    // To parse the intermediate URI as a Java URI, we'll give a dummy authority(dummy:00000).
    // Later, we'll substitute the dummy authority for a resolved authority.
    String dummyAuthorityString = "dummyhost:00000";
    String suppliedAuthorities = getAuthorities(uri, connParams);
    if ((suppliedAuthorities == null) || (suppliedAuthorities.isEmpty())) {
        // Given uri of the form:
        // jdbc:hive2:///dbName;sess_var_list?hive_conf_list#hive_var_list
        connParams.setEmbeddedMode(true);
    } else {
        LOG.info("Supplied authorities: " + suppliedAuthorities);
        String[] authorityList = suppliedAuthorities.split(",");
        connParams.setSuppliedAuthorityList(authorityList);
        uri = uri.replace(suppliedAuthorities, dummyAuthorityString);
    }

    // Now parse the connection uri with dummy authority
    URI jdbcURI = URI.create(uri.substring(URI_JDBC_PREFIX.length()));

    // key=value pattern
    Pattern pattern = Pattern.compile("([^;]*)=([^;]*)[;]?");

    // dbname and session settings
    String sessVars = jdbcURI.getPath();
    if ((sessVars != null) && !sessVars.isEmpty()) {
        String dbName = "";
        // removing leading '/' returned by getPath()
        sessVars = sessVars.substring(1);
        if (!sessVars.contains(";")) {
            // only dbname is provided
            dbName = sessVars;
        } else {
            // we have dbname followed by session parameters
            dbName = sessVars.substring(0, sessVars.indexOf(';'));
            sessVars = sessVars.substring(sessVars.indexOf(';') + 1);
            if (sessVars != null) {
                Matcher sessMatcher = pattern.matcher(sessVars);
                while (sessMatcher.find()) {
                    if (connParams.getSessionVars().put(sessMatcher.group(1), sessMatcher.group(2)) != null) {
                        throw new JdbcUriParseException(
                                "Bad URL format: Multiple values for property " + sessMatcher.group(1));
                    }
                }
            }
        }
        if (!dbName.isEmpty()) {
            connParams.setDbName(dbName);
        }
    }

    // parse hive conf settings
    String confStr = jdbcURI.getQuery();
    if (confStr != null) {
        Matcher confMatcher = pattern.matcher(confStr);
        while (confMatcher.find()) {
            connParams.getHiveConfs().put(confMatcher.group(1), confMatcher.group(2));
        }
    }

    // parse hive var settings
    String varStr = jdbcURI.getFragment();
    if (varStr != null) {
        Matcher varMatcher = pattern.matcher(varStr);
        while (varMatcher.find()) {
            connParams.getHiveVars().put(varMatcher.group(1), varMatcher.group(2));
        }
    }

    // Handle all deprecations here:
    String newUsage;
    String usageUrlBase = "jdbc:hive2://<host>:<port>/dbName;";
    // Handle deprecation of AUTH_QOP_DEPRECATED
    newUsage = usageUrlBase + JdbcConnectionParams.AUTH_QOP + "=<qop_value>";
    handleParamDeprecation(connParams.getSessionVars(), connParams.getSessionVars(),
            JdbcConnectionParams.AUTH_QOP_DEPRECATED, JdbcConnectionParams.AUTH_QOP, newUsage);

    // Handle deprecation of TRANSPORT_MODE_DEPRECATED
    newUsage = usageUrlBase + JdbcConnectionParams.TRANSPORT_MODE + "=<transport_mode_value>";
    handleParamDeprecation(connParams.getHiveConfs(), connParams.getSessionVars(),
            JdbcConnectionParams.TRANSPORT_MODE_DEPRECATED, JdbcConnectionParams.TRANSPORT_MODE, newUsage);

    // Handle deprecation of HTTP_PATH_DEPRECATED
    newUsage = usageUrlBase + JdbcConnectionParams.HTTP_PATH + "=<http_path_value>";
    handleParamDeprecation(connParams.getHiveConfs(), connParams.getSessionVars(),
            JdbcConnectionParams.HTTP_PATH_DEPRECATED, JdbcConnectionParams.HTTP_PATH, newUsage);

    // Extract host, port
    if (connParams.isEmbeddedMode()) {
        // In case of embedded mode we were supplied with an empty authority.
        // So we never substituted the authority with a dummy one.
        connParams.setHost(jdbcURI.getHost());
        connParams.setPort(jdbcURI.getPort());
    } else {
        // Else substitute the dummy authority with a resolved one.
        // In case of dynamic service discovery using ZooKeeper, it picks a server uri from ZooKeeper
        String resolvedAuthorityString = resolveAuthority(connParams);
        LOG.info("Resolved authority: " + resolvedAuthorityString);
        uri = uri.replace(dummyAuthorityString, resolvedAuthorityString);
        connParams.setJdbcUriString(uri);
        // Create a Java URI from the resolved URI for extracting the host/port
        URI resolvedAuthorityURI = null;
        try {
            resolvedAuthorityURI = new URI(null, resolvedAuthorityString, null, null, null);
        } catch (URISyntaxException e) {
            throw new JdbcUriParseException("Bad URL format: ", e);
        }
        connParams.setHost(resolvedAuthorityURI.getHost());
        connParams.setPort(resolvedAuthorityURI.getPort());
    }

    return connParams;
}

From source file:org.eclipse.scada.configuration.recipe.lib.internal.DefaultExecutableFactory.java

private Executable lookupByUri(final String name, final Execute execute, final RunnerContext ctx) {
    logger.debug("Looking up by uri - name: {}, execute: {}", name, execute);

    try {//from w  w  w  .jav a  2s  .  c  o m
        final URI uri = new URI(name);
        if (!"bundle-class".equals(uri.getScheme())) {
            logger.debug("Wrong URI scheme: {}", uri.getScheme());
            return null;
        }

        final String host = uri.getHost();

        String clazzName = uri.getPath();
        if (clazzName.startsWith("/")) {
            // cut of first slash
            clazzName = clazzName.substring(1);
        }

        if (clazzName.startsWith(".")) {
            clazzName = host + clazzName;
        }

        final Class<?> clazz = findBundle(host, clazzName);

        if (Executable.class.isAssignableFrom(clazz)) {
            logger.debug("Return by Executable interface");
            if (clazz.isAnnotationPresent(Singleton.class)) {
                if (!ctx.getSingletons().containsKey(clazz)) {
                    ctx.getSingletons().put(clazz, clazz.newInstance());
                }
                return (Executable) ctx.getSingletons().get(clazz);
            } else {
                return (Executable) clazz.newInstance();
            }
        } else {
            String fragment = uri.getFragment();
            if (fragment == null) {
                fragment = "execute";
            }

            logger.debug("Return by call wrapper: #{}", fragment);
            return createCallWrapper(name, clazz, fragment, execute, ctx);
        }
    } catch (final Exception e) {
        logger.info("Failed to lookup", e);
        return null;
    }
}

From source file:fr.gael.dhus.olingo.v1.V1Processor.java

private URI makeLink(boolean remove_last_segment) throws ODataException {
    URI selfLnk = getServiceRoot();
    StringBuilder sb = new StringBuilder(selfLnk.getPath());

    if (remove_last_segment) {
        // Removes the last segment.
        int lio = sb.lastIndexOf("/");
        while (lio != -1 && lio == sb.length() - 1) {
            sb.deleteCharAt(lio);/*from   w  w w . ja v a  2  s.co  m*/
            lio = sb.lastIndexOf("/");
        }
        if (lio != -1)
            sb.delete(lio + 1, sb.length());

        // Removes the `$links` segment.
        lio = sb.lastIndexOf("$links/");
        if (lio != -1)
            sb.delete(lio, lio + 7);
    } else {
        if (!sb.toString().endsWith("/") && !sb.toString().endsWith("\\")) {
            sb.append("/");
        }
    }
    try {
        URI res = new URI(selfLnk.getScheme(), selfLnk.getUserInfo(), selfLnk.getHost(), selfLnk.getPort(),
                sb.toString(), null, selfLnk.getFragment());
        return res;
    } catch (Exception e) {
        throw new ODataException(e);
    }
}

From source file:org.orbisgis.view.geocatalog.Catalog.java

/**
 * The user can load several WMS layers from the same server.
 *//*w  w w .ja  v a2s.c o m*/
public void onMenuAddWMSServer() {
    DataManager dm = Services.getService(DataManager.class);
    SourceManager sm = dm.getSourceManager();
    SRSPanel srsPanel = new SRSPanel();
    LayerConfigurationPanel layerConfiguration = new LayerConfigurationPanel(srsPanel);
    WMSConnectionPanel wmsConnection = new WMSConnectionPanel(layerConfiguration);
    if (UIFactory.showDialog(new UIPanel[] { wmsConnection, layerConfiguration, srsPanel })) {
        WMService service = wmsConnection.getServiceDescription();
        Capabilities cap = service.getCapabilities();
        MapImageFormatChooser mfc = new MapImageFormatChooser(service.getVersion());
        mfc.setTransparencyRequired(true);
        String validImageFormat = mfc.chooseFormat(cap.getMapFormats());
        if (validImageFormat == null) {
            LOGGER.error(I18N.tr("Cannot find a valid image format for this WMS server"));
        } else {
            Object[] layers = layerConfiguration.getSelectedLayers();
            for (Object layer : layers) {
                String layerName = ((MapLayer) layer).getName();
                String uniqueLayerName = layerName;
                if (sm.exists(layerName)) {
                    uniqueLayerName = sm.getUniqueName(layerName);
                }
                URI origin = URI.create(service.getServerUrl());
                StringBuilder url = new StringBuilder(origin.getQuery());
                url.append("SERVICE=WMS&REQUEST=GetMap");
                String version = service.getVersion();
                url.append("&VERSION=").append(version);
                if (WMService.WMS_1_3_0.equals(version)) {
                    url.append("&CRS=");
                } else {
                    url.append("&SRS=");
                }
                url.append(srsPanel.getSRS());
                url.append("&LAYERS=").append(layerName);
                url.append("&FORMAT=").append(validImageFormat);
                try {
                    URI streamUri = new URI(origin.getScheme(), origin.getUserInfo(), origin.getHost(),
                            origin.getPort(), origin.getPath(), url.toString(), origin.getFragment());
                    WMSStreamSource wmsSource = new WMSStreamSource(streamUri);
                    StreamSourceDefinition streamSourceDefinition = new StreamSourceDefinition(wmsSource);
                    sm.register(uniqueLayerName, streamSourceDefinition);
                } catch (UnsupportedEncodingException uee) {
                    LOGGER.error(I18N.tr("Can't read the given URI: " + uee.getCause()));
                } catch (URISyntaxException use) {
                    LOGGER.error(I18N.tr("The given URI contains illegal character"), use);
                }
            }
        }
    }
}

From source file:org.apache.tez.client.TezClientUtils.java

private static boolean addLocalResources(Configuration conf, String[] configUris,
        Map<String, LocalResource> tezJarResources, Credentials credentials) throws IOException {
    boolean usingTezArchive = false;
    if (configUris == null || configUris.length == 0) {
        return usingTezArchive;
    }/*from  w w  w  .  jav a  2s .c om*/
    List<Path> configuredPaths = Lists.newArrayListWithCapacity(configUris.length);
    for (String configUri : configUris) {
        URI u = null;
        try {
            u = new URI(configUri);
        } catch (URISyntaxException e) {
            throw new IOException("Unable to convert " + configUri + "to URI", e);
        }
        Path p = new Path(u);
        FileSystem remoteFS = p.getFileSystem(conf);
        p = remoteFS.resolvePath(p.makeQualified(remoteFS.getUri(), remoteFS.getWorkingDirectory()));

        LocalResourceType type = null;

        //Check if path is an archive
        if (p.getName().endsWith(".tar.gz") || p.getName().endsWith(".tgz") || p.getName().endsWith(".zip")
                || p.getName().endsWith(".tar")) {
            type = LocalResourceType.ARCHIVE;
        } else {
            type = LocalResourceType.FILE;
        }

        FileStatus[] fileStatuses = getLRFileStatus(configUri, conf);

        for (FileStatus fStatus : fileStatuses) {
            String linkName;
            if (fStatus.isDirectory()) {
                // Skip directories - no recursive search support.
                continue;
            }
            // If the resource is an archive, we've already done this work
            if (type != LocalResourceType.ARCHIVE) {
                u = fStatus.getPath().toUri();
                p = new Path(u);
                remoteFS = p.getFileSystem(conf);
                p = remoteFS.resolvePath(p.makeQualified(remoteFS.getUri(), remoteFS.getWorkingDirectory()));
                if (null != u.getFragment()) {
                    LOG.warn("Fragment set for link being interpreted as a file," + "URI: " + u.toString());
                }
            }

            // Add URI fragment or just the filename
            Path name = new Path((null == u.getFragment()) ? p.getName() : u.getFragment());
            if (name.isAbsolute()) {
                throw new IllegalArgumentException("Resource name must be " + "relative, not absolute: " + name
                        + " in URI: " + u.toString());
            }

            URL url = ConverterUtils.getYarnUrlFromURI(p.toUri());
            linkName = name.toUri().getPath();
            // For legacy reasons, set archive to tezlib if there is
            // only a single archive and no fragment
            if (type == LocalResourceType.ARCHIVE && configUris.length == 1 && null == u.getFragment()) {
                linkName = TezConstants.TEZ_TAR_LR_NAME;
                usingTezArchive = true;
            }

            LocalResourceVisibility lrVisibility;
            if (checkAncestorPermissionsForAllUsers(conf, p, FsAction.EXECUTE)
                    && fStatus.getPermission().getOtherAction().implies(FsAction.READ)) {
                lrVisibility = LocalResourceVisibility.PUBLIC;
            } else {
                lrVisibility = LocalResourceVisibility.PRIVATE;
            }

            if (tezJarResources.containsKey(linkName)) {
                String message = "Duplicate resource found" + ", resourceName=" + linkName + ", existingPath="
                        + tezJarResources.get(linkName).getResource().toString() + ", newPath="
                        + fStatus.getPath();
                LOG.warn(message);
            }

            tezJarResources.put(linkName, LocalResource.newInstance(url, type, lrVisibility, fStatus.getLen(),
                    fStatus.getModificationTime()));
            configuredPaths.add(fStatus.getPath());
        }
    }
    // Obtain credentials.
    if (!configuredPaths.isEmpty()) {
        TokenCache.obtainTokensForFileSystems(credentials,
                configuredPaths.toArray(new Path[configuredPaths.size()]), conf);
    }
    return usingTezArchive;
}

From source file:com.snowplowanalytics.snowplow.hadoop.hive.SnowPlowEventStruct.java

/**
 * Parses the input row String into a Java object.
 * For performance reasons this works in-place updating the fields
 * within this SnowPlowEventStruct, rather than creating a new one.
 *
 * @param row The raw String containing the row contents
 * @return true if row was successfully parsed, false otherwise
 * @throws SerDeException For any exception during parsing
 *///from   w ww. j  a  va  2  s  . com
public boolean updateByParsing(String row) throws SerDeException {

    // First we reset the object's fields
    nullify();

    // We have to handle any header rows
    if (row.startsWith("#Version:") || row.startsWith("#Fields:")) {
        return false; // Empty row will be discarded by Hive
    }

    final Matcher m = cfRegex.matcher(row);

    // 0. First check our row is kosher

    // -> is row from a CloudFront log? Will throw an exception if not
    if (!m.matches())
        throw new SerDeException("Row does not match expected CloudFront regexp pattern");

    // -> was generated by sp.js? If not (e.g. favicon.ico request), then silently return
    final String object = m.group(8);
    final String querystring = m.group(12);
    if (!(object.startsWith("/ice.png") || object.equals("/i") || object.startsWith("/i?"))
            || isNullField(querystring)) { // Also works if Forward Query String = yes
        return false;
    }

    // 1. Now we retrieve the fields which get directly passed through
    this.dt = m.group(1);
    this.collector_dt = this.dt;
    this.collector_tm = m.group(2); // CloudFront date format matches Hive's
    this.user_ipaddress = m.group(5);

    // 2. Now grab the user agent
    final String ua = m.group(11);
    try {
        this.useragent = decodeSafeString(ua);
    } catch (Exception e) {
        getLog().warn(e.getClass().getSimpleName() + " on { useragent: " + ua + " }");
    }

    // 3. Next we dis-assemble the user agent...
    final UserAgent userAgent = UserAgent.parseUserAgentString(ua);

    // -> browser fields
    final Browser b = userAgent.getBrowser();
    this.br_name = b.getName();
    this.br_family = b.getGroup().getName();
    final Version v = userAgent.getBrowserVersion();
    this.br_version = (v == null) ? null : v.getVersion();
    this.br_type = b.getBrowserType().getName();
    this.br_renderengine = b.getRenderingEngine().toString();

    // -> OS-related fields
    final OperatingSystem os = userAgent.getOperatingSystem();
    this.os_name = os.getName();
    this.os_family = os.getGroup().getName();
    this.os_manufacturer = os.getManufacturer().getName();

    // -> device/hardware-related fields
    this.dvce_type = os.getDeviceType().getName();
    this.dvce_ismobile = os.isMobileDevice();
    this.dvce_ismobile_bt = (byte) (this.dvce_ismobile ? 1 : 0);

    // 4. Now for the versioning (tracker versioning is handled below)
    this.v_collector = collectorVersion;
    this.v_etl = "serde-" + ProjectSettings.VERSION;

    // 5. Now we generate the event vendor and ID
    this.event_vendor = eventVendor; // TODO: this becomes part of the protocol eventually
    this.event_id = generateEventId();

    // 6. Now we dis-assemble the querystring.
    String qsUrl = null; // We use this in the block below, and afterwards
    List<NameValuePair> params = null; // We re-use this for efficiency
    try {
        params = URLEncodedUtils.parse(URI.create("http://localhost/?" + querystring), cfEncoding);

        // For performance, don't convert to a map, just loop through and match to our variables as we go
        for (NameValuePair pair : params) {

            final String name = pair.getName();
            final String value = pair.getValue();

            final QuerystringFields field;
            try {
                field = QuerystringFields.valueOf(name.toUpperCase()); // Java pre-7 can't switch on a string, so hash the string
            } catch (IllegalArgumentException e) {
                getLog().warn("Unexpected params { " + name + ": " + value + " }");
                continue;
            }

            try {
                switch (field) {
                // Common fields
                case E:
                    this.event = asEventType(value);
                    break;
                case IP:
                    this.user_ipaddress = value;
                    break;
                case AID:
                    this.app_id = value;
                    break;
                case P:
                    this.platform = value;
                    break;
                case TID:
                    this.txn_id = value;
                    break;
                case UID:
                    this.user_id = value;
                    break;
                case DUID:
                    this.domain_userid = value;
                    break;
                case NUID:
                    this.network_userid = value;
                    break;
                case FP:
                    this.user_fingerprint = value;
                    break;
                case VID:
                    this.domain_sessionidx = Integer.parseInt(value);
                    break;
                case DTM:
                    // Set our dvce_dt, _tm and _epoch fields
                    this.dvce_epoch = Long.parseLong(value);
                    Date deviceDate = new Date(this.dvce_epoch);
                    this.dvce_dt = dateFormat.format(deviceDate);
                    this.dvce_tm = timeFormat.format(deviceDate);
                    break;
                case TV:
                    this.v_tracker = value;
                    break;
                case LANG:
                    this.br_lang = value;
                    break;
                case CS:
                    this.doc_charset = value;
                    break;
                case VP:
                    String[] viewport = value.split("x");
                    if (viewport.length != 2)
                        throw new Exception("Couldn't parse vp field");
                    this.br_viewwidth = Integer.parseInt(viewport[0]);
                    this.br_viewheight = Integer.parseInt(viewport[1]);
                    break;
                case DS:
                    String[] docsize = value.split("x");
                    if (docsize.length != 2)
                        throw new Exception("Couldn't parse ds field");
                    this.doc_width = Integer.parseInt(docsize[0]);
                    this.doc_height = Integer.parseInt(docsize[1]);
                    break;
                case F_PDF:
                    if ((this.br_features_pdf = stringToByte(value)) == 1)
                        this.br_features.add("pdf");
                    break;
                case F_FLA:
                    if ((this.br_features_flash = stringToByte(value)) == 1)
                        this.br_features.add("fla");
                    break;
                case F_JAVA:
                    if ((this.br_features_java = stringToByte(value)) == 1)
                        this.br_features.add("java");
                    break;
                case F_DIR:
                    if ((this.br_features_director = stringToByte(value)) == 1)
                        this.br_features.add("dir");
                    break;
                case F_QT:
                    if ((this.br_features_quicktime = stringToByte(value)) == 1)
                        this.br_features.add("qt");
                    break;
                case F_REALP:
                    if ((this.br_features_realplayer = stringToByte(value)) == 1)
                        this.br_features.add("realp");
                    break;
                case F_WMA:
                    if ((this.br_features_windowsmedia = stringToByte(value)) == 1)
                        this.br_features.add("wma");
                    break;
                case F_GEARS:
                    if ((this.br_features_gears = stringToByte(value)) == 1)
                        this.br_features.add("gears");
                    break;
                case F_AG:
                    if ((this.br_features_silverlight = stringToByte(value)) == 1)
                        this.br_features.add("ag");
                    break;
                case COOKIE:
                    this.br_cookies = stringToBoolean(value);
                    this.br_cookies_bt = (byte) (this.br_cookies ? 1 : 0);
                    break;
                case RES:
                    String[] resolution = value.split("x");
                    if (resolution.length != 2)
                        throw new Exception("Couldn't parse res field");
                    this.dvce_screenwidth = Integer.parseInt(resolution[0]);
                    this.dvce_screenheight = Integer.parseInt(resolution[1]);
                    break;
                case CD:
                    this.br_colordepth = value;
                    break;
                case TZ:
                    this.os_timezone = decodeSafeString(value);
                    break;
                case REFR:
                    this.page_referrer = decodeSafeString(value);
                    break;
                case URL:
                    qsUrl = pair.getValue(); // We might use this later for the page URL
                    break;

                // Page-view only
                case PAGE:
                    this.page_title = decodeSafeString(value);
                    break;

                // Event only
                case EV_CA:
                    this.ev_category = decodeSafeString(value);
                    break;
                case EV_AC:
                    this.ev_action = decodeSafeString(value);
                    break;
                case EV_LA:
                    this.ev_label = decodeSafeString(value);
                    break;
                case EV_PR:
                    this.ev_property = decodeSafeString(value);
                    break;
                case EV_VA:
                    this.ev_value = decodeSafeString(value);
                    break;

                // Ecommerce
                case TR_ID:
                    this.tr_orderid = decodeSafeString(value);
                    break;
                case TR_AF:
                    this.tr_affiliation = decodeSafeString(value);
                    break;
                case TR_TT:
                    this.tr_total = decodeSafeString(value);
                    break;
                case TR_TX:
                    this.tr_tax = decodeSafeString(value);
                    break;
                case TR_SH:
                    this.tr_shipping = decodeSafeString(value);
                    break;
                case TR_CI:
                    this.tr_city = decodeSafeString(value);
                    break;
                case TR_ST:
                    this.tr_state = decodeSafeString(value);
                    break;
                case TR_CO:
                    this.tr_country = decodeSafeString(value);
                    break;
                case TI_ID:
                    this.ti_orderid = decodeSafeString(value);
                    break;
                case TI_SK:
                    this.ti_sku = decodeSafeString(value);
                    break;
                case TI_NA:
                    this.ti_name = decodeSafeString(value);
                    break;
                case TI_CA:
                    this.ti_category = decodeSafeString(value);
                    break;
                case TI_PR:
                    this.ti_price = decodeSafeString(value);
                    break;
                case TI_QU:
                    this.ti_quantity = decodeSafeString(value);
                    break;

                // Page pings
                case PP_MIX:
                    this.pp_xoffset_min = Integer.parseInt(value);
                    break;
                case PP_MAX:
                    this.pp_xoffset_max = Integer.parseInt(value);
                    break;
                case PP_MIY:
                    this.pp_yoffset_min = Integer.parseInt(value);
                    break;
                case PP_MAY:
                    this.pp_yoffset_max = Integer.parseInt(value);
                    break;
                }
            } catch (Exception e) {
                getLog().warn(e.getClass().getSimpleName() + " on { " + name + ": " + value + " }");
            }
        }
    } catch (IllegalArgumentException e) {
        getLog().warn("Corrupted querystring { " + querystring + " }");
    }

    // 7. Choose the page_url
    final String cfUrl = m.group(10);
    if (!isNullField(cfUrl)) { // CloudFront didn't provide the URL as cs(Referer)
        this.page_url = cfUrl; // The CloudFront cs(Referer) URL
    } else {
        try {
            this.page_url = decodeSafeString(qsUrl); // Use the decoded querystring URL. Might be null (returned as null)
        } catch (Exception e) {
            getLog().warn(e.getClass().getSimpleName() + " on { qsUrl: " + qsUrl + " }");
        }
    }

    // 8. Now try to convert the page_url into a valid Java URI and store the 6 out of 9 components we are interested in:
    try {
        final URI pageUri = URI.create(this.page_url);
        this.page_urlscheme = pageUri.getScheme();
        this.page_urlhost = pageUri.getHost();
        final Integer port = pageUri.getPort();
        this.page_urlport = (port == -1) ? 80 : port;
        this.page_urlpath = pageUri.getPath();
        this.page_urlquery = pageUri.getQuery();
        this.page_urlfragment = pageUri.getFragment();
    } catch (Exception e) {
        getLog().warn("Could not parse page_url " + this.page_url + " }");
    }

    // 9. Finally handle the marketing fields in the page_url
    // Re-use params to avoid creating another object
    if (this.page_url != null) {
        params = null;
        try {
            params = URLEncodedUtils.parse(URI.create(this.page_url), "UTF-8");
        } catch (IllegalArgumentException e) {
            getLog().warn("Couldn't parse page_url: " + page_url);
        }
        if (params != null) {
            // For performance, don't convert to a map, just loop through and match to our variables as we go
            for (NameValuePair pair : params) {

                final String name = pair.getName();
                final String value = pair.getValue();

                final MarketingFields field;
                try {
                    field = MarketingFields.valueOf(name.toUpperCase()); // Java pre-7 can't switch on a string, so hash the string
                } catch (IllegalArgumentException e) {
                    // Do nothing: non-marketing related querystring fields are not an issue.
                    continue;
                }

                try {
                    switch (field) {
                    // Marketing fields
                    case UTM_MEDIUM:
                        this.mkt_medium = decodeSafeString(value);
                        break;
                    case UTM_SOURCE:
                        this.mkt_source = decodeSafeString(value);
                        break;
                    case UTM_TERM:
                        this.mkt_term = decodeSafeString(value);
                        break;
                    case UTM_CONTENT:
                        this.mkt_content = decodeSafeString(value);
                        break;
                    case UTM_CAMPAIGN:
                        this.mkt_campaign = decodeSafeString(value);
                        break;
                    }
                } catch (Exception e) {
                    getLog().warn(e.getClass().getSimpleName() + " on { " + name + ": " + value + " }");
                }
            }
        }
    }

    return true; // Successfully updated the row.
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

/**
 * Categorize current file type/*from  w  w  w . j a v a  2 s.c om*/
 * 
 * @param ref file path
 */
private void categorizeCurrentFile(final Reference ref) {
    final URI currentFile = ref.filename;
    if (listFilter.hasConaction()) {
        conrefpushSet.add(currentFile);
    }

    if (listFilter.hasConRef()) {
        conrefSet.add(currentFile);
    }

    if (listFilter.hasKeyRef()) {
        keyrefSet.add(currentFile);
    }

    if (listFilter.hasCodeRef()) {
        coderefSet.add(currentFile);
    }

    if (listFilter.isDitaTopic()) {
        if (ref.format != null && !ref.format.equals(ATTR_FORMAT_VALUE_DITA)) {
            assert currentFile.getFragment() == null;
            final URI f = currentFile.normalize();
            if (!fileinfos.containsKey(f)) {
                final FileInfo i = new FileInfo.Builder()
                        //.uri(tempFileNameScheme.generateTempFileName(currentFile))
                        .src(currentFile).format(ref.format).build();
                fileinfos.put(i.src, i);
            }
        }
        fullTopicSet.add(currentFile);
        hrefTargetSet.add(currentFile);
        if (listFilter.hasHref()) {
            hrefTopicSet.add(currentFile);
        }
    } else if (listFilter.isDitaMap()) {
        fullMapSet.add(currentFile);
    }
}