Author: ezheleznyakov
Date: 2007-09-21 09:51:48 -0400 (Fri, 21 Sep 2007)
New Revision: 3755
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-897
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2007-09-21
13:45:20 UTC (rev 3754)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2007-09-21
13:51:48 UTC (rev 3755)
@@ -925,8 +925,12 @@
while ((str = in.readLine()) != null) {
styleText.append(str);
}
+
+ String styleForParse = styleText.toString();
+ styleForParse = VpeStyleUtil.addFullPathIntoURLValue(styleForParse, href_val);
+
in.close();
- nsIDOMText textNode = visualDocument.createTextNode(styleText.toString());
+ nsIDOMText textNode = visualDocument.createTextNode(styleForParse);
linkNode.appendChild(textNode);
return linkNode;
} catch (FileNotFoundException fnfe) {
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java 2007-09-21
13:45:20 UTC (rev 3754)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java 2007-09-21
13:51:48 UTC (rev 3755)
@@ -7,7 +7,7 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.template;
import java.util.ArrayList;
@@ -17,6 +17,7 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilder;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.mozilla.interfaces.nsIDOMAttr;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
@@ -27,23 +28,28 @@
import org.w3c.dom.NodeList;
public class VpeCopyCreator extends VpeAbstractCreator {
+
+ private static String STYLE_ATTR_NAME = "style";
+
private boolean caseSensitive;
private HashSet attrSet;
private VpeCreator attrs[];
-
- VpeCopyCreator(Element copyElement, VpeDependencyMap dependencyMap, boolean
caseSensitive) {
+
+ VpeCopyCreator(Element copyElement, VpeDependencyMap dependencyMap,
+ boolean caseSensitive) {
this.caseSensitive = caseSensitive;
build(copyElement, dependencyMap);
}
private void build(Element copyElement, VpeDependencyMap dependencyMap) {
dependencyMap.setCreator(this, VpeExpressionBuilder.SIGNATURE_ANY_ATTR);
- Attr attrsAttr = copyElement.getAttributeNode(VpeTemplateManager.ATTR_COPY_ATTRS);
+ Attr attrsAttr = copyElement
+ .getAttributeNode(VpeTemplateManager.ATTR_COPY_ATTRS);
if (attrsAttr != null) {
attrSet = new HashSet();
String attrsValue = attrsAttr.getValue();
String[] attrsArr = attrsValue.split(",");
- for (int i = 0; i < attrsArr.length; i++) {
+ for (int i = 0; i < attrsArr.length; i++) {
String attr = attrsArr[i].trim();
if (attr.length() > 0) {
attrSet.add(caseSensitive ? attr : attr.toLowerCase());
@@ -54,34 +60,47 @@
if (copyChildren != null) {
int len = copyChildren.getLength();
if (len > 0) {
- List creatorAttrs = new ArrayList(len);
+ List creatorAttrs = new ArrayList(len);
for (int i = 0; i < len; i++) {
Node innerNode = copyChildren.item(i);
- if (innerNode.getNodeType() == Node.ELEMENT_NODE &&
- VpeTemplateManager.TAG_ATTRIBUTE.equals(innerNode.getNodeName())) {
- String attrName =
((Element)innerNode).getAttribute(VpeTemplateManager.ATTR_ATTRIBUTE_NAME).trim();
+ if (innerNode.getNodeType() == Node.ELEMENT_NODE
+ && VpeTemplateManager.TAG_ATTRIBUTE
+ .equals(innerNode.getNodeName())) {
+ String attrName = ((Element) innerNode).getAttribute(
+ VpeTemplateManager.ATTR_ATTRIBUTE_NAME).trim();
if (attrName.length() > 0) {
- String attrValue =
((Element)innerNode).getAttribute(VpeTemplateManager.ATTR_ATTRIBUTE_VALUE).trim();
- creatorAttrs.add(new VpeAttributeCreator(attrName, attrValue, dependencyMap,
caseSensitive));
+ String attrValue = ((Element) innerNode)
+ .getAttribute(
+ VpeTemplateManager.ATTR_ATTRIBUTE_VALUE)
+ .trim();
+ creatorAttrs.add(new VpeAttributeCreator(attrName,
+ attrValue, dependencyMap, caseSensitive));
}
}
}
if (creatorAttrs.size() > 0) {
- attrs = (VpeCreator[]) creatorAttrs.toArray(new VpeCreator[creatorAttrs.size()]);
+ attrs = (VpeCreator[]) creatorAttrs
+ .toArray(new VpeCreator[creatorAttrs.size()]);
}
}
}
}
- public VpeCreatorInfo create(VpePageContext pageContext, Node sourceNode, nsIDOMDocument
visualDocument, nsIDOMElement visualElement, Map visualNodeMap) {
- nsIDOMElement visualNewElement =
visualDocument.createElement(sourceNode.getNodeName());
+ public VpeCreatorInfo create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument, nsIDOMElement visualElement,
+ Map visualNodeMap) {
+ nsIDOMElement visualNewElement = visualDocument
+ .createElement(sourceNode.getNodeName());
visualNodeMap.put(this, visualNewElement);
- addAttributes((Element)sourceNode, visualNewElement);
+ addAttributes((Element) sourceNode, visualNewElement, pageContext);
if (attrs != null) {
for (int i = 0; i < attrs.length; i++) {
- VpeCreatorInfo attributeInfo = attrs[i].create(pageContext, (Element) sourceNode,
visualDocument, visualNewElement, visualNodeMap);
+ VpeCreatorInfo attributeInfo = attrs[i].create(pageContext,
+ (Element) sourceNode, visualDocument, visualNewElement,
+ visualNodeMap);
if (attributeInfo != null) {
- nsIDOMAttr newVisualAttribute = (nsIDOMAttr)attributeInfo.getVisualNode();
+ nsIDOMAttr newVisualAttribute = (nsIDOMAttr) attributeInfo
+ .getVisualNode();
if (newVisualAttribute != null) {
visualNewElement.setAttributeNode(newVisualAttribute);
}
@@ -90,26 +109,30 @@
}
return new VpeCreatorInfo(visualNewElement);
}
-
- public void setAttribute(VpePageContext pageContext, Element sourceElement, Map
visualNodeMap, String name, String value) {
+
+ public void setAttribute(VpePageContext pageContext, Element sourceElement,
+ Map visualNodeMap, String name, String value) {
if (isAttribute(name)) {
Element visualElement = (Element) visualNodeMap.get(this);
visualElement.setAttribute(name, value);
}
}
- public void removeAttribute(VpePageContext pageContext, Element sourceElement, Map
visualNodeMap, String name) {
+ public void removeAttribute(VpePageContext pageContext,
+ Element sourceElement, Map visualNodeMap, String name) {
if (isAttribute(name)) {
Element visualElement = (Element) visualNodeMap.get(this);
visualElement.removeAttribute(name);
}
}
- public void pseudo(VpePageContext pageContext, Node sourceNode, Node visualNode, Map
visualNodeMap) {
+ public void pseudo(VpePageContext pageContext, Node sourceNode,
+ Node visualNode, Map visualNodeMap) {
visualNodeMap.put(this, visualNode);
}
- private void addAttributes(Element sourceElement, nsIDOMElement visualElement) {
+ private void addAttributes(Element sourceElement,
+ nsIDOMElement visualElement, VpePageContext pageContext) {
NamedNodeMap sourceAttributes = sourceElement.getAttributes();
if (sourceAttributes == null) {
return;
@@ -118,8 +141,13 @@
for (int i = 0; i < len; i++) {
Attr sourceAttr = (Attr) sourceAttributes.item(i);
String name = sourceAttr.getName();
+
+ String value = sourceAttr.getValue();
+ if (name.equalsIgnoreCase(STYLE_ATTR_NAME))
+ value = VpeStyleUtil.addFullPathIntoURLValue(sourceAttr.getValue(),
pageContext.getEditPart().getEditorInput());
+
if (isAttribute(name)) {
- visualElement.setAttribute(name, sourceAttr.getValue());
+ visualElement.setAttribute(name, value);
}
}
}
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java 2007-09-21
13:45:20 UTC (rev 3754)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java 2007-09-21
13:51:48 UTC (rev 3755)
@@ -7,69 +7,77 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.template;
import java.util.Map;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
-public class VpeStyleCreator extends VpeAbstractCreator{
-
- public VpeStyleCreator(Element element, VpeDependencyMap dependencyMap, boolean
caseSensitive) {
- //this.caseSensitive = caseSensitive;
- //build(element, dependencyMap);
+public class VpeStyleCreator extends VpeAbstractCreator {
+
+ public VpeStyleCreator(Element element, VpeDependencyMap dependencyMap,
+ boolean caseSensitive) {
+ // this.caseSensitive = caseSensitive;
+ // build(element, dependencyMap);
}
public VpeCreatorInfo create(VpePageContext pageContext, Node sourceNode,
nsIDOMDocument visualDocument, nsIDOMElement visualElement,
Map visualNodeMap) {
-
+
Node textNode = sourceNode.getFirstChild();
String text = null;
- if(textNode != null){
+ if (textNode != null) {
text = textNode.getNodeValue();
+ text = VpeStyleUtil.addFullPathIntoURLValue(text,
pageContext.getEditPart().getEditorInput());
}
- nsIDOMNode newStyle = pageContext.getVisualBuilder().addStyleNodeToHead(text);
+
+ nsIDOMNode newStyle = pageContext.getVisualBuilder()
+ .addStyleNodeToHead(text);
visualNodeMap.put(this, newStyle);
return null;
}
- public void removeElement(VpePageContext pageContext, Element sourceElement, Map
visualNodeMap) {
-
- nsIDOMNode styleNode = (nsIDOMNode)visualNodeMap.get(this);
-
- if(styleNode != null){
+ 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);
}
-
+
}
- public void refreshElement(VpePageContext pageContext, Element sourceElement, Map
visualNodeMap) {
- nsIDOMNode oldStyleNode = (nsIDOMNode)visualNodeMap.get(this);
-
+ public void refreshElement(VpePageContext pageContext,
+ Element sourceElement, Map visualNodeMap) {
+ nsIDOMNode oldStyleNode = (nsIDOMNode) visualNodeMap.get(this);
+
Node textNode = sourceElement.getFirstChild();
String text = null;
- if(textNode != null){
+ if (textNode != null) {
text = textNode.getNodeValue();
}
nsIDOMNode newStyleNode;
- if(oldStyleNode == null){
- newStyleNode = pageContext.getVisualBuilder().addStyleNodeToHead(text);
+ if (oldStyleNode == null) {
+ newStyleNode = pageContext.getVisualBuilder().addStyleNodeToHead(
+ text);
visualNodeMap.put(this, newStyleNode);
- }else{
- newStyleNode = pageContext.getVisualBuilder().replaceStyleNodeToHead(oldStyleNode,
text);
- if(visualNodeMap.containsKey(this)) visualNodeMap.remove(this);
+ } else {
+ newStyleNode = pageContext.getVisualBuilder()
+ .replaceStyleNodeToHead(oldStyleNode, text);
+ if (visualNodeMap.containsKey(this))
+ visualNodeMap.remove(this);
visualNodeMap.put(this, newStyleNode);
}
-
+
}
}
Modified:
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2007-09-21
13:45:20 UTC (rev 3754)
+++
branches/jbosstools_xulrunner/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2007-09-21
13:51:48 UTC (rev 3755)
@@ -10,6 +10,15 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.util;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.editors.text.ILocationProvider;
import org.w3c.dom.Element;
public class VpeStyleUtil {
@@ -31,7 +40,14 @@
public static final String SPACE_STRING = " ";
public static final String EMPTY_STRING = "";
+ public static String ATTR_URL = "url";
+ public static String OPEN_BRACKET = "(";
+ public static String CLOSE_BRACKET = ")";
+ public static String FILE_PRTOCOL = "file:///";
+ public static String FILE_STR = "file:";
+ public static String FILE_SEPARAROT = "/";
+
// sets parameter position in atribute style to absolute value
public static void setAbsolute(Element sourceElement){
String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
@@ -225,5 +241,185 @@
return result;
}
+
+
+ /**
+ *
+ * @param value
+ * Css string
+ * @param input
+ * The editor input
+ * @return format style string
+ */
+ public static String addFullPathIntoURLValue(String value,
+ IEditorInput input) {
-}
+ String urls[] = value.split(ATTR_URL);
+
+ if (urls.length == 1)
+ return value;
+
+ String finalStr = EMPTY_STRING;
+ for (int i = 1; i < urls.length; i++) {
+
+ urls[i] = urls[i].replace("\'", EMPTY_STRING);
+ urls[i] = ATTR_URL + urls[i];
+
+ int startAttr = urls[i].indexOf(ATTR_URL);
+
+ int startPathIndex = urls[i].indexOf(OPEN_BRACKET, startAttr);
+ int endPathIndex = urls[i].indexOf(CLOSE_BRACKET,
+ startPathIndex + 1);
+
+ if (startPathIndex == -1 || endPathIndex == -1)
+ continue;
+
+ String filePath = urls[i].substring(startPathIndex + 1,
+ endPathIndex);
+ if (filePath.indexOf(FILE_STR) != -1)
+ continue;
+
+ if (!new File(filePath).isAbsolute())
+ filePath = getFilePath(input, filePath);
+
+ filePath = FILE_PRTOCOL + filePath;
+ URL url = null;
+ try {
+ url = new URL(filePath);
+ } catch (MalformedURLException e) {
+ continue;
+ }
+ filePath = url.toString();
+
+ String firstPartValue = urls[i].substring(0, startPathIndex + 1);
+ String secondPartValue = urls[i].substring(endPathIndex, urls[i]
+ .length());
+
+ urls[i] = firstPartValue + filePath + secondPartValue;
+ }
+ for (int i = 0; i < urls.length; i++)
+ finalStr += urls[i];
+ return finalStr;
+ }
+
+ /**
+ *
+ * @param nput
+ * The editor input
+ * @param fileName
+ * Relative path file
+ * @return Absolute path file
+ */
+ public static String getFilePath(IEditorInput input, String fileName) {
+ IPath inputPath = getInputParentPath(input);
+ return inputPath.toOSString() + File.separator + fileName;
+ }
+
+ /**
+ *
+ * @param input
+ * The editor input
+ * @return Path
+ */
+ public static IPath getInputParentPath(IEditorInput input) {
+ IPath inputPath = null;
+ if (input instanceof ILocationProvider) {
+ inputPath = ((ILocationProvider) input).getPath(input);
+ } else if (input instanceof IFileEditorInput) {
+ IFile inputFile = ((IFileEditorInput) input).getFile();
+ if (inputFile != null) {
+ inputPath = inputFile.getLocation();
+ }
+ }
+ if (inputPath != null && !inputPath.isEmpty()) {
+ inputPath = inputPath.removeLastSegments(1);
+ }
+ return inputPath;
+ }
+
+ /**
+ *
+ * @param value
+ * Css string
+ * @param href_val
+ * Path of css file
+ * @return Format style string
+ */
+ public static String addFullPathIntoURLValue(String value, String href_val) {
+
+ String urls[] = value.split(ATTR_URL);
+
+ if (urls.length == 1)
+ return value;
+
+ String finalStr = EMPTY_STRING;
+
+ for (int i = 1; i < urls.length; i++) {
+
+ urls[i] = urls[i].replace("\'", EMPTY_STRING);
+ urls[i] = ATTR_URL + urls[i];
+
+ int startAttr = urls[i].indexOf(ATTR_URL);
+
+ int startPathIndex = urls[i].indexOf(OPEN_BRACKET, startAttr);
+ int endPathIndex = urls[i].indexOf(CLOSE_BRACKET,
+ startPathIndex + 1);
+
+ String filePath = urls[i].substring(startPathIndex + 1,
+ endPathIndex);
+ if (filePath.indexOf(FILE_STR) != -1)
+ continue;
+
+ if (!new File(filePath).isAbsolute())
+ filePath = getAbsolutePathImage(filePath, href_val);
+ else
+ filePath = FILE_PRTOCOL + filePath;
+
+ URL url = null;
+ try {
+ url = new URL(filePath);
+ } catch (MalformedURLException e) {
+ continue;
+ }
+ filePath = url.toString();
+
+ String firstPartValue = urls[i].substring(0, startPathIndex + 1);
+ String secondPartValue = urls[i].substring(endPathIndex, urls[i]
+ .length());
+
+ urls[i] = firstPartValue + filePath + secondPartValue;
+ }
+ for (int i = 0; i < urls.length; i++)
+ finalStr += urls[i];
+ return finalStr;
+ }
+
+ /**
+ *
+ * @param pathImgRelative
+ * Relative path img file
+ * @param pathCssAbsolute
+ * Absolute path css file
+ * @return Absolute path img file
+ */
+ private static String getAbsolutePathImage(String pathImgRelative,
+ String pathCssAbsolute) {
+
+ int k = 0;
+ int j = 0;
+ URL url = null;
+ try {
+ url = new URL(pathCssAbsolute);
+ } catch (MalformedURLException e) {
+
+ }
+ pathCssAbsolute = url.toString();
+ while (j != -1) {
+ j = pathCssAbsolute.indexOf(FILE_SEPARAROT, j + 1);
+ if (j == -1)
+ break;
+ k = j;
+ }
+ return pathCssAbsolute.substring(0, k + 1) + pathImgRelative;
+ }
+}
\ No newline at end of file