use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class DefaultSolrReferenceResolver method getResover.
/**
* @param reference the reference
* @return the resolver associated to the reference type
* @throws SolrIndexerException when failed to find a resolve associated to the passed reference
*/
private SolrReferenceResolver getResover(EntityReference reference) throws SolrIndexerException {
EntityType type = reference.getType();
SolrReferenceResolver resolver;
try {
resolver = this.componentManager.getInstance(SolrReferenceResolver.class, type.getLowerCase());
} catch (ComponentLookupException e) {
throw new SolrIndexerException("Failed to get SolrDocumentReferenceResolver corresponding to entity type [" + type + "]", e);
}
return resolver;
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class AbstractTypedStringEntityReferenceResolver method resolve.
/**
* {@inheritDoc}
* <p>
* Override to allow detecting the type of the reference from the prefix specified in the beginning of the
* serialized reference (e.g. DOCUMENT://Page). In case no type is specified, the second part parameter will be used
* as the default type.
* </p>
*
* @see TypedStringEntityReferenceResolver#resolve(String, org.xwiki.model.EntityType)
*/
@Override
public EntityReference resolve(String entityReferenceRepresentation, EntityType defaultType) {
String refToParse = entityReferenceRepresentation;
EntityType type = defaultType;
// get the type specified at the beginning
EntityType specifiedType = getSerializedType(refToParse);
// if such type is specified
if (specifiedType != null) {
// this will be used to parse...
type = specifiedType;
// ...what's left of the reference after the protocol part
refToParse = refToParse.substring(type.toString().length() + 3);
}
// use the super resolver to resolve the stripped reference and the resolved type
return getResolver().resolve(refToParse, type);
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class SolrEntityReferenceResolverTest method configure.
@Before
public void configure() throws Exception {
solrDocument = new SolrDocument();
solrDocument.setField(FieldUtils.WIKI, "chess");
solrDocument.setField(FieldUtils.SPACES, Arrays.asList("Path", "To", "Success"));
solrDocument.setField(FieldUtils.NAME, "WebHome");
solrDocument.setField(FieldUtils.DOCUMENT_LOCALE, "fr");
// The file name field can have multiple values.
solrDocument.addField(FieldUtils.FILENAME, "image.png");
solrDocument.addField(FieldUtils.FILENAME, "presentation.odp");
// The class name field can have multiple values too.
solrDocument.addField(FieldUtils.CLASS, "App.Code.PlayerClass");
solrDocument.addField(FieldUtils.CLASS, "App.Code.TrainerClass");
solrDocument.setField(FieldUtils.NUMBER, 13);
solrDocument.setField(FieldUtils.PROPERTY_NAME, "age");
EntityReferenceResolver<EntityReference> explicitReferenceEntityReferenceResolver = this.mocker.getInstance(EntityReferenceResolver.TYPE_REFERENCE, "explicit");
doAnswer(new Answer<EntityReference>() {
@Override
public EntityReference answer(InvocationOnMock invocation) throws Throwable {
EntityReference reference = invocation.getArgument(0);
EntityType type = invocation.getArgument(1);
return reference.extractReference(type);
}
}).when(explicitReferenceEntityReferenceResolver).resolve(any(EntityReference.class), any(EntityType.class));
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class EntityReferenceConverter method convertToType.
private EntityReference convertToType(Type type, String value) {
Namespace namespace = NamespaceUtils.toNamespace(value);
EntityType entityType = namespace.getType() != null ? EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase()) : null;
String entityReference = namespace.getValue();
if (entityType == null) {
entityType = EntityType.DOCUMENT;
entityReference = value;
}
return this.stringResolver.resolve(entityReference, entityType);
}
use of org.xwiki.model.EntityType in project xwiki-platform by xwiki.
the class DefaultStringEntityReferenceSerializer method serializeEntityReference.
@Override
protected void serializeEntityReference(EntityReference currentReference, StringBuilder representation, boolean isLastReference, Object... parameters) {
EntityType currentType = currentReference.getType();
EntityReference parentReference = currentReference.getParent();
// type has already been processed).
if (parentReference != null && representation.length() > 0) {
// Get the separator to use between the previous type and the current type
Character separator = getSymbolScheme().getSeparatorSymbols().get(currentType).get(parentReference.getType());
if (separator != null) {
representation.append(separator);
} else {
// The reference is invalid, the parent type is not an allowed type. Thus there's no valid separator
// to separate the 2 types. Use the "???" character to show the user it's invalid.
representation.append("???");
}
}
// Escape characters that require escaping for the current type
representation.append(StringUtils.replaceEach(currentReference.getName(), getSymbolScheme().getSymbolsRequiringEscapes(currentType), getSymbolScheme().getReplacementSymbols(currentType)));
}
Aggregations