@Test public void testParseWhenInWikiMode() throws Exception { this.componentManager.registerMockComponent(WikiModel.class); ResourceReference reference = this.parser.parse(""); Assert.assertEquals("", reference.getReference()); Assert.assertFalse(reference.isTyped()); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("Typed = [false] Type = [doc] Reference = []", reference.toString()); reference = this.parser.parse("Hello World"); Assert.assertEquals("Hello World", reference.getReference()); Assert.assertFalse(reference.isTyped()); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("Typed = [false] Type = [doc] Reference = [Hello World]", reference.toString()); reference = this.parser.parse("http: Assert.assertEquals("http: Assert.assertFalse(reference.isTyped()); Assert.assertEquals(ResourceType.URL, reference.getType()); Assert.assertEquals("Typed = [false] Type = [url] Reference = [http: reference = this.parser.parse("mailto:john@smith.com?subject=test"); Assert.assertEquals("john@smith.com?subject=test", reference.getReference()); Assert.assertTrue(reference.isTyped()); Assert.assertEquals(ResourceType.MAILTO, reference.getType()); Assert.assertEquals("Typed = [true] Type = [mailto] Reference = [john@smith.com?subject=test]", reference.toString()); reference = this.parser.parse("attach:some:content"); Assert.assertEquals("some:content", reference.getReference()); Assert.assertTrue(reference.isTyped()); Assert.assertEquals(ResourceType.ATTACHMENT, reference.getType()); Assert.assertEquals("Typed = [true] Type = [attach] Reference = [some:content]", reference.toString()); reference = this.parser.parse("mywiki:http: Assert.assertEquals("mywiki:http: Assert.assertFalse(reference.isTyped()); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("Typed = [false] Type = [doc] Reference = [mywiki:http: reference.toString()); reference = this.parser.parse("doc:wiki:space.page"); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("wiki:space.page", reference.getReference()); Assert.assertEquals("Typed = [true] Type = [doc] Reference = [wiki:space.page]", reference.toString()); Assert.assertTrue(reference.isTyped()); reference = this.parser.parse("space:wiki:space"); Assert.assertEquals(ResourceType.SPACE, reference.getType()); Assert.assertEquals("wiki:space", reference.getReference()); Assert.assertEquals("Typed = [true] Type = [space] Reference = [wiki:space]", reference.toString()); Assert.assertTrue(reference.isTyped()); reference = this.parser.parse("page:wiki:page"); Assert.assertEquals(ResourceType.PAGE, reference.getType()); Assert.assertEquals("wiki:page", reference.getReference()); Assert.assertEquals("Typed = [true] Type = [page] Reference = [wiki:page]", reference.toString()); Assert.assertTrue(reference.isTyped()); reference = this.parser.parse("interwiki:alias:content"); Assert.assertEquals(ResourceType.INTERWIKI, reference.getType()); Assert.assertEquals("content", reference.getReference()); Assert.assertTrue(reference.isTyped()); Assert.assertEquals("alias", ((InterWikiResourceReference) reference).getInterWikiAlias()); Assert.assertEquals("Typed = [true] Type = [interwiki] Reference = [content] " + "Parameters = [[interWikiAlias] = [alias]]", reference.toString()); reference = this.parser.parse("interwiki:invalid_since_doesnt_have_colon"); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("interwiki:invalid_since_doesnt_have_colon", reference.getReference()); Assert.assertFalse(reference.isTyped()); Assert.assertEquals("Typed = [false] Type = [doc] Reference = [interwiki:invalid_since_doesnt_have_colon]", reference.toString()); reference = this.parser.parse("url:http: Assert.assertEquals(ResourceType.URL, reference.getType()); Assert.assertTrue(reference.isTyped()); Assert.assertEquals("http: Assert.assertEquals("Typed = [true] Type = [url] Reference = [http: reference = this.parser.parse("Hello World?no=queryString#notAnAnchor"); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("Hello World?no=queryString#notAnAnchor", reference.getReference()); Assert.assertFalse(reference.isTyped()); Assert.assertNull(((DocumentResourceReference) reference).getAnchor()); Assert.assertNull(((DocumentResourceReference) reference).getQueryString()); Assert.assertEquals("Typed = [false] Type = [doc] Reference = [Hello World?no=queryString#notAnAnchor]", reference.toString()); reference = this.parser.parse("page@alias"); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertFalse(reference.isTyped()); Assert.assertEquals("page@alias", reference.getReference()); Assert.assertEquals("Typed = [false] Type = [doc] Reference = [page@alias]", reference.toString()); reference = this.parser.parse("path:/some/path"); Assert.assertEquals(ResourceType.PATH, reference.getType()); Assert.assertTrue(reference.isTyped()); Assert.assertEquals("/some/path", reference.getReference()); Assert.assertEquals("Typed = [true] Type = [path] Reference = [/some/path]", reference.toString()); reference = this.parser.parse("unc:\\\\myserver\\myshare\\mydoc.txt"); Assert.assertEquals(ResourceType.UNC, reference.getType()); Assert.assertTrue(reference.isTyped()); Assert.assertEquals("\\\\myserver\\myshare\\mydoc.txt", reference.getReference()); Assert.assertEquals("Typed = [true] Type = [unc] Reference = [\\\\myserver\\myshare\\mydoc.txt]", reference.toString()); reference = this.parser.parse("pa\\.ge"); Assert.assertEquals(ResourceType.DOCUMENT, reference.getType()); Assert.assertEquals("pa\\.ge", reference.getReference()); }
@Override public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedLinkReferenceParser.parse(rawReference); } return reference; }
DefaultLinkReferenceParser implements ResourceReferenceParser { @Override public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedLinkReferenceParser.parse(rawReference); } return reference; } }
DefaultLinkReferenceParser implements ResourceReferenceParser { @Override public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedLinkReferenceParser.parse(rawReference); } return reference; }  }
DefaultLinkReferenceParser implements ResourceReferenceParser { @Override public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedLinkReferenceParser.parse(rawReference); } return reference; }  @Override ResourceReference parse(String rawReference); }
DefaultLinkReferenceParser implements ResourceReferenceParser { @Override public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedLinkReferenceParser.parse(rawReference); } return reference; }  @Override ResourceReference parse(String rawReference);  }