Search in sources :

Example 11 with EntityType

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;
}
Also used : EntityType(org.xwiki.model.EntityType) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 12 with EntityType

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);
}
Also used : EntityType(org.xwiki.model.EntityType)

Example 13 with EntityType

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));
}
Also used : EntityType(org.xwiki.model.EntityType) SolrDocument(org.apache.solr.common.SolrDocument) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityReference(org.xwiki.model.reference.EntityReference) Before(org.junit.Before)

Example 14 with EntityType

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);
}
Also used : EntityType(org.xwiki.model.EntityType) Namespace(org.xwiki.component.namespace.Namespace)

Example 15 with 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)));
}
Also used : EntityType(org.xwiki.model.EntityType) EntityReference(org.xwiki.model.reference.EntityReference)

Aggregations

EntityType (org.xwiki.model.EntityType)16 EntityReference (org.xwiki.model.reference.EntityReference)11 Namespace (org.xwiki.component.namespace.Namespace)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SolrDocument (org.apache.solr.common.SolrDocument)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 InvalidEntityReferenceException (org.xwiki.model.reference.InvalidEntityReferenceException)1 CreateResourceReferenceException (org.xwiki.resource.CreateResourceReferenceException)1 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)1 SolrIndexerException (org.xwiki.search.solr.internal.api.SolrIndexerException)1 Right (org.xwiki.security.authorization.Right)1 DefaultTestAccessRule (org.xwiki.security.authorization.testwikis.internal.entities.DefaultTestAccessRule)1