Solved

how to dynamically change the values of a style sheet

Posted on 2006-06-09
14
341 Views
Last Modified: 2013-12-03
I am creating a 2 level content management system, where the admin would be able to change the content and layout of the entire website. Currently I am working on so that the admin would be able change diiffrent style sheet attributes from the admin menu

e.g.

For the <h1> defined in the stylesheet, the admin would be able to dynamically change the font_size, font_color etc.
It might be looking easy to you but the tricky part is this same web content managenet appliation wll be used by many people, which means that many people will have this same website but with differnt data and layout(color, images) etc, all differntiated by a webiste ID.

Now what I thought was that  I will have a form where I take the users input on the font and save it in a database using that webiste ID. When the users of the wesite try to access the site the style is generated from the data in the database. But this seems to be hectic procedure because everytime the user tried to access a page of the wesite it will have to re-generate the stylesheet again.

Now is there any easy way I can generate the stylesheet only once. Any help will be greatly appreciated
0
Comment
Question by:royalcyber
  • 5
  • 3
  • 3
  • +2
14 Comments
 
LVL 3

Expert Comment

by:runa_paathak
Comment Utility
Generate the stylesheet once, and store the contents of the stylesheet (text) into your database against the website id for the user. When the user accesses the page, you can obtain the stylesheet directly without generating it everytime.
0
 

Author Comment

by:royalcyber
Comment Utility
I actually thought about this method but my question is when should i generate the stylesheet? everytime a change is made and should there be one stylesheet for all different websites? because what if more than one website are being accessed at the same time? If I need to do that that also it will be too cumersome. Would there be an other method easier than this.

Thanks

0
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
Hi,

Can you explain more about your problem? I can't really understand it :)

David
0
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
Do you want the content management to have a customizable CSS that each user can choose on? or only admin can change the CSS style?

David
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
I think you will have to keep as many stylesheets as your web site ids... these style sheets can be stored on your web server locally...
depending upon the web site id, you will need to apply the appropriate style sheet..
this saves your from generating the style sheet on every access of the site.. however you will have to make your pages dynamic to pick up the correct style sheet depending upon the web site id.
0
 

Author Comment

by:royalcyber
Comment Utility
David I am actually creating a content management software for a institute, which have students throughpot the country. Each state has a different chapter(hence a website) and an admin assigned to that chapter. The admin should have the priveleges to change the stylesheet of their chapter and the problem I am facing is that if one admin logs on to change values of the stylesheet and then a student logs on to view data in that chapter  so do I need to generate the stylesheet for every page it accesses. Is there any better solution.

Kuldeepchatruvedi if i use differnt stylesheet for all the chapter website then should I probably have to use if statement in my jsp code to use stylesheet based on the id but in that case I new chapters are created i need to add them in the if statement. also how would I change the contents of the different stylesheets.

Thanks
0
 
LVL 4

Accepted Solution

by:
pablomorales earned 500 total points
Comment Utility
The solution to your problem is to have one file for each chapter and generate the filename of the CSS file dynamically in the JSP. Like this:

<%@page language="java" %><%

String chapterName="chapter1"; // Get chapter name from wherever you have it.

%>
<html>
<head>
<title>Testing</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()+"/css/"+chapterName+".ccs"%>">
</head>
<body>
<h1>Testing for chapter1</h1>
<p>This is a test</p>
</body>
</html>

This way when the administrator of the chapter changes the CSS you just modify the corresponding file and all users will see the changes as soon as they reload the page.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 4

Expert Comment

by:pablomorales
Comment Utility
By the way you can include this code in all your pages by using the <%@include file="..." %> directive.

The other option would be to insert Javascript in the page that dynamically loads the correct CSS file. Since the chapter id is in the URL you could extract it and then call a JSP that generates the CSS file.

Unfortunatly there is really no way arround having to modify all your pages one way or another the easiest may be to just include the JSP to generate the correct CSS filename.
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
I dont think you need if conditions in your jsp pages..
you can create a table in the database where you can keep the name of CSS & the web id... at runtime query the table to get the CSS & then include it..
you can write a short jsp page which then gets included in all your pages...
like CSS.jsp..
<%
//connect to the database
get the CSS Name

String CSS = CSS name
%>

in all your jsps

<%@include file="CSS.jsp" %>
<link rel=stylesheet href="<%=CSS%>" type="text/css">
0
 
LVL 4

Expert Comment

by:pablomorales
Comment Utility
The problem with the approach given by Kuldeepchaturvedi is that is not as efficient since the browser will not be able to cache the CSS file. Most modern browsers will ask the server if the file has changed since it was last downloaded and only download it if it has.
0
 

Author Comment

by:royalcyber
Comment Utility
pablomorales, If I use your idea, can you please tell me how would I be able to change the stylesheet when the admin makes some changes

Thanks
0
 
LVL 4

Expert Comment

by:pablomorales
Comment Utility
I'm guessing you hava a Servlet or JSP that processes the changes from Admin interface. This is where you would generate the CSS file and save it to the correct directory. You can use something like this in the JSP that receives the POST of the form data:
<%

String chapterName="chapter1";
String headerSize=request.getParameter("headerSize");
...

PrintWriter css = new PrintWriter(  application.getRealPath( "/css/"+chapterName+".css" );
css.println("h1 { font-size:" + headerSize + "; }");
...
css.close();

%>
<html>
<head>
<title>Style changed</title>
</head>
<body>
Your style has been changed
</doby>
</html>
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
>>The problem with the approach given by Kuldeepchaturvedi is that is not as efficient since the browser will not be able to cache
Well I beg to differ on this... at the end of the day browser only gets to see the generated HTML from your jsp..
so no matter how you get to the CSS name, it will always be cached...
basically there is no difference between your approach & mine... I am only saying to get the CSS name from database ( or wherever else it can be stored).. while you are asking the chapter name to be stored somewhere...
End result will be the same in both cases...
0
 
LVL 4

Expert Comment

by:pablomorales
Comment Utility
I agree with you to a degree. You can get the browser to cache a JSP file generated from a database file, but only if you override the getLastModified() method of javax.servlet.http.HttpServlet in your JSP. You would also need to store the last modified date on your database and preform a query against the database every time a user request the CSS file. This requires more programming work and it is still not as efficient as a file access.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now