@Test public void generateWhithRegexpSyntax() throws Exception { ResourceReference resourceReference = new DocumentResourceReference("HelloWorld"); DocumentReference documentReference = new DocumentReference("$0", "\\", "$0"); EntityReferenceResolver<ResourceReference> resourceReferenceResolver = this.mocker.getInstance( new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class)); when(resourceReferenceResolver.resolve(resourceReference, EntityType.DOCUMENT)).thenReturn(documentReference); DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class); DocumentModelBridge dmb = mock(DocumentModelBridge.class); when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(dmb); when(dmb.getTitle()).thenReturn("$0"); EntityReferenceSerializer<String> localSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local"); when(localSerializer.serialize(new SpaceReference("$0", "\\"))).thenReturn("\\"); assertEquals("%l%la%n%na%N%NA [$0:\\.$0] \\ $0 $0 $0 ($0) [$0:\\.$0] \\ $0 $0 $0 ($0)", this.mocker.getComponentUnderTest().generate(resourceReference)); }
@Override public String generate(ResourceReference reference) { StringBuilder result = new StringBuilder(); String format = this.renderingConfiguration.getLinkLabelFormat(); EntityReference resolvedReference = resourceReferenceResolver.resolve(reference, EntityType.DOCUMENT); if (resolvedReference == null) { throw new IllegalArgumentException(String.valueOf(reference)); } DocumentReference documentReference = new DocumentReference(resolvedReference); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); if (c == '%' && i + 1 < format.length()) { i++; char cc = format.charAt(i); switch (cc) { case 's': result.append(getSpacesLabel(documentReference)); break; case 'p': result.append(getPageLabel(documentReference)); break; case 't': result.append(getTitleLabel(documentReference)); break; case 'P': result.append(getCamelPageLabel(documentReference)); break; case 'w': result.append(getWikiLabel(documentReference)); break; case 'l': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 's') { result.append(getLastSpaceLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'n': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'p') { result.append(getNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'N': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'P') { result.append(getCamelNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; default: result.append(c); result.append(cc); } } else { result.append(c); } } return result.toString(); }
XWikiLinkLabelGenerator implements LinkLabelGenerator { @Override public String generate(ResourceReference reference) { StringBuilder result = new StringBuilder(); String format = this.renderingConfiguration.getLinkLabelFormat(); EntityReference resolvedReference = resourceReferenceResolver.resolve(reference, EntityType.DOCUMENT); if (resolvedReference == null) { throw new IllegalArgumentException(String.valueOf(reference)); } DocumentReference documentReference = new DocumentReference(resolvedReference); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); if (c == '%' && i + 1 < format.length()) { i++; char cc = format.charAt(i); switch (cc) { case 's': result.append(getSpacesLabel(documentReference)); break; case 'p': result.append(getPageLabel(documentReference)); break; case 't': result.append(getTitleLabel(documentReference)); break; case 'P': result.append(getCamelPageLabel(documentReference)); break; case 'w': result.append(getWikiLabel(documentReference)); break; case 'l': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 's') { result.append(getLastSpaceLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'n': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'p') { result.append(getNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'N': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'P') { result.append(getCamelNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; default: result.append(c); result.append(cc); } } else { result.append(c); } } return result.toString(); } }
XWikiLinkLabelGenerator implements LinkLabelGenerator { @Override public String generate(ResourceReference reference) { StringBuilder result = new StringBuilder(); String format = this.renderingConfiguration.getLinkLabelFormat(); EntityReference resolvedReference = resourceReferenceResolver.resolve(reference, EntityType.DOCUMENT); if (resolvedReference == null) { throw new IllegalArgumentException(String.valueOf(reference)); } DocumentReference documentReference = new DocumentReference(resolvedReference); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); if (c == '%' && i + 1 < format.length()) { i++; char cc = format.charAt(i); switch (cc) { case 's': result.append(getSpacesLabel(documentReference)); break; case 'p': result.append(getPageLabel(documentReference)); break; case 't': result.append(getTitleLabel(documentReference)); break; case 'P': result.append(getCamelPageLabel(documentReference)); break; case 'w': result.append(getWikiLabel(documentReference)); break; case 'l': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 's') { result.append(getLastSpaceLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'n': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'p') { result.append(getNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'N': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'P') { result.append(getCamelNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; default: result.append(c); result.append(cc); } } else { result.append(c); } } return result.toString(); }  }
XWikiLinkLabelGenerator implements LinkLabelGenerator { @Override public String generate(ResourceReference reference) { StringBuilder result = new StringBuilder(); String format = this.renderingConfiguration.getLinkLabelFormat(); EntityReference resolvedReference = resourceReferenceResolver.resolve(reference, EntityType.DOCUMENT); if (resolvedReference == null) { throw new IllegalArgumentException(String.valueOf(reference)); } DocumentReference documentReference = new DocumentReference(resolvedReference); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); if (c == '%' && i + 1 < format.length()) { i++; char cc = format.charAt(i); switch (cc) { case 's': result.append(getSpacesLabel(documentReference)); break; case 'p': result.append(getPageLabel(documentReference)); break; case 't': result.append(getTitleLabel(documentReference)); break; case 'P': result.append(getCamelPageLabel(documentReference)); break; case 'w': result.append(getWikiLabel(documentReference)); break; case 'l': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 's') { result.append(getLastSpaceLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'n': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'p') { result.append(getNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'N': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'P') { result.append(getCamelNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; default: result.append(c); result.append(cc); } } else { result.append(c); } } return result.toString(); }  @Override String generate(ResourceReference reference); }
XWikiLinkLabelGenerator implements LinkLabelGenerator { @Override public String generate(ResourceReference reference) { StringBuilder result = new StringBuilder(); String format = this.renderingConfiguration.getLinkLabelFormat(); EntityReference resolvedReference = resourceReferenceResolver.resolve(reference, EntityType.DOCUMENT); if (resolvedReference == null) { throw new IllegalArgumentException(String.valueOf(reference)); } DocumentReference documentReference = new DocumentReference(resolvedReference); for (int i = 0; i < format.length(); i++) { char c = format.charAt(i); if (c == '%' && i + 1 < format.length()) { i++; char cc = format.charAt(i); switch (cc) { case 's': result.append(getSpacesLabel(documentReference)); break; case 'p': result.append(getPageLabel(documentReference)); break; case 't': result.append(getTitleLabel(documentReference)); break; case 'P': result.append(getCamelPageLabel(documentReference)); break; case 'w': result.append(getWikiLabel(documentReference)); break; case 'l': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 's') { result.append(getLastSpaceLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'n': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'p') { result.append(getNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; case 'N': if (i + 1 < format.length()) { i++; char ccc = format.charAt(i); if (ccc == 'P') { result.append(getCamelNestedPageLabel(documentReference)); } else { result.append(c); result.append(cc); result.append(ccc); } } else { result.append(c); result.append(cc); } break; default: result.append(c); result.append(cc); } } else { result.append(c); } } return result.toString(); }  @Override String generate(ResourceReference reference);  }