Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » How to retrieve Web content settings?
How to retrieve Web content settings? [message #668194] Wed, 04 May 2011 12:53 Go to next message
Dwight Johnson is currently offline Dwight JohnsonFriend
Messages: 19
Registered: March 2011
Junior Member
Hello,

Does anybody know how to read the css-profile from a project .prefs file?

No problem with reading (for instance) java compiler settings for a project:

IEclipsePreferences nodeCoreJava = new ProjectScope(myProject).getNode("org.eclipse.jdt.core");
String source = nodeCoreJava.get("org.eclipse.jdt.core.compiler.source", "");

with this part of the org.eclipse.jdt.core.prefs file:
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.source=1.5



But how do I retrieve the CSS profile? This returns an emtpy string:

IEclipsePreferences nodeCoreCSS = new rojectScope(myProject).getNode("org.eclipse.wst.css.core");
String profile = nodeCoreCSS.get("org.eclipse.wst.css.core.cssprofile", "");

The org.eclipse.wst.css.core.prefs file is this:
#Tue May 03 15:25:08 CEST 2011
css-profile/<project>=org.eclipse.wst.css.core.cssprofile.mobile1_0
eclipse.preferences.version=1


What I want is the string "mobile1_0".

Thanks in advance!

[Updated on: Wed, 04 May 2011 12:54]

Report message to a moderator

Re: How to retrieve Web content settings? [message #668228 is a reply to message #668194] Wed, 04 May 2011 15:23 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4430
Registered: July 2009
Senior Member

If you look closely at the second file you'll see that the parameter you passed to the get method doesn't match what's to the left of the '=' on the same line as the value you seek.

_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: How to retrieve Web content settings? [message #668232 is a reply to message #668194] Wed, 04 May 2011 15:29 Go to previous messageGo to next message
Nick Sandonato is currently offline Nick SandonatoFriend
Messages: 126
Registered: July 2009
Senior Member
Hi Dwight,

These profile settings are sub-nodes of "org.eclipse.wst.css.core". The reason for this is that you can have a profile defined for the entire project, or individual CSS files.

To get that node, you would need
new ProjectScope(project).getNode("org.eclipse.wst.css.core").node( "css-profile");

The key <project> is paired with the project-level profile setting. So profileNode.get("<project>", null) will give you the project's profile.

To get the profile for a particular resource--using the same node--you would pass in the project-relative path as the key. So for example profileNode.get("WebContent/style.css", null).

org.eclipse.wst.css.core.internal.contentproperties.CSSConte ntProperties.getProperty(String, IResource, boolean) does all of this work; however, it is not API.
Re: How to retrieve Web content settings? [message #668337 is a reply to message #668232] Thu, 05 May 2011 09:23 Go to previous messageGo to next message
Dwight Johnson is currently offline Dwight JohnsonFriend
Messages: 19
Registered: March 2011
Junior Member
Ex-cel-lent, thanks gentlemen!

This indeed finally gave me the desired preference:

String profile = new ProjectScope(project).getNode("org.eclipse.wst.css.core").node( "css-profile").get("<project>", null);

I never would have guessed to have to introduce a subnode.

What I need to do is make a plugin with a custom project and custom nature(s) that overrules the default CSS code completion behaviour with MyCSS. Or in other words: my problem is solved if I can programmatically emulate the behavior of going into the Web content settings preference page, change the profile and press Apply, which updates the projects org.eclipse.wst.css.core.prefs file. The profile combobox shows mycss as a result of the presence of an extension in the plugin.xml of my plugin next to the other css profiles that originate from the org.eclipse.wst.css.core plugin.

So armed with my new knowledge acquired from Nick I tried this:

IScopeContext scopeContext = new ProjectScope(project);
IEclipsePreferences nodeCoreCSS = scopeContext.getNode("css-profile");
nodeCoreCSS.put("css-profile/<project>", "com.mycompany.ide.cssprofile.mycss");
nodeCoreCSS.flush();
// check result
profile = new ProjectScope(project).getNode("org.eclipse.wst.css.core").node( "css-profile").get("<project>", null);


Unfortunately the string profile still contains org.eclipse.wst.css.core.cssprofile.css2 and not com.mycompany.ide.cssprofile.mycss and the org.eclipse.wst.css.core.prefs file has not changed.

Problem: how can I write cssprofile programmatically such that it applies to the entire project and that code completion in .css editors acts accordingly?

P.S. I have seen this code before:
org.eclipse.wst.css.core.internal.contentproperties.CSSContentProperties.getProperty(String, IResource, boolean) does all of this work; however, it is not API.

but I could not figure out what to put into IResource and null does not work.

Re: How to retrieve Web content settings? [message #668361 is a reply to message #668337] Thu, 05 May 2011 12:12 Go to previous messageGo to next message
Dwight Johnson is currently offline Dwight JohnsonFriend
Messages: 19
Registered: March 2011
Junior Member
I found out the solution of my problem myself, always the most satisfying.

I did what I should have earlier, namely enabling Eclipse code debugging to find out what is going on. Through that I learned that the IResource should be simply the project itself! Thus I could apply the setter variant of the snippet of code suggested by Nick:

private void setProjectCSSProfile(IProject project) {
   try {
      CSSContentProperties.setProperty(CSSContentProperties.CSS_PROFILE, project, "org.eclipse.wst.css.core.cssprofile.wap");
   } catch (CoreException e) {
      Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
   }
}


And this neatly sets the CSS profile!

But as Nick already indicated, this is not the official way to set a property since I get this warning:
Multiple markers at this line
	- Discouraged access: The type CSSContentProperties is not accessible due to restriction on required project 
	 org.eclipse.wst.css.core
	- Discouraged access: The type CSSContentProperties is not accessible due to restriction on required project 
	 org.eclipse.wst.css.core
	- Discouraged access: The method setProperty(String, IResource, String) from the type CSSContentProperties is not accessible 
	 due to restriction on required project org.eclipse.wst.css.core
	- Discouraged access: The field CSS_PROFILE from the type CSSContentProperties is not accessible due to restriction on required 
	 project org.eclipse.wst.css.core


So I still would be interested to learn the proper way to set the project level preferences CSSProfile.

[Updated on: Thu, 05 May 2011 12:25]

Report message to a moderator

Re: How to retrieve Web content settings? [message #668363 is a reply to message #668361] Thu, 05 May 2011 12:19 Go to previous messageGo to next message
Dwight Johnson is currently offline Dwight JohnsonFriend
Messages: 19
Registered: March 2011
Junior Member
And for those who might be interested, here is how to enable Eclipse platform code debugging (Eclipse 3.6/Helios)

In the workspace:

- click File > Import >
- under 'Plug-in development' select 'Plug-ins and fragments'
- click Next >
- under 'Import As' select 'Projects from a repository'
- click Next >
- In ID start typing org.eclipse.wst.css... or whatever plugin you want to debug
- click Add
- repeat for all plugins
- click Next >
- select 'Import from HEAD'
- click Finish >
- if the 'Password required' dialog pops up enter 'Anonymous' for user name and leave password empty
- click OK >


The plugin will be downloaded from the Eclipse site. Set breakpoints at interesting locations and off you go!

[Updated on: Thu, 05 May 2011 12:20]

Report message to a moderator

Re: How to retrieve Web content settings? [message #668413 is a reply to message #668363] Thu, 05 May 2011 15:14 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1354
Registered: July 2009
Senior Member
On 5/5/2011 8:19 AM, Dwight Johnson wrote:
> And for those who might be interested, here is how to enable Eclipse
> platform code debuggin in Eclipse 3.6/Helios
>
> In the workspace:
>
> - click File > Import >
> - under 'Plug-in development' select 'Plug-ins and fragments'
> - click Next >
> - under 'Import As' select 'Projects from a repository'
> - click Next >
> - In ID start typing org.eclipse.wst.css... or whatever plugin you want
> to debug
> - click Add
> - repeat for all plugins
> - click Next >
> - select 'Import from HEAD'
> - click Finish >
> - if the 'Password required' dialog pops up enter 'Anonymous' for user
> name and leave password empty
> - click OK >
>
> The plugin will be downloaded from the Eclipse site. Set breakpoints at
> interesting locations and off you go!
>
>

If you not running the latest version of Eclipse under development (at
this moment Indigo), I would recommend using "Import specific version(s)
shown below" instead of "Import from HEAD" . By running Helios (i.e.
WTP 3.2.x) and using "Import from HEAD" at this point in time, you are
pulling down source code for WTP 3.3, which may or may not be
sufficiently different from 3.2.x code to cause problems. By using
"Import specific version(s) shown below" you get the source code that
matches the version of plug-in you are currently running. If you want
the latest code for the version you are running (i.e. latest WTP 3.2.x
source instead of latest WTP 3.3 source) you can update the plug-in
project using these steps:

- right-click on the plug-in project and select 'Replace With' ->
'Another Branch or Version'
- click 'Refresh Tags'
- expand the Branches and select the appropriate branch (which is
hopefully obvious) For WTP 3.2.x, the branch would be 'R3_2_maintenance".
- click Finish.

This will update the plug-in project to the very latest source for that
version. It's possible, though not likely, that this latest source has
not yet been included in the latest build. However, trying to update to
a newer Version instead of a Branch is possible, but more complicated,
because you have to look elsewhere to see which version is the latest
one for the branch you are using.

Cheers,
Larry
Re: How to retrieve Web content settings? [message #668456 is a reply to message #668337] Thu, 05 May 2011 17:49 Go to previous messageGo to next message
Nick Sandonato is currently offline Nick SandonatoFriend
Messages: 126
Registered: July 2009
Senior Member
Hey Dwight,

There's still a problem in your preference setting code

IScopeContext scopeContext = new ProjectScope(project);
IEclipsePreferences nodeCoreCSS = scopeContext.getNode("css-profile");
nodeCoreCSS.put("css-profile/<project>", "com.mycompany.ide.cssprofile.mycss");
nodeCoreCSS.flush();
// check result
profile = new ProjectScope(project).getNode("org.eclipse.wst.css.core").node( "css-profile").get("<project>", null);


The wrong node is gotten from scopeContext. It should be "org.eclipse.wst.css.core" instead of "css-profile". Then the put("<project>", "foo") call should be on the "css-profile" subnode of "org.eclipse.wst.css.core"

Something like this should work:

IScopeContext scopeContext = new ProjectScope(project);
IEclipsePreferences nodeCoreCSS = scopeContext.getNode("org.eclipse.wst.css.core");
nodeCoreCSS.node("css-profile").put("<project>", "com.mycompany.ide.cssprofile.mycss");
nodeCoreCSS.flush();


Hope this helps.

[Updated on: Thu, 05 May 2011 17:50]

Report message to a moderator

Re: How to retrieve Web content settings? [message #668583 is a reply to message #668456] Fri, 06 May 2011 10:38 Go to previous message
Dwight Johnson is currently offline Dwight JohnsonFriend
Messages: 19
Registered: March 2011
Junior Member
Yep, code works perfect.
Thanks everybody, this was a great help!
Have a nice weekend.
Previous Topic:Trimming dynamic web projects
Next Topic:Adding a Java XSLT Processor
Goto Forum:
  


Current Time: Fri Mar 29 05:50:01 GMT 2024

Powered by FUDForum. Page generated in 0.02734 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top