Ejemplo n.º 1
0
 /**
  * Create URI as string for a given handle and optional bitstream. URI is relative to top of DAV
  * hierarchy, but starts with '/'.
  *
  * @param dso a DSpace object (Item, Collection, etc)
  * @param bsPid bitstream persistent identifier.
  * @return "absolute" URI from top of DAV hierarchy
  * @throws IOException Signals that an I/O exception has occurred.
  * @throws SQLException the SQL exception
  */
 private String makeURI(DSpaceObject dso, String bsPid) throws IOException, SQLException {
   // make sure that bitstream actually exists:
   if (bsPid != null) {
     if (dso.getType() != Constants.ITEM) {
       log.warn("Non-Item with Bitstream Sequence ID in DAV Lookup.");
       return null;
     }
     try {
       int pid = Integer.parseInt(bsPid);
       if (DAVBitstream.getBitstreamBySequenceID((Item) dso, pid) == null) {
         log.warn("Bitstream Sequence ID Not Found in DAV Lookup: \"" + bsPid + "\"");
         return null;
       }
     } catch (NumberFormatException nfe) {
       log.warn("Invalid Bitstream Sequence ID in DAV Lookup: \"" + bsPid + "\"");
       return null;
     }
   }
   String base = "/" + DAVDSpaceObject.getPathElt(dso);
   if (bsPid != null) {
     return base + "/bitstream_" + bsPid;
   } else {
     return base;
   }
 }
Ejemplo n.º 2
0
  /**
   * Return this resource's children. Item's children are its bitstreams.
   *
   * @return the DAV resource[]
   * @throws SQLException the SQL exception
   */
  @Override
  protected DAVResource[] children() throws SQLException {
    // Check for overall read permission on Item
    if (!AuthorizeManager.authorizeActionBoolean(this.context, this.item, Constants.READ)) {
      return new DAVResource[0];
    }

    Vector result = new Vector();
    Bundle[] bundles = this.item.getBundles();
    for (Bundle element : bundles) {
      // check read permission on this Bundle
      if (!AuthorizeManager.authorizeActionBoolean(this.context, element, Constants.READ)) {
        continue;
      }

      Bitstream[] bitstreams = element.getBitstreams();
      for (Bitstream element0 : bitstreams) {
        String ext[] = element0.getFormat().getExtensions();
        result.add(
            new DAVBitstream(
                this.context,
                this.request,
                this.response,
                makeChildPath(
                    DAVBitstream.getPathElt(
                        element0.getSequenceID(), ext.length < 1 ? null : ext[0])),
                this.item,
                element0));
      }
    }
    return (DAVResource[]) result.toArray(new DAVResource[result.size()]);
  }
