Author: dmaliarevich
Date: 2011-03-15 11:54:57 -0400 (Tue, 15 Mar 2011)
New Revision: 29793
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsAction.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsContributionItem.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsKeysListPage.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsSelectBundlePage.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JspEditorPlugin.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsAction.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-7004 , Base version of the Externalize All Strings
dialog was implemented.
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/i18n/I18nValidationComponent.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -15,14 +15,14 @@
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.messages.JSFUIMessages;
import org.jboss.tools.jsf.web.validation.JSFAbstractValidationComponent;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
/**
* @author mareshkau
*
*/
public class I18nValidationComponent extends JSFAbstractValidationComponent{
- public static String PROBLEM_ID = JSFModelPlugin.PLUGIN_ID
- + ".i18nproblemmarker"; //$NON-NLS-1$
+ public static String PROBLEM_ID = JspEditorPlugin.I18N_VALIDATION_PROBLEM_ID;
private String inValidString;
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2011-03-15 15:23:13 UTC
(rev 29792)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2011-03-15 15:54:57 UTC
(rev 29793)
@@ -30,6 +30,7 @@
Require-Bundle: org.jboss.tools.common.el.core,
org.jboss.tools.common.model.ui,
org.jboss.tools.jst.web,
+ org.jboss.tools.jst.web.kb,
org.eclipse.gef,
org.eclipse.jface.text,
org.eclipse.ui.workbench.texteditor,
@@ -39,21 +40,22 @@
org.eclipse.wst.html.core,
org.eclipse.wst.html.ui,
org.eclipse.wst.xml.ui,
- org.eclipse.jst.jsp.ui,
org.eclipse.wst.css.core,
org.eclipse.wst.css.ui,
+ org.eclipse.jst.jsp.ui,
org.eclipse.help.ui,
org.eclipse.jem,
org.eclipse.ui.views,
org.eclipse.core.databinding,
org.eclipse.jface.databinding,
- org.jboss.tools.jst.web.kb,
org.eclipse.core.databinding.property,
org.eclipse.emf.ecore,
org.eclipse.compare,
org.eclipse.wst.dtd.core,
+ org.eclipse.wst.validation,
org.eclipse.ui,
org.eclipse.jst.standard.schemas,
org.eclipse.wst.standard.schemas
Bundle-Version: 3.3.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2011-03-15 15:23:13 UTC (rev
29792)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2011-03-15 15:54:57 UTC (rev
29793)
@@ -377,12 +377,26 @@
<menuContribution
locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor.source.EditorContext?after=org.jboss.tools.vpe.editor.menu.SetupTemplateContributionItem">
<dynamic
+
class="org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsContributionItem"
+
id="org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsContributionItem">
+ </dynamic>
+ </menuContribution>
+ <menuContribution
+
locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor.source.EditorContext?after=org.jboss.tools.vpe.editor.menu.SetupTemplateContributionItem">
+ <dynamic
+
class="org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsContributionItem"
+
id="org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsContributionItem">
+ </dynamic>
+ </menuContribution>
+ <menuContribution
+ locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor.source.EditorContext?after=org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsContributionItem">
+ <dynamic
class="org.jboss.tools.jst.jsp.i18n.ExternalizeStringsContributionItem"
id="org.jboss.tools.jst.jsp.i18n.ExternalizeStringsContributionItem">
</dynamic>
</menuContribution>
<menuContribution
-
locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor.source.EditorContext?after=org.jboss.tools.vpe.editor.menu.SetupTemplateContributionItem">
+
locationURI="popup:org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor.source.EditorContext?after=org.jboss.tools.jst.jsp.i18n.ExternalizeAllStringsContributionItem">
<dynamic
class="org.jboss.tools.jst.jsp.i18n.ExternalizeStringsContributionItem"
id="org.jboss.tools.jst.jsp.i18n.ExternalizeStringsContributionItem">
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JspEditorPlugin.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JspEditorPlugin.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JspEditorPlugin.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -44,9 +44,8 @@
//The shared instance.
private static JspEditorPlugin plugin;
-
public static final String PLUGIN_ID = "org.jboss.tools.jst.jsp";
//$NON-NLS-1$
-
+ public static final String I18N_VALIDATION_PROBLEM_ID = PLUGIN_ID +
".i18nproblemmarker"; //$NON-NLS-1$
public static final String RESOURCES_PATH = "/resources"; //$NON-NLS-1$
// A Map to save a descriptor for each image
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsAction.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsAction.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsAction.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.i18n;
+
+import org.eclipse.ui.PlatformUI;
+
+public class ExternalizeAllStringsAction extends ExternalizeStringsAction {
+
+ @Override
+ public void run() {
+ /*
+ * Pass null for Bundle Map that it will be created by the page itself.
+ */
+ ExternalizeStringsDialog dlg = new ExternalizeStringsDialog(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ new ExternalizeAllStringsWizard(editor.getSourceEditor(), null));
+ dlg.open();
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsContributionItem.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsContributionItem.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsContributionItem.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.i18n;
+
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.swt.widgets.Menu;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+
+public class ExternalizeAllStringsContributionItem extends
+ ActionContributionItem {
+
+ public ExternalizeAllStringsContributionItem() {
+ super(new ExternalizeAllStringsAction());
+ }
+
+ @Override
+ public void fill(Menu parent, int index) {
+ /*
+ * Simply sets the title
+ */
+ getAction().setText(JstUIMessages.EXTERNALIZE_ALL_STRINGS_POPUP_MENU_TITLE);
+ super.fill(parent, index);
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsKeysListPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsKeysListPage.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsKeysListPage.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -0,0 +1,307 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.i18n;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.jboss.tools.common.model.ui.ModelUIImages;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.util.Constants;
+
+public class ExternalizeAllStringsKeysListPage extends WizardPage {
+
+ private static final String KEY_PROPERTY = "key"; //$NON-NLS-1$
+ private static final String VALUE_PROPERTY = "value"; //$NON-NLS-1$
+ private List<KeyValueElement> keys = new ArrayList<KeyValueElement>();
+ private IDocument doc = null;
+
+ protected ExternalizeAllStringsKeysListPage(String pageName) {
+ super(pageName,
+ JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE,
+ ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
+ setDescription(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_DESCRIPTION);
+ setPageComplete(false);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ keys = getAllStrings();
+ Table table = createTable(parent);
+ setControl(table);
+ }
+
+ private List<KeyValueElement> getAllStrings() {
+ List<KeyValueElement> keys = new ArrayList<KeyValueElement>();
+ if (getWizard() instanceof ExternalizeAllStringsWizard) {
+ ExternalizeAllStringsWizard wiz = (ExternalizeAllStringsWizard) getWizard();
+ IEditorInput in = wiz.getEditor().getEditorInput();
+ if (in instanceof IFileEditorInput) {
+ IFileEditorInput fin = (IFileEditorInput) in;
+ IFile file = fin.getFile();
+ try {
+ ValidationFramework.getDefault().validate(file, new NullProgressMonitor());
+ IMarker[] markers = fin.getFile().findMarkers(
+ JspEditorPlugin.I18N_VALIDATION_PROBLEM_ID,
+ true, IResource.DEPTH_ZERO);
+ doc = wiz.getEditor().getDocumentProvider().getDocument(in);
+ /*
+ * Iterate over all the markers
+ */
+ String text = null;
+ for (IMarker m : markers) {
+ Integer offset = (Integer) m.getAttribute("PROBLEM_OFFSET");
//$NON-NLS-1$
+ Integer length = (Integer) m.getAttribute("PROBLEM_LENGHT");
//$NON-NLS-1$
+ try {
+ text = doc.get(offset.intValue(), length.intValue());
+ keys.add(new KeyValueElement(
+ ExternalizeStringsUtils.generatePropertyKey(text),
+ text, offset.intValue(), length.intValue()));
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (CoreException e) {
+ JspEditorPlugin.getDefault().logError(e);
+ }
+ }
+ }
+ return keys;
+ }
+
+ private Table createTable(Composite parent) {
+ Table table = new Table(parent, SWT.FULL_SELECTION | SWT.BORDER);
+ TableViewer tv = layoutTableInViewer(table);
+ attachContentProvider(tv);
+ attachLabelProvider(tv);
+ attachCellEditors(tv, table);
+ addProperties(tv);
+ return table;
+ }
+
+ private TableViewer layoutTableInViewer(Table table) {
+ TableViewer tableViewer = new TableViewer(table);
+
+ TableLayout layout = new TableLayout();
+ layout.addColumnData(new ColumnWeightData(200, 200, true));
+ layout.addColumnData(new ColumnWeightData(200, 200, true));
+ table.setLayout(layout);
+
+ TableColumn nameColumn = new TableColumn(table, SWT.LEFT);
+ nameColumn.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTY_NAME);
+ TableColumn valColumn = new TableColumn(table, SWT.LEFT);
+ valColumn.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTY_VALUE);
+
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ return tableViewer;
+ }
+
+ private void attachContentProvider(TableViewer tv) {
+ tv.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return (Object[]) inputElement;
+ }
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+ public void dispose() {}
+ });
+ }
+
+ private void attachLabelProvider(TableViewer tv) {
+ tv.setLabelProvider(new ITableLabelProvider() {
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+ public String getColumnText(Object element, int columnIndex) {
+ switch (columnIndex) {
+ case 0:
+ return ((KeyValueElement) element).key;
+ case 1:
+ return ((KeyValueElement) element).value;
+ default:
+ return "Invalid column: " + columnIndex; //$NON-NLS-1$
+ }
+ }
+ public void addListener(ILabelProviderListener listener) { }
+ public void dispose() { }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener lpl) { }
+ });
+ }
+
+ private void attachCellEditors(final TableViewer viewer, Composite parent) {
+ viewer.setCellModifier(new ICellModifier() {
+ public boolean canModify(Object element, String property) {
+ return true;
+ }
+ public Object getValue(Object element, String property) {
+ if (KEY_PROPERTY.equals(property)) {
+ return ((KeyValueElement) element).key;
+ } else {
+ return ((KeyValueElement) element).value;
+ }
+ }
+ public void modify(Object element, String property, Object value) {
+ TableItem tableItem = (TableItem) element;
+ KeyValueElement kve = (KeyValueElement) tableItem.getData();
+ if (KEY_PROPERTY.equals(property)) {
+ kve.key = value.toString();
+ } else {
+ kve.value = value.toString();
+ }
+ viewer.refresh(kve);
+ }
+ });
+ viewer.setCellEditors(new CellEditor[] {
+ new TextCellEditor(parent), null });
+ viewer.setColumnProperties(new String[] {
+ KEY_PROPERTY, VALUE_PROPERTY });
+ }
+
+ private void addProperties(TableViewer viewer) {
+ for (KeyValueElement k : keys) {
+ viewer.add(k);
+ }
+ }
+
+ /**
+ * Gets <code>key=value</code> pair
+ *
+ * @return a pair <code>key=value</code>
+ */
+ public String getKeyValuePairsList() {
+ StringBuffer sb = new StringBuffer();
+ for (KeyValueElement k : keys) {
+ sb.append(k.key + Constants.EQUAL + k.value);
+ sb.append('\n');
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Replaces the text in the current file
+ */
+ public void replaceAllStrings(String bundlePrefix) {
+ if ((doc == null) && (getWizard() instanceof ExternalizeAllStringsWizard)){
+ doc = ((ExternalizeAllStringsWizard) getWizard()).getDocument();
+ }
+ if (doc != null) {
+ /*
+ * Go from the end to the top of the file.
+ */
+ Collections.sort(keys);
+ for (int i = keys.size()-1; i >= 0; i--) {
+ KeyValueElement k = keys.get(i);
+ try {
+ doc.replace(k.offset, k.length, "#{" +bundlePrefix + Constants.DOT + k.key
+ "}"); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (BadLocationException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean isPageComplete() {
+ return true;
+ }
+
+ class KeyValueElement implements Comparable<KeyValueElement> {
+ public String key;
+ public String value;
+ public int offset;
+ public int length;
+ public KeyValueElement(String k, String v, int o, int l) {
+ key = k;
+ value = v;
+ offset = o;
+ length = l;
+ }
+ @Override
+ public int compareTo(KeyValueElement aThat) {
+ final int BEFORE = -1;
+ final int EQUAL = 0;
+ final int AFTER = 1;
+ if (this == aThat) return EQUAL;
+ if (this.offset < aThat.offset) return BEFORE;
+ if (this.offset > aThat.offset) return AFTER;
+ assert this.equals(aThat) : "compareTo inconsistent with equals.";
//$NON-NLS-1$
+ return EQUAL;
+ }
+ @Override
+ public int hashCode() {
+ int result = 47;
+ if (key != null) {
+ result+= key.hashCode();
+ }
+ result = result*7;
+ if (value != null) {
+ result+= value.hashCode();
+ }
+ result = result*7;
+ result+= offset;
+ result = result*7;
+ result+= length;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object aThat) {
+ if (this == aThat) return true;
+ if (!(aThat instanceof KeyValueElement)) return false;
+ KeyValueElement that = (KeyValueElement)aThat;
+ return ((this.key == that.key) &&
+ (this.value == that.value) &&
+ (this.offset == that.offset) &&
+ (this.length == that.length));
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass() + "@" + this.hashCode() //$NON-NLS-1$
+ + " (key=" + this.key + ", value=" + this.value //$NON-NLS-1$
//$NON-NLS-2$
+ + ", offset=" + this.offset + ", length=" + this.length +
")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsSelectBundlePage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsSelectBundlePage.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsSelectBundlePage.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.i18n;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.preference.FileFieldEditor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.jboss.tools.common.model.ui.ModelUIImages;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+
+public class ExternalizeAllStringsSelectBundlePage extends WizardPage {
+
+ IFile editorFile;
+ File bundleFile;
+ private FileFieldEditor fileFieldEditor;
+
+ protected ExternalizeAllStringsSelectBundlePage(String pageName) {
+ super(pageName,
+ JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE,
+ ModelUIImages.getImageDescriptor(ModelUIImages.WIZARD_DEFAULT));
+ setDescription(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_DESCRIPTION);
+ setPageComplete(false);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(1, false));
+
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(gd);
+ fileFieldEditor = new FileFieldEditor("storageKey", "Select bundle
file:", composite);
+ fileFieldEditor.setFileExtensions(new String[] {"*.properties"});
+ fileFieldEditor.setEmptyStringAllowed(false);
+
+ if (getWizard() instanceof ExternalizeAllStringsWizard) {
+ ExternalizeAllStringsWizard wiz = (ExternalizeAllStringsWizard) getWizard();
+ IEditorInput in = wiz.getEditor().getEditorInput();
+ if (in instanceof IFileEditorInput) {
+ IFileEditorInput fin = (IFileEditorInput) in;
+ editorFile = fin.getFile();
+ }
+ if (null != editorFile) {
+ fileFieldEditor.setFilterPath(editorFile.getProject().getLocation().toFile());
+ }
+ }
+ final Table table = ExternalizeStringsUtils.createPropertiesTable(composite,
SWT.BORDER);
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,true, 3, 1));
+ fileFieldEditor.setPropertyChangeListener(new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (FileFieldEditor.VALUE.equalsIgnoreCase(event.getProperty())) {
+ bundleFile = new File((String)event.getNewValue());
+ ExternalizeStringsUtils.populatePropertiesTable(table, bundleFile);
+ /*
+ * Set page complete
+ */
+ setPageComplete(isPageComplete());
+ }
+ }
+ });
+ /*
+ * Wizard Page control should be initialized.
+ */
+ setControl(composite);
+ }
+
+ @Override
+ public boolean isPageComplete() {
+ return fileFieldEditor.isValid();
+ }
+
+ public File getBundleFile() {
+ return bundleFile;
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.i18n;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.bundle.BundleMap;
+import org.jboss.tools.jst.jsp.bundle.BundleMap.BundleEntry;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.util.Constants;
+
+public class ExternalizeAllStringsWizard extends Wizard {
+
+ private ITextEditor editor = null;
+ private BundleMap bm = null;
+ ExternalizeAllStringsSelectBundlePage page1;
+ ExternalizeAllStringsKeysListPage page2;
+ ExternalizeStringsWizardRegisterBundlePage page3 = null;
+
+ public ExternalizeAllStringsWizard(ITextEditor editor, BundleMap bm) {
+ super();
+ setHelpAvailable(false);
+ setWindowTitle(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE);
+ this.editor = editor;
+ this.bm = bm;
+ if (this.bm == null) {
+ this.bm = ExternalizeStringsUtils.createBundleMap(editor);
+ }
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ page1 = new ExternalizeAllStringsSelectBundlePage("page1");
+ page2 = new ExternalizeAllStringsKeysListPage("page2");
+ page3 = new ExternalizeStringsWizardRegisterBundlePage("page3");
+ /*
+ * Add all the pages to the wizard
+ */
+ addPage(page1);
+ addPage(page2);
+ addPage(page3);
+ }
+
+ protected ITextEditor getEditor() {
+ return editor;
+ }
+
+ protected IDocument getDocument() {
+ return editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ }
+
+ @Override
+ public boolean performFinish() {
+ File bundleFile = page1.getBundleFile();
+ /*
+ * Exit when the file is null
+ */
+ if (bundleFile == null) {
+ JspEditorPlugin.getDefault().logError("Cannot externalize all string, because
bundle file is not found");
+ return false;
+ }
+ if (bundleFile.exists()) {
+ PrintWriter out = null;
+ try {
+ out = new PrintWriter(new BufferedWriter(new FileWriter(bundleFile, true)));
+ out.println();
+ out.println(page2.getKeyValuePairsList());
+ } catch (IOException e) {
+ JspEditorPlugin.getDefault().logError(e);
+ }
+ if (out.checkError()) {
+ JspEditorPlugin.getDefault().logError("Error while writing to the properties
file");
+ }
+ out.close();
+ out = null;
+ }
+ /*
+ * Find bundle prefix
+ */
+ String bundlePrefix = Constants.EMPTY;
+ String ap = bundleFile.getAbsolutePath();
+ for (BundleEntry be : bm.getBundles()) {
+ IFile bf = bm.getBundleFile(be.uri);
+ if (ap.equalsIgnoreCase(bf.getLocation().toOSString())) {
+ bundlePrefix = be.prefix;
+ break;
+ }
+ }
+ page2.replaceAllStrings(bundlePrefix);
+ return true;
+ }
+
+}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsAction.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsAction.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsAction.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -21,7 +21,7 @@
public class ExternalizeStringsAction extends Action {
- private JSPMultiPageEditor editor;
+ protected JSPMultiPageEditor editor;
public ExternalizeStringsAction() {
super();
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -10,22 +10,76 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.i18n;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ColumnLayoutData;
+import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.ui.internal.provisional.IDOMSourceEditingTextTools;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.ModelFeatureFactory;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jst.jsp.JspEditorPlugin;
+import org.jboss.tools.jst.jsp.bundle.BundleMap;
+import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.SourceEditorPageContext;
+import org.jboss.tools.jst.jsp.messages.JstUIMessages;
+import org.jboss.tools.jst.jsp.util.Constants;
+import org.jboss.tools.jst.jsp.util.FaceletsUtil;
+import org.jboss.tools.jst.web.project.WebProject;
import org.jboss.tools.jst.web.project.list.IWebPromptingProvider;
+import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
+import org.jboss.tools.jst.web.tld.TaglibData;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* The Utils class for externalize strings routine.
*/
public class ExternalizeStringsUtils {
+
+ public static final char[] REPLACED_CHARACTERS = new char[] {'~', '!',
'@', '#',
+ '$', '%', '^', '&', '*', '(',
')', '-', '+', '=', '{', '}', '[',
']', ':', ';', ',', '.', '?',
'\\', '/'};
+ public static final char[] LINE_DELEMITERS = new char[] {'\r', '\n',
'\t'};
/**
* Checks that the user has selected a correct string.
@@ -70,4 +124,289 @@
return null;
}
+ /**
+ * Creates new bundle map if no one was specified
+ * during initialization of the page.
+ *
+ * @param editor the source editor
+ * @return the new bundle map
+ */
+ public static BundleMap createBundleMap(ITextEditor editor) {
+ String uri = null;
+ String prefix = null;
+ int hash;
+ Map<?, ?> map = null;
+ BundleMap bm = new BundleMap();
+ bm.init(editor.getEditorInput());
+
+ /*
+ * Check JSF Nature
+ */
+ boolean hasJsfProjectNatureType = false;
+ try {
+ IEditorInput ei = editor.getEditorInput();
+ if(ei instanceof IFileEditorInput) {
+ IProject project = ((IFileEditorInput)ei).getFile().getProject();
+ if (project.exists() && project.isOpen()) {
+ if (project.hasNature(WebProject.JSF_NATURE_ID)) {
+ hasJsfProjectNatureType = true;
+ }
+ }
+ }
+ } catch (CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ /*
+ * Get Bundles from faces-config.xml
+ */
+ if (hasJsfProjectNatureType
+ && (editor.getEditorInput() instanceof IFileEditorInput)) {
+ IProject project = ((IFileEditorInput) editor.getEditorInput())
+ .getFile().getProject();
+ IModelNature modelNature = EclipseResourceUtil.getModelNature(project);
+ if (modelNature != null) {
+ XModel model = modelNature.getModel();
+ List<Object> l = WebPromptingProvider.getInstance().getList(model,
+ WebPromptingProvider.JSF_REGISTERED_BUNDLES, null, null);
+ if (l != null && l.size() > 1 && (l.get(1) instanceof Map)) {
+ map = (Map<?, ?>) l.get(1);
+ if ((null != map) && (map.keySet().size() > 0)) {
+ Iterator<?> it = map.keySet().iterator();
+ while (it.hasNext()) {
+ uri = it.next().toString();
+ prefix = map.get(uri).toString();
+ hash = (prefix + ":" + uri).hashCode(); //$NON-NLS-1$
+ bm.addBundle(hash, prefix, uri, false);
+ }
+ }
+ }
+ }
+ }
+ ISourceEditingTextTools sourceEditingTextTools =
+ (ISourceEditingTextTools) editor
+ .getAdapter(ISourceEditingTextTools.class);
+ IDOMSourceEditingTextTools domSourceEditingTextTools =
+ (IDOMSourceEditingTextTools) sourceEditingTextTools;
+ Document documentWithBundles = domSourceEditingTextTools.getDOMDocument();
+
+ /*
+ * When facelets are used -- get bundles from the template file
+ */
+ if (editor instanceof JSPTextEditor) {
+ IVisualContext context = ((JSPTextEditor) editor).getPageContext();
+ List<TaglibData> taglibs = null;
+ if (context instanceof SourceEditorPageContext) {
+ SourceEditorPageContext sourcePageContext = (SourceEditorPageContext) context;
+ taglibs = sourcePageContext.getTagLibs();
+ }
+ if (null == taglibs) {
+ JspEditorPlugin.getDefault().logError(
+ JstUIMessages.CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT);
+ } else {
+ Element root =
FaceletsUtil.findComponentElement(documentWithBundles.getDocumentElement());
+ if ((root != null) && FaceletsUtil.isFacelet(root, taglibs)
+ && root.hasAttribute("template")) { //$NON-NLS-1$
+ String filePath= root.getAttributeNode("template").getNodeValue();
//$NON-NLS-1$
+ if (((JSPTextEditor) editor).getEditorInput() instanceof FileEditorInput) {
+ FileEditorInput fei = (FileEditorInput) ((JSPTextEditor) editor).getEditorInput();
+ IResource webContentResource =
EclipseResourceUtil.getFirstWebContentResource(fei.getFile().getProject());
+ if (webContentResource instanceof IContainer) {
+ IFile templateFile = (IFile) ((IContainer)
webContentResource).findMember(filePath);
+ Document document = null;
+ IDOMModel wtpModel = null;
+ try {
+ wtpModel =
(IDOMModel)StructuredModelManager.getModelManager().getModelForRead(templateFile);
+ if (wtpModel != null) {
+ document = wtpModel.getDocument();
+ }
+ } catch(IOException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } catch(CoreException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ } finally {
+ if(wtpModel!=null) {
+ wtpModel.releaseFromRead();
+ }
+ }
+ if (null != document) {
+ /*
+ * Change the document where to look bundles
+ */
+ documentWithBundles = document;
+ }
+ }
+ }
+ }
+ }
+ }
+ /*
+ * Add bundles from <f:loadBundle> tags on the current page
+ */
+ NodeList list = documentWithBundles.getElementsByTagName("f:loadBundle");
//$NON-NLS-1$
+ for (int i = 0; i < list.getLength(); i++) {
+ Element node = (Element) list.item(i);
+ uri = node.getAttribute("basename"); //$NON-NLS-1$
+ prefix = node.getAttribute("var"); //$NON-NLS-1$
+ hash = node.hashCode();
+ bm.addBundle(hash, prefix, uri, false);
+ }
+ return bm;
+ }
+
+ public static Table createPropertiesTable(Composite parent, int style) {
+ Table table = new Table(parent, style);
+ TableLayout layout = new TableLayout();
+ table.setLayout(layout);
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ ColumnLayoutData columnLayoutData;
+ TableColumn propNameColumn = new TableColumn(table, SWT.NONE);
+ propNameColumn.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTY_NAME);
+ columnLayoutData = new ColumnWeightData(200, true);
+ layout.addColumnData(columnLayoutData);
+ TableColumn propValueColumn = new TableColumn(table, SWT.NONE);
+
propValueColumn.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTY_VALUE);
+ columnLayoutData = new ColumnWeightData(200, true);
+ layout.addColumnData(columnLayoutData);
+
+ return table;
+ }
+
+ /**
+ * Update resource bundle table according to the selected file:
+ * put key and value pairs to the table
+ *
+ * @param table the UI table
+ * @param propertiesFile resource bundle file
+ */
+ public static void populatePropertiesTable(Table table, IFile propertiesFile) {
+ if ((propertiesFile != null) && propertiesFile.exists()) {
+ BufferedReader in = null;
+ try {
+ /*
+ * Read the file content
+ */
+ String encoding = FileUtil.getEncoding(propertiesFile);
+ in = new BufferedReader(new InputStreamReader(
+ propertiesFile.getContents(), encoding));
+ readFileToProperies(table, in);
+ in.close();
+ } catch (CoreException e) {
+ JspEditorPlugin.getDefault().logError(
+ "Could not load file content for '" + propertiesFile +
"'", e); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (IOException e) {
+ JspEditorPlugin.getDefault().logError(
+ "Could not read file: '" + propertiesFile + "'", e);
//$NON-NLS-1$ //$NON-NLS-2$
+ } finally {
+ in = null;
+ }
+
+ } else {
+ JspEditorPlugin.getDefault().logError(
+ "Bundle File '" + propertiesFile + "' does not
exist!"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public static void populatePropertiesTable(Table table, File propertiesFile) {
+ if ((propertiesFile != null) && (propertiesFile.exists())) {
+ /*
+ * Read the file content
+ */
+ FileReader fr = null;
+ try {
+ fr = new FileReader(propertiesFile);
+ readFileToProperies(table, fr);
+ fr.close();
+ } catch (FileNotFoundException e) {
+ JspEditorPlugin.getDefault().logError(e);
+ } catch (IOException e) {
+ JspEditorPlugin.getDefault().logError(
+ "Could not read file: '" + propertiesFile + "'", e);
//$NON-NLS-1$ //$NON-NLS-2$
+ } finally {
+ fr = null;
+ }
+ } else {
+ JspEditorPlugin.getDefault().logError(
+ "Bundle File '" + propertiesFile + "' does not exist!");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ private static void readFileToProperies(Table table, Reader r) {
+ Properties properties = new Properties();
+ try {
+ properties.load(r);
+ r.close();
+ } catch (IOException e) {
+ JspEditorPlugin.getDefault().logError(
+ "Could not parse properties file.", e); //$NON-NLS-1$
+ }
+ /*
+ * Clear the table
+ */
+ table.removeAll();
+ /*
+ * Fill in new values
+ */
+ int k = 0;
+ Set<String> keys = properties.stringPropertyNames();
+ List<String> keysList = new ArrayList<String>(keys);
+ Collections.sort(keysList);
+ for (String key : keysList) {
+ TableItem tableItem = null;
+ tableItem = new TableItem(table, SWT.BORDER, k);
+ k++;
+ tableItem.setText(new String[] {key, properties.getProperty(key)});
+ }
+ }
+
+ /**
+ * Generate properties key.
+ * Replaces all non-word characters with
+ * underline character.
+ *
+ * @param text the text
+ * @return the result string
+ */
+ public static String generatePropertyKey(String text) {
+ String result = text.trim();
+ /*
+ * Update text string field.
+ * Trim the text to remove line breaks and caret returns.
+ * Replace line delimiters white space
+ */
+ for (char ch : LINE_DELEMITERS) {
+ text = text.trim().replace(ch, ' ');
+ }
+ /*
+ * Replace all other symbols with '_'
+ */
+ for (char ch : REPLACED_CHARACTERS) {
+ result = result.replace(ch, '_');
+ }
+ /*
+ * Replace all white spaces with '_'
+ */
+ result = result.replaceAll(Constants.WHITE_SPACE,
+ Constants.UNDERSCORE);
+ /*
+ * Correct underline symbols:
+ * show only one of them
+ */
+ result = result.replaceAll("_+", Constants.UNDERSCORE); //$NON-NLS-1$
+ /*
+ * Remove leading and trailing '_'
+ */
+ if (result.startsWith(Constants.UNDERSCORE)) {
+ result = result.substring(1);
+ }
+ if (result.endsWith(Constants.UNDERSCORE)) {
+ result = result.substring(0, result.length() - 1);
+ }
+ /*
+ * Return the result
+ */
+ return result;
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -13,12 +13,9 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -30,26 +27,19 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
-import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.ui.internal.provisional.IDOMSourceEditingTextTools;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.meta.action.XActionInvoker;
import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.ui.ModelUIImages;
import org.jboss.tools.common.model.ui.editors.dnd.DropURI;
import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
@@ -64,15 +54,10 @@
import org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteTaglibInserter;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.util.Constants;
-import org.jboss.tools.jst.jsp.util.FaceletsUtil;
-import org.jboss.tools.jst.web.project.WebProject;
-import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.jst.web.tld.URIConstants;
-import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
public class ExternalizeStringsWizard extends Wizard {
@@ -91,8 +76,8 @@
setWindowTitle(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE);
this.editor = editor;
this.bm = bm;
- if(this.bm==null){
- this.bm=createBundleMap(editor);
+ if (this.bm == null) {
+ this.bm = ExternalizeStringsUtils.createBundleMap(editor);
}
}
@@ -386,135 +371,6 @@
}
- /**
- * Creates new bundle map if no one was specified
- * during initialization of the page.
- *
- * @param editor the source editor
- * @return the new bundle map
- */
- private BundleMap createBundleMap(ITextEditor editor) {
- String uri = null;
- String prefix = null;
- int hash;
- Map<?, ?> map = null;
- BundleMap bm = new BundleMap();
- bm.init(editor.getEditorInput());
-
- /*
- * Check JSF Nature
- */
- boolean hasJsfProjectNatureType = false;
- try {
- IEditorInput ei = editor.getEditorInput();
- if(ei instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput)ei).getFile().getProject();
- if (project.exists() && project.isOpen()) {
- if (project.hasNature(WebProject.JSF_NATURE_ID)) {
- hasJsfProjectNatureType = true;
- }
- }
- }
- } catch (CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
- /*
- * Get Bundles from faces-config.xml
- */
- if (hasJsfProjectNatureType
- && (editor.getEditorInput() instanceof IFileEditorInput)) {
- IProject project = ((IFileEditorInput) editor.getEditorInput())
- .getFile().getProject();
- IModelNature modelNature = EclipseResourceUtil.getModelNature(project);
- if (modelNature != null) {
- XModel model = modelNature.getModel();
- List<Object> l = WebPromptingProvider.getInstance().getList(model,
- WebPromptingProvider.JSF_REGISTERED_BUNDLES, null, null);
- if (l != null && l.size() > 1 && (l.get(1) instanceof Map)) {
- map = (Map<?, ?>) l.get(1);
- if ((null != map) && (map.keySet().size() > 0)) {
- Iterator<?> it = map.keySet().iterator();
- while (it.hasNext()) {
- uri = it.next().toString();
- prefix = map.get(uri).toString();
- hash = (prefix + ":" + uri).hashCode(); //$NON-NLS-1$
- bm.addBundle(hash, prefix, uri, false);
- }
- }
- }
- }
- }
- ISourceEditingTextTools sourceEditingTextTools =
- (ISourceEditingTextTools) editor
- .getAdapter(ISourceEditingTextTools.class);
- IDOMSourceEditingTextTools domSourceEditingTextTools =
- (IDOMSourceEditingTextTools) sourceEditingTextTools;
- Document documentWithBundles = domSourceEditingTextTools.getDOMDocument();
-
- /*
- * When facelets are used -- get bundles from the template file
- */
- if (editor instanceof JSPTextEditor) {
- IVisualContext context = ((JSPTextEditor) editor).getPageContext();
- List<TaglibData> taglibs = null;
- if (context instanceof SourceEditorPageContext) {
- SourceEditorPageContext sourcePageContext = (SourceEditorPageContext) context;
- taglibs = sourcePageContext.getTagLibs();
- }
- if (null == taglibs) {
- JspEditorPlugin.getDefault().logError(
- JstUIMessages.CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT);
- } else {
- Element root =
FaceletsUtil.findComponentElement(documentWithBundles.getDocumentElement());
- if ((root != null) && FaceletsUtil.isFacelet(root, taglibs)
- && root.hasAttribute("template")) { //$NON-NLS-1$
- String filePath= root.getAttributeNode("template").getNodeValue();
//$NON-NLS-1$
- if (((JSPTextEditor) editor).getEditorInput() instanceof FileEditorInput) {
- FileEditorInput fei = (FileEditorInput) ((JSPTextEditor) editor).getEditorInput();
- IResource webContentResource =
EclipseResourceUtil.getFirstWebContentResource(fei.getFile().getProject());
- if (webContentResource instanceof IContainer) {
- IFile templateFile = (IFile) ((IContainer)
webContentResource).findMember(filePath); //$NON-NLS-1$
- Document document = null;
- IDOMModel wtpModel = null;
- try {
- wtpModel =
(IDOMModel)StructuredModelManager.getModelManager().getModelForRead(templateFile);
- if (wtpModel != null) {
- document = wtpModel.getDocument();
- }
- } catch(IOException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } catch(CoreException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- } finally {
- if(wtpModel!=null) {
- wtpModel.releaseFromRead();
- }
- }
- if (null != document) {
- /*
- * Change the document where to look bundles
- */
- documentWithBundles = document;
- }
- }
- }
- }
- }
- }
- /*
- * Add bundles from <f:loadBundle> tags on the current page
- */
- NodeList list = documentWithBundles.getElementsByTagName("f:loadBundle");
//$NON-NLS-1$
- for (int i = 0; i < list.getLength(); i++) {
- Element node = (Element) list.item(i);
- uri = node.getAttribute("basename"); //$NON-NLS-1$
- prefix = node.getAttribute("var"); //$NON-NLS-1$
- hash = node.hashCode();
- bm.addBundle(hash, prefix, uri, false);
- }
- return bm;
- }
-
private IDocument getDocument(){
IDocumentProvider prov = editor.getDocumentProvider();
return prov.getDocument(editor.getEditorInput());
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -10,18 +10,10 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.i18n;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
import java.util.Set;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.DialogPage;
@@ -29,13 +21,10 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ColumnLayoutData;
-import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
@@ -50,13 +39,11 @@
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.xml.core.internal.document.AttrImpl;
import org.eclipse.wst.xml.core.internal.document.TextImpl;
import org.jboss.tools.common.model.ui.ModelUIImages;
-import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.bundle.BundleMap;
import org.jboss.tools.jst.jsp.bundle.BundleMap.BundleEntry;
@@ -68,9 +55,6 @@
public static final String PAGE_NAME = "ExternalizeStringsWizardBasicPage";
//$NON-NLS-1$
- private final char[] REPLACED_CHARACTERS = new char[] {'~', '!',
'@', '#',
- '$', '%', '^', '&', '*', '(',
')', '-', '+', '=', '{', '}', '[',
']', ':', ';', ',', '.', '?',
'\\', '/'};
- private final char[] LINE_DELEMITERS = new char[] {'\r', '\n',
'\t'};
private final int DIALOG_WIDTH = 450;
private final int DIALOG_HEIGHT = 650;
private Text propsKey;
@@ -208,23 +192,7 @@
/*
* Create properties file table of content
*/
- tagsTable = new Table(propsFilesGroup, SWT.BORDER);
- TableLayout layout = new TableLayout();
- tagsTable.setLayout(layout);
- tagsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
- tagsTable.setHeaderVisible(true);
- tagsTable.setLinesVisible(true);
-
- ColumnLayoutData columnLayoutData;
- TableColumn propNameColumn = new TableColumn(tagsTable, SWT.NONE);
- propNameColumn.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTY_NAME);
- columnLayoutData = new ColumnWeightData(200, true);
- layout.addColumnData(columnLayoutData);
- TableColumn propValueColumn = new TableColumn(tagsTable, SWT.NONE);
-
propValueColumn.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTY_VALUE);
- columnLayoutData = new ColumnWeightData(200, true);
- layout.addColumnData(columnLayoutData);
-
+ tagsTable = ExternalizeStringsUtils.createPropertiesTable(propsFilesGroup, SWT.BORDER);
/*
* Initialize all fields with real values.
*/
@@ -235,53 +203,6 @@
*/
setControl(composite);
}
-
- /**
- * Generate properties key.
- * Replaces all non-word characters with
- * underline character.
- *
- * @param text the text
- * @return the result string
- */
- public String generatePropertyKey(String text) {
- String result = text.trim();
- /*
- * Replace all other symbols with '_'
- */
- for (char ch : REPLACED_CHARACTERS) {
- result = result.replace(ch, '_');
- }
- /*
- * Replace line delimiters white space
- */
- for (char ch : LINE_DELEMITERS) {
- result = result.replace(ch, ' ');
- }
- /*
- * Replace all white spaces with '_'
- */
- result = result.replaceAll(Constants.WHITE_SPACE,
- Constants.UNDERSCORE);
- /*
- * Correct underline symbols:
- * show only one of them
- */
- result = result.replaceAll("_+", Constants.UNDERSCORE); //$NON-NLS-1$
- /*
- * Remove leading and trailing '_'
- */
- if (result.startsWith(Constants.UNDERSCORE)) {
- result = result.substring(1);
- }
- if (result.endsWith(Constants.UNDERSCORE)) {
- result = result.substring(0, result.length() - 1);
- }
- /*
- * Return the result
- */
- return result;
- }
/**
* Gets the bundle prefix.
@@ -391,7 +312,7 @@
*/
doc.replace(offset, length, replacement);
} catch (BadLocationException ex) {
- ex.printStackTrace();
+ JspEditorPlugin.getPluginLog().logError(ex);
}
}
}
@@ -461,16 +382,8 @@
text = stringToUpdate;
}
}
- /*
- * Update text string field.
- * Trim the text to remove line breaks and caret returns.
- * Replace line delimiters white space
- */
- for (char ch : LINE_DELEMITERS) {
- text = text.trim().replace(ch, ' ');
- }
propsValue.setText(text);
- propsKey.setText(generatePropertyKey(text));
+ propsKey.setText(ExternalizeStringsUtils.generatePropertyKey(text));
/*
* Initialize bundle messages field
*/
@@ -685,55 +598,6 @@
}
/**
- * Update resource bundle table according to the selected file:
- * it fills key and value columns.
- *
- * @param file the resource bundle file
- */
- private void updateTable(IFile file) {
- if ((file != null) && file.exists()) {
- try {
- /*
- * Read the file content
- */
- String encoding = FileUtil.getEncoding(file);
- BufferedReader in = new BufferedReader(new InputStreamReader(
- file.getContents(), encoding));
- Properties properties = new Properties();
- properties.load(in);
- in.close();
- in = null;
- /*
- * Clear the table
- */
- tagsTable.removeAll();
- /*
- * Fill in new values
- */
- int k = 0;
- Set<String> keys = properties.stringPropertyNames();
- List<String> keysList = new ArrayList<String>(keys);
- Collections.sort(keysList);
- for (String key : keysList) {
- TableItem tableItem = null;
- tableItem = new TableItem(tagsTable, SWT.BORDER, k);
- k++;
- tableItem.setText(new String[] {key, properties.getProperty(key)});
- }
- } catch (CoreException e) {
- JspEditorPlugin.getDefault().logError(
- "Could not load file content for '" + file + "'", e);
//$NON-NLS-1$ //$NON-NLS-2$
- } catch (IOException e) {
- JspEditorPlugin.getDefault().logError(
- "Could not read file: '" + file + "'", e); //$NON-NLS-1$
//$NON-NLS-2$
- }
- } else {
- JspEditorPlugin.getDefault().logError(
- "Bundle File'" + file + "' does not exist!");
//$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- /**
* Enables or disables resource bundle information
*
* @param enabled shows the status
@@ -884,7 +748,7 @@
String bundlePath = Constants.EMPTY;
if (bundleFile != null) {
bundlePath = bundleFile.getFullPath().toString();
- updateTable(bundleFile);
+ ExternalizeStringsUtils.populatePropertiesTable(tagsTable, bundleFile);
} else {
JspEditorPlugin.getDefault().logError(
"Could not get Bundle File for resource '" //$NON-NLS-1$
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2011-03-15
15:54:57 UTC (rev 29793)
@@ -131,6 +131,7 @@
public static String EXTERNALIZE_STRINGS;
public static String EXTERNALIZE_STRINGS_POPUP_MENU_TITLE;
+ public static String EXTERNALIZE_ALL_STRINGS_POPUP_MENU_TITLE;
public static String EXTERNALIZE_STRINGS_DIALOG_TITLE;
public static String EXTERNALIZE_STRINGS_DIALOG_DESCRIPTION;
public static String EXTERNALIZE_STRINGS_DIALOG_TEXT_STRING;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2011-03-15
15:23:13 UTC (rev 29792)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2011-03-15
15:54:57 UTC (rev 29793)
@@ -109,7 +109,8 @@
# Externalize Strings Dialog
EXTERNALIZE_STRINGS=Externalize strings
-EXTERNALIZE_STRINGS_POPUP_MENU_TITLE=Externalize strings...
+EXTERNALIZE_ALL_STRINGS_POPUP_MENU_TITLE=Externalize all strings...
+EXTERNALIZE_STRINGS_POPUP_MENU_TITLE=Externalize selected string...
EXTERNALIZE_STRINGS_DIALOG_TITLE=Externalize Strings
EXTERNALIZE_STRINGS_DIALOG_DESCRIPTION=Externalize your strings via properties file
EXTERNALIZE_STRINGS_DIALOG_TEXT_STRING=Text string: