Abstract way to get Content Type of a File?

Using a java.io.File or java.io.FileInputStream is there any was the get the mime type of that file? I am working with a JEditorPane which loads files from a JTree, however I would like to take advantage of the tree's setContentType method for formatting...

I think the
JAVABEANS ACTIVATION FRAMEWORK (JAF)
is what you're looking for.
http://java.sun.com/products/javabeans/glasgow/jaf.html
But I actually never used it... (or not yet :-) )
Greets
Puce

Similar Messages

  • Content type of .key files

    Dear team ,
    please tell me the "contenttype" of the .pages file format....
    example: .doc....is having the content type as "application/ms-word"
    similarly can u tell me content type of .pages
    Regards,
    spradeepkumar

    hi balusC thanks, it works very well.
    your site http://balusc.xs4all.nl/srv/dev-jep-pdf.html helped me a lot.
    But one point. There is another method : URLConnection.guessContentTypeFromStream(InputStream)but it don't work and i receive as result a null.
    Is there another classes/methods which helps getting the content type of a file? not necessarily from sun. thanks
    bye

  • Set content type based on file extension after uploading into document library

    when there are multiple content types associated with a document library, say, report builder report, and excel documents, after you drag and drop a document into the document library, content type will not be detected based on the file extension. Suppose
    your default content type is document, and you had added the report build report content type, and you uploaded a .RDL file, the content type for the file will be set to the default document content type.
    I get a requirement to update the content type automatically based on the file extension, what follows is my code:
    public class setCNTByFileExtItemAdded : SPItemEventReceiver
    /// <summary>
    /// An item was added.
    /// </summary>
    public override void ItemAdded(SPItemEventProperties properties)
    if (properties.Web.GetFile(properties.AfterUrl).Exists)
    SPListItem CurrentListItem = properties.Web.GetFile(properties.AfterUrl).Item;
    String FileName = CurrentListItem.Name;
    if (FileName.EndsWith(".rdl",StringComparison.OrdinalIgnoreCase))
    CurrentListItem.Properties["ContentTypeId"] = "0x010100C3676CDFA2F24E1D949A8BF2B06F6B8B";
    CurrentListItem.SystemUpdate(false);
    base.ItemAdded(properties);
    What follows are references that helped me:
    http://stackoverflow.com/questions/7984300/properties-listitem-is-null-in-itemadded-event-while-uploading-documents-using
    http://williamvanstrien.blogspot.in/2011/10/read-content-of-uploaded-file-within.html
    http://blogs.msdn.com/b/manuj/archive/2009/09/22/itemadded-event-on-document-library-the-file-has-been-modified-by-on-error.aspx
    http://support.microsoft.com/kb/2647429

    user may have further requirement to detect whether the uploaded .xlsx file contains powerpivot data model, i tried the following code, the caveat is that .xlsx is actually a zip file, i just test whether the uploaded stream contains an entry xl/model/item.data.
    public partial class ApplicationPage2 : LayoutsPageBase
    protected void Page_Load(object sender, EventArgs e)
    if (this.IsPostBack)
    if (FileUpload1.PostedFile == null)
    return;
    string destWeb = DestinationUrl.Url;
    string destUrl = destWeb + "/" + FileUpload1.FileName;
    using (SPSite site = new SPSite(destWeb))
    using (SPWeb web = site.OpenWeb())
    SPFile f = web.Files.Add(destUrl, FileUpload1.PostedFile.InputStream);
    if (FileUpload1.FileName.EndsWith(".xlsx") )
    Stream fs = f.OpenBinaryStream() as Stream;
    using (ZipArchive zfs = new ZipArchive(fs, ZipArchiveMode.Read))
    if (zfs.GetEntry("xl/model/item.data") == null)
    Debug.WriteLine("Does not contain data model");
    else
    Debug.WriteLine("Contain data model");
    The code i posted here is part of an application page in layout folder, the reason why i use application page is described in
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/065d010a-d37e-4da4-9873-172ab2c50d6d/custom-list-new-application-page-with-listfielditerator-and-savebutton?forum=sharepointdevelopment#288a686e-bfbe-41aa-83d0-58a80f0cec07

  • Get content type info

    Hello Friends,
    I have 4 list based content types which have a similar column "appendix" as single line of text. I have added them to my list. My requirement is, when I click on the new item and select the content type, I should get the content type info in the appendix
    column.
    Can someone help me on getting that info? I cannot use the InfoPath forms to get the information.
    Please suggest

    Hi ChandraShekhar
    You need to first go through the below links in-order to resolve you problem
    Content Types
    Indul Hassan
    Microsoft Community Contributor
    http://www.indulhassan.com
    You Snooze.. You Lose !!

  • REST Query to Get Content Type Name

    I'm just getting started learning to use the SharePoint REST interface.  One of the first things I'd like to do is return the content type name for a list item in a document library (the document library is configured with several content types).  From
    what I've read, it looks like I need to use the $expand query option.  So, my REST query looks like this:
    http://localhost/_api/web/lists/Documents/Items()?&$select=ContentType/Name&$expand=ContentType/Name
    But it's not working.  I can't "dig" out the content type name property.  In other words the $expand query option is not working.  I just receive the following which includes a link to the content type: 
      <entry m:etag="&quot;2&quot;">
        <id>4078e129-ac4b-44b8-b469-bcc083f2268d</id>
        <category term="SP.Data.DocumentsItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
        <link rel="edit" href="Web/Lists(guid'cd710fd1-057e-4ee7-b0bd-1f014218ea3e')/Items(36)" />
        <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'cd710fd1-057e-4ee7-b0bd-1f014218ea3e')/Items(36)/ContentType"
    />
        <title />
        <updated>2013-04-12T00:16:26Z</updated>
        <author>
          <name />
        </author>
        <content type="application/xml" />
      </entry>
    I've tried difference variations and if I just use "$expand=ContentType" then I get all the list items with the content type fully expanded within each item.
    What am I missing?

    It's been awhile since this question got asked, but I figured i'd post for anyone who happens to stumble
    on it.
    Try this:
    http://localhost/_api/web/lists/Documents/Items(<item
    id>)/ContentType?$select=Name

  • Apple TV stopped showing up in iTunes. No way to get content across :(

    I have an ATV1 that I hook up to my computer at work to load content onto via ethernet. This has been working fine for the last couple of years. I plugged it in recently and I am not getting an Apple TV icon showing up under the devices section. Uploading through my computer is the only way to get the same content on my iPod as well as on my ATV1.
    The weird thing is iTunes seems to recognize that there is an ATV1 attached because I am getting the icon that lets me choose to use the computer's speaker or the TV's speakers. How can I get the icon to show up so that I can start moving content across?

    The ATV2 does not stream the same way the ATV1 does, In other words ATV2 requires HomeSharing instead of streaming like the ATV1.
    1) Make sure you have the most recent version of itunes (Check updates)
    2) Turn on home sharing in iTunes
    3) Turn on home sharing on ATV2.
    4) Input name/password for iTunes account and your good to go.

  • Content type of .pages file format

    Dear team ,
    please tell me the "contenttype" of the .pages file format....
    example: .doc....is having the content type as "application/ms-word"
    similarly can u tell me content type of .pages
    Regards,
    spradeepkumar

    For Numbers it is:
    kind = "Document Numbers" (localization dependent )
    type identifier = "com.apple.iwork.numbers.sffnumbers"
    For Pages it is:
    kind = "Publication Pages" (localization dependent )
    type identifier = "com.apple.iwork.pages.sffpages"
    For Keynote it is:
    kind = "Keynote Document" ( not sure of localization behavior)
    type identifier:"com.apple.keynote.key"
    grab it with this script after changing the pathname
    set pathName to (choose file) as text
    tell application "System Events"
    get properties of item pathName
    end tell
    Yvan KOENIG (from FRANCE lundi 12 janvier 2009 16:31:07)

  • Easy way to add content from a last file like a word document?

    Is there somebody who can tell me how i can display content from a word file.
    I have files with content inside on my network for example a word document.
    Inside this document i've got hyperlinks to content on other pages from the same document. Is the a way or a method how i can display the content in the portal.
    Do i need to cut and paste the word content of should i save the content as a XML or a HTML document and then add the document to portal
    Regards
    Andre

    Yeah, I have an idea... Have you tried the pdf export yet? If it is already formated then that maybe the way to go. But you may need acrobat to save it in another format. If I recall InDesign renders the pdf, which would make editing the pdf in Indesign useless.
    OK, did a quick test with PDF. Load the PDF into Acrobat and save as a word file. Place the word file into InDesign and you will have the styles paragraphs.    You just have to alter the style taste, may be fix a few paragraphs if needed.

  • Changing content type of xml file to pdf

    Hello,
    I have an xml file (extension is *.xdp) which can locally be opened with Adobe Reader and displays as a regular pdf file. Adobe has a technology that allows xml to be merged with a pdf shell, and thus populating the pdf file with the values retrieved from the xml file.
    My issue is that I want this to be done on an application server level (jboss in particular). In a servlet, I stream the xml file for the contents to be printed out within a browser (IE). I specify the content type to be application/pdf, however, the data is not being displayed within Adobe Reader, but rather as a regular xml file.
    Any help is greatly appreciated. Here is the code below:
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "max-age=30");
    response.setContentType("application/pdf");
    ServletOutputStream out = response.getOutputStream();
    byte[] fileBytes = readFile();
    out.write(fileBytes);

    Yes, the xml does contain a reference to the shell pdf. This works fine if I do so manually (open the xml file using Adobe Reader). However, through a browser, it seems that the forced content type is completely ignored:
    <?xml version="1.0"?>
    <?xfa generator="XFA2_0" APIVersion="1.4.4127.0"?>
    <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
    <xfa:datasets xmlns="" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
    <xfa:data>
    <DocRoot>
    <Cldemographics<Cldatecreated>7/21/05</Cldatecreated...
    </DocRoot>
    </xfa:data>
    </xfa:datasets>
    <pdf href="/opt/jboss-tomcat-server-build-4.0.0-2/.../pdfShell/Shell.pdf"
    xmlns="http://ns.adobe.com/xdp/pdf/"/>
    </xdp:xdp>

  • Is there a way to get Automator to select invisible files?

    I need a way to get Automator to be able to select invisible files. Does anybody know a workaround?
    Shift-Command-Period doesn't do anything (except make a beep).

    The regular Automator actions typically use the current Finder settings, so (depending on your workflow) you can temporarily set the Finder to show all files (including invisibles) and reset it when you are done, or you can use a *Run AppleScript* action to put up a file choice dialog that includes invisible items.

  • Content type of .numbers files

    Dear team ,
    please tell me the "contenttype" of the .pages file format....
    example: .doc....is having the content type as "application/ms-word"
    similarly can u tell me content type of .pages
    Regards,
    spradeepkumar

    If the document is a Numbers '09 single file,
    package folder = false
    kind = "Document Numbers" (localization dependant )
    type identifier = "com.apple.iwork.numbers.sffnumbers"
    If the document is a Numbers '08 or 09 package,
    package folder = true
    kind = "Document Numbers" (localization dependant )
    type identifier = "com.apple.iwork.numbers.sffnumbers"
    Yvan KOENIG (from FRANCE lundi 12 janvier 2009 11:06:20)

  • Setting Content-Type in .jspx file

    Hello,
    My application is not rendered by an HTML Browser.
    I need to set the contentType to application/x-ywidget+xml in my JSPX file.
    The content type returned is always text/xml !!!
    I have tried:
    1. To create a phaseListener and overloading before or after phase in ANY_PHASE
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext extContext = context.getExternalContext();
    HttpServletResponse response =
    (HttpServletResponse)extContext.getResponse();
    String contentType = "application/x-ywidget+xml";
    response.setContentType(contentType);
    2. To add a new MimeType extension in web.xml and create my file under this extension
    <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.xygo</url-pattern>
    </servlet-mapping>
    <mime-mapping>
    <extension>xygo</extension>
    <mime-type>application/x-ywidget+xml</mime-type>
    </mime-mapping>

    Frank,
    Thanks you for you help.
    What i would like to do is to use a JSF library components to build YahooGO pages (Yahoo mobile widgets).
    For this my server needs to return an xml document with the application/x-ywidget+xml content type.
    Regarding you question i don't think that the target device understand the HTML.. on my mobile, it's J2ME application...
    Perhaps you can provide me some advices.
    Regards,
    Fred

  • Is there a way to get elements to reference a file/photo instead of making a copy of the file/photo???

    So I have a MBP with a 512GB SSD and my photo library is about 100GB. My music library is about 250GB. Videos make up another 70GB. I just installed Elements 11 photoshop and premiere and I don't have the space for it to duplicate everything. Is there a way to get the program to reference the file instead of making a duplicate/space hogging copy? Help!

    For PSE, the only time the organizer makes a copy is if you use the "from iphoto" command, in which case it's necessary because other programs should not write to the iphoto library, a great way to corrupt it and cause loss of photos. For PRE, you should ask in the Premiere Elements forum:
    Premiere Elements

  • Any way to get Open Type features to work in Pages 5?

    It seems that the Open Type support, which already has been very wonky to say the least and felt more like a hack in Pages 09 has been completely broken now in Pages 5.
    It used to be possible to use the system wide typography menu (CMD+T > Gear Icon > Typography), but the settings here now seem to be ignored by Pages. So now we're stuck with faux small caps and wrong superscript number cases etc.
    Has anyone figured out workarounds?

    It works in a very unpredictable way - I have plenty of purchased fonts with ligatures and several variants and styles (and some of them don’t work properly in Pages 4.3).
    In Pages 5 the “Format > Font > Ligatures > (Use Default or Use All) produces quite random effects on its own but doesn’t seem to work well together with the Typography submenu in Fonts. There is no consistency - I have to keep closing and opening the “Typography” submenu in Fonts and sometimes it works. For some fonts it doesn’t work at all.
    Try changing the “Use Default” and “Use All” few times and see if it helps.
    It’s true enough OTF ligatures do work better in Mavericks - but didn’t improve in Pages 4.3 and are out of control in Pages 5. I was desperate enough today to download a trial version of Swift Publisher and all the ligatures work perfectly.
    This is very frustrating. I’m grateful I have Pages 4.3 for the time being, but since I use Pages daily for layout work I will have to start looking for alternatives.

  • A way to get content from MONI to SAP BW?

    Hi,
    I'm a student and at the moment I'm working on a project to monitor the user behaviour on 40 SAP systems with 1 SAP BW.
    One source for that is the transaction st03n with the table MONI. As I know, the content from MONI can only be read out with ABAP and I haven't much experience with this programming language.
    So my questions:
    - Has anyone experience with reading out MONI with ABAP?
    - Is it possible to get the content in a file (csv) or in a DataSource so that SAP BW can read it?
    Thanks a lot for any help
    Joschi

    Thanks Bill,
    but as far as I know you first need to create a view over the table and then create a generic datasource with this view.
    But creating a view over this table isn't possible. You can only extract data from MONI with ABAP fundtions or extract the data with ABAP from the stat-files which are saved on the application-server.