Ejemplo n.º 3
0
  /**
   * Match the URIs this subclass understands and return the corresponding resource. Since the
   * "dso_" format can lead to several different resource types, handle it here.
   *
   * @param context the context
   * @param request the request
   * @param response the response
   * @param pathElt the path elt
   * @return the DAV resource
   * @throws DAVStatusException the DAV status exception
   * @throws SQLException the SQL exception
   * @throws AuthorizeException the authorize exception
   */
  protected static DAVResource matchResourceURI(
      Context context, HttpServletRequest request, HttpServletResponse response, String pathElt[])
      throws DAVStatusException, SQLException, AuthorizeException {
    // Match /dso_<handle>{...} .. look for last "dso_" element
    if (pathElt[0].startsWith("dso_")) {
      int i = 1;
      for (; i < pathElt.length && pathElt[i].startsWith("dso_"); ++i) {
        // empty
      }
      --i;
      String handle = decodeHandle(pathElt[i].substring(4));

      // Replace substituted handle separator char with '/' to
      // get back a normal handle: (inverse of getPathElt() above)
      int sepIndex = handle.indexOf(handleSeparator);
      if (sepIndex >= 0) {
        char hc[] = handle.toCharArray();
        hc[sepIndex] = '/';
        handle = String.copyValueOf(hc);
      }

      DSpaceObject dso = HandleManager.resolveToObject(context, handle);
      if (dso == null) {
        throw new DAVStatusException(
            HttpServletResponse.SC_NOT_FOUND, "Cannot resolve handle \"" + handle + "\"");
      } else if (dso.getType() == Constants.ITEM) {
        if (i + 1 < pathElt.length) {
          if (pathElt[i + 1].startsWith("bitstream_")) {
            Bitstream bs = DAVBitstream.findBitstream(context, (Item) dso, pathElt[i + 1]);
            if (bs == null) {
              throw new DAVStatusException(
                  HttpServletResponse.SC_NOT_FOUND,
                  "Bitstream \"" + pathElt[i + 1] + "\" not found in item: " + pathElt[i]);
            }
            return new DAVBitstream(context, request, response, pathElt, (Item) dso, bs);
          } else {
            throw new DAVStatusException(
                HttpServletResponse.SC_NOT_FOUND,
                "Illegal resource path, \""
                    + pathElt[i + 1]
                    + "\" is not a Bitstream identifier for item: "
                    + pathElt[i]);
          }
        } else {
          return new DAVItem(context, request, response, pathElt, (Item) dso);
        }
      } else if (dso.getType() == Constants.COLLECTION) {
        return new DAVCollection(context, request, response, pathElt, (Collection) dso);
      } else if (dso.getType() == Constants.COMMUNITY) {
        return new DAVCommunity(context, request, response, pathElt, (Community) dso);
      } else {
        throw new DAVStatusException(
            HttpServletResponse.SC_BAD_REQUEST,
            "Unrecognized DSpace object type for handle=" + handle);
      }
    }
    return null;
  }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see org.dspace.app.dav.DAVResource#proppatchInternal(int, org.jdom.Element)
   */
  @Override
  protected int proppatchInternal(int action, Element prop)
      throws SQLException, AuthorizeException, IOException, DAVStatusException {
    String newValue = (action == DAV.PROPPATCH_REMOVE) ? null : prop.getText();

    // these are "metadata" values..
    if (elementsEqualIsh(prop, short_descriptionProperty)
        || elementsEqualIsh(prop, introductory_textProperty)
        || elementsEqualIsh(prop, side_bar_textProperty)
        || elementsEqualIsh(prop, copyright_textProperty)
        || elementsEqualIsh(prop, provenance_descriptionProperty)) {
      this.collection.setMetadata(prop.getName(), newValue);
    } else if (elementsEqualIsh(prop, displaynameProperty)) {
      this.collection.setMetadata("name", newValue);
    } else if (elementsEqualIsh(prop, default_licenseProperty)) {
      this.collection.setLicense(newValue);
    } else if (elementsEqualIsh(prop, logoProperty)) {
      if (action == DAV.PROPPATCH_REMOVE) {
        this.collection.setLogo(null);
      } else {
        Element bs = prop.getChild("bitstream", DAV.NS_DSPACE);
        if (bs != null) {
          InputStream bis = DAVBitstream.getXmlBitstreamContent(this.context, bs);
          BitstreamFormat bsf = DAVBitstream.getXmlBitstreamFormat(this.context, bs);
          if (bis == null || bsf == null) {
            throw new DAVStatusException(DAV.SC_CONFLICT, "Unacceptable value for logo property.");
          }
          Bitstream nbs = this.collection.setLogo(bis);
          nbs.setFormat(bsf);
          nbs.update();
        } else {
          throw new DAVStatusException(
              DAV.SC_CONFLICT, "No <bitstream> element value found for logo property.");
        }
      }
    } else {
      throw new DAVStatusException(
          DAV.SC_CONFLICT, "The " + prop.getName() + " property cannot be changed.");
    }

    this.collection.update();
    return HttpServletResponse.SC_OK;
  }
