0

I'm using code from an imported library (that I have no way to modify) and trying to just call the path of the item. This is suppose to be the command to do so:

Document.getSourceWorkspace().getPathById(id, Boolean, boolean)

So for this I am using a DocumentId called contentId as the id and just using "true" for the boolean values:

    String contentIdStr = request.getParameter("contentId");
    DocumentId contentId = workspace.createDocumentId(contentIdStr);

    Document.getSourceWorkspace().getPathById(contentId, true, true);

getPathById is type java.lang.String, so all I want to do (for right now) is display it:

out.println("Path: " + Document.getSourceWorkspace().getPathById(contentId, true, true));

But when I try to run this I get the error: Cannot make a static reference to the non-static method getSourceWorkspace() from the type Document

Since the only code that I wrote here is the out.println, I'm not really sure what is going on. Why can't I simply output it like that? How is that a static reference? What do I need to do to make it non-static (keeping in mind that I can't change anything in the library or whatnot)?

I did try to create a string and assign this to it, but that didn't work either...

String contentPath = Document.getSourceWorkspace().getPathById(contentId, 1, 1);

This is (hopefully) probably simple, but I'm not very familiar with Java at all. I don't really know what the syntax is supposed to be, so maybe I'm just writing it wrong?

Appreciate any help, thanks.

ZeekLTK
  • 233
  • 2
  • 9
  • 2
    What is the library ? – mrroboaat Feb 25 '14 at 20:56
  • are you working with atlassian API ? – Saddam Abu Ghaida Feb 25 '14 at 20:56
  • 1
    Sounds like IBM WebSphere ;) Are you sure, that `Document` has a static method `getSourceWorkspace`? I would rather guess, that thats an instance method. – qqilihq Feb 25 '14 at 20:57
  • You are correct, trying to get a path of an item in WebSphere v7. I think that it's the correct method, but it's very hard to find any documentation or tutorials for it. I'm basing it off this: http://www-01.ibm.com/support/docview.wss?uid=swg1PK71825 - is there another (easier) way to call the path of the item? Thanks – ZeekLTK Feb 25 '14 at 21:06
  • 1
    Look here: http://public.dhe.ibm.com/software/dw/lotus/portal_javadoc/7/lwcm/api-javadoc/index.html .. as being said, it's an **instance** method (no offense, but these are programming basics and not special to the WP/WCM API). It's been ages since I've been using it, but after skimming over the given link, it looks like you can get the document by ID through the `Workspace` instance. – qqilihq Feb 25 '14 at 21:09
  • Thanks for the link, but now I'm getting the error on GetById: Cannot make a static reference to the non-static method getById(DocumentId) from the type Workspace --- I used this code, is my syntax wrong?: Document myDoc = Workspace.getById(contentId); out.println("Path: " + myDoc.getSourceWorkspace().getPathById(contentId, true, true)); – ZeekLTK Feb 25 '14 at 21:18
  • 1
    It's an **instance method** (how often was that repeated here already?). Learn about the basics. (edit:) I don't mean to sound rude, but without the necessary foundations you will face trouble over and over again. If you want a solution, and don't care about why it is like it is, try `workspace.getPathById(contentId, true, true);`. – qqilihq Feb 25 '14 at 21:20
  • Thanks that worked, but like I said, I'm not familiar with Java. I understand what an instance is but I don't know how to write it - what would be the correct way to do so here? I tried: Document myDoc = new Document(Workspace.getById(contentId)); and got the error: Cannot instantiate the type Document. I just don't know the syntax, I guess I will try to look up some examples, but it's difficult because a lot of the examples are much more simplified, they are just things like: Book firstBook = new Book("Name"); thats hard to replicate trying to use workspace.method(vars) where "Name" goes. – ZeekLTK Feb 25 '14 at 21:47
  • `Document` is an interface, you cannot instantiate it (the whole WCM API is made up of interfaces). Usually you need to take the workspace, to create objects. Again, this has nothing to do with "syntax", but with basic concepts of OOP. Getting familiar to them, will help you in understanding. – qqilihq Feb 25 '14 at 21:51
  • possible duplicate of [Java Error: Cannot make a static reference to the non-static method](http://stackoverflow.com/questions/14744746/java-error-cannot-make-a-static-reference-to-the-non-static-method) – JasonMArcher Nov 16 '14 at 06:22

1 Answers1

1

I think you meant to say this:

someDocument.getSourceWorkspace().getPathById(contentId, true, true);

Instead of this:

Document.getSourceWorkspace().getPathById(contentId, true, true);

In other words: getSourceWorkspace() is an instance method (not a static method), so it must be called over an instance of the Document class.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • I tried this, it gives a different error: The method getSourceWorkspace() is undefined for the type DocumentId. contentId is a documentId, not a document, so it doesn't have a method .getSourceWorkspace() – ZeekLTK Feb 25 '14 at 21:09
  • @ZeekLTK then you need to create an instance of `Document`, perhaps using the `contentId` to obtain it – Óscar López Feb 25 '14 at 21:14