Maybe you are looking for

  • Adding a pc to an airport extreme lan

    I need to connect a pc to my macs airport network (right now it has a tower and a laptop on it) The Airport is the flying triangle with the silver metalic Apple logo. I bought a belkin wireless G adapter (model F5D7050 )the pc sees my airport. It kno

  • I have been using my ipod classic as a hard drive whilst travelling, but at least half of the photo folders no longer show up when accessing the Ipod in My Computer

    Hello All, My concern is growing rapidly that i may have lost a large chunk photographs, i take some solice in the fact that when looking at the properties of my Ipod the correct amount of memory is still being used thisa is the same when looking at

  • Problem accessing files via Blackberry Bridge

    Not sure if anyone is having this issue....I've got the blackberry bridge installed, and I can access my messages, contacts, etc.  However if I go into the Bridge Files menu, I am unable to open anything.  I tap it and it just does nothing.  If I go

  • Cannot download trial

    I cannot download the trial CC Illustrator (or any trial versions). All the links are to download CC which I already have on my computer. I tried to follow those anyway thinking that it was something else I needed, but then I get an error saying that

  • BSP Navigation

    Hello, I have following problem: I have created a BSP-application, with 2 bsp-sites. The main-site contains a submit-button. If the user clicks on that a new windows is opened via javascript with the command window.open. The 2. site is displayed in t