Package org.dspace.content

Examples of org.dspace.content.BitstreamFormat


        FileInputStream fis = new FileInputStream(tempFile);
        Bitstream bitstream = swordBundle.createBitstream(fis);
        bitstream.setName(fn);
        bitstream.setDescription("SWORD deposit package");

        BitstreamFormat bf = BitstreamFormat.findByMIMEType(context, deposit.getContentType());
        if (bf != null)
        {
          bitstream.setFormat(bf);
        }
View Full Code Here


    String idsString = parameters.getParameter("formatIDs", null);
   
    ArrayList<BitstreamFormat> formats = new ArrayList<BitstreamFormat>();
    for (String id : idsString.split(","))
    {
      BitstreamFormat format = BitstreamFormat.find(context,Integer.valueOf(id));
      formats.add(format);
    }
    // DIVISION: bitstream-format-confirm-delete
      Division deleted = body.addInteractiveDivision("bitstream-format-confirm-delete",contextPath+"/admin/format-registry",Division.METHOD_POST,"primary administrative format-registry");
      deleted.setHead(T_head);
      deleted.addPara(T_para1);
     
      Table table = deleted.addTable("format-confirm-delete",formats.size() + 1, 3);
        Row header = table.addRow(Row.ROLE_HEADER);
        header.addCell().addContent(T_column1);
        header.addCell().addContent(T_column2);
        header.addCell().addContent(T_column3);
     
      for (BitstreamFormat format : formats)
      {
        if (format == null)
          continue;
       
        String formatID = String.valueOf(format.getID());
        String mimetype = format.getMIMEType();
        String name = format.getShortDescription();

       
        Row row = table.addRow();
        row.addCell().addContent(formatID);
          row.addCell().addContent(mimetype);
View Full Code Here

            String url = makeBitstreamLink(item, bitstream);
            long bytes = bitstream.getSize();
            String desc = bitstream.getDescription();
            String algorithm = bitstream.getChecksumAlgorithm();
            String checksum = bitstream.getChecksum();
            BitstreamFormat format = bitstream.getFormat();
            int support = format.getSupportLevel();
           
           
            Row row = summary.addRow();

              // Add radio-button to select this as the primary bitstream
                Radio primary = row.addCell().addRadio("primary_bitstream_id");
                primary.addOption(String.valueOf(id));
               
                // If this bitstream is already marked as the primary bitstream
                // mark it as such.
                if(bundles[0].getPrimaryBitstreamID() == id) {
                    primary.setOptionSelected(String.valueOf(id));
                }
           
            if (!workflow)
            {
              // Workflow users can not remove files.
                CheckBox remove = row.addCell().addCheckBox("remove");
                remove.setLabel("remove");
                remove.addOption(id);
            }
            else
            {
              row.addCell();
            }
           
              row.addCell().addXref(url,name);
              row.addCellContent(bytes + " bytes");
              if (desc == null || desc.length() == 0)
                row.addCellContent(T_unknown_name);
              else
                row.addCellContent(desc);
             
              if (format == null)
              {
                row.addCellContent(T_unknown_format);
              }
              else
              {
                Cell cell = row.addCell();
                cell.addContent(format.getMIMEType());
                cell.addContent(" ");
                switch (support)
                {
                case 1:
                  cell.addContent(T_supported);
View Full Code Here

            bitstreams = bundles[0].getBitstreams();
        }
       
        for (Bitstream bitstream : bitstreams)
        {
            BitstreamFormat bitstreamFormat = bitstream.getFormat();
           
            int id = item.getID();
            String name = bitstream.getName();
            String url = makeBitstreamLink(item, bitstream);
            String format = bitstreamFormat.getShortDescription();
            Message support = ReviewStep.T_unknown;
            if (bitstreamFormat.getSupportLevel() == BitstreamFormat.KNOWN)
                support = T_known;
            else if (bitstreamFormat.getSupportLevel() == BitstreamFormat.SUPPORTED)
                support = T_supported;
           
            org.dspace.app.xmlui.wing.element.Item file = uploadSection.addItem();
            file.addXref(url,name);
            file.addContent(" - "+ format + " ");
View Full Code Here

                }

                // reconcile bitstream format; if there's a MIMEtype,
                // get it from that, otherwise try to divine from file extension
                // (guessFormat() looks at bitstream Name, which we just set)
                BitstreamFormat bf = (MIMEType == null) ? null :
                        BitstreamFormat.findByMIMEType(context, MIMEType);
                if (bf == null)
                    bf = FormatIdentifier.guessFormat(context, bitstream);
                if (bf != null)
                    bitstream.setFormat(bf);
View Full Code Here

        // get some more information
        String license_text = fetchLicenseText(cc_license_url);
        String license_rdf = fetchLicenseRDF(cc_license_url);
       
        // set the formats
        BitstreamFormat bs_url_format = BitstreamFormat.findByShortDescription(
                context, "License");
        BitstreamFormat bs_text_format = BitstreamFormat.findByShortDescription(
                context, "CC License");
        BitstreamFormat bs_rdf_format = BitstreamFormat.findByShortDescription(
                context, "RDF XML");

        // set the URL bitstream
        setBitstreamFromBytes(item, bundle, BSN_LICENSE_URL, bs_url_format,
                cc_license_url.getBytes());
View Full Code Here

            throws SQLException, IOException, AuthorizeException
    {
        Bundle bundle = getCcBundle(item);

        // set the format
        BitstreamFormat bs_format;
        if (mimeType.equalsIgnoreCase("text/xml"))
        {
            bs_format = BitstreamFormat.findByShortDescription(context, "CC License");
        }
        else if (mimeType.equalsIgnoreCase("text/rdf")) {
View Full Code Here

                        bs = mdBundle.createBitstream(new PackageUtils.UnclosableInputStream(zip));
                        bs.setName(fname);
                        bs.setSource(fname);

                        // Get magic bitstream format to identify manifest.
                        BitstreamFormat manifestFormat = null;
                        manifestFormat = PackageUtils.findOrCreateBitstreamFormat(context,
                             MANIFEST_BITSTREAM_FORMAT, "application/xml",
                             MANIFEST_BITSTREAM_FORMAT+" package manifest");
                        bs.setFormat(manifestFormat);

                        manifest = METSManifest.create(bs.retrieve(), validate);
                    }
                    else
                    {
                        manifest = METSManifest.create(new PackageUtils.UnclosableInputStream(zip), validate);
                        continue;
                    }
                }
                else
                {
                  // we need to create the bundle only the first time
                  if (contentBundle == null)
                  {
                    contentBundle = item.createBundle(Constants.CONTENT_BUNDLE_NAME);
                  }
                    bs = contentBundle.createBitstream(new PackageUtils.UnclosableInputStream(zip));
                    bs.setSource(fname);
                    bs.setName(fname);
                }
                packageFiles.add(fname);
                bs.setSource(fname);
                bs.update();
            }
            zip.close();

            if (manifest == null)
                throw new PackageValidationException("No METS Manifest found (filename="+MANIFEST_FILE+").  Package is unacceptable.");

            // initial sanity checks on manifest (in subclass)
            checkManifest(manifest);

            /* 2. Grovel a file list out of METS Manifest and compare
             *  it to the files in package, as an integrity test.
             */
            List manifestContentFiles = manifest.getContentFiles();

            // Compare manifest files with the ones found in package:
            //  a. Start with content files (mentioned in <fileGrp>s)
            HashSet missingFiles = new HashSet();
            for (Iterator mi = manifestContentFiles.iterator(); mi.hasNext(); )
            {
                // First locate corresponding Bitstream and make
                // map of Bitstream to <file> ID.
                Element mfile = (Element)mi.next();
                String mfileId = mfile.getAttributeValue("ID");
                if (mfileId == null)
                    throw new PackageValidationException("Invalid METS Manifest: file element without ID attribute.");
                String path = METSManifest.getFileName(mfile);
                Bitstream bs = contentBundle.getBitstreamByName(path);
                if (bs == null)
                {
                    log.warn("Cannot find bitstream for filename=\""+path+
                             "\", skipping it..may cause problems later.");
                    missingFiles.add(path);
                }
                else
                {
                    fileIdToBitstream.put(mfileId, bs);

                    // Now that we're done using Name to match to <file>,
                    // set default bitstream Name to last path element;
                    // Zip entries all have '/' pathname separators
                    // NOTE: set default here, hopefully crosswalk of
                    // a bitstream techMD section will override it.
                    String fname = bs.getName();
                    int lastSlash = fname.lastIndexOf('/');
                    if (lastSlash >= && lastSlash+1 < fname.length())
                        bs.setName(fname.substring(lastSlash+1));

                    // Set Default bitstream format:
                    //  1. attempt to guess from MIME type
                    //  2. if that fails, guess from "name" extension.
                    String mimeType = mfile.getAttributeValue("MIMETYPE");
                    BitstreamFormat bf = (mimeType == null) ? null :
                            BitstreamFormat.findByMIMEType(context, mimeType);
                    if (bf == null)
                        bf = FormatIdentifier.guessFormat(context, bs);
                    bs.setFormat(bf);

View Full Code Here

        boolean internal = new Boolean(internalString).booleanValue();

        String[] extensions = getRepeatedElementData(node, "extension");

        // Create the format object
        BitstreamFormat format = BitstreamFormat.create(context);

        // Fill it out with the values
        format.setMIMEType(mimeType);
        format.setShortDescription(shortDesc);
        format.setDescription(desc);
        format.setSupportLevel(supportLevel);
        format.setInternal(internal);
        format.setExtensions(extensions);

        // Write to database
        format.update();
    }
View Full Code Here

 
  public void addBody(Body body) throws WingException, SQLException
  {
    // Get our parameters & state
    int formatID = parameters.getParameterAsInteger("formatID",-1);
    BitstreamFormat format = null;
   
    if (formatID >= 0)
      format = BitstreamFormat.find(context,formatID);
 
    String errorString = parameters.getParameter("errors",null);
    ArrayList<String> errors = new ArrayList<String>();
    if (errorString != null)
      for (String error : errorString.split(","))
        errors.add(error);
   
    Request request = ObjectModelHelper.getRequest(objectModel);
        String mimetypeValue = request.getParameter("mimetype");
        String nameValue = request.getParameter("short_description");
        String descriptionValue = request.getParameter("description");
        String supportLevelValue = request.getParameter("support_level");
        String internalValue = request.getParameter("internal");
        java.util.List<String> extensionsList = RequestUtils.getFieldValues(request, "extensions");
        String[] extensionValues = extensionsList.toArray(new String[extensionsList.size()]);
       
        // Remove leading periods from file extensions.
        for (int i = 0; i < extensionValues.length; i++)
          if (extensionValues[i].startsWith("."))
            extensionValues[i] = extensionValues[i].substring(1);
       
        if (format != null)
        {
          if (mimetypeValue == null)
            mimetypeValue = format.getMIMEType();
          if (nameValue == null)
            nameValue = format.getShortDescription();
          if (descriptionValue == null)
            descriptionValue = format.getDescription();
          if (supportLevelValue == null)
            supportLevelValue = String.valueOf(format.getSupportLevel());
          if (request.getParameter("mimetype") == null)
            internalValue = format.isInternal() ? "true" : null;
          if (request.getParameter("extensions") == null)
            extensionValues = format.getExtensions();
        }
   
       
 
       
        // DIVISION: edit-bitstream-format
    Division main = body.addInteractiveDivision("edit-bitstream-format",contextPath+"/admin/format-registry",Division.METHOD_POST,"primary administrative format-registry");
    if (formatID == -1)
      main.setHead(T_head1);
    else
      main.setHead(T_head2.parameterize(nameValue));
    main.addPara(T_para1);
 
    List form = main.addList("edit-bitstream-format",List.TYPE_FORM);
   
    Text name = form.addItem().addText("short_description");
    name.setRequired();
    name.setLabel(T_name);
    name.setHelp(T_name_help);
    name.setValue(nameValue);
    name.setSize(35);
    if (errors.contains("short_description"))
      name.addError(T_name_error);
   
    Text mimeType = form.addItem().addText("mimetype");
    mimeType.setLabel(T_mimetype);
    mimeType.setHelp(T_mimetype_help);
    mimeType.setValue(mimetypeValue);
    mimeType.setSize(35);
   
    // Do not allow anyone to change the name of the unknown format.
    if (format != null && format.getID() == 1)
      name.setDisabled();

    TextArea description = form.addItem().addTextArea("description");
    description.setLabel(T_description);
    description.setValue(descriptionValue);
View Full Code Here

TOP

Related Classes of org.dspace.content.BitstreamFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.