/** * @param scheme see {@link #getScheme()} */ public ResourceType(String scheme) { setScheme(scheme); }
@Override public ResourceReference parse(String rawReference) { String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(rawReference, COMMENT_SEPARATOR); boolean isTyped = "true".equalsIgnoreCase(tokens[0]); ResourceType type = new ResourceType(tokens[1]); String reference = tokens[2]; ResourceReference resourceReference = new ResourceReference(reference, type); resourceReference.setTyped(isTyped); if (tokens.length == 4) { for (WikiParameter parameter : WikiParameters.newWikiParameters(tokens[3])) { resourceReference.setParameter(parameter.getKey(), parameter.getValue()); } } return resourceReference; } }
/** * {@inheritDoc} * @see org.xwiki.rendering.parser.ResourceReferenceParser#parse(String) */ public ResourceReference parse(String rawReference) { String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(rawReference, COMMENT_SEPARATOR); boolean isTyped = tokens[0].equalsIgnoreCase("true") ? true : false; ResourceType type = new ResourceType(tokens[1]); String reference = tokens[2]; ResourceReference resourceReference = new ResourceReference(reference, type); resourceReference.setTyped(isTyped); if (tokens.length == 4) { for (WikiParameter parameter : WikiParameters.newWikiParameters(tokens[3])) { resourceReference.setParameter(parameter.getKey(), parameter.getValue()); } } return resourceReference; } }
/** * Indicate if the provided type is supported by this syntax. * * @param type the type of resource * @return true if the type is supported */ protected boolean isSupportedType(ResourceType type) { return XWiki20LinkReferenceParser.URI_PREFIXES.contains(type.getScheme()); } }
@Override public boolean isDocumentAvailable(ResourceReference documentReference) { ResourceType resourceType = documentReference.getType(); String resourceValue = documentReference.getReference(); if (ResourceType.DOCUMENT.equals(resourceType)) { return "Space.ExistingPage".equals(resourceValue); } else if (ResourceType.SPACE.equals(resourceType)) { return "ExistingSpace".equals(resourceValue); } else if (ResourceType.PAGE.equals(resourceType)) { return "ExistingPage".equals(resourceValue); } return false; } }
@Override protected boolean isSupportedType(ResourceType type) { return XWiki20LinkReferenceParser.URI_PREFIXES.contains(type.getScheme()); } }
private XDOMOfficeDocument createXDOM(DocumentReference ownerDocument, ResourceReference resourceReference, Map<String, ?> parameters) throws Exception { InputStream officeFileStream; String officeFileName; if (resourceReference.getType().equals(ResourceType.URL)) { URL url = new URL(resourceReference.getReference()); officeFileStream = url.openStream(); officeFileName = StringUtils.substringAfterLast(url.getPath(), "/"); } else { throw new Exception(String.format("Unsupported resource type [%s].", resourceReference.getType())); } return createXDOM(ownerDocument, officeFileStream, officeFileName, parameters); }
/** * {@inheritDoc} * * @see Object#equals(Object) */ @Override public boolean equals(Object object) { boolean result; // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm. if (this == object) { result = true; } else { if ((object == null) || (object.getClass() != this.getClass())) { result = false; } else { // object must be ResourceType at this point ResourceType type = (ResourceType) object; result = (getScheme() == type.getScheme() || (getScheme() != null && getScheme().equals(type.getScheme()))); } } return result; } }
@Override protected void onReference(ResourceReference reference, String label, boolean freestanding, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the link syntax used for a link to a document has the // query string and/or the anchor specified as parameters. This is how the XWiki Syntax 2.1 specifies // query string and anchor (ex: [[label>>doc:docReference||queryString="a=b" anchor="anchor"]]). ResourceType resourceType = reference.getType(); if (ResourceType.DOCUMENT.equals(resourceType) || ResourceType.SPACE.equals(resourceType) || ResourceType.PAGE.equals(resourceType)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } String anchor = parameters.remove(ANCHOR); if (anchor != null) { reference.setParameter(DocumentResourceReference.ANCHOR, anchor); } } else if (ResourceType.ATTACHMENT.equals(resourceType)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString); } } super.onReference(reference, label, freestanding, parameters); }
/** * {@inheritDoc} * * @see AbstractXHTMLLinkTypeRenderer#beginLinkExtraAttributes(ResourceReference, java.util.Map, java.util.Map) */ @Override protected void beginLinkExtraAttributes(ResourceReference reference, Map<String, String> spanAttributes, Map<String, String> anchorAttributes) { anchorAttributes.put(XHTMLLinkRenderer.HREF, reference.getType().getScheme() + ':' + reference.getReference()); } }
@Override protected void onImage(ResourceReference reference, boolean freestanding, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified. if (ResourceType.ATTACHMENT.equals(reference.getType())) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } } super.onImage(reference, freestanding, parameters); } }
@Override protected String getImageSrcAttributeValue(ResourceReference reference, Map<String, String> parameters) { return String.format("%s:%s", reference.getType().getScheme(), reference.getReference()); } }
@Override protected void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified. if (reference.getType().equals(ResourceType.ATTACHMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } } super.onImage(reference, isFreeStandingURI, parameters); } }
@Override protected void beginLinkExtraAttributes(ResourceReference reference, Map<String, String> spanAttributes, Map<String, String> anchorAttributes) { anchorAttributes.put(XHTMLLinkRenderer.HREF, reference.getType().getScheme() + ':' + reference.getReference()); } }
/** * {@inheritDoc} * * @see DefaultXWikiGeneratorListener#onImage(org.xwiki.rendering.listener.reference.ResourceReference , boolean, * java.util.Map) */ protected void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified. if (reference.getType().equals(ResourceType.ATTACHMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } } super.onImage(reference, isFreeStandingURI, parameters); } }
@Override public String serialize(ResourceReference reference) { StringBuilder result = new StringBuilder(); result.append(reference.getType().getScheme()); result.append(DefaultResourceReferenceParser.TYPE_SEPARATOR); String interWikiAlias = reference.getParameter(InterWikiResourceReference.INTERWIKI_ALIAS); if (interWikiAlias != null) { result.append(interWikiAlias); result.append(InterWikiResourceReferenceTypeParser.INTERWIKI_ALIAS_SEPARATOR); } result.append(reference.getReference()); return result.toString(); } }
@Override protected void onReference(ResourceReference reference, String label, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the link syntax used for a link to a document has the // query string and/or the anchor specified as parameters. This is how the XWiki Syntax 2.1 specifies // query string and anchor (ex: [[label>>doc:docReference||queryString="a=b" anchor="anchor"]]). if (reference.getType().equals(ResourceType.DOCUMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } String anchor = parameters.remove(ANCHOR); if (anchor != null) { reference.setParameter(DocumentResourceReference.ANCHOR, anchor); } } else if (reference.getType().equals(ResourceType.ATTACHMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString); } } super.onReference(reference, label, isFreeStandingURI, parameters); }