Here you can find the source of loadStyleSheet(URL url)
Parameter | Description |
---|---|
url | location to the css file |
Parameter | Description |
---|---|
IOException | if file doesn't exist or some problem occurs during readingdata from file |
public static StyleSheet loadStyleSheet(URL url) throws IOException
//package com.java2s; /*//www .ja va 2 s . c o m * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Reader; import java.io.Writer; import java.net.URL; import javax.swing.text.html.StyleSheet; public class Main { /** * Loads a set of rules that have been specified in terms of CSS1 grammar. * * @param path * absolute path to the css file. * @return style sheet (css1) * @throws IOException * if file doesn't exist or some problem occurs during reading * data from file */ public static StyleSheet loadStyleSheet(String path) throws IOException { StyleSheet ss = new StyleSheet(); FileReader fr = new FileReader(path); BufferedReader reader = new BufferedReader(fr); ss.loadRules(reader, null); reader.close(); return ss; } /** * Loads a set of rules that have been specified in terms of CSS1 grammar. * * @param url * location to the css file * @return style sheet (css1) * @throws IOException * if file doesn't exist or some problem occurs during reading * data from file */ public static StyleSheet loadStyleSheet(URL url) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( url.openStream())); StyleSheet ss = new StyleSheet(); ss.loadRules(reader, null); return ss; } /** * Closes the streams and resources. * * @param resource * to be closed. */ public static void close(Object resource) { try { if (resource instanceof InputStream) { ((InputStream) resource).close(); } else if (resource instanceof OutputStream) { ((OutputStream) resource).close(); } else if (resource instanceof Reader) { ((Reader) resource).close(); } else if (resource instanceof Writer) { ((Writer) resource).close(); } else if (resource instanceof RandomAccessFile) { ((RandomAccessFile) resource).close(); } else if (resource != null) { throw new IllegalArgumentException("Unknown resource: " + resource); } } catch (IOException e) { } } }