### Eclipse Workspace Patch 1.0
#P org.jboss.tools.vpe
Index: src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
--- src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java	(revision 37260)
+++ src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java	(working copy)
@@ -19,6 +19,8 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -81,6 +83,8 @@
 	 * (.*) should be replaced with ([^;]*) 
 	 */
 	public static final Pattern CSS_URL_PATTERN = Pattern.compile("(?<=\\burl\\b)(?:[\\p{Space}]*\\()[\\p{Space}]*([^;]*)[\\p{Space}]*(?:\\)[\\p{Space}]*)(?=(?>[^\\)]*;|[^\\)]*))"); //$NON-NLS-1$
+	public static final Pattern CSS_IMPORT_PATTERN = Pattern.compile("@import[\\p{Space}]+(?:\\burl\\b[\\p{Space}]*\\()*[\\p{Space}]*([^;]*)[\\p{Space}]*(?:\\)[\\p{Space}]*(?=(?>[^\\)]*;|[^\\)]*)))*"); //$NON-NLS-1$
+	public static final Pattern CSS_URI_PATTERN = Pattern.compile("(?:\\\"{1}(.*)\\\"{1})|(?:\\'{1}(.*)\\'{1})"); //$NON-NLS-1$
 	
 	public static String ATTR_URL = "url"; //$NON-NLS-1$
 	public static String OPEN_BRACKET = "("; //$NON-NLS-1$
@@ -438,11 +442,7 @@
 		if (urls.length == 1) {
 			return value;
 		}
-		IFile file = null;
-		final VpeIncludeInfo vii = pageContext.getVisualBuilder().getCurrentIncludeInfo();
-		if (vii != null && (vii.getStorage() instanceof IFile)) {
-			file = (IFile) vii.getStorage();
-		}
+		IFile file = getSourceFileFromPageContext(pageContext);
 		for (int i = 1; i < urls.length; i++) {
 			urls[i] = removeQuotesUpdate(urls[i]);
 			String[] urlParts = splitURL(urls[i]);
@@ -450,7 +450,7 @@
 				continue;
 			}
 			if (file != null) {
-				urlParts[1] = processUrl(urlParts[1], file);
+				urlParts[1] = processUrl(urlParts[1], file, true);
 			}
 			urls[i] = collectArrayInto1Str(urlParts);
 		}
