<commit_before>/// <reference path="../../typings/tsd.d.ts" />

import {Injectable, provide} from 'angular2/angular2';
import {LocationStrategy} from 'angular2/router';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';

// TODO: see https://github.com/angular/universal/issues/60#issuecomment-130463593
class MockServerHistory implements History {
  length: number;
  state: any;
  constructor () {/*TODO*/}
  back(distance?: any): void {/*TODO*/}
  forward(distance?: any): void {/*TODO*/}
  go(delta?: any): void {/*TODO*/}
  pushState(statedata: any, title?: string, url?: string): void {/*TODO*/}
  replaceState(statedata: any, title?: string, url?: string): void {/*TODO*/}
}

class MockServerLocation implements Location {
  hash: string;
  host: string;
  hostname: string;
  href: string;
  origin: string;
  pathname: string;
  port: string;
  protocol: string;
  search: string;
  constructor () {/*TODO*/}
  assign(url: string): void {/*TODO*/}
  reload(forcedReload?: boolean): void {/*TODO*/}
  replace(url: string): void {/*TODO*/}
  toString(): string { /*TODO*/ return ''; }
}


@Injectable()
export class ServerLocationStrategy extends LocationStrategy {
  private _location: Location = new MockServerLocation();
  private _history:  History = new MockServerHistory();
  private _baseHref: string = '/';

  constructor() { super(); }

  onPopState(fn: EventListener): void {/*TODO*/}

  getBaseHref(): string { return this._baseHref; }

  path(): string { return this._location.pathname; }

  pushState(state: any, title: string, url: string) {/*TODO*/}

  forward(): void {
    this._history.forward();
  }

  back(): void {
    this._history.back();
  }
}

export const SERVER_LOCATION_PROVIDERS: Array<any> = [
  provide(LocationStrategy, {useClass: ServerLocationStrategy})
];<commit_msg>fix(ServerLocationStrategy): use baseurl<commit_after>/// <reference path="../../typings/tsd.d.ts" />
import * as nodeUrl from 'url';
import {Injectable, Inject, provide} from 'angular2/angular2';
import {LocationStrategy} from 'angular2/router';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
import {BASE_URL} from '../http/server_http';

// TODO: see https://github.com/angular/universal/issues/60#issuecomment-130463593
class MockServerHistory implements History {
  length: number;
  state: any;
  constructor () {/*TODO*/}
  back(distance?: any): void {/*TODO*/}
  forward(distance?: any): void {/*TODO*/}
  go(delta?: any): void {/*TODO*/}
  pushState(statedata: any, title?: string, url?: string): void {/*TODO*/}
  replaceState(statedata: any, title?: string, url?: string): void {/*TODO*/}
}

class MockServerLocation implements Location {
  hash: string;
  host: string;
  hostname: string;
  href: string;
  origin: string;
  pathname: string;
  port: string;
  protocol: string;
  search: string;
  constructor () {/*TODO*/}
  assign(url: string): void {
    var parsed = nodeUrl.parse(url);
    this.hash = parsed.hash;
    this.host = parsed.host;
    this.hostname = parsed.hostname;
    this.href = parsed.href;
    this.pathname = parsed.pathname;
    this.port = parsed.port;
    this.protocol = parsed.protocol;
    this.search = parsed.search;
    this.origin = parsed.protocol + '//' + parsed.hostname + ':' + parsed.port;
  }
  reload(forcedReload?: boolean): void {/*TODO*/}
  replace(url: string): void {
    this.assign(url);
  }
  toString(): string { /*TODO*/ return ''; }
}


@Injectable()
export class ServerLocationStrategy extends LocationStrategy {
  private _location: Location = new MockServerLocation();
  private _history:  History = new MockServerHistory();
  private _baseHref: string = '/';

  constructor(@Inject(BASE_URL) baseUrl: string) {
    super();
    this._location.assign(baseUrl);
  }

  onPopState(fn: EventListener): void {/*TODO*/}

  getBaseHref(): string { return this._baseHref; }

  path(): string { return this._location.pathname; }

  pushState(state: any, title: string, url: string) {/*TODO*/}

  forward(): void {
    this._history.forward();
  }

  back(): void {
    this._history.back();
  }
}

export const SERVER_LOCATION_PROVIDERS: Array<any> = [
  provide(LocationStrategy, {useClass: ServerLocationStrategy})
];
{'fraction_non_alphanumeric': 0.16086547507055504, 'fraction_numerical': 0.0070555032925682035, 'mean_word_length': 4.263613861386139, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5102485', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1344, 'n_words': 337}