Ejemplo n.º 5
0
  /* (non-Javadoc)
   * @see org.dspace.app.dav.DAVDSpaceObject#propfindInternal(org.jdom.Element)
   */
  @Override
  protected Element propfindInternal(Element property)
      throws SQLException, AuthorizeException, IOException, DAVStatusException {
    String value = null;

    // displayname - title or handle.
    if (elementsEqualIsh(property, displaynameProperty)) {
      value = getObjectMetadata("name");
      if (value == null) {
        value = this.collection.getIdentifier().getCanonicalForm();
      }
    } else if (elementsEqualIsh(property, handleProperty)) {
      value = canonicalizeHandle(this.collection.getIdentifier().getCanonicalForm());
    } else if (elementsEqualIsh(property, logoProperty)) {
      Bitstream lbs = this.collection.getLogo();
      Element le;
      if (lbs != null && (le = DAVBitstream.makeXmlBitstream(lbs, this)) != null) {
        Element p = new Element("logo", DAV.NS_DSPACE);
        p.addContent(le);
        return p;
      }
    } else if (elementsEqualIsh(property, short_descriptionProperty)) {
      value = getObjectMetadata("short_description");
    } else if (elementsEqualIsh(property, introductory_textProperty)) {
      value = getObjectMetadata("introductory_text");
    } else if (elementsEqualIsh(property, side_bar_textProperty)) {
      value = getObjectMetadata("side_bar_text");
    } else if (elementsEqualIsh(property, copyright_textProperty)) {
      value = getObjectMetadata("copyright_text");
    } else if (elementsEqualIsh(property, default_licenseProperty)) {
      value = this.collection.hasCustomLicense() ? this.collection.getLicense() : null;
    } else if (elementsEqualIsh(property, provenance_descriptionProperty)) {
      value = getObjectMetadata("provenance_description");
    } else {
      return super.propfindInternal(property);
    }

    // value was set up by "if" clause:
    if (value == null) {
      throw new DAVStatusException(HttpServletResponse.SC_NOT_FOUND, "Not found.");
    }
    Element p = new Element(property.getName(), property.getNamespace());
    p.setText(filterForXML(value));
    return p;
  }
Ejemplo n.º 6
0
  /**
   * Match Item URIs that identify the item by a database ID. Handle URIs are matched by
   * DAVDSpaceObject.
   *
   * @param context the context
   * @param request the request
   * @param response the response
   * @param pathElt the path elt
   * @return the DAV resource
   * @throws DAVStatusException the DAV status exception
   * @throws SQLException the SQL exception
   */
  protected static DAVResource matchResourceURI(
      Context context, HttpServletRequest request, HttpServletResponse response, String pathElt[])
      throws DAVStatusException, SQLException {
    int id = -1;
    String bsElt = null;

    try {
      // The "/item_db_" element in last or next-to-last element
      if (pathElt[pathElt.length - 1].startsWith("item_db_")) {
        id = Integer.parseInt(pathElt[pathElt.length - 1].substring(8));
      } else if (pathElt[pathElt.length - 1].startsWith("bitstream_")
          && pathElt.length > 1
          && pathElt[pathElt.length - 2].startsWith("item_db_")) {
        id = Integer.parseInt(pathElt[pathElt.length - 2].substring(8));
        bsElt = pathElt[pathElt.length - 1];
      }
      if (id >= 0) {
        Item item = Item.find(context, id);
        if (item == null) {
          throw new DAVStatusException(
              HttpServletResponse.SC_NOT_FOUND,
              "Item with ID=" + String.valueOf(id) + " not found.");
        }
        if (bsElt != null) {
          Bitstream bs = DAVBitstream.findBitstream(context, item, bsElt);
          if (bs == null) {
            throw new DAVStatusException(HttpServletResponse.SC_NOT_FOUND, "Bitstream not found.");
          }
          return new DAVBitstream(context, request, response, pathElt, item, bs);
        } else {
          return new DAVItem(context, request, response, pathElt, item);
        }
      }
      return null;
    } catch (NumberFormatException ne) {
      throw new DAVStatusException(
          HttpServletResponse.SC_BAD_REQUEST, "Error parsing number in request URI.");
    }
  }