Author: yradtsevich
Date: 2011-07-27 11:22:17 -0400 (Wed, 27 Jul 2011)
New Revision: 33247
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/ElPreferencesTestCase.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2594Test.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.richfaces.test/src/org/jboss/tools/jsf/vpe/richfaces/test/jbide/RichFacesJBIDE1169Test.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.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/context/VpePageContext.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/proxy/VpeNodeInvocationHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/resize/VpeResizer.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-9372 : VPE has a serious performance drawback for
rather big pages
- Applied JBIDE-9372_20110722_2.patch provided by Vitali Yemialyanchyk
- Minor code changes
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.richfaces/src/org/jboss/tools/jsf/vpe/richfaces/ComponentUtil.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -278,7 +278,7 @@
if (file == null)
return resolvedValue;
- resolvedValue = ElService.getInstance().replaceEl(file, resolvedValue);
+ resolvedValue = ElService.replaceEl(file, resolvedValue);
URI uri = null;
try {
@@ -584,7 +584,7 @@
||!(pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage()
instanceof IFile)) {
return;
}
- String path =
ElService.getInstance().replaceEl((IFile)pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage(),
fileImageName);
+ String path =
ElService.replaceEl((IFile)pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage(),
fileImageName);
File file = new File(inputPath.toOSString() + File.separator + path);
if (file.exists()) {
img.setAttribute(HTML.ATTR_SRC, HtmlComponentUtil.FILE_PROTOCOL +
inputPath.toString() + "/" //$NON-NLS-1$
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/ElPreferencesTestCase.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/ElPreferencesTestCase.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/ElPreferencesTestCase.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -42,7 +42,7 @@
*/
public void testReplaceAttributeValue() throws CoreException {
String string1 = "#{beanA.property1}/images/smalle.gif"; //$NON-NLS-1$
- String replacedValue = ElService.getInstance().replaceEl(file, string1);
+ String replacedValue = ElService.replaceEl(file, string1);
assertEquals("Should be equals " + elValuesMap.get(KEY_1) +
"/images/smalle.gif", replacedValue, elValuesMap.get(KEY_1) //$NON-NLS-1$
//$NON-NLS-2$
+ "/images/smalle.gif"); //$NON-NLS-1$
@@ -57,7 +57,7 @@
public void testReplaceAttributeValue2() throws CoreException {
String string1 =
"#{beanA.property1}/images/#{beanA.property2}/path2/#{facesContext.requestPath}/smalle.gif";
//$NON-NLS-1$
- final String replacedValue = ElService.getInstance().replaceEl(file, string1);
+ final String replacedValue = ElService.replaceEl(file, string1);
final String check = elValuesMap.get(KEY_1) + "/images/" +
elValuesMap.get(KEY_2) + "/path2/" + elValuesMap.get(KEY_3) //$NON-NLS-1$
//$NON-NLS-2$
+ "/smalle.gif"; //$NON-NLS-1$
assertEquals("Should be equals " + check, check, replacedValue);
//$NON-NLS-1$
@@ -70,6 +70,6 @@
public void testReplaceNotInSet() {
String string1 = "#{requestScope}/smalle.gif"; //$NON-NLS-1$
- assertEquals("Should be equals", string1,
ElService.getInstance().replaceEl(file, string1)); //$NON-NLS-1$
+ assertEquals("Should be equals", string1, ElService.replaceEl(file,
string1)); //$NON-NLS-1$
}
}
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2594Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2594Test.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE2594Test.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -67,7 +67,7 @@
public void testReplaceGlobalElVariable(){
String replaceString=
"#{"+KEY_6+"}"+"images/test.gif"; //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- String replacedString = ElService.getInstance().replaceEl(file, replaceString);
+ String replacedString = ElService.replaceEl(file, replaceString);
assertEquals("Should be equals " + globalElMap.get(KEY_6) +
"images/test.gif", replacedString, globalElMap.get(KEY_6) //$NON-NLS-1$
//$NON-NLS-2$
+ "images/test.gif"); //$NON-NLS-1$
@@ -80,7 +80,7 @@
*/
public void testOverrideLocalVariable() throws CoreException {
String string1 = "${" + KEY_1 + "}" + KEY_1_POSTFIX;
//$NON-NLS-1$ //$NON-NLS-2$
- String replacedValue = ElService.getInstance().replaceEl(file, string1);
+ String replacedValue = ElService.replaceEl(file, string1);
assertEquals(elValuesMap.get(KEY_1) + KEY_1_POSTFIX, replacedValue);
}
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.richfaces.test/src/org/jboss/tools/jsf/vpe/richfaces/test/jbide/RichFacesJBIDE1169Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.richfaces.test/src/org/jboss/tools/jsf/vpe/richfaces/test/jbide/RichFacesJBIDE1169Test.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.richfaces.test/src/org/jboss/tools/jsf/vpe/richfaces/test/jbide/RichFacesJBIDE1169Test.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -48,7 +48,7 @@
}
public void testJBIDE1169() {
- String replacedValue =
ElService.getInstance().replaceEl(testFile,"#{"+RICH_FACES_SKIN_KEY+'}');
//$NON-NLS-1$
+ String replacedValue =
ElService.replaceEl(testFile,"#{"+RICH_FACES_SKIN_KEY+'}');
//$NON-NLS-1$
assertEquals("Skin value should be equals",SKIN_VALUE, replacedValue);
//$NON-NLS-1$
}
/**
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/dnd/VpeDnDHelper.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -97,7 +97,7 @@
}
public boolean isDropEnabled(VpePageContext pageContext, Node container, Node node){
- if(!pageContext.isAbsolutePosition() && isAncestor(container, node)) return
false;
+ if(!VpePageContext.isAbsolutePosition() && isAncestor(container, node)) return
false;
if(isContainer){
if(enabledTags != null && enabledTags.size() > 0){
String name = node.getNodeType() == Node.ELEMENT_NODE ?
node.getLocalName().toLowerCase() : node.getNodeName();
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpePreviewDomBuilder.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -74,7 +74,7 @@
//FIX FOR JBIDE-1568, added by Max Areshkau
try {
- if (ElService.getInstance().isELNode(getPageContext(), sourceNode)) {
+ if (ElService.isELNode(getPageContext(), sourceNode)) {
final Node sourceNodeProxy =
VpeProxyUtil.createProxyForELExpressionNode(getPageContext(),
sourceNode);
try {
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 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -173,7 +173,7 @@
for (long i = len - 1; i >= 0; i--) {
getContentArea().removeChild(children.item(i));
}
- VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
+ final VpeSourceDomBuilder sourceBuilder = pageContext.getSourceBuilder();
IDocument document = sourceBuilder.getStructuredTextViewer()
.getDocument();
if (document == null) {
@@ -184,12 +184,12 @@
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) input).getFile();
if (file != null) {
- includeStack.add(new VpeIncludeInfo(null, file, pageContext
- .getSourceBuilder().getSourceDocument()));
+ pushIncludeStack(new VpeIncludeInfo(null, file, sourceBuilder.getSourceDocument()));
}
}
pageContext.refreshConnector();
+ pageContext.refreshResReferences();
// FIXED FOR JBIDE-3799 by sdzmitrovich
// it code is not necessary because addExternalLinks() does the same but
@@ -263,7 +263,15 @@
*/
private boolean addNode(Node sourceNode, nsIDOMNode visualNextNode, nsIDOMNode
visualContainer) {
try {
- nsIDOMNode visualNewNode = createNode(sourceNode, visualContainer);
+
+ nsIDOMNode visualNewNode = null;
+
+ try {
+ visualNewNode = createNode(sourceNode, visualContainer);
+ } catch (Exception ex) {
+ VpePlugin.getPluginLog().logError(ex);
+ }
+
// Commented as fix for JBIDE-3012.
// // Fix for JBIDE-1097
// try {
@@ -329,7 +337,7 @@
if(visualEditor.getController().getSelectionManager()!=null) {
// reads and dispatch events, this code prevent eclipse
//from sleeping during processing big pages
- getPageContext().processDisplayEvents();
+ VpePageContext.processDisplayEvents();
}
// JBIDE-675, checks if editor was disposed or not
if (getPageContext().getSourceBuilder() == null
@@ -357,7 +365,7 @@
Node sourceNodeProxy = null;
// FIX FOR JBIDE-1568, added by Max Areshkau
try {
- if (ElService.getInstance().isELNode(getPageContext(), sourceNode)) {
+ if (ElService.isELNode(getPageContext(), sourceNode)) {
sourceNodeProxy = VpeProxyUtil.createProxyForELExpressionNode(
getPageContext(), sourceNode);
try {
@@ -381,6 +389,11 @@
VpeTemplate defTemplate = getTemplateManager().getDefTemplate();
creationData = defTemplate.create(getPageContext(), sourceNode,
getVisualDocument());
+ } catch (Exception ex) {
+ VpePlugin.getPluginLog().logError(ex);
+ VpeTemplate defTemplate = getTemplateManager().getDefTemplate();
+ creationData = defTemplate.create(getPageContext(), sourceNode,
+ getVisualDocument());
}
if (creationData == null) {
VpePlugin.getDefault().logError(
@@ -476,14 +489,16 @@
visualNewNode= span;
}
getPageContext().setCurrentVisualNode(visualOldContainer);
- template.validate(getPageContext(), sourceNode, getVisualDocument(),
- creationData);
+ try {
+ template.validate(getPageContext(), sourceNode, getVisualDocument(), creationData);
+ } catch (Exception ex) {
+ VpePlugin.getPluginLog().logError(ex);
+ }
getPageContext().setCurrentVisualNode(null);
if (border != null) {
return border;
- } else {
- return visualNewNode;
}
+ return visualNewNode;
}
protected void correctVisualAttribute(nsIDOMElement element) {
@@ -679,8 +694,12 @@
private void setPseudoContent(VpeTemplate containerTemplate,
Node sourceContainer, nsIDOMNode visualContainer) {
if (containerTemplate != null) {
- containerTemplate.setPseudoContent(pageContext, sourceContainer,
+ try {
+ containerTemplate.setPseudoContent(pageContext, sourceContainer,
visualContainer, getVisualDocument());
+ } catch (Exception ex) {
+ VpePlugin.getPluginLog().logError(ex);
+ }
} else {
try {
VpeDefaultPseudoContentCreator.getInstance().setPseudoContent(
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -7,19 +7,15 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.vpe.editor.context;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
@@ -29,11 +25,12 @@
import org.jboss.tools.jst.jsp.editor.IVisualContext;
import org.jboss.tools.jst.jsp.preferences.VpePreference;
import org.jboss.tools.jst.web.tld.TaglibData;
-import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.VpeEditorPart;
+import org.jboss.tools.vpe.editor.VpeIncludeInfo;
import org.jboss.tools.vpe.editor.VpeSourceDomBuilder;
import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.util.ElService;
import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
import org.jboss.tools.vpe.resref.core.RelativeFolderReferenceList;
@@ -45,47 +42,48 @@
/**
* Contains the information on edited page.
*/
-
+@SuppressWarnings("restriction")
public class VpePageContext implements IVisualContext {
- private Set connectorDocuments = new HashSet();
+
+ public static final String CUSTOM_ELEMENTS_ATTRS = "customElementsAttributes";
//$NON-NLS-1$
+ public static final String CURRENT_VISUAL_NODE = "currentVisualNode";
//$NON-NLS-1$
+ public static final String RES_REFERENCES = "resourceReferences";
//$NON-NLS-1$
+
private BundleMap bundle;
- private Set bundleDependencySet = new HashSet();
private VpeSourceDomBuilder sourceBuilder;
private VpeVisualDomBuilder visualBuilder;
private VpeEditorPart editPart;
- private nsIDOMNode currentVisualNode;
- /**
- * Created to store custom element attributes and use it in time of
- * rendering
- * @author mareshkau
- */
- private Map<String,String> customElementsAttributes;
-
-
+ protected Map<String, Object> values = new HashMap<String, Object>();
+
public VpePageContext(BundleMap bundle, VpeEditorPart editPart) {
this.bundle = bundle;
this.editPart = editPart;
}
-
- public VpeSourceDomBuilder getSourceBuilder(){
+
+ public VpeSourceDomBuilder getSourceBuilder() {
return sourceBuilder;
}
-
- public boolean isAbsolutePosition(){
- if("yes".equals(VpePreference.USE_ABSOLUTE_POSITION.getValue()))return true;
//$NON-NLS-1$
- else return false;
+
+ public static boolean isAbsolutePosition() {
+ if ("yes".equals(VpePreference.USE_ABSOLUTE_POSITION.getValue())) {
//$NON-NLS-1$
+ return true;
+ }
+ return false;
}
-
+
/**
* Adds attribute to element attribute map
+ *
* @param key
* @param value
*/
- public void addAttributeInCustomElementsMap(String key, String value){
+ public void addAttributeInCustomElementsMap(String key, String value) {
getCustomElementsAttributes().put(key, value);
}
+
/**
* Removes attribute from custom attribute map
+ *
* @param sourceBuilder
*/
public void clearCustomElementAttributesMap() {
@@ -96,57 +94,58 @@
this.sourceBuilder = sourceBuilder;
refreshConnector();
}
-
+
public void refreshConnector() {
- //TODO we need to provide loading of kb here
+ // TODO we need to provide loading of kb here
}
-
- public VpeVisualDomBuilder getVisualBuilder(){
+
+ public VpeVisualDomBuilder getVisualBuilder() {
return visualBuilder;
}
-
+
public void setVisualDomBuilder(VpeVisualDomBuilder visualBuilder) {
this.visualBuilder = visualBuilder;
}
-
- public VpeDomMapping getDomMapping () {
+
+ public void refreshResReferences() {
+ if (visualBuilder != null ) {
+ final VpeIncludeInfo vii = visualBuilder.getCurrentIncludeInfo();
+ if (vii != null && (vii.getStorage() instanceof IFile)) {
+ final IFile file = (IFile)vii.getStorage();
+ ResourceReference[] rr = ElService.getAllResources(file);
+ rr = ElService.sortReferencesByScope2(rr);
+ putValue(RES_REFERENCES, rr);
+ }
+ }
+ }
+
+ public VpeDomMapping getDomMapping() {
return visualBuilder.getDomMapping();
}
-
+
public void clearAll() {
- bundleDependencySet.clear();
bundle.clearAll();
+ clearValues();
}
-
+
public void dispose() {
- for (Iterator iterator = connectorDocuments.iterator(); iterator.hasNext();) {
- IDocument document = (IDocument) iterator.next();
- }
- connectorDocuments.clear();
- connectorDocuments = null;
bundle.dispose();
clearAll();
- editPart=null;
- sourceBuilder=null;
- visualBuilder=null;
+ editPart = null;
+ sourceBuilder = null;
+ visualBuilder = null;
}
-
+
public BundleMap getBundle() {
return bundle;
}
- public void addBundleDependency(Element sourceNode) {
- //bundleDependencySet.add(sourceNode);
- }
-
- public void removeBundleDependency(Element sourceNode) {
- bundleDependencySet.remove(sourceNode);
- }
-
public void refreshBundleValues() {
- if (getVisualBuilder() == null) return;
+ if (getVisualBuilder() == null) {
+ return;
+ }
List<Node> nodes = getVisualBuilder().getSourceNodes();
- //Iterator iterator = bundleDependencySet.iterator();
+ // Iterator iterator = bundleDependencySet.iterator();
for (Node node : nodes) {
if (node instanceof Element) {
Element sourceElement = (Element) node;
@@ -154,54 +153,43 @@
}
}
}
-
+
/**
- * Checks for URI for source node was registred on page
+ * Checks for URI for source node was registred on page
+ *
* @param sourceNode
- * @return true - if uri was registred
- * false- if uri doesn't was registered
+ * @return true - if uri was registred false- if uri doesn't was registered
*/
public boolean isCorrectNS(Node sourceNode) {
String sourcePrefix = sourceNode.getPrefix();
-
- if (sourcePrefix == null || ((ElementImpl)sourceNode).isJSPTag()) {
+ if (sourcePrefix == null || ((ElementImpl) sourceNode).isJSPTag()) {
return true;
}
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,this);
-
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode, this);
TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
-
- if(sourceNodeTaglib!=null) {
-
+ if (sourceNodeTaglib != null) {
return true;
- }
+ }
return false;
}
+
/**
- * Returns
+ * Returns
+ *
* @param sourceNode
* @return
*/
-
public String getSourceTaglibUri(Node sourceNode) {
-
String sourcePrefix = sourceNode.getPrefix();
if (sourcePrefix == null || ((ElementImpl) sourceNode).isJSPTag()) {
return null;
}
-
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,
- this);
-
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix,
- taglibs);
-
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode, this);
+ TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
if (sourceNodeTaglib == null) {
-
return null;
}
String sourceNodeUri = sourceNodeTaglib.getUri();
-
return sourceNodeUri;
}
@@ -209,7 +197,6 @@
return editPart;
}
-
public List<TaglibData> getIncludeTaglibs() {
if (getEditPart() == null) {
return new ArrayList<TaglibData>();
@@ -217,18 +204,18 @@
IEditorInput input = getEditPart().getEditorInput();
IFile file = null;
if (input instanceof IFileEditorInput) {
- file = ((IFileEditorInput)input).getFile();
- }
+ file = ((IFileEditorInput) input).getFile();
+ }
ResourceReference[] resourceReferences = new ResourceReference[0];
if (file != null) {
- resourceReferences = TaglibReferenceList.getInstance().getAllResources(file);
+ resourceReferences = TaglibReferenceList.getInstance().getAllResources(file);
}
- //added by Max Areshkau Fix for JBIDE-2065
+ // added by Max Areshkau Fix for JBIDE-2065
List<TaglibData> taglibData = new ArrayList<TaglibData>();
for (ResourceReference resourceReference : resourceReferences) {
- taglibData.add(new TaglibData(0,resourceReference.getLocation(),
resourceReference.getProperties()));
+ taglibData.add(new TaglibData(0, resourceReference.getLocation(),
resourceReference.getProperties()));
}
- return taglibData;
+ return taglibData;
}
public ResourceReference getRuntimeRelativeFolder(IFile file) {
@@ -248,7 +235,6 @@
}
public List<TaglibData> getTagLibs(Node sourceNode) {
-
return XmlUtil.getTaglibsForNode(sourceNode, this);
}
@@ -256,39 +242,72 @@
* @return the currentVisualNode
*/
public nsIDOMNode getCurrentVisualNode() {
- return this.currentVisualNode;
+ return (nsIDOMNode)getValue(CURRENT_VISUAL_NODE);
}
/**
- * @param currentVisualNode the currentVisualNode to set
+ * @param currentVisualNode
+ * the currentVisualNode to set
*/
public void setCurrentVisualNode(nsIDOMNode currentVisualNode) {
- this.currentVisualNode = currentVisualNode;
+ putValue(CURRENT_VISUAL_NODE, currentVisualNode);
}
/**
* Processes display events to prevent eclipse froze
*/
- public void processDisplayEvents() {
-
- Display display=null;
- display = Display.getCurrent();
- if(display==null) {
- display=Display.getDefault();
+ public static void processDisplayEvents() {
+ Display display = Display.getCurrent();
+ if (display == null) {
+ display = Display.getDefault();
}
- if(display!=null) {
- while(display.readAndDispatch()){}
- }
+ if (display != null) {
+ while (display.readAndDispatch()) {
+ }
+ }
}
/**
* @return the customElementsAttributes
*/
+ @SuppressWarnings("unchecked")
public Map<String, String> getCustomElementsAttributes() {
- if(this.customElementsAttributes==null) {
- this.customElementsAttributes = new HashMap<String, String>();
+ Map<String, String> res = null;
+ Object obj = values.get(CUSTOM_ELEMENTS_ATTRS);
+ if (obj == null || !(obj instanceof HashMap)) {
+ res = new HashMap<String, String>();
+ values.put(CUSTOM_ELEMENTS_ATTRS, res);
+ } else {
+ res = (Map<String, String>)obj;
}
- return this.customElementsAttributes;
+ return res;
}
+
+ /**
+ * @param key
+ * @param val
+ * @return false in case of element replacement
+ */
+ public boolean putValue(String key, Object val) {
+ final boolean res = !values.containsKey(key);
+ values.put(key, val);
+ return res;
+ }
-}
\ No newline at end of file
+ public Object removeValue(String key) {
+ return values.remove(key);
+ }
+
+ public Object getValue(String key) {
+ return values.get(key);
+ }
+
+ public void clearValues() {
+ values.clear();
+ }
+
+ public String[] getValueNames() {
+ return values.keySet().toArray(new String[0]);
+ }
+
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/proxy/VpeNodeInvocationHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/proxy/VpeNodeInvocationHandler.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/proxy/VpeNodeInvocationHandler.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -20,7 +20,7 @@
/**
* @author mareshkau
- *
+ *
*/
public class VpeNodeInvocationHandler implements InvocationHandler {
@@ -28,38 +28,38 @@
* Node for which we process events
*/
private Node node;
-
- private VpePageContext pageContext;
-
+
+ private VpePageContext pageContext;
+
/**
* @param node
*/
- public VpeNodeInvocationHandler(VpePageContext pageContext,Node node) {
+ public VpeNodeInvocationHandler(VpePageContext pageContext, Node node) {
this.node = node;
this.pageContext = pageContext;
}
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- Object result = method.invoke(this.node, args);
- if(result instanceof String) {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Object result = method.invoke(node, args);
+ if (result instanceof String) {
String processedStr = (String) result;
result = replaceEL(processedStr);
- } else if(result instanceof Attr) {
- result = VpeProxyUtil.createProxyForELExpressionNode(this.pageContext,
- (Node)result);
- } else if(result instanceof NamedNodeMap) {
- result = VpeProxyUtil.createProxyForNamedNodeMap(this.pageContext,
(NamedNodeMap)result);
+ } else if (result instanceof Attr) {
+ result = VpeProxyUtil.createProxyForELExpressionNode(pageContext, (Node) result);
+ } else if (result instanceof NamedNodeMap) {
+ result = VpeProxyUtil.createProxyForNamedNodeMap(pageContext, (NamedNodeMap) result);
}
- return result;
+ return result;
}
+
/**
* Replaced string with el value
+ *
* @param toReplace
* @return
*/
private String replaceEL(String toReplace) {
- return ElService.getInstance().replaceElAndResources(this.pageContext, toReplace);
+ return ElService.replaceElAndResources(pageContext, toReplace);
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeHtmlTemplate.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -224,9 +224,6 @@
visualNodeMap.put(this, new ModifyInfo(visualElement, curModify));
}
}
- if (dependencyFromBundle) {
- pageContext.addBundleDependency(sourceElement);
- }
return elementInfo;
}
@@ -491,9 +488,6 @@
//////////////////////////////////////////////
private void removeElement(VpePageContext pageContext, Element sourceElement,
Map<VpeTemplate,?> visualNodeMap) {
if (creator != null) {
- if (dependencyFromBundle) {
- pageContext.removeBundleDependency(sourceElement);
- }
creator.removeElement(pageContext, sourceElement, visualNodeMap);
}
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/resize/VpeResizer.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/resize/VpeResizer.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/resize/VpeResizer.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -97,7 +97,7 @@
*/
public void resize(VpePageContext pageContext, Element sourceElement, nsIDOMDocument
visualDocument, nsIDOMElement visualElement, Object data, int resizeConstrant, int top,
int left, int width, int height) {
pageContext.getEditPart().getSourceEditor().getTextViewer().getUndoManager().beginCompoundChange();
- if (pageContext.isAbsolutePosition() && (
+ if (VpePageContext.isAbsolutePosition() && (
resizeConstrant == VpeTagDescription.RESIZE_CONSTRAINS_BOTTOMLEFT||
resizeConstrant == VpeTagDescription.RESIZE_CONSTRAINS_LEFT||
resizeConstrant == VpeTagDescription.RESIZE_CONSTRAINS_TOPLEFT||
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/ElService.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -11,125 +11,96 @@
package org.jboss.tools.vpe.editor.util;
-
import java.util.Arrays;
import java.util.Comparator;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.jboss.tools.common.el.core.ELReferenceList;
import org.jboss.tools.common.el.core.GlobalELReferenceList;
import org.jboss.tools.common.resref.core.ResourceReference;
-import org.jboss.tools.jst.jsp.bundle.BundleMap;
import org.jboss.tools.jst.jsp.bundle.BundleMapUtil;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-
/**
- * The {@link IELService} implementation.
- *
+ *
* @author Eugeny Stherbin
+ * @author Vitali Yemialyanchyk
*/
-public final class ElService implements IELService {
+public final class ElService {
- /** The Constant INSTANCE. */
- private static final IELService INSTANCE = new ElService();
+ public static final String DOLLAR_PREFIX = "${"; //$NON-NLS-1$
- public static final String DOLLAR_PREFIX = "${"; //$NON-NLS-1$
+ private static final String SUFFIX = "}"; //$NON-NLS-1$
- private static final String SUFFIX = "}"; //$NON-NLS-1$
+ public static final String SHARP_PREFIX = "#{"; //$NON-NLS-1$
- public static final String SHARP_PREFIX = "#{"; //$NON-NLS-1$
+ /**
+ * Replace el.
+ *
+ * @param resourceFile
+ * the resource file
+ * @param resourceString
+ * the resource string
+ *
+ * @return the string
+ *
+ * @see IELService#replaceEl(IFile, String)
+ */
+ public static String replaceEl(IFile file, String resourceString) {
+ if (resourceString == null) {
+ return ""; //$NON-NLS-1$
+ }
+ String rst = resourceString;
+ ResourceReference[] references = getAllResources(file);
+ if (references == null || references.length == 0) {
+ return rst;
+ }
+ references = sortReferencesByScope2(references);
+ rst = replace(resourceString, references);
+ return rst;
+ }
- /**
- * Checks if is available.
- *
- * @param resourceFile the resource file
- *
- * @return true, if is available
- */
- public boolean isAvailable(IFile resourceFile) {
- boolean rst = false;
- final ResourceReference[] references = getAllResources(resourceFile);
-
- if ((references != null) && (references.length > 0)) {
- rst = true;
- }
- return rst;
- }
-
-
- /**
- * Gets the singleton instance.
- *
- * @return the singleton instance
- */
- public static synchronized IELService getInstance() {
- return INSTANCE;
- }
-
- /**
- * The Constructor.
- */
- private ElService() {
- super();
- }
-
-
- /**
- * Replace el.
- *
- * @param resourceFile the resource file
- * @param resourceString the resource string
- *
- * @return the string
- *
- * @see IELService#replaceEl(IFile, String)
- */
- public String replaceEl(IFile resourceFile, String resourceString) {
-
- // Assert.isNotNull(resourceString);
- if ((resourceString == null) || (resourceFile == null)) {
- return ""; //$NON-NLS-1$
- }
- Assert.isNotNull(resourceFile);
- String rst = resourceString;
- final ResourceReference[] references = getAllResources(resourceFile);
-
-
- if ((references != null) && (references.length > 0)) {
- rst = replace(resourceString, references);
- }
- return rst;
- }
-
-
-
-
- /**
+ public static String replaceEl(VpePageContext pageContext, String resourceString) {
+ if (resourceString == null) {
+ return ""; //$NON-NLS-1$
+ }
+ String rst = resourceString;
+ final ResourceReference[] references = getResourceReferences(pageContext);
+ if (references == null || references.length == 0) {
+ return rst;
+ }
+ rst = replace(resourceString, references);
+ return rst;
+ }
+
+ /**
* Replace.
- *
- * @param resourceString the resource string
- * @param references the references
- *
+ *
+ * @param resourceString
+ * the resource string
+ * @param references
+ * the references
+ *
* @return the string
*/
- private String replace(String resourceString, ResourceReference[] references) {
+ private static String replace(String resourceString, ResourceReference[]
sortedReferences) {
String result = resourceString;
-
- // yradtsevich: JBIDE-3576: EL expression overriding.
- // Values with higher precedence are replaced in the first place.
- ResourceReference[] sortedReferences = sortReferencesByScope(references);
-
+ // Values with higher precedence should be replaced in the first place.
+ // Expect sorted by scope references.
+ final int nPrefLen = getPrefLen(); // for small-simple optimization
for (ResourceReference rf : sortedReferences) {
- final String dollarEl = DOLLAR_PREFIX + rf.getLocation() + SUFFIX;
- final String sharpEl = SHARP_PREFIX + rf.getLocation() + SUFFIX;
-
+ final String tmp = rf.getLocation();
+ if (tmp.length() + nPrefLen > resourceString.length()) {
+ continue; // no sense for sequence contains checks...
+ }
+ final String dollarEl = DOLLAR_PREFIX + tmp + SUFFIX;
+ final String sharpEl = SHARP_PREFIX + tmp + SUFFIX;
if (resourceString.contains(dollarEl)) {
result = result.replace(dollarEl, rf.getProperties());
}
@@ -137,243 +108,238 @@
result = result.replace(sharpEl, rf.getProperties());
}
}
+ return result;
+ }
+ private static String replaceCustomAttributes(VpePageContext pageContext, String value)
{
+ String result = value;
+ final int nPrefLen = getPrefLen(); // for small-simple optimization
+ final Map<String, String> tmp = pageContext.getCustomElementsAttributes();
+ for (String el : tmp.keySet()) {
+ if (el.length() + nPrefLen > result.length()) {
+ continue; // no sense for sequence contains checks...
+ }
+ final String dollarEl = DOLLAR_PREFIX + el + SUFFIX;
+ final String sharpEl = SHARP_PREFIX + el + SUFFIX;
+
+ if (result.contains(dollarEl)) {
+ result = result.replace(dollarEl, tmp.get(el));
+ }
+ if (result.contains(sharpEl)) {
+ result = result.replace(sharpEl, tmp.get(el));
+ }
+ }
return result;
}
+ private static int getPrefLen() {
+ int nPrefLen = DOLLAR_PREFIX.length();
+ if (nPrefLen > SHARP_PREFIX.length()) {
+ nPrefLen = SHARP_PREFIX.length();
+ }
+ nPrefLen += SUFFIX.length();
+ return nPrefLen;
+ }
+
/**
- * Creates a copy of {@code references} array and sorts its elements by
- * scope value.
- *
- * References with the lowest scope value ({@link ResourceReference#FILE_SCOPE})
- * become the first in the array and so on.
- *
- * @param references array to be sorted
+ * Creates a copy of {@code references} array and sorts its elements by scope value.
+ *
+ * References with the lowest scope value ({@link ResourceReference#FILE_SCOPE}) become
the first in the array and
+ * so on.
+ *
+ * @param references
+ * array to be sorted
* @return sorted copy of {@code references}
* @author yradtsevich
*/
- private ResourceReference[] sortReferencesByScope(ResourceReference[] references) {
+ public static ResourceReference[] sortReferencesByScope(ResourceReference[] references)
{
ResourceReference[] sortedReferences = references.clone();
+ return sortReferencesByScope(sortedReferences);
+ }
- Arrays.sort(sortedReferences, new Comparator<ResourceReference>() {
+ public static ResourceReference[] sortReferencesByScope2(ResourceReference[] references)
{
+ Arrays.sort(references, new Comparator<ResourceReference>() {
public int compare(ResourceReference r1, ResourceReference r2) {
return r1.getScope() - r2.getScope();
}
- });
+ });
+ return references;
+ }
- return sortedReferences;
+ /**
+ * Checks if is cloneable node.
+ *
+ * @param sourceNode
+ * the source node
+ * @param pageContext
+ * the page context
+ *
+ * @return true, if is cloneable node
+ */
+ public static boolean isELNode(VpePageContext pageContext, Node sourceNode) {
+ boolean rst = false;
+ if (isInCustomElementsAttributes(pageContext, sourceNode)) {
+ return true;
+ }
+ if (isAvailableForNode(pageContext, sourceNode)
+ || BundleMapUtil.isInResourcesBundle(pageContext.getBundle(), sourceNode)) {
+ rst = true;
+ } else if (Jsf2ResourceUtil.isContainJSFContextPath(sourceNode)) {
+ rst = true;
+ }
+ if (Jsf2ResourceUtil.isContainJSF2ResourceAttributes(sourceNode)) {
+ // added by Maksim Areshkau, see JBIDE-4812
+ rst = true;
+ }
+ return rst;
}
- /**
- * Checks if is cloneable node.
- *
- * @param sourceNode the source node
- * @param pageContext the page context
- *
- * @return true, if is cloneable node
- */
- public boolean isELNode(VpePageContext pageContext,Node sourceNode) {
- boolean rst = false;
- if(isInCustomElementsAttributes(pageContext,sourceNode)){
- return true;
- }
- // fix for JBIDE-3030
- if((pageContext.getVisualBuilder().getCurrentIncludeInfo())==null
- || !(pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage()
instanceof IFile)) {
- return rst;
- }
- final IFile file = (IFile)
pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage();
-
- if (((this.isAvailable(file) && this.isAvailableForNode(sourceNode,
file)))
- || BundleMapUtil.isInResourcesBundle(pageContext.getBundle(), sourceNode)){
- rst = true;
- }else if(Jsf2ResourceUtil.isContainJSFContextPath(sourceNode)){
- rst = true;
- }if(Jsf2ResourceUtil.isContainJSF2ResourceAttributes(sourceNode)) {
- //added by Maksim Areshkau, see JBIDE-4812
- rst = true;
- }
- return rst;
- }
- /**
- * Checks is node exist in source custom element attribute map and if so,
- * then retrun true
- * @param pageContext
- * @param sourceNode
- * @return
- */
-
- private static boolean isInCustomElementsAttributes(VpePageContext pageContext,Node
sourceNode){
-
- String textValue = null;
- if(sourceNode.getNodeType() == Node.TEXT_NODE) {
- textValue = sourceNode.getNodeValue();
- if (textValue != null) {
- for(String key : pageContext.getCustomElementsAttributes().keySet()){
- if(equalsExppression(textValue,key)){
- return true;
- }
- }
- }
- }else if(sourceNode.getNodeType() == Node.ELEMENT_NODE) {
+ /**
+ * Checks is node exist in source custom element attribute map and if so, then retrun
true
+ *
+ * @param pageContext
+ * @param sourceNode
+ * @return
+ */
+ private static boolean isInCustomElementsAttributes(VpePageContext pageContext, Node
sourceNode) {
+ boolean res = false;
+ String textValue = null;
+ if (sourceNode.getNodeType() == Node.TEXT_NODE) {
+ textValue = sourceNode.getNodeValue();
+ res = isInCustomElementsAttributes(pageContext, textValue);
+ } else if (sourceNode.getNodeType() == Node.ELEMENT_NODE) {
NamedNodeMap attributesMap = sourceNode.getAttributes();
- for(int i=0;i<attributesMap.getLength();i++) {
+ for (int i = 0; !res && i < attributesMap.getLength(); i++) {
Attr attr = (Attr) attributesMap.item(i);
- textValue =attr.getValue();
- if(textValue!=null) {
- for(String key : pageContext.getCustomElementsAttributes().keySet()){
- if(equalsExppression(textValue,key)){
- return true;
- }
- }
- }
+ textValue = attr.getValue();
+ res = isInCustomElementsAttributes(pageContext, textValue);
}
- }
- return false;
- }
+ }
+ return res;
+ }
- /**
- * Checks if is available for node.
- *
- * @param resourceFile the resource file
- * @param sourceNode the source node
- *
- * @return true, if is available for node
- */
- private boolean isAvailableForNode(Node sourceNode, IFile resourceFile) {
- boolean rst = findForNode(sourceNode, resourceFile);
- return rst;
- }
+ private static boolean isInCustomElementsAttributes(VpePageContext pageContext, String
textValue) {
+ boolean res = false;
+ if (textValue != null) {
+ for (String key : pageContext.getCustomElementsAttributes().keySet()) {
+ if (equalsExppression(textValue, key)) {
+ res = true;
+ break;
+ }
+ }
+ }
+ return res;
+ }
+ /**
+ * Checks if is available for node.
+ *
+ * @param resourceFile
+ * the resource file
+ * @param sourceNode
+ * the source node
+ *
+ * @return true, if is available for node
+ */
+ private static boolean isAvailableForNode(VpePageContext pageContext, Node sourceNode)
{
+ boolean rst = findForNode(pageContext, sourceNode);
+ return rst;
+ }
- /**
- * @param sourceNode
- * @param resourceFile
- * @return
- */
- private boolean findForNode(Node sourceNode, IFile resourceFile) {
- boolean rst = false;
- final ResourceReference[] references = getAllResources(resourceFile);
- String textValue = null;
+ /**
+ * @param sourceNode
+ * @param resourceFile
+ * @return
+ */
+ private static boolean findForNode(VpePageContext pageContext, Node sourceNode) {
+ final ResourceReference[] references = getResourceReferences(pageContext);
+ if (references == null || references.length == 0) {
+ return false;
+ }
+ String textValue = null;
+ if (sourceNode.getNodeType() == Node.TEXT_NODE) {
+ textValue = sourceNode.getNodeValue();
+ if (textValue != null && isInReferenceResourcesList(references, textValue)) {
+ return true;
+ }
+ }
+ final NamedNodeMap nodeMap = sourceNode.getAttributes();
+ if (nodeMap != null) {
+ for (int i = 0; i < nodeMap.getLength(); i++) {
+ if (isInReferenceResourcesList(references, ((Attr) nodeMap.item(i)).getValue())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static ResourceReference[] getResourceReferences(VpePageContext pageContext) {
+ final ResourceReference[] res =
(ResourceReference[])pageContext.getValue(VpePageContext.RES_REFERENCES);
+ return res;
+ }
- if (sourceNode.getNodeType() == Node.TEXT_NODE) {
- textValue = sourceNode.getNodeValue();
- if (textValue != null) {
- if (isInReferenceResourcesList(references, textValue)) {
- return true;
- }
- }
- }
- final NamedNodeMap nodeMap = sourceNode.getAttributes();
- if ((nodeMap != null) && (nodeMap.getLength() > 0)) {
- for (int i = 0; i < nodeMap.getLength(); i++) {
- if (isInReferenceResourcesList(references, ((Attr)
nodeMap.item(i)).getValue())) {
- return true;
- }
- }
- }
- return rst;
- }
-
-
- /**
- * Checks if is in reference resources list.
- *
- * @param value the value
- * @param references the references
- *
- * @return true, if is in reference resources list
- */
- private boolean isInReferenceResourcesList(ResourceReference[] references, String
value) {
- boolean rst = false;
-
- for (ResourceReference ref : references) {
-
- //FIXED FOR JBIDE-3149 by sdzmitrovich
+ /**
+ * Checks if is in reference resources list.
+ *
+ * @param value
+ * the value
+ * @param references
+ * the references
+ *
+ * @return true, if is in reference resources list
+ */
+ private static boolean isInReferenceResourcesList(ResourceReference[] references, String
value) {
+ for (ResourceReference ref : references) {
+ // FIXED FOR JBIDE-3149 by sdzmitrovich
if (equalsExppression(value, ref.getLocation())) {
return true;
}
- }
- return rst;
- }
+ }
+ return false;
+ }
- protected ResourceReference[] getAllResources(IFile resourceFile) {
- ResourceReference[] rst = null;
- final IPath workspacePath = Platform.getLocation();
+ public static ResourceReference[] getAllResources(IFile resourceFile) {
+ final IPath workspacePath = Platform.getLocation();
+ final ResourceReference[] gResources =
GlobalELReferenceList.getInstance().getAllResources(workspacePath);
+ final ResourceReference[] elResources =
ELReferenceList.getInstance().getAllResources(resourceFile);
- final ResourceReference[] gResources =
GlobalELReferenceList.getInstance().getAllResources(workspacePath);
- final ResourceReference[] elResources =
ELReferenceList.getInstance().getAllResources(resourceFile);
+ int size = (gResources == null ? 0 : gResources.length);
+ size += (elResources == null ? 0 : elResources.length);
+ ResourceReference[] rst = new ResourceReference[size];
- int size = (gResources == null ? 0 : gResources.length);
- size += (elResources == null ? 0 : elResources.length);
- rst = new ResourceReference[size];
+ if ((gResources != null) && (gResources.length > 0)) {
+ System.arraycopy(gResources, 0, rst, 0, gResources.length);
+ }
+ if ((elResources != null) && (elResources.length > 0)) {
+ System.arraycopy(elResources, 0, rst, gResources == null ? 0 : gResources.length,
elResources.length);
+ }
+ return rst;
- if ((gResources != null) && (gResources.length > 0)) {
- System.arraycopy(gResources, 0, rst,0, gResources.length);
- }
- if ((elResources != null) && (elResources.length > 0)) {
- System.arraycopy(elResources, 0, rst, gResources==null?0:gResources.length,
elResources.length);
- }
+ }
- return rst;
-
- }
-
- public String replaceElAndResources(VpePageContext pageContext, String value) {
-
-
- String rst = value;
-
- rst = ResourceUtil.getBundleValue(pageContext, value);
- //replace custom attributes
- rst = replaceCustomAttributes(pageContext,rst);
-
- if(Jsf2ResourceUtil.isExternalContextPathString(value)){
- rst = Jsf2ResourceUtil.processExternalContextPath(value);
- }
-
- if(Jsf2ResourceUtil.isRequestContextPathString(value)){
- rst = Jsf2ResourceUtil.processRequestContextPath(value);
- }
-
- if(Jsf2ResourceUtil.isJSF2ResourceString(rst)){
- rst = Jsf2ResourceUtil.processCustomJSFAttributes(pageContext, rst);
- }
- //fix for JBIDE-3030
- if((pageContext.getVisualBuilder().getCurrentIncludeInfo()==null)
- || !(pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage()
instanceof IFile)) {
- return rst;
- }
- final IFile file = (IFile)
pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage();
- rst = replaceEl(file, rst);
-
- return rst;
- }
-
- private String replaceCustomAttributes(VpePageContext pageContext, String value){
- String result = value;
- for (String el : pageContext.getCustomElementsAttributes().keySet()) {
- final String dollarEl = DOLLAR_PREFIX + el + SUFFIX;
- final String sharpEl = SHARP_PREFIX + el + SUFFIX;
-
- if (result.contains(dollarEl)) {
- result = result.replace(dollarEl,
pageContext.getCustomElementsAttributes().get(el));
- }
- if (result.contains(sharpEl)) {
- result = result.replace(sharpEl,pageContext.getCustomElementsAttributes().get(el));
- }
+ public static String replaceElAndResources(VpePageContext pageContext, String value) {
+ String rst = value;
+ rst = ResourceUtil.getBundleValue(pageContext, value);
+ // replace custom attributes
+ rst = replaceCustomAttributes(pageContext, rst);
+ if (Jsf2ResourceUtil.isExternalContextPathString(value)) {
+ rst = Jsf2ResourceUtil.processExternalContextPath(value);
}
- return result;
- }
+ if (Jsf2ResourceUtil.isRequestContextPathString(value)) {
+ rst = Jsf2ResourceUtil.processRequestContextPath(value);
+ }
+ if (Jsf2ResourceUtil.isJSF2ResourceString(rst)) {
+ rst = Jsf2ResourceUtil.processCustomJSFAttributes(pageContext, rst);
+ }
+ rst = replaceEl(pageContext, rst);
+ return rst;
+ }
- private static boolean equalsExppression(String value, String expression) {
-
- final String dollarEl = String.valueOf(DOLLAR_PREFIX) + expression
- + String.valueOf(SUFFIX);
- final String sharpEl = String.valueOf(SHARP_PREFIX) + expression
- + String.valueOf(SUFFIX);
-
+ private static boolean equalsExppression(String value, String expression) {
+ final String dollarEl = DOLLAR_PREFIX + expression + SUFFIX;
+ final String sharpEl = SHARP_PREFIX + expression + SUFFIX;
if (value.contains(dollarEl) || value.contains(sharpEl)) {
return true;
}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/IELService.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.vpe.editor.util;
-
-
-import org.eclipse.core.resources.IFile;
-import org.jboss.tools.jst.jsp.bundle.BundleMap;
-import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.w3c.dom.Node;
-
-
-/**
- * The service that substitute El values in vpe source editor. For more details
- * see issues
http://jira.jboss.com/jira/browse/JBIDE-2010 and
- *
http://jira.jboss.com/jira/browse/JBIDE-1410
- *
- * @author Eugeny Stherbin
- */
-public interface IELService {
-
- /**
- * Return the {@link String} with substitued el values for given resource.
- *
- * @param resourceFile the resource file where resource
- * @param resourceString the source string that will be substitute
- *
- * @return string where el values was substituted.
- */
- String replaceEl(IFile resourceFile, String resourceString);
-
- /**
- * Replace el and resources.
- *
- * @param attributeNode the attribute node
- * @param resourceFile the resource file
- * @param resourceString the resource string
- * @param pageContext the page context
- *
- * @return the string
- */
- String replaceElAndResources(VpePageContext pageContext, String value);
-
- /**
- * Checks if is available.
- *
- * @param resourceFile the resource file
- *
- * @return true, if is available
- */
- boolean isAvailable(IFile resourceFile);
-
- /**
- * Checks if is node contains el expressions which should be replaced
- * from el or from resource bundles.
- *
- * @param sourceNode the source node
- * @param pageContext the page context
- *
- * @return true, if is cloneable node
- */
- public boolean isELNode(VpePageContext pageContext, Node sourceNode);
-
-}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/SourceDomUtil.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -80,7 +80,7 @@
final String attrName = "rendered"; //$NON-NLS-1$
Element tempElement = sourceNode;
if (sourceNode.hasAttribute(attrName)) {
- if (ElService.getInstance().isELNode(pageContext, sourceNode)) {
+ if (ElService.isELNode(pageContext, sourceNode)) {
tempElement = (Element) VpeProxyUtil
.createProxyForELExpressionNode(pageContext, sourceNode);
}
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 2011-07-27
14:51:50 UTC (rev 33246)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-07-27
15:22:17 UTC (rev 33247)
@@ -35,6 +35,7 @@
import org.jboss.tools.common.resref.core.ResourceReference;
import org.jboss.tools.jst.web.project.WebProject;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.VpeIncludeInfo;
import org.jboss.tools.vpe.editor.VpeVisualDomBuilder;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
@@ -52,372 +53,299 @@
public static final String ATTRIBUTE_STYLE = "style"; //$NON-NLS-1$
- public static final String PARAMETER_POSITION = "position"; //$NON-NLS-1$
- public static final String PARAMETER_TOP = "top"; //$NON-NLS-1$
- public static final String PARAMETER_LEFT = "left"; //$NON-NLS-1$
- public static final String PARAMETER_WIDTH = "width"; //$NON-NLS-1$
- public static final String PARAMETER_HEIGHT = "height"; //$NON-NLS-1$
- public static final String PARAMETR_BACKGROND = "background";
//$NON-NLS-1$
- public static final String PARAMETR_VERTICAL_ALIGN = "vertical-align";
//$NON-NLS-1$
+ public static final String PARAMETER_POSITION = "position"; //$NON-NLS-1$
+ public static final String PARAMETER_TOP = "top"; //$NON-NLS-1$
+ public static final String PARAMETER_LEFT = "left"; //$NON-NLS-1$
+ public static final String PARAMETER_WIDTH = "width"; //$NON-NLS-1$
+ public static final String PARAMETER_HEIGHT = "height"; //$NON-NLS-1$
+ public static final String PARAMETR_BACKGROND = "background"; //$NON-NLS-1$
+ public static final String PARAMETR_VERTICAL_ALIGN = "vertical-align";
//$NON-NLS-1$
- public static final String VALUE_ABSOLUTE = "absolute"; //$NON-NLS-1$
+ public static final String VALUE_ABSOLUTE = "absolute"; //$NON-NLS-1$
- public static final String DOT_STRING = "."; //$NON-NLS-1$
- public static final String COLON_STRING = ":"; //$NON-NLS-1$
- public static final String SEMICOLON_STRING = ";"; //$NON-NLS-1$
- public static final String PX_STRING = "px"; //$NON-NLS-1$
- public static final String SPACE_STRING = " "; //$NON-NLS-1$
- public static final String EMPTY_STRING = ""; //$NON-NLS-1$
- public static final String SINGLE_QUOTE_STRING = "\'"; //$NON-NLS-1$
- public static final String QUOTE_STRING = "\""; //$NON-NLS-1$
-
- public static String ATTR_URL = "url"; //$NON-NLS-1$
- public static String OPEN_BRACKET = "("; //$NON-NLS-1$
- public static String CLOSE_BRACKET = ")"; //$NON-NLS-1$
- public static String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
- public static String HTTP_PROTOCOL = "http:"; //$NON-NLS-1$
- public static String SLASH = "/"; //$NON-NLS-1$
-
- /**
- * Returns CSS style declaration corresponding to the given {@code element}.
- */
- public static nsIDOMCSSStyleDeclaration getStyle(nsIDOMElement element) {
+ public static final String DOT_STRING = "."; //$NON-NLS-1$
+ public static final String COLON_STRING = ":"; //$NON-NLS-1$
+ public static final String SEMICOLON_STRING = ";"; //$NON-NLS-1$
+ public static final String PX_STRING = "px"; //$NON-NLS-1$
+ public static final String SPACE_STRING = " "; //$NON-NLS-1$
+ public static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ public static final String SINGLE_QUOTE_STRING = "\'"; //$NON-NLS-1$
+ public static final String QUOTE_STRING = "\""; //$NON-NLS-1$
+
+ public static String ATTR_URL = "url"; //$NON-NLS-1$
+ public static String OPEN_BRACKET = "("; //$NON-NLS-1$
+ public static String CLOSE_BRACKET = ")"; //$NON-NLS-1$
+ public static String FILE_PROTOCOL = "file:"; //$NON-NLS-1$
+ public static String HTTP_PROTOCOL = "http:"; //$NON-NLS-1$
+ public static String SLASH = "/"; //$NON-NLS-1$
+
+ /**
+ * Returns CSS style declaration corresponding to the given {@code element}.
+ */
+ public static nsIDOMCSSStyleDeclaration getStyle(nsIDOMElement element) {
nsIDOMElementCSSInlineStyle inlineStyle =
queryInterface(element, nsIDOMElementCSSInlineStyle.class);
- return inlineStyle.getStyle();
- }
-
-
-
- // sets parameter position in attribute style to absolute value
- public static void setAbsolute(Element sourceElement) {
- String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
- if (style == null) {
- style = EMPTY_STRING;
- } else { // remove old sizes
- style = deleteFromString(style, PARAMETER_POSITION,
- SEMICOLON_STRING);
+ return inlineStyle.getStyle();
}
- if (style.length() > 0) {
- if (!style.endsWith(SEMICOLON_STRING))
- style += SEMICOLON_STRING;
- }
- style += SPACE_STRING + PARAMETER_POSITION + SPACE_STRING
- + COLON_STRING + SPACE_STRING + VALUE_ABSOLUTE
- + SEMICOLON_STRING;
+ // sets parameter position in attribute style to absolute value
+ public static void setAbsolute(Element sourceElement) {
+ String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
+ if (style == null) {
+ style = EMPTY_STRING;
+ } else { // remove old sizes
+ style = deleteFromString(style, PARAMETER_POSITION, SEMICOLON_STRING);
+ }
+ if (style.length() > 0) {
+ if (!style.endsWith(SEMICOLON_STRING))
+ style += SEMICOLON_STRING;
+ }
- sourceElement.setAttribute(ATTRIBUTE_STYLE, style);
- }
+ style += SPACE_STRING + PARAMETER_POSITION + SPACE_STRING
+ + COLON_STRING + SPACE_STRING + VALUE_ABSOLUTE + SEMICOLON_STRING;
- // sets parameter position in absolute value
- public static String setAbsolute(String styleString) {
- String style = styleString;
- if (style == null) {
- style = EMPTY_STRING;
- } else { // remove old sizes
- style = deleteFromString(style, PARAMETER_POSITION,
- SEMICOLON_STRING);
+ sourceElement.setAttribute(ATTRIBUTE_STYLE, style);
}
- if (style.length() > 0) {
- if (!style.endsWith(SEMICOLON_STRING))
- style += SEMICOLON_STRING;
- }
- style += SPACE_STRING + PARAMETER_POSITION + SPACE_STRING
- + COLON_STRING + SPACE_STRING + VALUE_ABSOLUTE
- + SEMICOLON_STRING;
+ // sets parameter position in absolute value
+ public static String setAbsolute(String styleString) {
+ String style = styleString;
+ if (style == null) {
+ style = EMPTY_STRING;
+ } else { // remove old sizes
+ style = deleteFromString(style, PARAMETER_POSITION, SEMICOLON_STRING);
+ }
+ if (style.length() > 0) {
+ if (!style.endsWith(SEMICOLON_STRING))
+ style += SEMICOLON_STRING;
+ }
- return style;
- }
+ style += SPACE_STRING + PARAMETER_POSITION + SPACE_STRING
+ + COLON_STRING + SPACE_STRING + VALUE_ABSOLUTE + SEMICOLON_STRING;
- // return true if parameter position was set to absolute
- public static boolean getAbsolute(Element sourceElement) {
- String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
- if (style == null) {
- return false;
- } else { // remove old sizes
- if (style.indexOf(VALUE_ABSOLUTE) >= 0)
- return true;
+ return style;
}
- return false;
- }
- // return true if parameter position was set to absolute
- public static boolean getAbsolute(String style) {
- if (style == null) {
- return false;
- } else { // remove old sizes
- if (style.indexOf(VALUE_ABSOLUTE) >= 0)
- return true;
+ // return true if parameter position was set to absolute
+ public static boolean getAbsolute(Element sourceElement) {
+ String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
+ if (style == null) {
+ return false;
+ } else { // remove old sizes
+ if (style.indexOf(VALUE_ABSOLUTE) >= 0)
+ return true;
+ }
+ return false;
}
- return false;
- }
- // return value of parameter described in sizeAttribute, for example
- // "style.width"
- public static int getSizeFromStyle(Element sourceElement,
- String sizeAttribute) {
- int dotPosition = sizeAttribute.indexOf(DOT_STRING);
- String attribute = sizeAttribute.substring(0, dotPosition);
- String parameter = sizeAttribute.substring(dotPosition + 1,
- sizeAttribute.length());
-
- String style = sourceElement.getAttribute(attribute);
- if (style == null || EMPTY_STRING.equals(style))
- return -1;
-
- int parameterPosition = style.indexOf(parameter);
- if (parameterPosition >= 0) {
- int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
- if (valuePosition >= 0) {
- int endPosition = style.indexOf(PX_STRING, valuePosition);
- if (endPosition >= 0) {
- return Integer.parseInt(style.substring(valuePosition + 1,
- endPosition).trim());
+ // return true if parameter position was set to absolute
+ public static boolean getAbsolute(String style) {
+ if (style == null) {
+ return false;
+ } else { // remove old sizes
+ if (style.indexOf(VALUE_ABSOLUTE) >= 0)
+ return true;
}
- }
+ return false;
}
- return -1;
- }
- // return value of parameter described in sizeAttribute, for example
- // "style.width"
- public static String getParameterFromStyle(Element sourceElement,
- String sizeAttribute) {
- int dotPosition = sizeAttribute.indexOf(DOT_STRING);
- String attribute = sizeAttribute.substring(0, dotPosition);
- String parameter = sizeAttribute.substring(dotPosition + 1,
- sizeAttribute.length());
+ // return value of parameter described in sizeAttribute, for example
+ // "style.width"
+ public static int getSizeFromStyle(Element sourceElement, String sizeAttribute) {
+ int dotPosition = sizeAttribute.indexOf(DOT_STRING);
+ String attribute = sizeAttribute.substring(0, dotPosition);
+ String parameter = sizeAttribute.substring(dotPosition + 1, sizeAttribute.length());
- String style = sourceElement.getAttribute(attribute);
- if (style == null || EMPTY_STRING.equals(style))
- return null;
+ String style = sourceElement.getAttribute(attribute);
+ if (style == null || EMPTY_STRING.equals(style))
+ return -1;
- int parameterPosition = style.indexOf(parameter);
- if (parameterPosition >= 0) {
- int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
- if (valuePosition >= 0) {
- int endPosition = style.indexOf(PX_STRING, valuePosition);
- if (endPosition >= 0) {
- return style.substring(valuePosition + 1, endPosition)
- .trim();
+ int parameterPosition = style.indexOf(parameter);
+ if (parameterPosition >= 0) {
+ int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
+ if (valuePosition >= 0) {
+ int endPosition = style.indexOf(PX_STRING, valuePosition);
+ if (endPosition >= 0) {
+ return Integer.parseInt(style.substring(valuePosition + 1, endPosition).trim());
+ }
+ }
}
- }
+ return -1;
}
- return null;
- }
- /**
- * This method is used to get parameter value from <code>style</code>
attribute.
- * For instance, in case of style="width:65px; color:red" for parameter
<code>color</code>
- * method should return <code>red</code> string value.
- *
- * @param styleAttr the style attribute value
- * @param parameter the name of parameter of style attribute
- * @return the parameter value
- */
- public static String getParameterFromStyleAttribute(String style, String parameter)
{
- if (style == null || EMPTY_STRING.equals(style)) {
- return null;
- }
- int parameterPosition = style.indexOf(parameter);
- if (parameterPosition >= 0) {
- int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
- if (valuePosition >= 0) {
- int endPosition = style.indexOf(SEMICOLON_STRING, valuePosition);
- if (endPosition >= 0) {
- style = style.substring(valuePosition + 1, endPosition).trim();
- endPosition = style.indexOf(PX_STRING, valuePosition);
- if (endPosition >= 0) {
- return style.substring(valuePosition + 1, endPosition).trim();
- }
- return style;
- } else {
- // last parameter ends without closing semicolon symbol
- return style.substring(valuePosition + 1).trim();
- }
- }
- }
+ // return value of parameter described in sizeAttribute, for example
+ // "style.width"
+ public static String getParameterFromStyle(Element sourceElement, String sizeAttribute)
{
+ int dotPosition = sizeAttribute.indexOf(DOT_STRING);
+ String attribute = sizeAttribute.substring(0, dotPosition);
+ String parameter = sizeAttribute.substring(dotPosition + 1, sizeAttribute.length());
- return null;
- }
+ String style = sourceElement.getAttribute(attribute);
+ if (style == null || EMPTY_STRING.equals(style))
+ return null;
- // sets value of parameter described in sizeAttribute, for example
- // "style.width"
- public static void setParameterInStyle(Element sourceElement,
- String sizeAttribute, String value) {
- int dotPosition = sizeAttribute.indexOf(DOT_STRING);
- String attribute = sizeAttribute.substring(0, dotPosition);
- String parameter = sizeAttribute.substring(dotPosition + 1,
- sizeAttribute.length());
+ int parameterPosition = style.indexOf(parameter);
+ if (parameterPosition >= 0) {
+ int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
+ if (valuePosition >= 0) {
+ int endPosition = style.indexOf(PX_STRING, valuePosition);
+ if (endPosition >= 0) {
+ return style.substring(valuePosition + 1, endPosition).trim();
+ }
+ }
+ }
+ return null;
+ }
- String style = sourceElement.getAttribute(attribute);
- if (style == null) {
- style = EMPTY_STRING;
- } else { // remove old sizes
- style = deleteFromString(style, parameter, SEMICOLON_STRING);
+ /**
+ * This method is used to get parameter value from <code>style</code>
attribute. For instance, in case of
+ * style="width:65px; color:red" for parameter <code>color</code>
method should return <code>red</code> string
+ * value.
+ *
+ * @param styleAttr
+ * the style attribute value
+ * @param parameter
+ * the name of parameter of style attribute
+ * @return the parameter value
+ */
+ public static String getParameterFromStyleAttribute(String style, String parameter) {
+ if (style == null || EMPTY_STRING.equals(style)) {
+ return null;
+ }
+ int parameterPosition = style.indexOf(parameter);
+ if (parameterPosition >= 0) {
+ int valuePosition = style.indexOf(COLON_STRING, parameterPosition);
+ if (valuePosition >= 0) {
+ int endPosition = style.indexOf(SEMICOLON_STRING, valuePosition);
+ if (endPosition >= 0) {
+ style = style.substring(valuePosition + 1, endPosition).trim();
+ endPosition = style.indexOf(PX_STRING, valuePosition);
+ if (endPosition >= 0) {
+ return style.substring(valuePosition + 1, endPosition).trim();
+ }
+ return style;
+ } else {
+ // last parameter ends without closing semicolon symbol
+ return style.substring(valuePosition + 1).trim();
+ }
+ }
+ }
+
+ return null;
}
- if (style.length() > 0) {
- if (!style.endsWith(SEMICOLON_STRING))
- style += SEMICOLON_STRING;
- }
- style += SPACE_STRING + parameter + SPACE_STRING + COLON_STRING
- + SPACE_STRING + value + SEMICOLON_STRING;
+ // sets value of parameter described in sizeAttribute, for example
+ // "style.width"
+ public static void setParameterInStyle(Element sourceElement, String sizeAttribute,
String value) {
+ int dotPosition = sizeAttribute.indexOf(DOT_STRING);
+ String attribute = sizeAttribute.substring(0, dotPosition);
+ String parameter = sizeAttribute.substring(dotPosition + 1, sizeAttribute.length());
- sourceElement.setAttribute(attribute, style);
- }
+ String style = sourceElement.getAttribute(attribute);
+ if (style == null) {
+ style = EMPTY_STRING;
+ } else { // remove old sizes
+ style = deleteFromString(style, parameter, SEMICOLON_STRING);
+ }
+ if (style.length() > 0) {
+ if (!style.endsWith(SEMICOLON_STRING))
+ style += SEMICOLON_STRING;
+ }
- public static String setSizeInStyle(String style, String parameter, int size) {
- if (style == null) {
- style = EMPTY_STRING;
- } else { // remove old sizes
- style = deleteFromString(style, parameter, SEMICOLON_STRING);
+ style += SPACE_STRING + parameter + SPACE_STRING + COLON_STRING
+ + SPACE_STRING + value + SEMICOLON_STRING;
+
+ sourceElement.setAttribute(attribute, style);
}
- if (style.length() > 0) {
- if (!style.endsWith(SEMICOLON_STRING))
- style += SEMICOLON_STRING;
- }
+ public static String setSizeInStyle(String style, String parameter, int size) {
+ if (style == null) {
+ style = EMPTY_STRING;
+ } else { // remove old sizes
+ style = deleteFromString(style, parameter, SEMICOLON_STRING);
+ }
+ if (style.length() > 0) {
+ if (!style.endsWith(SEMICOLON_STRING))
+ style += SEMICOLON_STRING;
+ }
+
style += SPACE_STRING + parameter + SPACE_STRING + COLON_STRING
+ SPACE_STRING + size + PX_STRING + SEMICOLON_STRING;
- return style;
- }
-
- public static String setParameterInStyle(String style, String parameter,
- String value) {
- if (style == null) {
- style = EMPTY_STRING;
- } else { // remove old sizes
- style = deleteFromString(style, parameter, SEMICOLON_STRING);
+ return style;
}
- if (style.length() > 0) {
- if (!style.endsWith(SEMICOLON_STRING))
- style += SEMICOLON_STRING;
- }
+ public static String setParameterInStyle(String style, String parameter, String value)
{
+ if (style == null) {
+ style = EMPTY_STRING;
+ } else { // remove old sizes
+ style = deleteFromString(style, parameter, SEMICOLON_STRING);
+ }
+ if (style.length() > 0) {
+ if (!style.endsWith(SEMICOLON_STRING))
+ style += SEMICOLON_STRING;
+ }
+
style += SPACE_STRING + parameter + SPACE_STRING + COLON_STRING
+ SPACE_STRING + value + SEMICOLON_STRING;
- return style;
- }
+ return style;
+ }
- // selets parameter from atribute style
- public static void deleteFromStyle(Element sourceElement, String begin,
- String end) {
- String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
- style = deleteFromString(style, begin, end);
- sourceElement.setAttribute(ATTRIBUTE_STYLE, style);
- }
-
- // selects parameter from attribute style
- public static String deleteFromString(String data, String begin, String end) {
- int startPosition = data.indexOf(begin);
-
- if (startPosition < 0)
- return data;
-
- int endPosition = data.indexOf(end, startPosition);
-
- String result = data.substring(0, startPosition).trim();
- if (endPosition > 0) {
- result += data.substring(endPosition + 1, data.length()).trim();
+ // selets parameter from atribute style
+ public static void deleteFromStyle(Element sourceElement, String begin, String end) {
+ String style = sourceElement.getAttribute(ATTRIBUTE_STYLE);
+ style = deleteFromString(style, begin, end);
+ sourceElement.setAttribute(ATTRIBUTE_STYLE, style);
}
- return result;
- }
+ // selects parameter from attribute style
+ public static String deleteFromString(String data, String begin, String end) {
+ int startPosition = data.indexOf(begin);
- /**
- *
- * @param value
- * Css string
- * @param input
- * The editor input
- * @return format style string
- */
- public static String addFullPathIntoBackgroundValue(String value,
- IEditorInput input) {
+ if (startPosition < 0)
+ return data;
- if (value.indexOf(FILE_PROTOCOL) != -1) {
- return value;
- }
+ int endPosition = data.indexOf(end, startPosition);
- if (!new File(value).isAbsolute()) {
- value = getFilePath(input, value);
- }
+ String result = data.substring(0, startPosition).trim();
+ if (endPosition > 0) {
+ result += data.substring(endPosition + 1, data.length()).trim();
+ }
- value = FILE_PROTOCOL + SLASH + SLASH + value.replace('\\', '/');
- URL url = null;
- try {
- url = new URL(value);
- } catch (MalformedURLException e) {
- return value;
+ return result;
}
- return url.toString();
- }
+ /**
+ *
+ * @param value
+ * Css string
+ * @param input
+ * The editor input
+ * @return format style string
+ */
+ public static String addFullPathIntoBackgroundValue(String value, IEditorInput input) {
- /**
- *
- * @param value
- * Css string
- * @param input
- * The editor input
- * @return format style string
- */
- public static String addFullPathIntoURLValue(String value,
- VpePageContext pageContext) {
-
- String urls[] = value.split(ATTR_URL);
-
- if (urls.length == 1) {
+ if (value.indexOf(FILE_PROTOCOL) != -1) {
return value;
}
- String finalStr = EMPTY_STRING;
- for (int i = 1; i < urls.length; i++) {
+ if (!new File(value).isAbsolute()) {
+ value = getFilePath(input, value);
+ }
- urls[i] = urls[i].replace(SINGLE_QUOTE_STRING, EMPTY_STRING);
- urls[i] = urls[i].replace(QUOTE_STRING, 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 < 0 || endPathIndex < 0) {
- continue;
- }
-
- String filePath = urls[i].substring(startPathIndex + 1,
- endPathIndex);
-
- IFile file = null;
- if ((pageContext.getVisualBuilder().getCurrentIncludeInfo() != null)
- &&(pageContext.getVisualBuilder().getCurrentIncludeInfo()
- .getStorage() instanceof IFile)) {
- file = (IFile) pageContext.getVisualBuilder().getCurrentIncludeInfo()
- .getStorage();
- }
- if(file!=null)
- filePath = processUrl(filePath, file);
-
- String firstPartValue = urls[i].substring(0, startPathIndex + 1);
- String secondPartValue = urls[i].substring(endPathIndex, urls[i]
- .length());
-
- urls[i] = firstPartValue + filePath + secondPartValue;
+ value = FILE_PROTOCOL + SLASH + SLASH + value.replace('\\', '/');
+ URL url = null;
+ try {
+ url = new URL(value);
+ } catch (MalformedURLException e) {
+ return value;
}
- for (int i = 0; i < urls.length; i++)
- finalStr += urls[i];
- return finalStr;
+
+ return url.toString();
}
- /**
+ /**
*
* @param nput
* The editor input
@@ -425,31 +353,33 @@
* Relative path file
* @return Absolute path file
*/
- public static String getFilePath(IEditorInput input, String fileName) {
+ public static String getFilePath(IEditorInput input, String fileName) {
IPath inputPath = getInputParentPath(input);
return inputPath.toOSString() + File.separator + fileName;
}
- /**
- * Gets the file path.
- *
- * @param href_val the href_val
- * @param fileName the file name
- *
- * @return the file path
- */
- public static String getFilePath(String href_val, String fileName) {
- IPath inputPath = getInputParentPath(href_val);
- return inputPath.toOSString() + File.separator + fileName;
- }
+ /**
+ * Gets the file path.
+ *
+ * @param href_val
+ * the href_val
+ * @param fileName
+ * the file name
+ *
+ * @return the file path
+ */
+ public static String getFilePath(String href_val, String fileName) {
+ IPath inputPath = getInputParentPath(href_val);
+ return inputPath.toOSString() + File.separator + fileName;
+ }
- /**
- *
- * @param input
- * The editor input
- * @return Path
- */
- public static IPath getInputParentPath(IEditorInput input) {
+ /**
+ *
+ * @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);
@@ -465,14 +395,15 @@
return inputPath;
}
- /**
- * Gets the href file path.
- *
- * @param href_val the href_val
- *
- * @return href file path
- */
- public static IPath getInputParentPath(String href_val) {
+ /**
+ * Gets the href file path.
+ *
+ * @param href_val
+ * the href_val
+ *
+ * @return href file path
+ */
+ public static IPath getInputParentPath(String href_val) {
IPath inputPath = null;
inputPath = new Path(href_val);
if (inputPath != null && !inputPath.isEmpty()) {
@@ -483,124 +414,166 @@
}
return inputPath;
}
-
- /**
+
+ /**
*
* @param value
* Css string
+ * @param input
+ * The editor input
+ * @return format style string
+ */
+ public static String addFullPathIntoURLValue(String value, VpePageContext pageContext)
{
+
+ String urls[] = value.split(ATTR_URL);
+ 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();
+ }
+ for (int i = 1; i < urls.length; i++) {
+ urls[i] = updateURLItem(urls[i]);
+ String[] urlParts = splitURL(urls[i]);
+ if (urlParts == null) {
+ continue;
+ }
+ if (file != null) {
+ urlParts[1] = processUrl(urlParts[1], file);
+ }
+ urls[i] = collectArrayInto1Str(urlParts);
+ }
+ return collectArrayInto1Str(urls);
+ }
+
+ /**
+ *
+ * @param value
+ * Css string
* @param href_val
* Path of css file
* @return Format style string
*/
- public static String addFullPathIntoURLValue(String value, String href_val) {
+ 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(SINGLE_QUOTE_STRING, EMPTY_STRING);
- urls[i] = urls[i].replace(QUOTE_STRING, 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 < 0 || endPathIndex < 0) {
+ urls[i] = updateURLItem(urls[i]);
+ String[] urlParts = splitURL(urls[i]);
+ if (urlParts == null) {
continue;
}
-
- String filePath = urls[i].substring(startPathIndex + 1,
- endPathIndex);
-
IFile sourceFile = null;
try {
URL url1 = new URL(href_val);
-
- sourceFile = ResourcesPlugin.getWorkspace().getRoot()
- .getFileForLocation(new Path( url1.getPath()));
+ sourceFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(url1.getPath()));
} catch (MalformedURLException e1) {
// ignore
}
-
if (sourceFile != null) {
-
- filePath = processUrl(filePath, sourceFile);
-
+ urlParts[1] = processUrl(urlParts[1], sourceFile);
} else {
-
- //TODO to redesign next code
- try {
- URL url = new URL(filePath);
- // with url all ok
+ urlParts[1] = updateURLFilePath(urlParts[1], href_val);
+ if (urlParts[1] == null) {
continue;
- } catch (MalformedURLException e) {
- // ignore, continue work with url
}
-
- if (filePath.indexOf(FILE_PROTOCOL) != -1) {
- continue;
- }
-
- if (!new File(filePath).isAbsolute()) {
- filePath = getFilePath(href_val, filePath);
- } else {
- filePath = FILE_PROTOCOL + SLASH + SLASH
- + filePath.replace('\\', '/');
- }
-
- URL url = null;
- try {
- url = new URL(filePath);
- } catch (MalformedURLException e) {
- continue;
- }
- filePath = url.toString();
}
-
+ urls[i] = collectArrayInto1Str(urlParts);
+ }
+ return collectArrayInto1Str(urls);
+ }
- String firstPartValue = urls[i].substring(0, startPathIndex + 1);
- String secondPartValue = urls[i].substring(endPathIndex, urls[i]
- .length());
+ private static String[] splitURL(String url) {
+ int startAttr = url.indexOf(ATTR_URL);
+ int startPathIndex = url.indexOf(OPEN_BRACKET, startAttr);
+ int endPathIndex = url.indexOf(CLOSE_BRACKET, startPathIndex + 1);
+ if (startPathIndex < 0 || endPathIndex < 0) {
+ return null;
+ }
+ String[] res = new String[3];
+ res[0] = url.substring(0, startPathIndex + 1);
+ res[1] = url.substring(startPathIndex + 1, endPathIndex);
+ res[2] = url.substring(endPathIndex, url.length());
+ return res;
+ }
- urls[i] = firstPartValue + filePath + secondPartValue;
+ private static String updateURLItem(String url) {
+ url = url.replace(SINGLE_QUOTE_STRING, EMPTY_STRING);
+ url = url.replace(QUOTE_STRING, EMPTY_STRING);
+ url = ATTR_URL + url;
+ return url;
+ }
+
+ private static String collectArrayInto1Str(String arr[]) {
+ String finalStr = EMPTY_STRING;
+ for (int i = 0; i < arr.length; i++) {
+ finalStr += arr[i];
}
- for (int i = 0; i < urls.length; i++) {
- finalStr += urls[i];
- }
return finalStr;
}
-
- public static String getAbsoluteResourcePathUrl(String resourcePathInPlugin) {
- return FILE_PROTOCOL + SLASH + SLASH + SLASH
- + getAbsoluteResourcePath(resourcePathInPlugin)
- .replace('\\', '/');
- }
+
+ private static String updateURLFilePath(String filePath, String href_val) {
+ try {
+ URL url = new URL(filePath);
+ // with url all ok
+ return null;
+ } catch (MalformedURLException e) {
+ // ignore, continue work with url
+ }
+ if (filePath.indexOf(FILE_PROTOCOL) != -1) {
+ return null;
+ }
+ if (!new File(filePath).isAbsolute()) {
+ filePath = getFilePath(href_val, filePath);
+ } else {
+ filePath = FILE_PROTOCOL + SLASH + SLASH + filePath.replace('\\',
'/');
+ }
+ URL url = null;
+ try {
+ url = new URL(filePath);
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ filePath = url.toString();
+ return filePath;
+ }
- /**
+ public static String getAbsoluteResourcePathUrl(String resourcePathInPlugin) {
+ return FILE_PROTOCOL + SLASH + SLASH + SLASH
+ + getAbsoluteResourcePath(resourcePathInPlugin).replace('\\', '/');
+ }
+
+ /**
* Adds the full path to image "src" attribute.
*
- * @param path image "src" attribute value
- * @param pageContext the pageContext
- * @param showUnresolvedImage flag to display unresolved image
+ * @param path
+ * image "src" attribute value
+ * @param pageContext
+ * the pageContext
+ * @param showUnresolvedImage
+ * flag to display unresolved image
*
* @return the full path to image "src" attribute
*/
public static String addFullPathToImgSrc(String path,
VpePageContext pageContext, boolean showUnresolvedImage) {
-
- if (path == null) {
- if (showUnresolvedImage) {
- return FILE_PROTOCOL + SLASH + SLASH
- + getAbsoluteResourcePath(UNRESOLVED_IMAGE_PATH).replace('\\',
'/');
- } else {
- return EMPTY_STRING;
- }
- }
-
+
+ if (path == null) {
+ if (showUnresolvedImage) {
+ return FILE_PROTOCOL + SLASH + SLASH
+ + getAbsoluteResourcePath(UNRESOLVED_IMAGE_PATH).replace('\\',
'/');
+ } else {
+ return EMPTY_STRING;
+ }
+ }
+
IPath tagPath = new Path(path);
if (tagPath.isEmpty()) {
if (showUnresolvedImage) {
@@ -611,11 +584,8 @@
}
}
- String device = (tagPath.getDevice() == null ? tagPath.segment(0)
- : tagPath.getDevice());
- if (device != null
- && (HTTP_PROTOCOL.equalsIgnoreCase(device) || FILE_PROTOCOL
- .equalsIgnoreCase(device))) {
+ String device = (tagPath.getDevice() == null ? tagPath.segment(0) :
tagPath.getDevice());
+ if (device != null && (HTTP_PROTOCOL.equalsIgnoreCase(device) ||
FILE_PROTOCOL.equalsIgnoreCase(device))) {
if (showUnresolvedImage) {
return FILE_PROTOCOL + SLASH + SLASH
+ getAbsoluteResourcePath(UNRESOLVED_IMAGE_PATH).replace('\\',
'/');
@@ -626,8 +596,7 @@
File locFile = tagPath.toFile();
if (locFile.exists()) {
- return FILE_PROTOCOL + SLASH + SLASH + SLASH
- + locFile.getAbsolutePath().replace('\\', '/');
+ return FILE_PROTOCOL + SLASH + SLASH + SLASH +
locFile.getAbsolutePath().replace('\\', '/');
}
IEditorInput input = pageContext.getEditPart().getEditorInput();
@@ -636,8 +605,7 @@
if (input instanceof ILocationProvider) {
imgPath = inputPath.append(path);
} else {
- IPath basePath = tagPath.isAbsolute() ? getRootPath(input)
- : inputPath;
+ IPath basePath = tagPath.isAbsolute() ? getRootPath(input) : inputPath;
if (basePath != null) {
imgPath = basePath.append(tagPath);
}
@@ -655,12 +623,10 @@
ResourceReference resourceReference = null;
String pathCopy = path;
if (SLASH.equals(path.substring(0, 1))) {
- resourceReference = pageContext
- .getRuntimeAbsoluteFolder(file);
+ resourceReference = pageContext.getRuntimeAbsoluteFolder(file);
pathCopy = pathCopy.substring(1);
} else {
- resourceReference = pageContext
- .getRuntimeRelativeFolder(file);
+ resourceReference = pageContext.getRuntimeRelativeFolder(file);
}
String location = null;
@@ -675,15 +641,13 @@
if (null != location) {
File f = new File(location + File.separator + pathCopy);
if (f.exists()) {
- return FILE_PROTOCOL + SLASH + SLASH + SLASH
- + f.getPath().replace('\\', '/');
+ return FILE_PROTOCOL + SLASH + SLASH + SLASH + f.getPath().replace('\\',
'/');
}
}
}
}
if (showUnresolvedImage) {
- return FILE_PROTOCOL + SLASH + SLASH
- + getAbsoluteResourcePath(UNRESOLVED_IMAGE_PATH).replace('\\',
'/');
+ return FILE_PROTOCOL + SLASH + SLASH +
getAbsoluteResourcePath(UNRESOLVED_IMAGE_PATH).replace('\\', '/');
} else {
return path.replace('\\', '/');
}
@@ -692,22 +656,20 @@
/**
* Gets the root path of the web project.
*
- * @param input the input
+ * @param input
+ * the input
*
* @return the root path
*/
public static IPath getRootPath(IEditorInput input) {
IPath rootPath = null;
if (input instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput) input).getFile()
- .getProject();
+ IProject project = ((IFileEditorInput) input).getFile().getProject();
if (project != null && project.isOpen()) {
- IModelNature modelNature = EclipseResourceUtil
- .getModelNature(project);
+ IModelNature modelNature = EclipseResourceUtil.getModelNature(project);
if (modelNature != null) {
XModel model = modelNature.getModel();
- String rootPathStr = WebProject.getInstance(model)
- .getWebRootLocation();
+ String rootPathStr = WebProject.getInstance(model).getWebRootLocation();
if (rootPathStr != null) {
rootPath = new Path(rootPathStr);
} else {
@@ -720,32 +682,28 @@
}
return rootPath;
}
-
+
/**
* refresh style element
+ *
* @param visualDomBuilder
* @param sourceElement
* @param oldStyleNode
* @return
*/
- public static void refreshStyleElement(
- VpeVisualDomBuilder visualDomBuilder,
- VpeElementMapping elementMapping) {
+ public static void refreshStyleElement(VpeVisualDomBuilder visualDomBuilder,
VpeElementMapping elementMapping) {
nsIDOMNode value = null;
/*
- * data property( of "style's" elementMapping ) contains
Map<Object,nsIDOMNode>.
- * There is only one "style" visual element in this map. So we get this
- * element from map
+ * data property( of "style's" elementMapping ) contains
Map<Object,nsIDOMNode>. There is only one "style"
+ * visual element in this map. So we get this element from map
*
- * there is potential danger in this manner of keeping "style"
- * element ( use property "data" of Object type )
+ * there is potential danger in this manner of keeping "style" element ( use
property "data" of Object type )
*/
-
- Map<Object, nsIDOMNode> map = (Map<Object, nsIDOMNode>) elementMapping
- .getData();
+ Map<Object, nsIDOMNode> map = (Map<Object, nsIDOMNode>)
elementMapping.getData();
+
// get "style" element
if (map != null) {
@@ -765,7 +723,6 @@
text = textNode.getNodeValue();
}
-
nsIDOMNodeList list = value.getChildNodes();
// remove all children of style element
@@ -773,12 +730,11 @@
value.removeChild(list.item(i));
// add new value of style element
- value.appendChild(visualDomBuilder.getXulRunnerEditor()
- .getDOMDocument().createTextNode(text));
+ value.appendChild(visualDomBuilder.getXulRunnerEditor().getDOMDocument().createTextNode(text));
}
-
- public static String getAbsoluteResourcePath(String resourcePathInPlugin) {
+
+ public static String getAbsoluteResourcePath(String resourcePathInPlugin) {
String pluginPath = VpePlugin.getPluginResourcePath();
IPath pluginFile = new Path(pluginPath);
File file = pluginFile.append(resourcePathInPlugin).toFile();
@@ -790,57 +746,54 @@
}
}
+ /**
+ * If the {@code size} ends with a digit, adds {@code "px"} to it.
+ *
+ * @param size
+ * non-null value of a size attribute (e.g. {@code width}).
+ */
+ public static String addPxIfNecessary(final String size) {
+ final String trimmed = size.trim();
+ int length = trimmed.length();
+ if (length > 0) {
+ final char lastChar = trimmed.charAt(length - 1);
+ if (Character.isDigit(lastChar)) {
+ return trimmed + PX_STRING;
+ }
+ }
- /**
- * If the {@code size} ends with a digit, adds {@code "px"} to it.
- *
- * @param size non-null value of a size attribute (e.g. {@code width}).
- */
- public static String addPxIfNecessary(final String size) {
- final String trimmed = size.trim();
- int length = trimmed.length();
- if (length > 0) {
- final char lastChar = trimmed.charAt(length - 1);
- if (Character.isDigit(lastChar)) {
- return trimmed + PX_STRING;
- }
- }
+ return size;
+ }
- return size;
- }
-
- /**
- * Converts the argument to the form {@code "Xpx"},
- * where {@code X=position}.
- */
- public static String toPxPosition(int position) {
+ /**
+ * Converts the argument to the form {@code "Xpx"}, where {@code X=position}.
+ */
+ public static String toPxPosition(int position) {
return Integer.toString(position) + PX_STRING;
}
-
- public static String processUrl(String url, IFile file) {
- String resolvedUrl = url
- .replaceFirst(
- "^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}",
Constants.EMPTY); //$NON-NLS-1$
+ public static String processUrl(String url, IFile file) {
+ String resolvedUrl = url.replaceFirst(
+ "^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}",
Constants.EMPTY); //$NON-NLS-1$
- resolvedUrl = ElService.getInstance().replaceEl(file, resolvedUrl);
+ resolvedUrl = ElService.replaceEl(file, resolvedUrl);
URI uri = null;
try {
uri = new URI(resolvedUrl);
} catch (URISyntaxException e) {
- // here we process user input, and when user enter url, there possible that we will not
be able parse it.
- // so we just ignore this.
- // VpePlugin.getDefault().logWarning("Error in parsiong URI string", e);
//$NON-NLS-1$
+ // here we process user input, and when user enter url, there possible that we will
not be able parse it.
+ // so we just ignore this.
+ // VpePlugin.getDefault().logWarning("Error in parsiong URI string", e);
//$NON-NLS-1$
}
- if ((uri != null) && (uri.isAbsolute())) {
+ if (uri != null && uri.isAbsolute()) {
return resolvedUrl;
}
-
+
String decodedUrl = decodeUrl(resolvedUrl);
-
+
Path path = new Path(decodedUrl);
if (decodedUrl.startsWith("/") //$NON-NLS-1$
&& path.segment(0).equals(file.getProject().getName())) {
@@ -851,15 +804,14 @@
IPath location = FileUtil.getFile(decodedUrl, file).getLocation();
if (location != null) {
return pathToUrl(location);
- } else {
- return resolvedUrl;
}
+ return resolvedUrl;
}
private static String pathToUrl(IPath location) {
String fullFilePath = location.toPortableString();
try {
- return new URI("file", "", "/" + fullFilePath,
null).toASCIIString(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ return new URI("file", "", "/" + fullFilePath,
null).toASCIIString(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
} catch (URISyntaxException e) {
VpePlugin.getPluginLog().logError(e);
return Constants.FILE_PREFIX + fullFilePath;
@@ -876,29 +828,25 @@
}
return decodedUrl;
}
-
- /**
- * Applies CSS attributes {@code left:x;top:y;} to the specified
- * {@code element}.
- */
- public static void moveElementTo(nsIDOMElement element, int x, int y) {
- nsIDOMCSSStyleDeclaration style = VpeStyleUtil.getStyle(element);
- style.setProperty(HTML.STYLE_PARAMETER_LEFT,
- VpeStyleUtil.toPxPosition(x), HTML.STYLE_PRIORITY_IMPORTANT);
- style.setProperty(HTML.STYLE_PARAMETER_TOP,
- VpeStyleUtil.toPxPosition(y), HTML.STYLE_PRIORITY_IMPORTANT);
- }
- /**
- * Applies CSS attribute {@code display} to the specified
- * {@code element} according to the {@code visible} parameter.
- */
- public static void setElementVisible(nsIDOMElement element,
- boolean visible) {
- nsIDOMCSSStyleDeclaration style = VpeStyleUtil.getStyle(element);
+ /**
+ * Applies CSS attributes {@code left:x;top:y;} to the specified {@code element}.
+ */
+ public static void moveElementTo(nsIDOMElement element, int x, int y) {
+ nsIDOMCSSStyleDeclaration style = VpeStyleUtil.getStyle(element);
+ style.setProperty(HTML.STYLE_PARAMETER_LEFT, VpeStyleUtil.toPxPosition(x),
HTML.STYLE_PRIORITY_IMPORTANT);
+ style.setProperty(HTML.STYLE_PARAMETER_TOP, VpeStyleUtil.toPxPosition(y),
HTML.STYLE_PRIORITY_IMPORTANT);
+ }
+
+ /**
+ * Applies CSS attribute {@code display} to the specified {@code element} according to
the {@code visible}
+ * parameter.
+ */
+ public static void setElementVisible(nsIDOMElement element, boolean visible) {
+ nsIDOMCSSStyleDeclaration style = VpeStyleUtil.getStyle(element);
style.setProperty(HTML.STYLE_PARAMETER_DISPLAY,
visible ? HTML.STYLE_VALUE_DEFAULT_DISPLAY
: HTML.STYLE_VALUE_NONE, HTML.STYLE_PRIORITY_IMPORTANT);
- }
+ }
}