Author: ezheleznyakov
Date: 2007-09-21 09:45:20 -0400 (Fri, 21 Sep 2007)
New Revision: 3754
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
trunk/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:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2007-09-21
09:27:07 UTC (rev 3753)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeEditorPart.java 2007-09-21
13:45:20 UTC (rev 3754)
@@ -53,7 +53,6 @@
import org.jboss.tools.common.model.event.XModelTreeEvent;
import org.jboss.tools.common.model.event.XModelTreeListener;
import org.jboss.tools.common.model.ui.util.ModelUtilities;
-import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
import org.jboss.tools.jst.jsp.editor.IVisualEditor;
import org.jboss.tools.jst.jsp.preferences.VpePreference;
import org.jboss.tools.vpe.VpePlugin;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2007-09-21
09:27:07 UTC (rev 3753)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2007-09-21
13:45:20 UTC (rev 3754)
@@ -990,8 +990,12 @@
while ((str = in.readLine()) != null) {
styleText.append(str);
}
+
+ String styleForParse = styleText.toString();
+ styleForParse = VpeStyleUtil.addFullPathIntoURLValue(styleForParse, href_val);
+
in.close();
- Node textNode = visualDocument.createTextNode(styleText.toString());
+ Node textNode = visualDocument.createTextNode(styleForParse);
linkNode.appendChild(textNode);
return linkNode;
} catch (FileNotFoundException fnfe) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java 2007-09-21
09:27:07 UTC (rev 3753)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCopyCreator.java 2007-09-21
13:45:20 UTC (rev 3754)
@@ -25,8 +25,12 @@
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.expression.VpeExpressionBuilder;
import org.jboss.tools.vpe.editor.util.MozillaSupports;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
public class VpeCopyCreator extends VpeAbstractCreator {
+
+ private static String STYLE_ATTR_NAME = "style";
+
private boolean caseSensitive;
private HashSet attrSet;
private VpeCreator attrs[];
@@ -76,7 +80,7 @@
public VpeCreatorInfo create(VpePageContext pageContext, Node sourceNode, Document
visualDocument, Element visualElement, Map visualNodeMap) {
Element 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);
@@ -110,17 +114,22 @@
visualNodeMap.put(this, visualNode);
}
- private void addAttributes(Element sourceElement, Element visualElement) {
+ private void addAttributes(Element sourceElement, Element visualElement, VpePageContext
pageContext) {
NamedNodeMap sourceAttributes = sourceElement.getAttributes();
if (sourceAttributes == null) {
return;
}
int len = sourceAttributes.getLength();
for (int i = 0; i < len; i++) {
- Attr sourceAttr = (Attr) sourceAttributes.item(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:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java 2007-09-21
09:27:07 UTC (rev 3753)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeStyleCreator.java 2007-09-21
13:45:20 UTC (rev 3754)
@@ -17,6 +17,7 @@
import org.w3c.dom.Node;
import org.jboss.tools.vpe.editor.context.VpePageContext;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
public class VpeStyleCreator extends VpeAbstractCreator{
@@ -33,6 +34,7 @@
String text = null;
if(textNode != null){
text = textNode.getNodeValue();
+ text = VpeStyleUtil.addFullPathIntoURLValue(text,
pageContext.getEditPart().getEditorInput());
}
Node newStyle = pageContext.getVisualBuilder().addStyleNodeToHead(text);
visualNodeMap.put(this, newStyle);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2007-09-21
09:27:07 UTC (rev 3753)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2007-09-21
13:45:20 UTC (rev 3754)
@@ -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,184 @@
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