List of usage examples for java.util Locale equals
@Override public boolean equals(Object obj)
From source file:org.dbgl.gui.SettingsDialog.java
protected void createContents() { shell = new Shell(getParent(), SWT.TITLE | SWT.CLOSE | SWT.BORDER | SWT.RESIZE | SWT.APPLICATION_MODAL); shell.setLayout(new BorderLayout(0, 0)); shell.addControlListener(new SizeControlAdapter(shell, "settingsdialog")); shell.setText(settings.msg("dialog.settings.title")); final TabFolder tabFolder = new TabFolder(shell, SWT.NONE); final TabItem generalTabItem = new TabItem(tabFolder, SWT.NONE); generalTabItem.setText(settings.msg("dialog.settings.tab.general")); final Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new GridLayout()); generalTabItem.setControl(composite); final Group dosboxGroup = new Group(composite, SWT.NONE); dosboxGroup.setText(settings.msg("dialog.settings.dosbox")); dosboxGroup.setLayout(new GridLayout(2, false)); final Label showConsoleLabel = new Label(dosboxGroup, SWT.NONE); showConsoleLabel.setText(settings.msg("dialog.settings.hidestatuswindow")); final Button console = new Button(dosboxGroup, SWT.CHECK); console.setSelection(conf.getBooleanValue("dosbox", "hideconsole")); final Group sendToGroup = new Group(composite, SWT.NONE); sendToGroup.setText(settings.msg("dialog.settings.sendto")); sendToGroup.setLayout(new GridLayout(2, false)); final Label enableCommLabel = new Label(sendToGroup, SWT.NONE); enableCommLabel.setText(settings.msg("dialog.settings.enableport")); final Button portEnabled = new Button(sendToGroup, SWT.CHECK); portEnabled.setSelection(conf.getBooleanValue("communication", "port_enabled")); portEnabled.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { port.setEnabled(portEnabled.getSelection()); }/*w w w . ja va2 s .co m*/ }); final Label portnumberLabel = new Label(sendToGroup, SWT.NONE); portnumberLabel.setText(settings.msg("dialog.settings.port")); port = new Text(sendToGroup, SWT.BORDER); port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); port.setText(conf.getValue("communication", "port")); port.setEnabled(portEnabled.getSelection()); final Group profileDefGroup = new Group(composite, SWT.NONE); profileDefGroup.setText(settings.msg("dialog.settings.profiledefaults")); profileDefGroup.setLayout(new GridLayout(3, false)); final Label configFileLabel = new Label(profileDefGroup, SWT.NONE); configFileLabel.setText(settings.msg("dialog.settings.configfile")); confLocation = new Combo(profileDefGroup, SWT.READ_ONLY); confLocation.setItems(confLocations); confLocation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); confLocation.select(conf.getIntValue("profiledefaults", "confpath")); confFilename = new Combo(profileDefGroup, SWT.READ_ONLY); confFilename.setItems(confFilenames); confFilename.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); confFilename.select(conf.getIntValue("profiledefaults", "conffile")); final Group i18nGroup = new Group(composite, SWT.NONE); i18nGroup.setText(settings.msg("dialog.settings.i18n")); i18nGroup.setLayout(new GridLayout(2, false)); final Label languageLabel = new Label(i18nGroup, SWT.NONE); languageLabel.setText(settings.msg("dialog.settings.languagecountry")); localeCombo = new Combo(i18nGroup, SWT.READ_ONLY); Locale locale = new Locale(conf.getValue("locale", "language"), conf.getValue("locale", "country"), conf.getValue("locale", "variant")); final SortedMap<String, Locale> locales = new TreeMap<String, Locale>(); String locString = ""; java.util.List<String> supportedLanguages = new ArrayList<String>(SUPPORTED_LANGUAGES); File[] files = new File("./plugins/i18n").listFiles(); if (files != null) { for (File file : files) { String name = file.getName(); if (name.startsWith("MessagesBundle_") && name.endsWith(".properties")) { String code = name.substring("MessagesBundle_".length(), name.indexOf(".properties")); if (code.length() > 0) { supportedLanguages.add(code); } } } } for (String lang : supportedLanguages) { Locale loc = allLocales.get(lang); String variant = null; if (loc == null && StringUtils.countMatches(lang, "_") == 2) { String langWithoutVariant = StringUtils.removeEnd(StringUtils.substringBeforeLast(lang, "_"), "_"); variant = StringUtils.substringAfterLast(lang, "_"); loc = allLocales.get(langWithoutVariant); } if (loc != null) { StringBuffer s = new StringBuffer(loc.getDisplayLanguage(Locale.getDefault())); if (loc.getCountry().length() > 0) s.append(" - ").append(loc.getDisplayCountry(Locale.getDefault())); if (variant != null) { s.append(" (").append(variant).append(')'); loc = new Locale(loc.getLanguage(), loc.getCountry(), variant); } locales.put(s.toString(), loc); if (loc.equals(locale)) { locString = s.toString(); } } } for (String sloc : locales.keySet()) { localeCombo.add(sloc); } localeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); localeCombo.setText(locString); localeCombo.setVisibleItemCount(20); columnsTabItem = new TabItem(tabFolder, SWT.NONE); columnsTabItem.setText(settings.msg("dialog.settings.tab.profiletable")); final Composite composite2 = new Composite(tabFolder, SWT.NONE); composite2.setLayout(new BorderLayout(0, 0)); columnsTabItem.setControl(composite2); final Group visColumnsGroup = new Group(composite2, SWT.NONE); visColumnsGroup.setLayout(new FillLayout()); visColumnsGroup.setText(settings.msg("dialog.settings.visiblecolunms")); visible_columns = new Table(visColumnsGroup, SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK); visible_columns.setLinesVisible(true); TableColumn column1 = new TableColumn(visible_columns, SWT.NONE); column1.setWidth(350); java.util.List<Integer> visibleColumnIDs = new ArrayList<Integer>(); for (int i = 0; i < MainWindow.columnNames.length; i++) if (conf.getBooleanValue("gui", "column" + (i + 1) + "visible")) visibleColumnIDs.add(i); java.util.List<Integer> orderedVisibleColumnIDs = new ArrayList<Integer>(); int[] columnOrder = conf.getIntValues("gui", "columnorder"); for (int i = 0; i < columnOrder.length; i++) orderedVisibleColumnIDs.add(visibleColumnIDs.get(columnOrder[i])); java.util.List<Integer> remainingColumnIDs = new ArrayList<Integer>(); for (int i = 0; i < MainWindow.columnNames.length; i++) if (!orderedVisibleColumnIDs.contains(i)) remainingColumnIDs.add(i); allColumnIDs = new ArrayList<Integer>(orderedVisibleColumnIDs); allColumnIDs.addAll(remainingColumnIDs); visibleColumns = new TableItem[MainWindow.columnNames.length]; for (int i = 0; i < MainWindow.columnNames.length; i++) { visibleColumns[i] = new TableItem(visible_columns, SWT.BORDER); visibleColumns[i].setText(MainWindow.columnNames[allColumnIDs.get(i)]); visibleColumns[i] .setChecked(conf.getBooleanValue("gui", "column" + (allColumnIDs.get(i) + 1) + "visible")); } final TableEditor editor = new TableEditor(visible_columns); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; editor.minimumWidth = 50; visible_columns.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { // Clean up any previous editor control Control oldEditor = editor.getEditor(); if (oldEditor != null) { oldEditor.dispose(); } // Identify the selected row TableItem item = (TableItem) event.item; if (item == null) { return; } int selIdx = item.getParent().getSelectionIndex(); if (selIdx == -1) return; int idx = allColumnIDs.get(selIdx); if (idx < Constants.RO_COLUMN_NAMES || idx >= (Constants.RO_COLUMN_NAMES + Constants.EDIT_COLUMN_NAMES)) return; // The control that will be the editor must be a child of the table Text newEditor = new Text(visible_columns, SWT.NONE); newEditor.setText(item.getText(EDITABLE_COLUMN)); newEditor.addModifyListener(new ModifyListener() { public void modifyText(final ModifyEvent mEvent) { Text text = (Text) editor.getEditor(); editor.getItem().setText(EDITABLE_COLUMN, text.getText()); } }); newEditor.selectAll(); newEditor.setFocus(); editor.setEditor(newEditor, item, EDITABLE_COLUMN); } }); final Group addProfGroup = new Group(composite2, SWT.NONE); addProfGroup.setLayout(new GridLayout(2, false)); addProfGroup.setText(settings.msg("dialog.settings.addeditduplicateprofile")); addProfGroup.setLayoutData(BorderLayout.SOUTH); final Label autoSortLabel = new Label(addProfGroup, SWT.NONE); autoSortLabel.setText(settings.msg("dialog.settings.autosort")); final Button autosort = new Button(addProfGroup, SWT.CHECK); autosort.setSelection(conf.getBooleanValue("gui", "autosortonupdate")); final TabItem dynTabItem = new TabItem(tabFolder, SWT.NONE); dynTabItem.setText(settings.msg("dialog.settings.tab.dynamicoptions")); final Composite composite_1 = new Composite(tabFolder, SWT.NONE); composite_1.setLayout(new FillLayout()); dynTabItem.setControl(composite_1); final Group dynOptionsGroup = new Group(composite_1, SWT.NONE); dynOptionsGroup.setLayout(new GridLayout(2, false)); dynOptionsGroup.setText(settings.msg("dialog.settings.dynamicoptions")); final Label optionsLabel = new Label(dynOptionsGroup, SWT.NONE); optionsLabel.setText(settings.msg("dialog.settings.options")); final Label valuesLabel = new Label(dynOptionsGroup, SWT.NONE); valuesLabel.setText(settings.msg("dialog.settings.values")); options = new List(dynOptionsGroup, SWT.V_SCROLL | SWT.BORDER); options.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { storeValues(); previousSelection = options.getSelectionIndex(); if (previousSelection != -1) { values.setText(conf.getMultilineValues("profile", options.getItem(previousSelection), values.getLineDelimiter())); } } }); options.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); for (String s : conf.getAllItemNames("profile")) { options.add(s); } values = new Text(dynOptionsGroup, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); values.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final TabItem guiTabItem = new TabItem(tabFolder, SWT.NONE); guiTabItem.setText(settings.msg("dialog.settings.tab.gui")); final Composite composite1 = new Composite(tabFolder, SWT.NONE); composite1.setLayout(new GridLayout(2, false)); guiTabItem.setControl(composite1); Group screenshots = new Group(composite1, SWT.NONE); screenshots.setLayout(new GridLayout(3, false)); GridData screenshotsLData = new GridData(); screenshotsLData.grabExcessHorizontalSpace = true; screenshotsLData.horizontalAlignment = GridData.FILL; screenshotsLData.horizontalSpan = 2; screenshots.setLayoutData(screenshotsLData); screenshots.setText(settings.msg("dialog.settings.screenshots")); Label heightLabel = new Label(screenshots, SWT.NONE); heightLabel.setText(settings.msg("dialog.settings.height")); GridData sshotsHeightData = new GridData(); sshotsHeightData.grabExcessHorizontalSpace = true; sshotsHeightData.horizontalAlignment = GridData.FILL; screenshotsHeight = new Scale(screenshots, SWT.NONE); screenshotsHeight.setMaximum(750); screenshotsHeight.setMinimum(50); screenshotsHeight.setLayoutData(sshotsHeightData); screenshotsHeight.setIncrement(25); screenshotsHeight.setPageIncrement(100); screenshotsHeight.setSelection(conf.getIntValue("gui", "screenshotsheight")); screenshotsHeight.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent evt) { heightValue.setText(screenshotsHeight.getSelection() + settings.msg("dialog.settings.px")); heightValue.pack(); } }); heightValue = new Label(screenshots, SWT.NONE); heightValue.setText(screenshotsHeight.getSelection() + settings.msg("dialog.settings.px")); final Label displayFilenameLabel = new Label(screenshots, SWT.NONE); displayFilenameLabel.setText(settings.msg("dialog.settings.screenshotsfilename")); final Button displayFilename = new Button(screenshots, SWT.CHECK); displayFilename.setSelection(conf.getBooleanValue("gui", "screenshotsfilename")); Group screenshotsColumn = new Group(composite1, SWT.NONE); screenshotsColumn.setLayout(new GridLayout(3, false)); GridData screenshotsCData = new GridData(); screenshotsCData.grabExcessHorizontalSpace = true; screenshotsCData.horizontalAlignment = GridData.FILL; screenshotsCData.horizontalSpan = 2; screenshotsColumn.setLayoutData(screenshotsCData); screenshotsColumn.setText(settings.msg("dialog.settings.screenshotscolumn")); Label columnHeightLabel = new Label(screenshotsColumn, SWT.NONE); columnHeightLabel.setText(settings.msg("dialog.settings.height")); screenshotsColumnHeight = new Scale(screenshotsColumn, SWT.NONE); screenshotsColumnHeight.setMaximum(200); screenshotsColumnHeight.setMinimum(16); GridData sshotsColumnHeightData = new GridData(); sshotsColumnHeightData.grabExcessHorizontalSpace = true; sshotsColumnHeightData.horizontalAlignment = GridData.FILL; screenshotsColumnHeight.setLayoutData(sshotsColumnHeightData); screenshotsColumnHeight.setIncrement(4); screenshotsColumnHeight.setPageIncrement(16); screenshotsColumnHeight.setSelection(conf.getIntValue("gui", "screenshotscolumnheight")); screenshotsColumnHeight.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent evt) { columnHeightValue .setText(screenshotsColumnHeight.getSelection() + settings.msg("dialog.settings.px")); columnHeightValue.pack(); } }); columnHeightValue = new Label(screenshotsColumn, SWT.NONE); columnHeightValue.setText(screenshotsColumnHeight.getSelection() + settings.msg("dialog.settings.px")); final Label stretchLabel = new Label(screenshotsColumn, SWT.NONE); stretchLabel.setText(settings.msg("dialog.settings.screenshotscolumnstretch")); final Button stretch = new Button(screenshotsColumn, SWT.CHECK); stretch.setSelection(conf.getBooleanValue("gui", "screenshotscolumnstretch")); new Label(screenshotsColumn, SWT.NONE); final Label keepAspectRatioLabel = new Label(screenshotsColumn, SWT.NONE); keepAspectRatioLabel.setText(settings.msg("dialog.settings.screenshotscolumnkeepaspectratio")); final Button keepAspectRatio = new Button(screenshotsColumn, SWT.CHECK); keepAspectRatio.setSelection(conf.getBooleanValue("gui", "screenshotscolumnkeepaspectratio")); new Label(screenshotsColumn, SWT.NONE); keepAspectRatio.setEnabled(stretch.getSelection()); stretch.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { keepAspectRatio.setEnabled(stretch.getSelection()); } }); Group buttonsGroup = new Group(composite1, SWT.NONE); buttonsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); buttonsGroup.setLayout(new GridLayout(2, false)); buttonsGroup.setText(settings.msg("dialog.settings.buttons")); final Label buttonLabel = new Label(buttonsGroup, SWT.NONE); buttonLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); buttonLabel.setText(settings.msg("dialog.settings.display")); buttonDisplay = new Combo(buttonsGroup, SWT.READ_ONLY); buttonDisplay.setItems(buttonDisplayOptions); buttonDisplay.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); buttonDisplay.select(conf.getIntValue("gui", "buttondisplay")); final Group notesGroup = new Group(composite1, SWT.NONE); notesGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); notesGroup.setLayout(new GridLayout(2, false)); notesGroup.setText(settings.msg("dialog.profile.notes")); final Label fontLabel = new Label(notesGroup, SWT.NONE); fontLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); fontLabel.setText(settings.msg("dialog.settings.font")); final Button fontButton = new Button(notesGroup, SWT.PUSH); fontButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Font f = GeneralPurposeGUI.stringToFont(shell.getDisplay(), port.getFont(), conf.getValues("gui", "notesfont")); fontButton.setText(f.getFontData()[0].getName()); fontButton.setFont(f); fontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(shell, SWT.NONE); fd.setFontList(fontButton.getFont().getFontData()); FontData newFont = fd.open(); if (newFont != null) { fontButton.setText(newFont.getName()); fontButton.setFont(new Font(shell.getDisplay(), newFont)); notesGroup.setSize(notesGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT)); composite1.layout(); } } }); final TabItem enginesTabItem = new TabItem(tabFolder, SWT.NONE); enginesTabItem.setText(settings.msg("dialog.settings.tab.engines")); Composite compositeHoldingSubTabs = new Composite(tabFolder, SWT.NONE); compositeHoldingSubTabs.setLayout(new FillLayout()); enginesTabItem.setControl(compositeHoldingSubTabs); final TabFolder enginesTabFolder = new TabFolder(compositeHoldingSubTabs, SWT.NONE); setTitle = new Button[NR_OF_ENGINES]; setDev = new Button[NR_OF_ENGINES]; setPub = new Button[NR_OF_ENGINES]; setYear = new Button[NR_OF_ENGINES]; setGenre = new Button[NR_OF_ENGINES]; setLink = new Button[NR_OF_ENGINES]; setRank = new Button[NR_OF_ENGINES]; setDescr = new Button[NR_OF_ENGINES]; allRegionsCoverArt = new Button[NR_OF_ENGINES]; chooseCoverArt = new Button[NR_OF_ENGINES]; chooseScreenshot = new Button[NR_OF_ENGINES]; maxCoverArt = new Spinner[NR_OF_ENGINES]; maxScreenshots = new Spinner[NR_OF_ENGINES]; platformFilterValues = new Text[NR_OF_ENGINES]; for (int i = 0; i < NR_OF_ENGINES; i++) { WebSearchEngine engine = EditProfileDialog.webSearchEngines.get(i); final TabItem engineTabItem = new TabItem(enginesTabFolder, SWT.NONE); engineTabItem.setText(settings.msg("dialog.settings.tab." + engine.getSimpleName())); Composite composite3 = new Composite(enginesTabFolder, SWT.NONE); composite3.setLayout(new GridLayout(1, true)); engineTabItem.setControl(composite3); Group consult = new Group(composite3, SWT.NONE); consult.setLayout(new GridLayout(2, false)); GridData consultLData = new GridData(); consultLData.grabExcessHorizontalSpace = true; consultLData.horizontalAlignment = GridData.FILL; consultLData.grabExcessVerticalSpace = true; consultLData.verticalAlignment = GridData.FILL; consult.setLayoutData(consultLData); consult.setText(settings.msg("dialog.settings.consult", new String[] { engine.getName() })); Label titleLabel = new Label(consult, SWT.NONE); titleLabel.setText(settings.msg("dialog.settings.settitle")); setTitle[i] = new Button(consult, SWT.CHECK); setTitle[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_title")); Label devLabel = new Label(consult, SWT.NONE); devLabel.setText(settings.msg("dialog.settings.setdeveloper")); setDev[i] = new Button(consult, SWT.CHECK); setDev[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_developer")); if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("hotud") || engine.getSimpleName().equals("thegamesdb")) { Label pubLabel = new Label(consult, SWT.NONE); pubLabel.setText(settings.msg("dialog.settings.setpublisher")); setPub[i] = new Button(consult, SWT.CHECK); setPub[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_publisher")); } Label yearLabel = new Label(consult, SWT.NONE); yearLabel.setText(settings.msg("dialog.settings.setyear")); setYear[i] = new Button(consult, SWT.CHECK); setYear[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_year")); Label genreLabel = new Label(consult, SWT.NONE); genreLabel.setText(settings.msg("dialog.settings.setgenre")); setGenre[i] = new Button(consult, SWT.CHECK); setGenre[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_genre")); Label linkLabel = new Label(consult, SWT.NONE); linkLabel.setText(settings.msg("dialog.settings.setlink", new String[] { engine.getName() })); setLink[i] = new Button(consult, SWT.CHECK); setLink[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_link")); Label rankLabel = new Label(consult, SWT.NONE); rankLabel.setText(settings.msg("dialog.settings.setrank", new Object[] { MainWindow.columnNames[Constants.RO_COLUMN_NAMES + 8] })); setRank[i] = new Button(consult, SWT.CHECK); setRank[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_rank")); if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("hotud") || engine.getSimpleName().equals("thegamesdb")) { Label descrLabel = new Label(consult, SWT.NONE); descrLabel.setText(settings.msg("dialog.settings.setdescription")); setDescr[i] = new Button(consult, SWT.CHECK); setDescr[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "set_description")); } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("thegamesdb")) { Label chooseCoverArtLabel = new Label(consult, SWT.NONE); chooseCoverArtLabel.setText(settings.msg("dialog.settings.choosecoverart")); Composite comp = new Composite(consult, SWT.NONE); GridLayout layout = new GridLayout(3, false); layout.marginWidth = 0; comp.setLayout(layout); chooseCoverArt[i] = new Button(comp, SWT.CHECK); chooseCoverArt[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "choose_coverart")); if (engine.getSimpleName().equals("mobygames")) { Label allRegionsCoverArtLabel = new Label(comp, SWT.NONE); allRegionsCoverArtLabel.setText(settings.msg("dialog.settings.allregionscoverart")); GridData gd = new GridData(); gd.horizontalIndent = 40; allRegionsCoverArtLabel.setLayoutData(gd); allRegionsCoverArt[i] = new Button(comp, SWT.CHECK); allRegionsCoverArt[i].setSelection( conf.getBooleanValue(engine.getSimpleName(), "force_all_regions_coverart")); } } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("pouet") || engine.getSimpleName().equals("thegamesdb")) { Label chooseScreenshotLabel = new Label(consult, SWT.NONE); chooseScreenshotLabel.setText(settings.msg("dialog.settings.choosescreenshot")); chooseScreenshot[i] = new Button(consult, SWT.CHECK); chooseScreenshot[i].setSelection(conf.getBooleanValue(engine.getSimpleName(), "choose_screenshot")); } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("thegamesdb")) { final Label maxCoverArtLabel = new Label(consult, SWT.NONE); maxCoverArtLabel.setText(settings.msg("dialog.settings.multieditmaxcoverart")); maxCoverArt[i] = new Spinner(consult, SWT.BORDER); maxCoverArt[i].setLayoutData(new GridData(100, SWT.DEFAULT)); maxCoverArt[i].setMinimum(0); maxCoverArt[i].setMaximum(Integer.MAX_VALUE); maxCoverArt[i].setSelection(conf.getIntValue(engine.getSimpleName(), "multi_max_coverart")); } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("pouet") || engine.getSimpleName().equals("thegamesdb")) { final Label maxScreenshotsLabel = new Label(consult, SWT.NONE); maxScreenshotsLabel.setText(settings.msg("dialog.settings.multieditmaxscreenshot")); maxScreenshots[i] = new Spinner(consult, SWT.BORDER); maxScreenshots[i].setLayoutData(new GridData(100, SWT.DEFAULT)); maxScreenshots[i].setMinimum(0); maxScreenshots[i].setMaximum(Integer.MAX_VALUE); maxScreenshots[i].setSelection(conf.getIntValue(engine.getSimpleName(), "multi_max_screenshot")); } Label filterLabel = new Label(consult, SWT.NONE); filterLabel.setText(settings.msg("dialog.settings.platformfilter")); if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("pouet")) { platformFilterValues[i] = new Text(consult, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); platformFilterValues[i].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); platformFilterValues[i].setText(conf.getMultilineValues(engine.getSimpleName(), "platform_filter", platformFilterValues[i].getLineDelimiter())); } else { platformFilterValues[i] = new Text(consult, SWT.BORDER); platformFilterValues[i].setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); platformFilterValues[i].setText(conf.getValue(engine.getSimpleName(), "platform_filter")); } } final TabItem envTabItem = new TabItem(tabFolder, SWT.NONE); envTabItem.setText(settings.msg("dialog.settings.tab.environment")); Composite composite4 = new Composite(tabFolder, SWT.NONE); composite4.setLayout(new GridLayout(1, true)); envTabItem.setControl(composite4); Group envGroup = new Group(composite4, SWT.NONE); envGroup.setLayout(new GridLayout(2, false)); GridData envLData = new GridData(); envLData.grabExcessHorizontalSpace = true; envLData.horizontalAlignment = GridData.FILL; envLData.grabExcessVerticalSpace = true; envLData.verticalAlignment = GridData.FILL; envGroup.setLayoutData(envLData); envGroup.setText(settings.msg("dialog.settings.environment")); Label enableEnvLabel = new Label(envGroup, SWT.NONE); enableEnvLabel.setText(settings.msg("dialog.settings.enableenvironment")); final Button enableEnv = new Button(envGroup, SWT.CHECK); enableEnv.setSelection(conf.getBooleanValue("environment", "use")); enableEnv.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { envValues.setEnabled(enableEnv.getSelection()); } }); Label envLabel = new Label(envGroup, SWT.NONE); envLabel.setText(settings.msg("dialog.settings.environmentvariables")); envValues = new Text(envGroup, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); envValues.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); envValues.setText(conf.getMultilineValues("environment", "value", envValues.getLineDelimiter())); envValues.setEnabled(enableEnv.getSelection()); final Composite composite_7 = new Composite(shell, SWT.NONE); composite_7.setLayout(new GridLayout(2, true)); composite_7.setLayoutData(BorderLayout.SOUTH); final Button okButton = new Button(composite_7, SWT.NONE); okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { if (!isValid()) { return; } changedVisColumns = haveColumnsBeenChanged(); if (changedVisColumns) updateColumnSettings(); conf.setBooleanValue("dosbox", "hideconsole", console.getSelection()); conf.setBooleanValue("communication", "port_enabled", portEnabled.getSelection()); conf.setValue("communication", "port", port.getText()); conf.setIntValue("profiledefaults", "confpath", confLocation.getSelectionIndex()); conf.setIntValue("profiledefaults", "conffile", confFilename.getSelectionIndex()); conf.setValue("locale", "language", locales.get(localeCombo.getText()).getLanguage()); conf.setValue("locale", "country", locales.get(localeCombo.getText()).getCountry()); conf.setValue("locale", "variant", locales.get(localeCombo.getText()).getVariant()); for (int i = 0; i < MainWindow.columnNames.length; i++) { conf.setBooleanValue("gui", "column" + (i + 1) + "visible", visibleColumns[allColumnIDs.indexOf(i)].getChecked()); } conf.setBooleanValue("gui", "autosortonupdate", autosort.getSelection()); for (int i = 0; i < Constants.EDIT_COLUMN_NAMES; i++) { conf.setValue("gui", "custom" + (i + 1), visibleColumns[allColumnIDs.indexOf(i + Constants.RO_COLUMN_NAMES)].getText()); } conf.setIntValue("gui", "screenshotsheight", screenshotsHeight.getSelection()); conf.setBooleanValue("gui", "screenshotsfilename", displayFilename.getSelection()); conf.setIntValue("gui", "screenshotscolumnheight", screenshotsColumnHeight.getSelection()); conf.setBooleanValue("gui", "screenshotscolumnstretch", stretch.getSelection()); conf.setBooleanValue("gui", "screenshotscolumnkeepaspectratio", keepAspectRatio.getSelection()); Rectangle rec = shell.getBounds(); conf.setIntValue("gui", "settingsdialog_width", rec.width); conf.setIntValue("gui", "settingsdialog_height", rec.height); conf.setIntValue("gui", "buttondisplay", buttonDisplay.getSelectionIndex()); conf.setMultilineValues("gui", "notesfont", GeneralPurposeGUI.fontToString(shell.getDisplay(), fontButton.getFont()), "|"); for (int i = 0; i < NR_OF_ENGINES; i++) { WebSearchEngine engine = EditProfileDialog.webSearchEngines.get(i); conf.setBooleanValue(engine.getSimpleName(), "set_title", setTitle[i].getSelection()); conf.setBooleanValue(engine.getSimpleName(), "set_developer", setDev[i].getSelection()); if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("hotud") || engine.getSimpleName().equals("thegamesdb")) { conf.setBooleanValue(engine.getSimpleName(), "set_publisher", setPub[i].getSelection()); conf.setBooleanValue(engine.getSimpleName(), "set_description", setDescr[i].getSelection()); } conf.setBooleanValue(engine.getSimpleName(), "set_year", setYear[i].getSelection()); conf.setBooleanValue(engine.getSimpleName(), "set_genre", setGenre[i].getSelection()); conf.setBooleanValue(engine.getSimpleName(), "set_link", setLink[i].getSelection()); conf.setBooleanValue(engine.getSimpleName(), "set_rank", setRank[i].getSelection()); if (engine.getSimpleName().equals("mobygames")) { conf.setBooleanValue(engine.getSimpleName(), "force_all_regions_coverart", allRegionsCoverArt[i].getSelection()); } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("thegamesdb")) { conf.setBooleanValue(engine.getSimpleName(), "choose_coverart", chooseCoverArt[i].getSelection()); conf.setIntValue(engine.getSimpleName(), "multi_max_coverart", maxCoverArt[i].getSelection()); } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("pouet") || engine.getSimpleName().equals("thegamesdb")) { conf.setBooleanValue(engine.getSimpleName(), "choose_screenshot", chooseScreenshot[i].getSelection()); conf.setIntValue(engine.getSimpleName(), "multi_max_screenshot", maxScreenshots[i].getSelection()); } if (engine.getSimpleName().equals("mobygames") || engine.getSimpleName().equals("pouet")) { conf.setMultilineValues(engine.getSimpleName(), "platform_filter", platformFilterValues[i].getText(), platformFilterValues[i].getLineDelimiter()); } else { conf.setValue(engine.getSimpleName(), "platform_filter", platformFilterValues[i].getText()); } } conf.setBooleanValue("environment", "use", enableEnv.getSelection()); conf.setMultilineValues("environment", "value", envValues.getText(), envValues.getLineDelimiter()); storeValues(); settings.getSettings().injectValuesFrom(conf); shell.close(); } private boolean haveColumnsBeenChanged() { for (int i = 0; i < MainWindow.columnNames.length; i++) if ((conf.getBooleanValue("gui", "column" + (allColumnIDs.get(i) + 1) + "visible") != visibleColumns[i].getChecked()) || !MainWindow.columnNames[allColumnIDs.get(i)].equals(visibleColumns[i].getText())) return true; return false; } }); shell.setDefaultButton(okButton); okButton.setText(settings.msg("button.ok")); final Button cancelButton = new Button(composite_7, SWT.NONE); cancelButton.setText(settings.msg("button.cancel")); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { shell.close(); } }); final GridData gridData = new GridData(); gridData.horizontalAlignment = SWT.FILL; gridData.widthHint = GeneralPurposeGUI.getWidth(okButton, cancelButton); okButton.setLayoutData(gridData); cancelButton.setLayoutData(gridData); }
From source file:org.apache.tapestry.engine.AbstractEngine.java
/** * Changes the locale for the engine./*from w ww.j av a 2 s . c o m*/ * **/ public void setLocale(Locale value) { if (value == null) throw new IllegalArgumentException("May not change engine locale to null."); // Because locale changes are expensive (it involves writing a cookie and all that), // we're careful not to really change unless there's a true change in value. if (!value.equals(_locale)) { _locale = value; _localeChanged = true; markDirty(); } }
From source file:org.olat.core.util.i18n.I18nManager.java
private final String getLocalizedString(String bundleName, String key, Object[] args, Locale locale, boolean overlayEnabled, boolean fallBackToDefaultLocale, boolean fallBackToFallbackLocale, boolean resolveRecursively, boolean allowDecoration, int recursionLevel) { String msg = null;//from ww w . j a v a2 s .com Properties properties = null; // a) If the overlay is enabled, lookup first in the overlay property // file if (overlayEnabled) { Locale overlayLocale = I18nModule.getOverlayLocales().get(locale); if (overlayLocale != null) { properties = getProperties(overlayLocale, bundleName, resolveRecursively, recursionLevel); if (properties != null) { msg = properties.getProperty(key); // if (log.isDebug() && msg == null) { // log.debug("Key::" + key + " not found in overlay::" + I18nModule.getOverlayName() + " for bundle::" + bundleName // + " and locale::" + locale.toString(), null); // } } } } // b) Otherwhise lookup in the regular bundle if (msg == null) { properties = getProperties(locale, bundleName, resolveRecursively, recursionLevel); // if LocalStrings File does not exist -> return error msg on screen // / fallback to default language if (properties == null) { if (Settings.isDebuging()) { log.warn(FILE_NOT_FOUND_ERROR_PREFIX + "! locale::" + locale.toString() + ", path::" + bundleName, null); } } else { msg = properties.getProperty(key); } } // The following fallback behaviour is similar to // java.util.ResourceBundle if (msg == null) { if (log.isDebug()) { log.debug("Key::" + key + " not found for bundle::" + bundleName + " and locale::" + locale.toString(), null); } // Fallback on the language if the locale has a country and/or a // variant // de_DE_variant -> de_DE -> de // Only after having all those checked we will fallback to the // default language // 1. Check on variant String variant = locale.getVariant(); if (!variant.equals("")) { Locale newLoc = I18nModule.getAllLocales().get(locale.getLanguage() + "_" + locale.getCountry()); if (newLoc != null) msg = getLocalizedString(bundleName, key, args, newLoc, overlayEnabled, false, fallBackToFallbackLocale, resolveRecursively, recursionLevel); } if (msg == null) { // 2. Check on country String country = locale.getCountry(); if (!country.equals("")) { Locale newLoc = I18nModule.getAllLocales().get(locale.getLanguage()); if (newLoc != null) msg = getLocalizedString(bundleName, key, args, newLoc, overlayEnabled, false, fallBackToFallbackLocale, resolveRecursively, recursionLevel); } // else we have an original locale with only a language given -> // no language specific fallbacks anymore } } if (msg == null) { // Message still empty? Use fallback to default language? // yes: return the call applied with the olatcore default locale // no: return null to indicate nothing was found so that callers may // use fallbacks if (fallBackToDefaultLocale) { return getLocalizedString(bundleName, key, args, I18nModule.getDefaultLocale(), overlayEnabled, false, fallBackToFallbackLocale, resolveRecursively, recursionLevel); } else { if (fallBackToFallbackLocale) { // fallback to fallback locale Locale fallbackLocale = I18nModule.getFallbackLocale(); if (fallbackLocale.equals(locale)) { // finish when when already in fallback locale if (isLogDebugEnabled()) { logWarn("Could not find translation for bundle::" + bundleName + " and key::" + key + " ; not even in default or fallback packages", null); } return null; } else { return getLocalizedString(bundleName, key, args, fallbackLocale, overlayEnabled, false, false, resolveRecursively, recursionLevel); } } else { return null; } } } // When caching not enabled we need to check for keys contained in this // value. In caching mode this is already done while loading the // properties // file if (resolveRecursively && (!cachingEnabled || properties != null)) { msg = resolveValuesInternalKeys(locale, bundleName, key, properties, overlayEnabled, recursionLevel, msg); } // Add markup code to identify translated strings if (allowDecoration && isCurrentThreadMarkLocalizedStringsEnabled() && !bundleName.startsWith(BUNDLE_INLINE_TRANSLATION_INTERCEPTOR) && !bundleName.startsWith(BUNDLE_EXCEPTION) && isInlineTranslationEnabledForKey(bundleName, key)) { // identifyer consists of bundle name and key and an id to // distinguish multiple translations of the same key String identifyer = bundleName + ":" + key + ":" + CodeHelper.getRAMUniqueID(); msg = IDENT_PREFIX + identifyer + IDENT_START_POSTFIX + msg + IDENT_PREFIX + identifyer + IDENT_END_POSTFIX; } // Add the the {0},{1} arguments to the GUI message if (args == null) { return msg; } else { // Escape single quotes with single quotes. Single quotes have special meaning in MessageFormat // See OLAT-5107, OLAT-5756 if (msg.indexOf("'") > -1) { msg = msg.replaceAll("'", "''"); } return MessageFormat.format(msg, args); } }
From source file:org.openmrs16.Concept.java
/** * Returns the best compatible name for a locale. The names are ordered as "best" according to * these rules://from ww w . j ava 2 s.c o m * <ol> * <li>preferred name in matching country (for example, tagged as PREFERRED_UG for preferred in * Uganda)</li> * <li>preferred name in matching language (for example, tagged as PREFERRED_EN for preferred * name in English)</li> * <li>any name in matching country (for example, matching Uganda)</li> * <li>any name in matching language (for example, matching English)</li> * <li>first name in any matching language</li> * </ol> * * @param locale the language and country in which the name is used * @return the best name possible {@link ConceptName}, never null * @should support plain preferred * @should always have a best name even if none match locale */ public ConceptName getBestName(Locale locale) { // fail early if this concept has no names defined if (getNames().size() == 0) { if (log.isDebugEnabled()) log.debug("there are no names defined for: " + conceptId); return null; } if (log.isDebugEnabled()) log.debug("Getting conceptName for locale: " + locale); ConceptName bestMatch = null; if (locale == null) locale = Context.getLocale(); // Don't presume en_US; ConceptNameTag desiredLanguageTag = ConceptNameTag.preferredLanguageTagFor(locale); ConceptNameTag desiredCountryTag = ConceptNameTag.preferredCountryTagFor(locale); List<ConceptName> compatibleNames = getCompatibleNames(locale); if (compatibleNames.size() == 0) { // no compatible names, so return first available name Iterator<ConceptName> nameIt = getNames().iterator(); bestMatch = nameIt.next(); } else if (compatibleNames.size() == 1) { bestMatch = compatibleNames.get(0); } else { // more than 1 choice? search through to find the "best" for (ConceptName possibleName : compatibleNames) { if (locale.equals(possibleName.getLocale()) && possibleName.hasTag(ConceptNameTag.PREFERRED)) { bestMatch = possibleName; break; } if (desiredCountryTag != null) { // country was specified, exact match must be preferred in country if (possibleName.hasTag(desiredCountryTag)) { bestMatch = possibleName; break; // can't get any better than this match } else if (possibleName.hasTag(desiredLanguageTag)) { bestMatch = possibleName; } else if (possibleName.hasTag(ConceptNameTag.PREFERRED)) { bestMatch = possibleName; } else if (bestMatch == null) { bestMatch = possibleName; } } else { // no country specified, so only worry about matching language if (possibleName.hasTag(desiredLanguageTag)) { bestMatch = possibleName; break; } else if (possibleName.hasTag(ConceptNameTag.PREFERRED)) { bestMatch = possibleName; } else if (bestMatch == null) { bestMatch = possibleName; } } } } if (bestMatch == null) { log.warn("No compatible concept name found for for concept id " + conceptId); } return bestMatch; }
From source file:com.globalsight.webservices.Ambassador4Falcon.java
/** * Exports the job. If p_workflowLocale is null then all pages for all * workflows are exported, otherwise the specific workflow corresponding to * the locale is exported.//from w w w. j a v a 2 s . co m * * @param p_jobName * -- name of job * @param p_workflowLocale * -- locale of workflow to export * @return String in JSON. A sample is like: * {"status":"Export Request Sent","workflowLocale":"de_DE","jobName":"3801_656474062"} * @exception WebServiceException */ public String exportWorkflow(String p_accessToken, String p_jobName, String p_workflowLocale) throws WebServiceException { checkAccess(p_accessToken, EXPORT_WORKFLOW); String returnStr = checkPermissionReturnStr(p_accessToken, Permission.JOB_WORKFLOWS_EXPORT); if (StringUtil.isNotEmpty(returnStr)) return returnStr; String jobName = p_jobName; String workflowLocale = p_workflowLocale; String returnXml = ""; WebServicesLog.Start activityStart = null; JSONObject jsonObj = new JSONObject(); try { String userName = getUsernameFromSession(p_accessToken); Map<Object, Object> activityArgs = new HashMap<Object, Object>(); activityArgs.put("loggedUserName", userName); activityArgs.put("jobName", p_jobName); activityArgs.put("workflowLocale", p_workflowLocale); activityStart = WebServicesLog.start(Ambassador.class, "exportWorkflow(p_accessToken, p_jobName,p_workflowLocale)", activityArgs); Job job = queryJob(jobName, p_accessToken, jsonObj); Object[] workflows = job.getWorkflows().toArray(); long projectId = job.getL10nProfile().getProject().getId(); User projectMgr = ServerProxy.getProjectHandler().getProjectById(projectId).getProjectManager(); boolean didExport = false; if (workflowLocale == null) { // export all workflow logger.info("Exporting all " + workflows.length + " workflows for job " + jobName); for (int i = 0; i < workflows.length; i++) { Workflow w = (Workflow) workflows[i]; if (!w.getState().equals(Workflow.IMPORT_FAILED) && !w.getState().equals(Workflow.CANCELLED)) { exportSingleWorkflow(job, w, projectMgr); } } didExport = true; } else { // export just one workflow Locale locale = GlobalSightLocale.makeLocaleFromString(workflowLocale); logger.info("Job " + jobName + " has " + workflows.length + " workflow."); for (int i = 0; i < workflows.length; i++) { Workflow w = (Workflow) workflows[i]; Locale wLocale = w.getTargetLocale().getLocale(); if (locale.equals(wLocale)) { exportSingleWorkflow(job, w, projectMgr); didExport = true; break; } } } if (didExport == false) throw new Exception("No workflow for locale " + workflowLocale); jsonObj.put("jobName", EditUtil.encodeXmlEntities(jobName)); if (workflowLocale == null) jsonObj.put("workflowLocale", "All Locales"); else jsonObj.put("workflowLocale", workflowLocale); jsonObj.put("status", "Export Request Sent"); returnXml = jsonObj.toString(); } catch (Exception e) { logger.error("exportWorkflow()", e); String message = "Could not export workflow for job " + jobName; return makeErrorJson(EXPORT_WORKFLOW, message); } finally { if (activityStart != null) { activityStart.end(); } } return returnXml; }
From source file:org.pentaho.di.ui.trans.steps.hadoopfileinput.HadoopFileInputDialog.java
private void getInfo(TextFileInputMeta meta) { stepname = wStepname.getText(); // return value // copy info to TextFileInputMeta class (input) meta.setAcceptingFilenames(wAccFilenames.getSelection()); meta.setPassingThruFields(wPassThruFields.getSelection()); meta.setAcceptingField(wAccField.getText()); meta.setAcceptingStepName(wAccStep.getText()); meta.setAcceptingStep(transMeta.findStep(wAccStep.getText())); meta.setFileType(wFiletype.getText()); meta.setFileFormat(wFormat.getText()); meta.setSeparator(wSeparator.getText()); meta.setEnclosure(wEnclosure.getText()); meta.setEscapeCharacter(wEscape.getText()); meta.setRowLimit(Const.toLong(wLimit.getText(), 0L)); meta.setFilenameField(wInclFilenameField.getText()); meta.setRowNumberField(wInclRownumField.getText()); meta.setAddResultFile(wAddResult.getSelection()); meta.setIncludeFilename(wInclFilename.getSelection()); meta.setIncludeRowNumber(wInclRownum.getSelection()); meta.setRowNumberByFile(wRownumByFile.getSelection()); meta.setHeader(wHeader.getSelection()); meta.setNrHeaderLines(Const.toInt(wNrHeader.getText(), 1)); meta.setFooter(wFooter.getSelection()); meta.setNrFooterLines(Const.toInt(wNrFooter.getText(), 1)); meta.setLineWrapped(wWraps.getSelection()); meta.setNrWraps(Const.toInt(wNrWraps.getText(), 1)); meta.setLayoutPaged(wLayoutPaged.getSelection()); meta.setNrLinesPerPage(Const.toInt(wNrLinesPerPage.getText(), 80)); meta.setNrLinesDocHeader(Const.toInt(wNrLinesDocHeader.getText(), 0)); meta.setFileCompression(wCompression.getText()); meta.setDateFormatLenient(wDateLenient.getSelection()); meta.setNoEmptyLines(wNoempty.getSelection()); meta.setEncoding(wEncoding.getText()); int nrfiles = wFilenameList.getItemCount(); int nrfields = wFields.nrNonEmpty(); int nrfilters = wFilter.nrNonEmpty(); meta.allocate(nrfiles, nrfields, nrfilters); meta.setFileName(wFilenameList.getItems(0)); meta.setFileMask(wFilenameList.getItems(1)); meta.setFileRequired(wFilenameList.getItems(2)); meta.setIncludeSubFolders(wFilenameList.getItems(3)); for (int i = 0; i < nrfields; i++) { TextFileInputField field = new TextFileInputField(); TableItem item = wFields.getNonEmpty(i); field.setName(item.getText(1));/*from w w w . j av a2s . com*/ field.setType(ValueMeta.getType(item.getText(2))); field.setFormat(item.getText(3)); field.setPosition(Const.toInt(item.getText(4), -1)); field.setLength(Const.toInt(item.getText(5), -1)); field.setPrecision(Const.toInt(item.getText(6), -1)); field.setCurrencySymbol(item.getText(7)); field.setDecimalSymbol(item.getText(8)); field.setGroupSymbol(item.getText(9)); field.setNullString(item.getText(10)); field.setIfNullValue(item.getText(11)); field.setTrimType(ValueMeta.getTrimTypeByDesc(item.getText(12))); field.setRepeated( BaseMessages.getString(BASE_PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(13))); (meta.getInputFields())[i] = field; } for (int i = 0; i < nrfilters; i++) { TableItem item = wFilter.getNonEmpty(i); TextFileFilter filter = new TextFileFilter(); (meta.getFilter())[i] = filter; filter.setFilterString(item.getText(1)); filter.setFilterPosition(Const.toInt(item.getText(2), -1)); filter.setFilterLastLine( BaseMessages.getString(BASE_PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(3))); filter.setFilterPositive( BaseMessages.getString(BASE_PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(4))); } // Error handling fields... meta.setErrorIgnored(wErrorIgnored.getSelection()); meta.setErrorLineSkipped(wSkipErrorLines.getSelection()); meta.setErrorCountField(wErrorCount.getText()); meta.setErrorFieldsField(wErrorFields.getText()); meta.setErrorTextField(wErrorText.getText()); meta.setWarningFilesDestinationDirectory(wWarnDestDir.getText()); meta.setWarningFilesExtension(wWarnExt.getText()); meta.setErrorFilesDestinationDirectory(wErrorDestDir.getText()); meta.setErrorLineFilesExtension(wErrorExt.getText()); meta.setLineNumberFilesDestinationDirectory(wLineNrDestDir.getText()); meta.setLineNumberFilesExtension(wLineNrExt.getText()); // Date format Locale Locale locale = EnvUtil.createLocale(wDateLocale.getText()); if (!locale.equals(Locale.getDefault())) { meta.setDateFormatLocale(locale); } else { meta.setDateFormatLocale(Locale.getDefault()); } }
From source file:org.opencms.xml.content.CmsDefaultXmlContentHandler.java
/** * @see org.opencms.xml.content.I_CmsXmlContentHandler#resolveMapping(org.opencms.file.CmsObject, org.opencms.xml.content.CmsXmlContent, org.opencms.xml.types.I_CmsXmlContentValue) *//*from w w w . j ava 2 s.c o m*/ public void resolveMapping(CmsObject cms, CmsXmlContent content, I_CmsXmlContentValue value) throws CmsException { if (!value.isSimpleType()) { // no mappings for a nested schema are possible // note that the sub-elements of the nested schema ARE mapped by the node visitor, // it's just the nested schema value itself that does not support mapping return; } // get the original VFS file from the content CmsFile file = content.getFile(); if (file == null) { throw new CmsXmlException(Messages.get().container(Messages.ERR_XMLCONTENT_RESOLVE_FILE_NOT_FOUND_0)); } // get the mappings for the element name List<String> mappings = getMappings(value.getPath()); if (mappings == null) { // nothing to do if we have no mappings at all return; } // create OpenCms user context initialized with "/" as site root to read all siblings CmsObject rootCms = OpenCms.initCmsObject(cms); Object logEntry = cms.getRequestContext().getAttribute(CmsLogEntry.ATTR_LOG_ENTRY); if (logEntry != null) { rootCms.getRequestContext().setAttribute(CmsLogEntry.ATTR_LOG_ENTRY, logEntry); } rootCms.getRequestContext().setSiteRoot("/"); // read all siblings of the file List<CmsResource> siblings = rootCms.readSiblings(content.getFile().getRootPath(), CmsResourceFilter.IGNORE_EXPIRATION); Set<CmsResource> urlNameMappingResources = new HashSet<CmsResource>(); boolean mapToUrlName = false; urlNameMappingResources.add(content.getFile()); // since 7.0.2 multiple mappings are possible for (String mapping : mappings) { // for multiple language mappings, we need to ensure // a) all siblings are handled // b) only the "right" locale is mapped to a sibling if (CmsStringUtil.isNotEmpty(mapping)) { for (int i = (siblings.size() - 1); i >= 0; i--) { // get filename String filename = (siblings.get(i)).getRootPath(); Locale locale = OpenCms.getLocaleManager().getDefaultLocale(rootCms, filename); if (mapping.startsWith(MAPTO_URLNAME)) { // should be written regardless of whether there is a sibling with the correct locale mapToUrlName = true; } if (!locale.equals(value.getLocale())) { // only map property if the locale fits continue; } // make sure the file is locked CmsLock lock = rootCms.getLock(filename); if (lock.isUnlocked()) { rootCms.lockResource(filename); } else if (!lock.isDirectlyOwnedInProjectBy(rootCms)) { rootCms.changeLock(filename); } // get the string value of the current node String stringValue = value.getStringValue(rootCms); if (mapping.startsWith(MAPTO_PERMISSION) && (value.getIndex() == 0)) { // map value to a permission // example of a mapping: mapto="permission:GROUP:+r+v|GROUP.ALL_OTHERS:|GROUP.Projectmanagers:+r+v+w+c" // get permission(s) to set String permissionMappings = mapping.substring(MAPTO_PERMISSION.length()); String mainMapping = permissionMappings; Map<String, String> permissionsToSet = new HashMap<String, String>(); // separate permission to set for element value from other permissions to set int sepIndex = permissionMappings.indexOf('|'); if (sepIndex != -1) { mainMapping = permissionMappings.substring(0, sepIndex); permissionMappings = permissionMappings.substring(sepIndex + 1); permissionsToSet = CmsStringUtil.splitAsMap(permissionMappings, "|", ":"); } // determine principal type and permission string to set String principalType = I_CmsPrincipal.PRINCIPAL_GROUP; String permissionString = mainMapping; sepIndex = mainMapping.indexOf(':'); if (sepIndex != -1) { principalType = mainMapping.substring(0, sepIndex); permissionString = mainMapping.substring(sepIndex + 1); } if (permissionString.toLowerCase().indexOf('o') == -1) { permissionString += "+o"; } // remove all existing permissions from the file List<CmsAccessControlEntry> aces = rootCms.getAccessControlEntries(filename, false); for (Iterator<CmsAccessControlEntry> j = aces.iterator(); j.hasNext();) { CmsAccessControlEntry ace = j.next(); if (ace.getPrincipal().equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID)) { // remove the entry "All others", which has to be treated in a special way rootCms.rmacc(filename, CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME, CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID.toString()); } else { // this is a group or user principal I_CmsPrincipal principal = CmsPrincipal.readPrincipal(rootCms, ace.getPrincipal()); if (principal.isGroup()) { rootCms.rmacc(filename, I_CmsPrincipal.PRINCIPAL_GROUP, principal.getName()); } else if (principal.isUser()) { rootCms.rmacc(filename, I_CmsPrincipal.PRINCIPAL_USER, principal.getName()); } } } // set additional permissions that are defined in mapping for (Iterator<Map.Entry<String, String>> j = permissionsToSet.entrySet().iterator(); j .hasNext();) { Map.Entry<String, String> entry = j.next(); sepIndex = entry.getKey().indexOf('.'); if (sepIndex != -1) { String type = entry.getKey().substring(0, sepIndex); String name = entry.getKey().substring(sepIndex + 1); String permissions = entry.getValue(); if (permissions.toLowerCase().indexOf('o') == -1) { permissions += "+o"; } try { rootCms.chacc(filename, type, name, permissions); } catch (CmsException e) { // setting permission did not work LOG.error(e); } } } // set permission(s) using the element value(s) // the set with all selected principals TreeSet<String> allPrincipals = new TreeSet<String>(); String path = CmsXmlUtils.removeXpathIndex(value.getPath()); List<I_CmsXmlContentValue> values = content.getValues(path, locale); Iterator<I_CmsXmlContentValue> j = values.iterator(); while (j.hasNext()) { I_CmsXmlContentValue val = j.next(); String principalName = val.getStringValue(rootCms); // the prinicipal name can be a principal list List<String> principalNames = CmsStringUtil.splitAsList(principalName, PRINCIPAL_LIST_SEPARATOR); // iterate over the principals Iterator<String> iterPrincipals = principalNames.iterator(); while (iterPrincipals.hasNext()) { // get the next principal String principal = iterPrincipals.next(); allPrincipals.add(principal); } } // iterate over the set with all principals and set the permissions Iterator<String> iterAllPricinipals = allPrincipals.iterator(); while (iterAllPricinipals.hasNext()) { // get the next principal String principal = iterAllPricinipals.next(); rootCms.chacc(filename, principalType, principal, permissionString); } // special case: permissions are written only to one sibling, end loop i = 0; } else if (mapping.startsWith(MAPTO_PROPERTY_LIST) && (value.getIndex() == 0)) { boolean mapToShared; int prefixLength; // check which mapping is used (shared or individual) if (mapping.startsWith(MAPTO_PROPERTY_LIST_SHARED)) { mapToShared = true; prefixLength = MAPTO_PROPERTY_LIST_SHARED.length(); } else if (mapping.startsWith(MAPTO_PROPERTY_LIST_INDIVIDUAL)) { mapToShared = false; prefixLength = MAPTO_PROPERTY_LIST_INDIVIDUAL.length(); } else { mapToShared = false; prefixLength = MAPTO_PROPERTY_LIST.length(); } // this is a property list mapping String property = mapping.substring(prefixLength); String path = CmsXmlUtils.removeXpathIndex(value.getPath()); List<I_CmsXmlContentValue> values = content.getValues(path, locale); Iterator<I_CmsXmlContentValue> j = values.iterator(); StringBuffer result = new StringBuffer(values.size() * 64); while (j.hasNext()) { I_CmsXmlContentValue val = j.next(); result.append(val.getStringValue(rootCms)); if (j.hasNext()) { result.append(CmsProperty.VALUE_LIST_DELIMITER); } } CmsProperty p; if (mapToShared) { // map to shared value p = new CmsProperty(property, null, result.toString()); } else { // map to individual value p = new CmsProperty(property, result.toString(), null); } // write the created list string value in the selected property rootCms.writePropertyObject(filename, p); if (mapToShared) { // special case: shared mappings must be written only to one sibling, end loop i = 0; } } else if (mapping.startsWith(MAPTO_PROPERTY)) { boolean mapToShared; int prefixLength; // check which mapping is used (shared or individual) if (mapping.startsWith(MAPTO_PROPERTY_SHARED)) { mapToShared = true; prefixLength = MAPTO_PROPERTY_SHARED.length(); } else if (mapping.startsWith(MAPTO_PROPERTY_INDIVIDUAL)) { mapToShared = false; prefixLength = MAPTO_PROPERTY_INDIVIDUAL.length(); } else { mapToShared = false; prefixLength = MAPTO_PROPERTY.length(); } // this is a property mapping String property = mapping.substring(prefixLength); CmsProperty p; if (mapToShared) { // map to shared value p = new CmsProperty(property, null, stringValue); } else { // map to individual value p = new CmsProperty(property, stringValue, null); } // just store the string value in the selected property rootCms.writePropertyObject(filename, p); if (mapToShared) { // special case: shared mappings must be written only to one sibling, end loop i = 0; } } else if (mapping.startsWith(MAPTO_URLNAME)) { // we write the actual mappings later urlNameMappingResources.add(siblings.get(i)); } else if (mapping.startsWith(MAPTO_ATTRIBUTE)) { // this is an attribute mapping String attribute = mapping.substring(MAPTO_ATTRIBUTE.length()); switch (ATTRIBUTES.indexOf(attribute)) { case 0: // date released long date = 0; try { date = Long.valueOf(stringValue).longValue(); } catch (NumberFormatException e) { // ignore, value can be a macro } if (date == 0) { date = CmsResource.DATE_RELEASED_DEFAULT; } // set the sibling release date rootCms.setDateReleased(filename, date, false); // set current file release date if (filename.equals(rootCms.getSitePath(file))) { file.setDateReleased(date); } break; case 1: // date expired date = 0; try { date = Long.valueOf(stringValue).longValue(); } catch (NumberFormatException e) { // ignore, value can be a macro } if (date == 0) { date = CmsResource.DATE_EXPIRED_DEFAULT; } // set the sibling expired date rootCms.setDateExpired(filename, date, false); // set current file expired date if (filename.equals(rootCms.getSitePath(file))) { file.setDateExpired(date); } break; default: // ignore invalid / other mappings } } } } } if (mapToUrlName) { // now actually write the URL name mappings for (CmsResource resourceForUrlNameMapping : urlNameMappingResources) { if (!CmsResource.isTemporaryFileName(resourceForUrlNameMapping.getRootPath())) { I_CmsFileNameGenerator nameGen = OpenCms.getResourceManager().getNameGenerator(); Iterator<String> nameSeq = nameGen.getUrlNameSequence(value.getStringValue(cms)); cms.writeUrlNameMapping(nameSeq, resourceForUrlNameMapping.getStructureId(), value.getLocale().toString()); } } } // make sure the original is locked CmsLock lock = rootCms.getLock(file); if (lock.isUnlocked()) { rootCms.lockResource(file.getRootPath()); } else if (!lock.isExclusiveOwnedBy(rootCms.getRequestContext().getCurrentUser())) { rootCms.changeLock(file.getRootPath()); } }
From source file:org.pentaho.big.data.kettle.plugins.hdfs.trans.HadoopFileInputDialog.java
private void getInfo(HadoopFileInputMeta meta) { stepname = wStepname.getText(); // return value // copy info to HadoopFileInputMeta class (input) meta.inputFiles.acceptingFilenames = wAccFilenames.getSelection(); meta.inputFiles.passingThruFields = wPassThruFields.getSelection(); meta.inputFiles.acceptingField = wAccField.getText(); meta.inputFiles.acceptingStepName = wAccStep.getText(); meta.setAcceptingStep(transMeta.findStep(wAccStep.getText())); meta.content.fileType = wFiletype.getText(); meta.content.fileFormat = wFormat.getText(); meta.content.separator = wSeparator.getText(); meta.content.enclosure = wEnclosure.getText(); meta.content.escapeCharacter = wEscape.getText(); meta.content.rowLimit = Const.toLong(wLimit.getText(), 0L); meta.content.filenameField = wInclFilenameField.getText(); meta.content.rowNumberField = wInclRownumField.getText(); meta.inputFiles.isaddresult = wAddResult.getSelection(); meta.content.includeFilename = wInclFilename.getSelection(); meta.content.includeRowNumber = wInclRownum.getSelection(); meta.content.rowNumberByFile = wRownumByFile.getSelection(); meta.content.header = wHeader.getSelection(); meta.content.nrHeaderLines = Const.toInt(wNrHeader.getText(), 1); meta.content.footer = wFooter.getSelection(); meta.content.nrFooterLines = Const.toInt(wNrFooter.getText(), 1); meta.content.lineWrapped = wWraps.getSelection(); meta.content.nrWraps = Const.toInt(wNrWraps.getText(), 1); meta.content.layoutPaged = wLayoutPaged.getSelection(); meta.content.nrLinesPerPage = Const.toInt(wNrLinesPerPage.getText(), 80); meta.content.nrLinesDocHeader = Const.toInt(wNrLinesDocHeader.getText(), 0); meta.content.fileCompression = wCompression.getText(); meta.content.dateFormatLenient = wDateLenient.getSelection(); meta.content.noEmptyLines = wNoempty.getSelection(); meta.content.encoding = wEncoding.getText(); int nrfiles = wFilenameList.getItemCount(); int nrfields = wFields.nrNonEmpty(); int nrfilters = wFilter.nrNonEmpty(); meta.allocate(nrfiles, nrfields, nrfilters); Map<String, String> namedClusterURLMappings = new HashMap<String, String>(); String[] fileNames = new String[wFilenameList.getItems(1).length]; meta.environment = wFilenameList.getItems(0); for (int i = 0; i < meta.environment.length; i++) { String sourceNc = meta.environment[i]; sourceNc = sourceNc.equals(LOCAL_ENVIRONMENT) ? HadoopFileInputMeta.LOCAL_SOURCE_FILE + i : sourceNc; sourceNc = sourceNc.equals(STATIC_ENVIRONMENT) ? HadoopFileInputMeta.STATIC_SOURCE_FILE + i : sourceNc; sourceNc = sourceNc.equals(S3_ENVIRONMENT) ? HadoopFileInputMeta.S3_SOURCE_FILE + i : sourceNc; String source = wFilenameList.getItems(1)[i]; if (!Const.isEmpty(source)) { fileNames[i] = input.loadUrl(source, sourceNc, getMetaStore(), namedClusterURLMappings); } else {//from w ww . jav a 2s . co m fileNames[i] = ""; } } meta.setFileName(fileNames); meta.inputFiles.fileMask = wFilenameList.getItems(2); meta.inputFiles.setFileRequired(wFilenameList.getItems(3)); meta.inputFiles.setIncludeSubFolders(wFilenameList.getItems(4)); input.setNamedClusterURLMapping(namedClusterURLMappings); for (int i = 0; i < nrfields; i++) { BaseFileField field = new BaseFileField(); TableItem item = wFields.getNonEmpty(i); field.setName(item.getText(1)); field.setType(ValueMeta.getType(item.getText(2))); field.setFormat(item.getText(3)); field.setPosition(Const.toInt(item.getText(4), -1)); field.setLength(Const.toInt(item.getText(5), -1)); field.setPrecision(Const.toInt(item.getText(6), -1)); field.setCurrencySymbol(item.getText(7)); field.setDecimalSymbol(item.getText(8)); field.setGroupSymbol(item.getText(9)); field.setNullString(item.getText(10)); field.setIfNullValue(item.getText(11)); field.setTrimType(ValueMeta.getTrimTypeByDesc(item.getText(12))); field.setRepeated( BaseMessages.getString(BASE_PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(13))); (meta.inputFields)[i] = field; } for (int i = 0; i < nrfilters; i++) { TableItem item = wFilter.getNonEmpty(i); TextFileFilter filter = new TextFileFilter(); (meta.getFilter())[i] = filter; filter.setFilterString(item.getText(1)); filter.setFilterPosition(Const.toInt(item.getText(2), -1)); filter.setFilterLastLine( BaseMessages.getString(BASE_PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(3))); filter.setFilterPositive( BaseMessages.getString(BASE_PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(4))); } // Error handling fields... meta.errorHandling.errorIgnored = wErrorIgnored.getSelection(); meta.setErrorLineSkipped(wSkipErrorLines.getSelection()); meta.setErrorCountField(wErrorCount.getText()); meta.setErrorFieldsField(wErrorFields.getText()); meta.setErrorTextField(wErrorText.getText()); meta.errorHandling.warningFilesDestinationDirectory = wWarnDestDir.getText(); meta.errorHandling.warningFilesExtension = wWarnExt.getText(); meta.errorHandling.errorFilesDestinationDirectory = wErrorDestDir.getText(); meta.errorHandling.errorFilesExtension = wErrorExt.getText(); meta.errorHandling.lineNumberFilesDestinationDirectory = wLineNrDestDir.getText(); meta.errorHandling.lineNumberFilesExtension = wLineNrExt.getText(); // Date format Locale Locale locale = EnvUtil.createLocale(wDateLocale.getText()); if (!locale.equals(Locale.getDefault())) { meta.content.dateFormatLocale = locale; } else { meta.content.dateFormatLocale = Locale.getDefault(); } }
From source file:org.pentaho.di.ui.trans.steps.textfileinput.TextFileInputDialog.java
private void getInfo(TextFileInputMeta meta) { stepname = wStepname.getText(); // return value // copy info to TextFileInputMeta class (input) meta.setAcceptingFilenames(wAccFilenames.getSelection()); meta.setPassingThruFields(wPassThruFields.getSelection()); meta.setAcceptingField(wAccField.getText()); meta.setAcceptingStepName(wAccStep.getText()); meta.setAcceptingStep(transMeta.findStep(wAccStep.getText())); meta.setFileType(wFiletype.getText()); meta.setFileFormat(wFormat.getText()); meta.setSeparator(wSeparator.getText()); meta.setEnclosure(wEnclosure.getText()); meta.setEscapeCharacter(wEscape.getText()); meta.setRowLimit(Const.toLong(wLimit.getText(), 0L)); meta.setFilenameField(wInclFilenameField.getText()); meta.setRowNumberField(wInclRownumField.getText()); meta.setAddResultFile(wAddResult.getSelection()); meta.setIncludeFilename(wInclFilename.getSelection()); meta.setIncludeRowNumber(wInclRownum.getSelection()); meta.setRowNumberByFile(wRownumByFile.getSelection()); meta.setHeader(wHeader.getSelection()); meta.setNrHeaderLines(Const.toInt(wNrHeader.getText(), 1)); meta.setFooter(wFooter.getSelection()); meta.setNrFooterLines(Const.toInt(wNrFooter.getText(), 1)); meta.setLineWrapped(wWraps.getSelection()); meta.setNrWraps(Const.toInt(wNrWraps.getText(), 1)); meta.setLayoutPaged(wLayoutPaged.getSelection()); meta.setNrLinesPerPage(Const.toInt(wNrLinesPerPage.getText(), 80)); meta.setNrLinesDocHeader(Const.toInt(wNrLinesDocHeader.getText(), 0)); meta.setFileCompression(wCompression.getText()); meta.setDateFormatLenient(wDateLenient.getSelection()); meta.setNoEmptyLines(wNoempty.getSelection()); meta.setEncoding(wEncoding.getText()); int nrfiles = wFilenameList.getItemCount(); int nrfields = wFields.nrNonEmpty(); int nrfilters = wFilter.nrNonEmpty(); meta.allocate(nrfiles, nrfields, nrfilters); meta.setFileName(wFilenameList.getItems(0)); meta.setFileMask(wFilenameList.getItems(1)); meta.setExcludeFileMask(wFilenameList.getItems(2)); meta.setFileRequired(wFilenameList.getItems(3)); meta.setIncludeSubFolders(wFilenameList.getItems(4)); for (int i = 0; i < nrfields; i++) { TextFileInputField field = new TextFileInputField(); TableItem item = wFields.getNonEmpty(i); field.setName(item.getText(1));//from w w w . ja v a2s. c om field.setType(ValueMeta.getType(item.getText(2))); field.setFormat(item.getText(3)); field.setPosition(Const.toInt(item.getText(4), -1)); field.setLength(Const.toInt(item.getText(5), -1)); field.setPrecision(Const.toInt(item.getText(6), -1)); field.setCurrencySymbol(item.getText(7)); field.setDecimalSymbol(item.getText(8)); field.setGroupSymbol(item.getText(9)); field.setNullString(item.getText(10)); field.setIfNullValue(item.getText(11)); field.setTrimType(ValueMeta.getTrimTypeByDesc(item.getText(12))); field.setRepeated(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(13))); // CHECKSTYLE:Indentation:OFF meta.getInputFields()[i] = field; } for (int i = 0; i < nrfilters; i++) { TableItem item = wFilter.getNonEmpty(i); TextFileFilter filter = new TextFileFilter(); // CHECKSTYLE:Indentation:OFF meta.getFilter()[i] = filter; filter.setFilterString(item.getText(1)); filter.setFilterPosition(Const.toInt(item.getText(2), -1)); filter.setFilterLastLine( BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(3))); filter.setFilterPositive( BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(4))); } // Error handling fields... meta.setErrorIgnored(wErrorIgnored.getSelection()); meta.setSkipBadFiles(wSkipBadFiles.getSelection()); meta.setFileErrorField(wBadFileField.getText()); meta.setFileErrorMessageField(wBadFileMessageField.getText()); meta.setErrorLineSkipped(wSkipErrorLines.getSelection()); meta.setErrorCountField(wErrorCount.getText()); meta.setErrorFieldsField(wErrorFields.getText()); meta.setErrorTextField(wErrorText.getText()); meta.setWarningFilesDestinationDirectory(wWarnDestDir.getText()); meta.setWarningFilesExtension(wWarnExt.getText()); meta.setErrorFilesDestinationDirectory(wErrorDestDir.getText()); meta.setErrorLineFilesExtension(wErrorExt.getText()); meta.setLineNumberFilesDestinationDirectory(wLineNrDestDir.getText()); meta.setLineNumberFilesExtension(wLineNrExt.getText()); // Date format Locale Locale locale = EnvUtil.createLocale(wDateLocale.getText()); if (!locale.equals(Locale.getDefault())) { meta.setDateFormatLocale(locale); } else { meta.setDateFormatLocale(Locale.getDefault()); } meta.setShortFileNameField(wShortFileFieldName.getText()); meta.setPathField(wPathFieldName.getText()); meta.setIsHiddenField(wIsHiddenName.getText()); meta.setLastModificationDateField(wLastModificationTimeName.getText()); meta.setUriField(wUriName.getText()); meta.setRootUriField(wRootUriName.getText()); meta.setExtensionField(wExtensionFieldName.getText()); meta.setSizeField(wSizeFieldName.getText()); }
From source file:org.pentaho.di.ui.trans.steps.fileinput.text.TextFileInputDialog.java
/** * Fill meta object from UI options./*from w w w . j a va 2s. co m*/ * * @param meta * meta object * @param preview * flag for preview or real options should be used. Currently, only one option is differ for preview - EOL * chars. It uses as "mixed" for be able to preview any file. */ private void getInfo(TextFileInputMeta meta, boolean preview) { stepname = wStepname.getText(); // return value // copy info to TextFileInputMeta class (input) meta.inputFiles.acceptingFilenames = wAccFilenames.getSelection(); meta.inputFiles.passingThruFields = wPassThruFields.getSelection(); meta.inputFiles.acceptingField = wAccField.getText(); meta.inputFiles.acceptingStepName = wAccStep.getText(); meta.setAcceptingStep(transMeta.findStep(wAccStep.getText())); meta.content.fileType = wFiletype.getText(); if (preview) { // mixed type for preview, for be able to eat any EOL chars meta.content.fileFormat = "mixed"; } else { meta.content.fileFormat = wFormat.getText(); } meta.content.separator = wSeparator.getText(); meta.content.enclosure = wEnclosure.getText(); meta.content.escapeCharacter = wEscape.getText(); meta.content.rowLimit = Const.toLong(wLimit.getText(), 0L); meta.content.filenameField = wInclFilenameField.getText(); meta.content.rowNumberField = wInclRownumField.getText(); meta.inputFiles.isaddresult = wAddResult.getSelection(); meta.content.includeFilename = wInclFilename.getSelection(); meta.content.includeRowNumber = wInclRownum.getSelection(); meta.content.rowNumberByFile = wRownumByFile.getSelection(); meta.content.header = wHeader.getSelection(); meta.content.nrHeaderLines = Const.toInt(wNrHeader.getText(), 1); meta.content.footer = wFooter.getSelection(); meta.content.nrFooterLines = Const.toInt(wNrFooter.getText(), 1); meta.content.lineWrapped = wWraps.getSelection(); meta.content.nrWraps = Const.toInt(wNrWraps.getText(), 1); meta.content.layoutPaged = wLayoutPaged.getSelection(); meta.content.nrLinesPerPage = Const.toInt(wNrLinesPerPage.getText(), 80); meta.content.nrLinesDocHeader = Const.toInt(wNrLinesDocHeader.getText(), 0); meta.content.fileCompression = wCompression.getText(); meta.content.dateFormatLenient = wDateLenient.getSelection(); meta.content.noEmptyLines = wNoempty.getSelection(); meta.content.encoding = wEncoding.getText(); meta.content.length = wLength.getText(); int nrfiles = wFilenameList.getItemCount(); int nrfields = wFields.nrNonEmpty(); int nrfilters = wFilter.nrNonEmpty(); meta.allocate(nrfiles, nrfields, nrfilters); meta.setFileName(wFilenameList.getItems(0)); meta.inputFiles.fileMask = wFilenameList.getItems(1); meta.inputFiles.excludeFileMask = wFilenameList.getItems(2); meta.inputFiles_fileRequired(wFilenameList.getItems(3)); meta.inputFiles_includeSubFolders(wFilenameList.getItems(4)); for (int i = 0; i < nrfields; i++) { BaseFileInputField field = new BaseFileInputField(); TableItem item = wFields.getNonEmpty(i); field.setName(item.getText(1)); field.setType(ValueMetaFactory.getIdForValueMeta(item.getText(2))); field.setFormat(item.getText(3)); field.setPosition(Const.toInt(item.getText(4), -1)); field.setLength(Const.toInt(item.getText(5), -1)); field.setPrecision(Const.toInt(item.getText(6), -1)); field.setCurrencySymbol(item.getText(7)); field.setDecimalSymbol(item.getText(8)); field.setGroupSymbol(item.getText(9)); field.setNullString(item.getText(10)); field.setIfNullValue(item.getText(11)); field.setTrimType(ValueMetaString.getTrimTypeByDesc(item.getText(12))); field.setRepeated(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(13))); // CHECKSTYLE:Indentation:OFF meta.inputFiles.inputFields[i] = field; } for (int i = 0; i < nrfilters; i++) { TableItem item = wFilter.getNonEmpty(i); TextFileFilter filter = new TextFileFilter(); // CHECKSTYLE:Indentation:OFF meta.getFilter()[i] = filter; filter.setFilterString(item.getText(1)); filter.setFilterPosition(Const.toInt(item.getText(2), -1)); filter.setFilterLastLine( BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(3))); filter.setFilterPositive( BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(4))); } // Error handling fields... meta.errorHandling.errorIgnored = wErrorIgnored.getSelection(); meta.errorHandling.skipBadFiles = wSkipBadFiles.getSelection(); meta.errorHandling.fileErrorField = wBadFileField.getText(); meta.errorHandling.fileErrorMessageField = wBadFileMessageField.getText(); meta.setErrorLineSkipped(wSkipErrorLines.getSelection()); meta.setErrorCountField(wErrorCount.getText()); meta.setErrorFieldsField(wErrorFields.getText()); meta.setErrorTextField(wErrorText.getText()); meta.errorHandling.warningFilesDestinationDirectory = wWarnDestDir.getText(); meta.errorHandling.warningFilesExtension = wWarnExt.getText(); meta.errorHandling.errorFilesDestinationDirectory = wErrorDestDir.getText(); meta.errorHandling.errorFilesExtension = wErrorExt.getText(); meta.errorHandling.lineNumberFilesDestinationDirectory = wLineNrDestDir.getText(); meta.errorHandling.lineNumberFilesExtension = wLineNrExt.getText(); // Date format Locale Locale locale = EnvUtil.createLocale(wDateLocale.getText()); if (!locale.equals(Locale.getDefault())) { meta.content.dateFormatLocale = locale; } else { meta.content.dateFormatLocale = Locale.getDefault(); } meta.additionalOutputFields.shortFilenameField = wShortFileFieldName.getText(); meta.additionalOutputFields.pathField = wPathFieldName.getText(); meta.additionalOutputFields.hiddenField = wIsHiddenName.getText(); meta.additionalOutputFields.lastModificationField = wLastModificationTimeName.getText(); meta.additionalOutputFields.uriField = wUriName.getText(); meta.additionalOutputFields.rootUriField = wRootUriName.getText(); meta.additionalOutputFields.extensionField = wExtensionFieldName.getText(); meta.additionalOutputFields.sizeField = wSizeFieldName.getText(); }