/** * Returns the optionnally decoded absolute resource identifier. * * @param decode * Indicates if the result should be decoded using the * {@link #decode(String)} method. * @return The optionnally decoded absolute resource identifier. * @see #getIdentifier() */ public String getIdentifier(boolean decode) { return decode ? decode(getIdentifier()) : getIdentifier(); }
/** * Returns the optionnally decoded absolute resource identifier. * * @param decode * Indicates if the result should be decoded using the * {@link #decode(String)} method. * @return The optionnally decoded absolute resource identifier. * @see #getIdentifier() */ public String getIdentifier(boolean decode) { return decode ? decode(getIdentifier()) : getIdentifier(); }
/** * Returns the optionnally decoded absolute resource identifier. * * @param decode * Indicates if the result should be decoded using the {@link #decode(String)} method. * @return The optionnally decoded absolute resource identifier. * @see #getIdentifier() */ public String getIdentifier(boolean decode) { return decode ? decode(getIdentifier()) : getIdentifier(); }
/** * Returns the reference of a resource according to its id and the reference * of its "parent". * * @param parentRef * parent reference. * @param childId * id of this resource * @return the reference object of the child resource. */ protected Reference getChildReference(Reference parentRef, String childId) { if (parentRef.getIdentifier().endsWith("/")) { return new Reference(parentRef.getIdentifier() + childId); } return new Reference(parentRef.getIdentifier() + "/" + childId); }
/** * Returns the base url of a request. */ public static String getBaseURL( Request request ) { Reference ref = request.getResourceRef(); HttpServletRequest servletRequest = getServletRequest(request); if ( servletRequest != null ) { String baseURL = ref.getIdentifier(); return baseURL.substring(0, baseURL.length()-servletRequest.getPathInfo().length()); } else { return ref.getParentRef().getIdentifier(); } }
public int compare(Reference rep0, Reference rep1) { final boolean bRep0Null = (rep0.getIdentifier() == null); final boolean bRep1Null = (rep1.getIdentifier() == null); if (bRep0Null && bRep1Null) { return 0; } if (bRep0Null) { return -1; } if (bRep1Null) { return 1; } return compare(rep0.toString(false, false), rep1.toString(false, false)); }
/** * Compares two references. * * @param ref0 * The first reference. * @param ref1 * The second reference. * @return The comparison result. * @see Comparator */ public int compare(Reference ref0, Reference ref1) { final boolean bRep0Null = (ref0.getIdentifier() == null); final boolean bRep1Null = (ref1.getIdentifier() == null); if (bRep0Null && bRep1Null) { return 0; } if (bRep0Null) { return -1; } if (bRep1Null) { return 1; } return compare(ref0.toString(false, false), ref1.toString(false, false)); }
result = reference.getHostIdentifier(); } else if (partName.equals("i")) { result = reference.getIdentifier(); } else if (partName.equals("p")) { result = reference.getPath();
/** * Constructor. * * @param context * The context. * @param rootLocalReference * The root URI. */ public Directory(Context context, Reference rootLocalReference) { super(context); // First, let's normalize the root reference to prevent any issue with // relative paths inside the reference leading to listing issues. final String rootIdentifier = rootLocalReference.getTargetRef() .getIdentifier(); if (rootIdentifier.endsWith("/")) { this.rootRef = new Reference(rootIdentifier); } else { // We don't take the risk of exposing directory "file:///C:/AA" // if only "file:///C:/A" was intended this.rootRef = new Reference(rootIdentifier + "/"); } this.comparator = new AlphaNumericComparator(); this.deeplyAccessible = true; this.indexName = "index"; this.listingAllowed = false; this.modifiable = false; this.negotiateContent = true; }
/** * Returns the request URI. * * @param resourceRef * The resource reference. * @param isProxied * Indicates if the request goes through a proxy and requires an * absolute URI. * @param request * The parent request. * @return The absolute request URI. */ public static String format(Reference resourceRef, boolean isProxied, Request request) { String result = null; Reference requestRef = update(resourceRef, request); if (isProxied) { result = requestRef.getIdentifier(); } else { if (requestRef.hasQuery()) { result = requestRef.getPath() + "?" + requestRef.getQuery(); } else { result = requestRef.getPath(); } if ((result == null) || (result.equals(""))) { result = "/"; } } return result; }
/** * Constructor. * * @param context * The context. * @param rootLocalReference * The root URI. */ public Directory(Context context, Reference rootLocalReference) { super(context); // First, let's normalize the root reference to prevent any issue with // relative paths inside the reference leading to listing issues. final String rootIdentifier = rootLocalReference.getTargetRef() .getIdentifier(); if (rootIdentifier.endsWith("/")) { this.rootRef = new Reference(rootIdentifier); } else { // We don't take the risk of exposing directory "file:///C:/AA" // if only "file:///C:/A" was intended this.rootRef = new Reference(rootIdentifier + "/"); } this.comparator = new AlphaNumericComparator(); this.deeplyAccessible = true; this.indexName = "index"; this.listingAllowed = false; this.modifiable = false; this.negotiatingContent = true; setTargetClass(DirectoryServerResource.class); setName("Directory"); }
return reference.getHostIdentifier(); case "i": return reference.getIdentifier(); case "p": return reference.getPath();
.getReferrerRef().getIdentifier());
/** * Handle POST requests: create a new item. */ @Post public Representation acceptItem(Representation entity) { Representation result = null; // Parse the given representation and retrieve pairs of // "name=value" tokens. Form form = new Form(entity); String itemName = form.getFirstValue("name"); String itemDescription = form.getFirstValue("description"); // Register the new item if one is not already registered. if (!getItems().containsKey(itemName) && getItems().putIfAbsent(itemName, new Item(itemName, itemDescription)) == null) { // Set the response's status and entity setStatus(Status.SUCCESS_CREATED); Representation rep = new StringRepresentation("Item created", MediaType.TEXT_PLAIN); // Indicates where is located the new resource. rep.setLocationRef(getRequest().getResourceRef().getIdentifier() + "/" + itemName); result = rep; } else { // Item is already registered. setStatus(Status.CLIENT_ERROR_NOT_FOUND); result = generateErrorRepresentation("Item " + itemName + " already exists.", "1"); } return result; }
/** * Handle POST requests: create a new item. */ @Post public Representation acceptItem(Representation entity) { Representation result = null; // Parse the given representation and retrieve pairs of // "name=value" tokens. Form form = new Form(entity); String itemName = form.getFirstValue("name"); String itemDescription = form.getFirstValue("description"); // Register the new item if one is not already registered. if (!getItems().containsKey(itemName) && getItems().putIfAbsent(itemName, new Item(itemName, itemDescription)) == null) { // Set the response's status and entity setStatus(Status.SUCCESS_CREATED); Representation rep = new StringRepresentation("Item created", MediaType.TEXT_PLAIN); // Indicates where is located the new resource. rep.setLocationRef(getRequest().getResourceRef().getIdentifier() + "/" + itemName); result = rep; } else { // Item is already registered. setStatus(Status.CLIENT_ERROR_NOT_FOUND); result = generateErrorRepresentation("Item " + itemName + " already exists.", "1"); } return result; }
String uri = getRequest().getResourceRef().getIdentifier(); int question = uri.indexOf( '?' ); if ( question != -1 ) {
if (!rr.getBaseRef().getIdentifier().endsWith("/")) { rr.setBaseRef(rr.getBaseRef() + "/");
private UnitOfWork createUnitOfWork( Request request ) { UsecaseBuilder usecaseBuilder = UsecaseBuilder.buildUsecase( request.getResourceRef().getIdentifier( true ) ); User user = request.getClientInfo().getUser(); if( user != null ) { UserIdentity userIdentity = new UserIdentity( user.getIdentifier(), user.getName(), user.getEmail(), user.getFirstName(), user.getLastName() ); usecaseBuilder.withMetaInfo( userIdentity ); } return uowf.newUnitOfWork( usecaseBuilder.newUsecase() ); }