@@ -484,7 +484,7 @@
 				// ignore
 			}
 			if (sourceFile != null) {
-				urlParts[1] = processUrl(urlParts[1], sourceFile);
+				urlParts[1] = processUrl(urlParts[1], sourceFile, true);
 			} else {
 				urlParts[1] = updateURLFilePath(urlParts[1], href_val);
 				if (urlParts[1] == null) {
@@ -685,20 +685,26 @@
 	public static IPath getRootPath(IEditorInput input) {
 		IPath rootPath = null;
 		if (input instanceof IFileEditorInput) {
-			IProject project = ((IFileEditorInput) input).getFile().getProject();
-			if (project != null && project.isOpen()) {
-				IModelNature modelNature = EclipseResourceUtil.getModelNature(project);
-				if (modelNature != null) {
-					XModel model = modelNature.getModel();
-					String rootPathStr = WebProject.getInstance(model).getWebRootLocation();
-					if (rootPathStr != null) {
-						rootPath = new Path(rootPathStr);
-					} else {
-						rootPath = project.getLocation();
-					}
+			rootPath = getRootPath(((IFileEditorInput) input).getFile());
+		}
+		return rootPath;
+	}
+	
+	public static IPath getRootPath(IFile inputFile) {
+		IPath rootPath = null;
+		IProject project = inputFile.getProject();
+		if (project != null && project.isOpen()) {
+			IModelNature modelNature = EclipseResourceUtil.getModelNature(project);
+			if (modelNature != null) {
+				XModel model = modelNature.getModel();
+				String rootPathStr = WebProject.getInstance(model).getWebRootLocation();
+				if (rootPathStr != null) {
+					rootPath = new Path(rootPathStr);
 				} else {
 					rootPath = project.getLocation();
 				}
+			} else {
+				rootPath = project.getLocation();
 			}
 		}
 		return rootPath;
@@ -783,7 +789,7 @@
 		return Integer.toString(position) + PX_STRING;
 	}
 
-	public static String processUrl(String url, IFile baseFile) {
+	public static String processUrl(String url, IFile baseFile, boolean putIntoQuotes) {
 		String resolvedUrl = url.replaceFirst(
 				"^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}", Constants.EMPTY); //$NON-NLS-1$
 		resolvedUrl = ElServiceUtil.replaceEl(baseFile, resolvedUrl);
@@ -799,22 +805,34 @@
 		}
 		if (uri == null || !uri.isAbsolute()) {
 			String decodedUrl = decodeUrl(resolvedUrl);
-			Path path = new Path(decodedUrl);
-			if (decodedUrl.startsWith("/") && (null != path.segment(0))//$NON-NLS-1$
-					&& path.segment(0).equals(baseFile.getProject().getName())) {
-				decodedUrl = "/" + path.removeFirstSegments(1).toPortableString(); //$NON-NLS-1$
-			}
+			Path decodedPath = new Path(decodedUrl);
+			IPath goodPath = null;  
+			if (decodedUrl.startsWith("/") && (null != decodedPath.segment(0))//$NON-NLS-1$
+					&& decodedPath.segment(0).equals(baseFile.getProject().getName())) {
+				decodedUrl = "/" + decodedPath.removeFirstSegments(1).toPortableString(); //$NON-NLS-1$
+			} 
 			IFile file = FileUtil.getFile(decodedUrl, baseFile);
 			if (file != null && file.getLocation() != null) {
-				resolvedUrl = pathToUrl(file.getLocation());
+				goodPath = file.getLocation();
+			} else if (decodedPath.isAbsolute()) {
+				goodPath = getRootPath(baseFile).append(decodedPath);
+				if (!goodPath.toFile().exists()) {
+					goodPath = null;
+				}
 			}
+			if (goodPath != null) {
+				resolvedUrl = pathToUrl(goodPath);
+			}
 		}
 		/*
 		 * https://issues.jboss.org/browse/JBIDE-9975
 		 * Put the URL into quotes.
 		 * It's default xulrunner behavior.
 		 */
-		return QUOTE_STRING + resolvedUrl + QUOTE_STRING;
+		if (putIntoQuotes) {
+			resolvedUrl = QUOTE_STRING + resolvedUrl + QUOTE_STRING; 
+		}
+		return resolvedUrl;
 	}
 
 	private static String pathToUrl(IPath location) {
@@ -858,4 +876,68 @@
 						: HTML.STYLE_VALUE_NONE, HTML.STYLE_PRIORITY_IMPORTANT);
 
 	}
+	
+	/**
+	 * Finds CSS @import url(".."); construction
+	 * 
+	 * @param cssText the css text
+	 * @param pageContext VPE page context 
+	 * @return the map with the import statement as a key and the css file path as a value
+	 */
+	public static List<String> findCssImportConstruction(String cssText, VpePageContext pageContext) {
+		ArrayList<String> list = new ArrayList<String>();
+		IFile sourceFile = getSourceFileFromPageContext(pageContext);
+		String path = null;
+		Matcher m = CSS_IMPORT_PATTERN.matcher(cssText);
+		while (m.find()) {
+			path = m.group(1);
+			/*
+			 * Path should be a well formed URI
+			 */
+			path = getCorrectURI(path);
+			list.add(processUrl(path, sourceFile, false));
+		}
+		return list;
+	}
+	
+	public static IFile getSourceFileFromPageContext(VpePageContext pageContext) {
+		IFile file = null;
+		final VpeIncludeInfo vii = pageContext.getVisualBuilder().getCurrentIncludeInfo();
+		if ((vii != null) && (vii.getStorage() instanceof IFile)) {
+			file = (IFile) vii.getStorage();
+		}
+		return file;
+	}
+	
+	/**
+	 * Determine correct uri in the input path:
+	 * Remove quotes and brackets
+	 * 
+	 * @param path input path
+	 * @return correct URI string
+	 */
+	private static String getCorrectURI(String path) {
+		String uri = path;
+		if (path.endsWith(CLOSE_BRACKET)) {
+			uri = uri.substring(0, uri.length() -1);
+		}
+		Matcher m = CSS_URI_PATTERN.matcher(uri);
+		/*
+		 * Find uri in quotes " or '
+		 */
+		if (m.find()) {
+			if ((m.group(1) != null) 
+					&& !EMPTY_STRING.equalsIgnoreCase(m.group(1))) {
+				uri = m.group(1);
+			} else if ((m.group(2) != null) 
+					&& !EMPTY_STRING.equalsIgnoreCase(m.group(2))) {
+				uri = m.group(2);
+			}
+		} else {
+			/*
+			 * There is no quotes
+			 */
+		}
+		return uri;
+	}
 }
Index: src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
--- src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java	(revision 37260)
+++ src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java	(working copy)
@@ -1117,8 +1117,8 @@
 
 	private nsIDOMElement createLinkNode(String href_val, String rel_val,
 			String ext_val) {
-		nsIDOMElement linkNode = null;
-		if ((ATTR_REL_STYLESHEET_VALUE.equalsIgnoreCase(rel_val))
+		nsIDOMElement inlineStyle = null;
+		if (ATTR_REL_STYLESHEET_VALUE.equalsIgnoreCase(rel_val)
 				&& href_val.startsWith("file:")) { //$NON-NLS-1$
 			/*
 			 * Because of the Mozilla caches the linked css files we replace tag
@@ -1126,33 +1126,29 @@
 			 * vpe="ATTR_VPE_INLINE_LINK_VALUE">file content</style> It is
 			 * LinkReplacer
 			 */
-			linkNode = getVisualDocument().createElement(HTML.TAG_STYLE);
-			linkNode.setAttribute(ATTR_VPE, ATTR_VPE_INLINE_LINK_VALUE);
+			inlineStyle = getVisualDocument().createElement(HTML.TAG_STYLE);
+			inlineStyle.setAttribute(ATTR_VPE, ATTR_VPE_INLINE_LINK_VALUE);
 
 			/* Copy links attributes into our <style> */
-			linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
-			linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
+			inlineStyle.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
+			inlineStyle.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
 			BufferedReader in = null;
 			try {
 				StringBuilder styleText = new StringBuilder(EMPTY_STRING);
 				URL url = new URL((new Path(href_val)).toOSString());
 				String fileName = url.getFile();
-				in = new BufferedReader(new FileReader(
-						(fileName)));
+				in = new BufferedReader(new FileReader((fileName)));
 				String str = EMPTY_STRING;
 				while ((str = in.readLine()) != null) {
 					styleText.append(str);
 				}
+				in.close();
 
 				String styleForParse = styleText.toString();
 				styleForParse = VpeStyleUtil.addFullPathIntoURLValue(
 						styleForParse, href_val);
-
-				in.close();
-				nsIDOMText textNode = getVisualDocument()
-						.createTextNode(styleForParse);
-				linkNode.appendChild(textNode);
-				return linkNode;
+				inlineStyle.appendChild(getVisualDocument().createTextNode(styleForParse));
+				return inlineStyle;
 			} catch (FileNotFoundException fnfe) {
 				/* File which was pointed by user is not exists. Do nothing. */
 			} catch (IOException ioe) {
@@ -1168,12 +1164,12 @@
 			}
 		}
 
-		linkNode = getVisualDocument().createElement(HTML.TAG_LINK);
-		linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_REL, rel_val);
-		linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
-		linkNode.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
+		inlineStyle = getVisualDocument().createElement(HTML.TAG_LINK);
+		inlineStyle.setAttribute(VpeTemplateManager.ATTR_LINK_REL, rel_val);
+		inlineStyle.setAttribute(VpeTemplateManager.ATTR_LINK_HREF, href_val);
+		inlineStyle.setAttribute(VpeTemplateManager.ATTR_LINK_EXT, ext_val);
 
-		return linkNode;
+		return inlineStyle;
 	}
 
 	private boolean isLinkReplacer(nsIDOMNode node) {
Index: src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
===================================================================
--- src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java	(revision 37260)
+++ src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java	(working copy)
@@ -10,9 +10,13 @@
  ******************************************************************************/
 package org.jboss.tools.vpe.editor.template;
 
+import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
 
+import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
 import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.util.Constants;
 import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
 import org.mozilla.interfaces.nsIDOMDocument;
 import org.mozilla.interfaces.nsIDOMElement;
@@ -35,9 +39,21 @@
 		String text = null;
 		if (textNode != null) {
 			text = textNode.getNodeValue();
+			/*
+			 * Add inline <style> element for each found css @import
+			 */
+			List<String> imports = VpeStyleUtil.findCssImportConstruction(text, pageContext);
+			VpeVisualDomBuilder vvdb = pageContext.getVisualBuilder();
+			for (String key : imports) {
+				vvdb.addLinkNodeToHead(key, "css_import_construction", false); //$NON-NLS-1$
+			}
+			/*
+			 * Replace the text
+			 */
+			Matcher m = VpeStyleUtil.CSS_IMPORT_PATTERN.matcher(text);
+			text = m.replaceAll(Constants.EMPTY);
 			text = VpeStyleUtil.addFullPathIntoURLValue(text, pageContext);
 		}
-
 		nsIDOMNode newStyle = pageContext.getVisualBuilder()
 				.addStyleNodeToHead(text);
 		visualNodeMap.put(this, newStyle);
@@ -47,14 +63,11 @@
 	@Override
 	public void removeElement(VpePageContext pageContext,
 			Element sourceElement, Map visualNodeMap) {
-
 		nsIDOMNode styleNode = (nsIDOMNode) visualNodeMap.get(this);
-
 		if (styleNode != null) {
 			pageContext.getVisualBuilder().removeStyleNodeFromHead(styleNode);
 			visualNodeMap.remove(this);
 		}
-
 	}
 
 	@Override
@@ -69,8 +82,8 @@
 		}
 		nsIDOMNode newStyleNode;
 		if (oldStyleNode == null) {
-			newStyleNode = pageContext.getVisualBuilder().addStyleNodeToHead(
-					text);
+			newStyleNode = pageContext.getVisualBuilder().
+					addStyleNodeToHead(text);
 			visualNodeMap.put(this, newStyleNode);
 		} else {
 			newStyleNode = pageContext.getVisualBuilder()
@@ -79,6 +92,5 @@
 				visualNodeMap.remove(this);
 			visualNodeMap.put(this, newStyleNode);
 		}
-
 	}
-}
+}
\ No newline at end of file
