-
-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XWIKI-22571: Backlinks update changes an absolute reference to the mo…
…ved page into one relative to the current wiki * Provide relative EntityResourceReference resolvers for ResourceReference and use those to determine if an entity reference contains a wiki part or not * WIP: need to check / improve actual implem of the resolvers and add test / doc
- Loading branch information
Showing
9 changed files
with
419 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...rendering/internal/resolver/AbstractRelativeResourceReferenceEntityReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.rendering.internal.resolver; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.xwiki.model.EntityType; | ||
import org.xwiki.model.reference.EntityReference; | ||
import org.xwiki.model.reference.EntityReferenceResolver; | ||
import org.xwiki.rendering.listener.reference.ResourceReference; | ||
import org.xwiki.rendering.listener.reference.ResourceType; | ||
|
||
/** | ||
* Convert document resource reference into entity reference. | ||
* | ||
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
public abstract class AbstractRelativeResourceReferenceEntityReferenceResolver | ||
extends AbstractResourceReferenceEntityReferenceResolver | ||
{ | ||
@Inject | ||
@Named("relative") | ||
private EntityReferenceResolver<String> relativeReferenceResolver; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public AbstractRelativeResourceReferenceEntityReferenceResolver(ResourceType type) | ||
{ | ||
super(type); | ||
} | ||
|
||
@Override | ||
protected EntityReference resolveTyped(ResourceReference resourceReference, EntityReference baseReference) | ||
{ | ||
return this.relativeReferenceResolver.resolve(resourceReference.getReference(), getEntityType()); | ||
} | ||
|
||
public abstract EntityType getEntityType(); | ||
} |
51 changes: 51 additions & 0 deletions
51
...ndering/internal/resolver/RelativeAttachmentResourceReferenceEntityReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.rendering.internal.resolver; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.rendering.listener.reference.ResourceType; | ||
|
||
/** | ||
* Convert attachment resource reference into entity reference. | ||
* | ||
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
@Component | ||
@Named("relative/attach") | ||
@Singleton | ||
public class RelativeAttachmentResourceReferenceEntityReferenceResolver | ||
extends AbstractRelativeResourceReferenceEntityReferenceResolver | ||
{ | ||
public RelativeAttachmentResourceReferenceEntityReferenceResolver() | ||
{ | ||
super(ResourceType.ATTACHMENT); | ||
} | ||
|
||
@Override | ||
public EntityType getEntityType() | ||
{ | ||
return EntityType.ATTACHMENT; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...rendering/internal/resolver/RelativeDocumentResourceReferenceEntityReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.rendering.internal.resolver; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.rendering.listener.reference.ResourceType; | ||
|
||
/** | ||
* Convert document resource reference into entity reference. | ||
* | ||
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
@Component | ||
@Named("relative/doc") | ||
@Singleton | ||
public class RelativeDocumentResourceReferenceEntityReferenceResolver | ||
extends AbstractRelativeResourceReferenceEntityReferenceResolver | ||
{ | ||
public RelativeDocumentResourceReferenceEntityReferenceResolver() | ||
{ | ||
super(ResourceType.DOCUMENT); | ||
} | ||
|
||
@Override | ||
public EntityType getEntityType() | ||
{ | ||
return EntityType.DOCUMENT; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ing/internal/resolver/RelativePageAttachmentResourceReferenceEntityReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.rendering.internal.resolver; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.rendering.listener.reference.ResourceType; | ||
|
||
/** | ||
* Convert attachment resource reference into entity reference. | ||
* | ||
* @version $Id$ | ||
* @since 13.10.5 | ||
* @since 17.0.0RC1 | ||
*/ | ||
@Component | ||
@Named("relative/pageAttach") | ||
@Singleton | ||
public class RelativePageAttachmentResourceReferenceEntityReferenceResolver | ||
extends AbstractRelativeResourceReferenceEntityReferenceResolver | ||
{ | ||
public RelativePageAttachmentResourceReferenceEntityReferenceResolver() | ||
{ | ||
super(ResourceType.PAGE_ATTACHMENT); | ||
} | ||
|
||
@Override | ||
public EntityType getEntityType() | ||
{ | ||
return EntityType.PAGE_ATTACHMENT; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...iki/rendering/internal/resolver/RelativePageResourceReferenceEntityReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.rendering.internal.resolver; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.rendering.listener.reference.ResourceType; | ||
|
||
/** | ||
* Convert page resource reference into entity reference. | ||
* | ||
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
@Component | ||
@Named("relative/page") | ||
@Singleton | ||
public class RelativePageResourceReferenceEntityReferenceResolver | ||
extends AbstractRelativeResourceReferenceEntityReferenceResolver | ||
{ | ||
public RelativePageResourceReferenceEntityReferenceResolver() | ||
{ | ||
super(ResourceType.PAGE); | ||
} | ||
|
||
@Override | ||
public EntityType getEntityType() | ||
{ | ||
return EntityType.PAGE; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...g/xwiki/rendering/internal/resolver/RelativeResourceReferenceEntityReferenceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.rendering.internal.resolver; | ||
|
||
import java.lang.reflect.ParameterizedType; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.component.manager.ComponentLookupException; | ||
import org.xwiki.component.manager.ComponentManager; | ||
import org.xwiki.component.util.DefaultParameterizedType; | ||
import org.xwiki.model.EntityType; | ||
import org.xwiki.model.reference.EntityReference; | ||
import org.xwiki.model.reference.EntityReferenceResolver; | ||
import org.xwiki.rendering.listener.reference.ResourceReference; | ||
|
||
/** | ||
* Default entry point to convert a resource reference into an entity reference. | ||
* | ||
* @version $Id$ | ||
* @since 17.0.0RC1 | ||
*/ | ||
@Component | ||
@Named("relative") | ||
@Singleton | ||
public class RelativeResourceReferenceEntityReferenceResolver implements EntityReferenceResolver<ResourceReference> | ||
{ | ||
/** | ||
* Type instance for EntityReferenceResolver<ResourceReference>. | ||
*/ | ||
public static final ParameterizedType TYPE_RESOURCEREFERENCE = | ||
new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class); | ||
|
||
private static final String RELATIVE_HINT = "relative/%s"; | ||
|
||
@Inject | ||
@Named("context") | ||
private Provider<ComponentManager> componentManagerProvider; | ||
|
||
@Override | ||
public EntityReference resolve(ResourceReference resourceReference, EntityType type, Object... parameters) | ||
{ | ||
if (resourceReference == null) { | ||
return null; | ||
} | ||
|
||
if (this.componentManagerProvider.get().hasComponent(TYPE_RESOURCEREFERENCE, | ||
getRelativeHint(resourceReference))) { | ||
EntityReferenceResolver<ResourceReference> resolver; | ||
try { | ||
resolver = this.componentManagerProvider.get().getInstance(TYPE_RESOURCEREFERENCE, | ||
getRelativeHint(resourceReference)); | ||
} catch (ComponentLookupException e) { | ||
throw new RuntimeException( | ||
String.format("Unknown error when trying to load resolver for reference [%s]", resourceReference), | ||
e); | ||
} | ||
|
||
return resolver.resolve(resourceReference, type, parameters); | ||
} | ||
|
||
// Unsupported resource reference type | ||
return null; | ||
} | ||
|
||
private String getRelativeHint(ResourceReference resourceReference) | ||
{ | ||
return String.format(RELATIVE_HINT, resourceReference.getType().getScheme()); | ||
} | ||
} |
Oops, something went wrong.