List of usage examples for org.apache.commons.lang3 StringUtils isNumeric
public static boolean isNumeric(final CharSequence cs)
Checks if the CharSequence contains only Unicode digits.
From source file:org.cgiar.ccafs.ap.interceptor.ValidateProjectParameterInterceptor.java
@Override public String intercept(ActionInvocation invocation) throws Exception { LOG.debug("=> ValidateProjectParameterInterceptor"); String actionName = ServletActionContext.getActionMapping().getName(); // if user is not in project list or creating a project. if (!actionName.equals("projectsList") && !actionName.equals("addNewCoreProject") && !actionName.equals("addNewBilateralProject") && !actionName.equals("addCoFundedProject") && !actionName.equals("projectsEvaluation")) { Map<String, Object> parameters = invocation.getInvocationContext().getParameters(); // Validate if project parameter exists in the URL. if (parameters.get(APConstants.PROJECT_REQUEST_ID) != null) { String projectParameter = ((String[]) parameters.get(APConstants.PROJECT_REQUEST_ID))[0]; // Validate if it is a number. if (StringUtils.isNumeric(projectParameter)) { int projectID = Integer.parseInt(projectParameter); // If project doesn't exist. if (!projectManager.existProject(projectID)) { return BaseAction.NOT_FOUND; }/*ww w .j av a 2s . c om*/ // If project exists, continue! return invocation.invoke(); } else { // If parameter is not a number. return BaseAction.NOT_FOUND; } } else { // if parameter does not exist. return BaseAction.NOT_FOUND; } } else { // if user is in project list, do nothing! return invocation.invoke(); } }
From source file:org.codice.ddf.catalog.ui.util.EndpointUtil.java
public Instant parseDate(Serializable value) { if (value instanceof Date) { return ((Date) value).toInstant(); }/*from www . j av a 2 s. c o m*/ if (value instanceof Long) { return Instant.ofEpochMilli((Long) value); } if (!(value instanceof String)) { return null; } String string = String.valueOf(value); if (StringUtils.isBlank(string)) { return null; } if (StringUtils.isNumeric(string)) { try { return Instant.ofEpochMilli(Long.parseLong(string)); } catch (NumberFormatException ex) { LOGGER.debug("Failed to create Epoch time from a numeric: {}", string, ex); return null; } } if (iso8601Z.matcher(string).matches()) { return Instant.parse(string); } if (iso8601Offset.matcher(string).matches()) { return OffsetDateTime.parse(string).toInstant(); } SimpleDateFormat dateFormat; if (jsonDefault.matcher(string).matches()) { dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy"); } else { dateFormat = new SimpleDateFormat(); } dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); try { return dateFormat.parse(string).toInstant(); } catch (ParseException e) { LOGGER.debug("Failed to parse as a dateFormat time from a date string: {}", string, e); return null; } }
From source file:org.dbgl.gui.EditMountDialog.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, "mountdialog")); if (result == null) { shell.setText(settings.msg("dialog.mount.title.add")); } else {//from ww w.j a v a 2 s .co m // meaning we are essentially editing an existing mount point shell.setText(settings.msg("dialog.mount.title.edit")); } final Composite composite = new Composite(shell, SWT.NONE); composite.setLayout(new GridLayout(6, false)); final Label driveLetterLabel = new Label(composite, SWT.NONE); driveLetterLabel.setText(settings.msg("dialog.mount.driveletter")); driveletter = new Combo(composite, SWT.READ_ONLY); driveletter.setItems(new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" }); driveletter.setLayoutData(new GridData()); driveletter.select(defDriveletter - 'A'); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); mountDirButton = new Button(composite, SWT.RADIO); mountDirButton.setText(settings.msg("dialog.mount.mountdir")); mount_dir = new Text(composite, SWT.BORDER); mount_dir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1)); final BrowseButton browseButton = new BrowseButton(composite, SWT.NONE); browseButton.connect(shell, mount_dir, null, BrowseType.DIR, CanonicalType.DOSROOT, false, null); new Label(composite, SWT.NONE); final Label asLabel = new Label(composite, SWT.NONE); asLabel.setLayoutData(new GridData()); asLabel.setText(settings.msg("dialog.mount.mountdiras")); mount_type = new Combo(composite, SWT.READ_ONLY); mount_type.setItems(settings.getSettings().getValues("profile", "mount_type")); mount_type.add("", 0); mount_type.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1)); mount_type.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { boolean enableLLItems = mount_type.getItem(mount_type.getSelectionIndex()) .equalsIgnoreCase("cdrom"); lowlevelcd_type.setEnabled(enableLLItems); usecd.setEnabled(enableLLItems); freesize.setEnabled(!enableLLItems); String sizeLabel = mount_type.getItem(mount_type.getSelectionIndex()).equalsIgnoreCase("floppy") ? settings.msg("dialog.mount.kb") : settings.msg("dialog.mount.mb"); mbLabel.setText(sizeLabel); mbLabel.pack(); } }); new Label(composite, SWT.NONE); final Label label = new Label(composite, SWT.NONE); label.setLayoutData(new GridData()); label.setText(settings.msg("dialog.mount.drivelabel")); mount_label = new Text(composite, SWT.BORDER); mount_label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); final Composite composite2 = new Composite(composite, SWT.NONE); composite2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); final GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; gridLayout.numColumns = 4; composite2.setLayout(gridLayout); final Label lowlevelcdLabel = new Label(composite2, SWT.NONE); lowlevelcdLabel.setText(settings.msg("dialog.mount.lowlevelcdsupport")); lowlevelcd_type = new Combo(composite2, SWT.READ_ONLY); lowlevelcd_type.setVisibleItemCount(10); lowlevelcd_type.setItems(settings.getSettings().getValues("profile", "lowlevelcd_type")); lowlevelcd_type.add("", 0); final Label usecdLabel = new Label(composite2, SWT.NONE); usecdLabel.setText(settings.msg("dialog.mount.usecd")); usecd = new Combo(composite2, SWT.READ_ONLY); usecd.setItems(new String[] { "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }); new Label(composite, SWT.NONE); final Label freesizeLabel = new Label(composite, SWT.NONE); freesizeLabel.setText(settings.msg("dialog.mount.freesize")); freesize = new Combo(composite, SWT.NONE); freesize.setItems(settings.getSettings().getValues("profile", "freesize")); freesize.setVisibleItemCount(10); freesize.add("", 0); freesize.setLayoutData(new GridData(70, SWT.DEFAULT)); mbLabel = new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); final Label label_1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 6, 1)); mountImageButton = new Button(composite, SWT.RADIO); mountImageButton.setText(settings.msg("dialog.mount.mountimages")); imgmount_image = new Text(composite, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); imgmount_image.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); final BrowseButton imgBrowseButton = new BrowseButton(composite, SWT.NONE); new Label(composite, SWT.NONE); final Label imgmountAsLabel = new Label(composite, SWT.NONE); imgmountAsLabel.setLayoutData(new GridData()); imgmountAsLabel.setText(settings.msg("dialog.mount.mountdiras")); final Composite composite3 = new Composite(composite, SWT.NONE); composite3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1)); final GridLayout gridLayout3 = new GridLayout(); gridLayout3.marginHeight = 0; gridLayout3.marginWidth = 0; gridLayout3.numColumns = 3; composite3.setLayout(gridLayout3); imgmount_type = new Combo(composite3, SWT.READ_ONLY); imgmount_type.setItems(settings.getSettings().getValues("profile", "imgmount_type")); imgmount_type.setText("iso"); imgBrowseButton.connect(shell, imgmount_image, null, BrowseType.FILE, CanonicalType.CDIMAGE, false, imgmount_type); final Label imgmountFsLabel = new Label(composite3, SWT.NONE); imgmountFsLabel.setText(settings.msg("dialog.mount.imgmountfs")); imgmount_fs = new Combo(composite3, SWT.READ_ONLY); imgmount_fs.setItems(settings.getSettings().getValues("profile", "imgmount_fs")); imgmount_fs.add("", 0); new Label(composite, SWT.NONE); final Label imgmountSizeLabel = new Label(composite, SWT.NONE); imgmountSizeLabel.setLayoutData(new GridData()); imgmountSizeLabel.setText(settings.msg("dialog.mount.imgmountsize")); final Composite imgSizeSettings = new Composite(composite, SWT.NONE); imgSizeSettings.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1)); GridLayout filler = new GridLayout(); filler.numColumns = 2; filler.horizontalSpacing = 2; filler.marginWidth = 0; imgSizeSettings.setLayout(filler); imgmount_size = new Text(imgSizeSettings, SWT.BORDER); imgmount_size.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final Button img_size_config = new Button(imgSizeSettings, SWT.NONE); img_size_config.setText("..."); img_size_config.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { EditImgSizeDialog dialog = new EditImgSizeDialog(shell); dialog.setImgMountSizeCommand(imgmount_size.getText()); String command = (String) dialog.open(); if (command != null) { imgmount_size.setText(command); } } }); new Label(composite, SWT.NONE); final SelectionAdapter driveLetterSelectionAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { boolean imgFsNone = imgmount_fs.getSelectionIndex() == -1 ? false : imgmount_fs.getItem(imgmount_fs.getSelectionIndex()).equalsIgnoreCase("none"); int sel = driveletter.getSelectionIndex(); if (mountImageButton.getSelection() && imgFsNone) { if (!StringUtils.isNumeric(driveletter.getItem(sel))) { driveletter.setItems(new String[] { "0", "1", "2", "3" }); driveletter.setText(driveletter.getItem(Math.min(sel, 3))); } } else { if (StringUtils.isNumeric(driveletter.getItem(sel))) { driveletter.setItems(new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" }); driveletter.setText(driveletter.getItem(Math.min(sel, 3))); } } } }; imgmount_fs.addSelectionListener(driveLetterSelectionAdapter); imgmount_fs.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { boolean imgFsNone = imgmount_fs.getItem(imgmount_fs.getSelectionIndex()).equalsIgnoreCase("none"); imgmount_size.setEnabled(imgFsNone); img_size_config.setEnabled(imgFsNone); } }); final Label label_2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); label_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 6, 1)); mountZipButton = new Button(composite, SWT.RADIO); mountZipButton.setText(settings.msg("dialog.mount.mountzip")); final Label zipLabel = new Label(composite, SWT.NONE); zipLabel.setLayoutData(new GridData()); zipLabel.setText(settings.msg("dialog.mount.zipfile")); zipmount_zip = new Text(composite, SWT.BORDER); zipmount_zip.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); final BrowseButton zipBrowseButton = new BrowseButton(composite, SWT.NONE); zipBrowseButton.connect(shell, zipmount_zip, null, BrowseType.FILE, CanonicalType.ZIP, false, null); zipmount_write_enable = new Button(composite, SWT.CHECK); zipmount_write_enable.setSelection(true); zipmount_write_enable.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false)); final Label writeLabel = new Label(composite, SWT.NONE); writeLabel.setLayoutData(new GridData()); writeLabel.setText(settings.msg("dialog.mount.writedirectory")); zipmount_write = new Text(composite, SWT.BORDER); zipmount_write.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); final BrowseButton writeBrowseButton = new BrowseButton(composite, SWT.NONE); writeBrowseButton.connect(shell, zipmount_write, null, BrowseType.DIR, CanonicalType.DOSROOT, false, null); zipmount_write_enable.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { zipmount_write.setEnabled(zipmount_write_enable.getSelection()); } }); zipmount_write.addModifyListener(new ModifyListener() { public void modifyText(final ModifyEvent event) { zipmount_write_enable.setSelection(true); zipmount_write.setEnabled(true); } }); new Label(composite, SWT.NONE); final Label asLabel_1 = new Label(composite, SWT.NONE); asLabel_1.setLayoutData(new GridData()); asLabel_1.setText(settings.msg("dialog.mount.mountzipas")); zipmount_type = new Combo(composite, SWT.READ_ONLY); zipmount_type.setItems(settings.getSettings().getValues("profile", "zipmount_type")); zipmount_type.add("", 0); zipmount_type.setLayoutData(new GridData()); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); new Label(composite, SWT.NONE); final Label label_3 = new Label(composite, SWT.NONE); label_3.setLayoutData(new GridData()); label_3.setText(settings.msg("dialog.mount.drivelabel")); zipmount_label = new Text(composite, SWT.BORDER); zipmount_label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); new Label(composite, SWT.NONE); mountDirButton.addSelectionListener(driveLetterSelectionAdapter); mountImageButton.addSelectionListener(driveLetterSelectionAdapter); mountZipButton.addSelectionListener(driveLetterSelectionAdapter); final Composite composite_1 = new Composite(shell, SWT.NONE); composite_1.setLayout(new RowLayout()); composite_1.setLayoutData(BorderLayout.SOUTH); final Button okButton = new Button(composite_1, SWT.NONE); shell.setDefaultButton(okButton); okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { if (!isValid()) { return; } Mount mount = null; if (mountDirButton.getSelection()) { mount = new Mount(Mount.MountingType.DIR, mount_type.getText(), driveletter.getText(), new String[] { mount_dir.getText() }, mount_label.getText(), lowlevelcd_type.isEnabled() ? lowlevelcd_type.getText() : "", usecd.isEnabled() ? usecd.getText() : "", "", freesize.isEnabled() ? freesize.getText() : "", "", ""); } else if (mountImageButton.getSelection()) { mount = new Mount(Mount.MountingType.IMAGE, imgmount_type.getText(), driveletter.getText(), StringRelatedUtils.textAreaToStringArray(imgmount_image.getText(), imgmount_image.getLineDelimiter()), "", "", "", "", "", imgmount_fs.getText(), imgmount_size.isEnabled() ? imgmount_size.getText() : ""); } else if (mountZipButton.getSelection()) { mount = new Mount(Mount.MountingType.PHYSFS, zipmount_type.getText(), driveletter.getText(), new String[] { zipmount_zip.getText() }, zipmount_label.getText(), "", "", zipmount_write_enable.getSelection() ? zipmount_write.getText() : null, "", "", ""); } if (mount != null) { result = mount.toString(); } shell.close(); } }); okButton.setText(settings.msg("button.ok")); final Button cancelButton = new Button(composite_1, SWT.NONE); cancelButton.setText(settings.msg("button.cancel")); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { result = null; shell.close(); } }); final RowData rowData = new RowData(); rowData.width = GeneralPurposeGUI.getWidth(cancelButton, okButton); okButton.setLayoutData(rowData); cancelButton.setLayoutData(rowData); ModifyListener modListener = new ModifyListener() { public void modifyText(final ModifyEvent event) { mountDirButton.setSelection(event.widget == mount_dir); mountImageButton.setSelection(event.widget == imgmount_image); mountZipButton.setSelection(event.widget == zipmount_zip); mountDirButton.notifyListeners(SWT.Selection, null); } }; mount_dir.addModifyListener(modListener); imgmount_image.addModifyListener(modListener); zipmount_zip.addModifyListener(modListener); Mount mount = null; if (result != null) { try { mount = new Mount((String) result); } catch (InvalidMountstringException e1) { // if the mount could not be instantiated, just take the default // values for a mount by pretending there was no string input result = null; } } if (result == null) { // new mount point, set default values mountDirButton.setSelection(true); mount_dir.setText("."); mount_dir.selectAll(); mount_dir.setFocus(); } else { // meaning we are essentially editing an existing mount point // so we need to set previous values if (mount.getFs().equalsIgnoreCase("none")) { driveletter.setItems(new String[] { "0", "1", "2", "3" }); } driveletter.setText(mount.getDriveletterString()); switch (mount.getMountingType()) { case DIR: mountDirButton.setSelection(true); mount_dir.setText(mount.getPathAsString()); if (!mount.getMountAs().equals("")) { mount_type.setText(mount.getMountAs()); } mount_label.setText(mount.getLabel()); lowlevelcd_type.setText(mount.getLowlevelCD()); usecd.setText(mount.getUseCD()); if (!mount.getFreesize().equals("")) { freesize.setText(mount.getFreesize()); } mount_dir.selectAll(); mount_dir.setFocus(); break; case PHYSFS: mountZipButton.setSelection(true); zipmount_zip.setText(mount.getPathAsString()); boolean writeable = (mount.getWrite() != null); zipmount_write_enable.setSelection(writeable); zipmount_write.setEnabled(writeable); if (writeable) zipmount_write.setText(mount.getWrite().getPath()); if (!mount.getMountAs().equals("")) { zipmount_type.setText(mount.getMountAs()); } zipmount_label.setText(mount.getLabel()); zipmount_zip.selectAll(); zipmount_zip.setFocus(); break; case IMAGE: mountImageButton.setSelection(true); if (!mount.getMountAs().equals("")) { imgmount_type.setText(mount.getMountAs()); } if (!mount.getFs().equals("")) { imgmount_fs.setText(mount.getFs()); } if (!mount.getSize().equals("")) { imgmount_size.setText(mount.getSize()); } imgmount_image.setText(mount.getImgMountAsString(imgmount_image.getLineDelimiter())); imgmount_image.selectAll(); imgmount_image.setFocus(); default: } } int idx = mount_type.getSelectionIndex(); boolean enableLLItems = idx == -1 ? false : mount_type.getItem(idx).equalsIgnoreCase("cdrom"); lowlevelcd_type.setEnabled(enableLLItems); usecd.setEnabled(enableLLItems); freesize.setEnabled(!enableLLItems); String sizeLabel = idx == -1 ? settings.msg("dialog.mount.mb") : (mount_type.getItem(idx).equalsIgnoreCase("floppy") ? settings.msg("dialog.mount.kb") : settings.msg("dialog.mount.mb")); mbLabel.setText(sizeLabel); idx = imgmount_fs.getSelectionIndex(); boolean imgFsNone = idx == -1 ? false : imgmount_fs.getItem(idx).equalsIgnoreCase("none"); imgmount_size.setEnabled(imgFsNone); img_size_config.setEnabled(imgFsNone); }
From source file:org.dd4t.core.serializers.impl.json.FieldTypeConverter.java
@Override public FieldType convert(Object value) { if (value == null) { return null; }/*from w ww . j a va2 s . c o m*/ if (value instanceof FieldType) { return (FieldType) value; } if (value instanceof String) { String possibleTypeValue = (String) value; if (StringUtils.isNumeric(possibleTypeValue)) { return FieldType.findByValue(Integer.parseInt(possibleTypeValue)); } else { return FieldType.findByName(possibleTypeValue); } } if (value instanceof Integer) { return FieldType.findByValue((int) value); } return null; }
From source file:org.dd4t.databind.serializers.json.TridionFieldTypeIdResolver.java
public static String getClassForKey(String type) { LOG.trace("Fetching field type for {}", type); FieldType fieldType;// w ww . j a v a 2s .com if (StringUtils.isNumeric(type)) { fieldType = FieldType.findByValue(Integer.parseInt(type)); } else { fieldType = FieldType.findByName(type); } String result = FIELD_TYPES.get(fieldType); LOG.trace("Returning field type {}", result); return result; }
From source file:org.dederem.common.service.VersionAnalyseService.java
/** * Extract method./* w w w . ja v a 2 s . com*/ * * @param data * Map of read data. * @param key * Key to extract. * @return The value for the given key in the map or null. The value is returned in long format. */ private long extractValueLong(final Map<String, StringBuilder> data, final String key) { final String val = this.extractValueStr(data, key); return StringUtils.isNumeric(val) ? Long.parseLong(val) : -1; }
From source file:org.diorite.cfg.system.elements.StringTemplateElement.java
@Override public void appendValue(final Appendable writer, final CfgEntryData field, final Object source, final Object elementRaw, final int level, final ElementPlace elementPlace) throws IOException { StringStyle style = field.getOption(FieldOptions.STRING_STYLE, StringStyle.DEFAULT); if ((style == StringStyle.ALWAYS_MULTI_LINE) && (elementPlace == ElementPlace.SIMPLE_LIST_OR_MAP)) // multi line strings don't works in simple lists/maps. {//w ww. ja v a2 s.c o m style = StringStyle.DEFAULT; } final String element = Enum.class.isAssignableFrom(elementRaw.getClass()) ? ((Enum<?>) elementRaw).name() : elementRaw.toString(); switch (style) { case ALWAYS_QUOTED: { writeQuoted(writer, element); break; } case ALWAYS_SINGLE_QUOTED: { writeSingleQuoted(writer, StringUtils.replaceEach(element, REP_PREV_1, REP_PREV_2)); break; } case ALWAYS_MULTI_LINE: { writeMultiLine(writer, element, level, elementPlace); break; } default: { final boolean haveNewLines = StringUtils.contains(element, '\n'); if ((elementPlace != ElementPlace.SIMPLE_LIST_OR_MAP) && haveNewLines) { writeMultiLine(writer, element, level, elementPlace); return; } boolean needQuote = false; if (element.isEmpty()) { writeSingleQuoted(writer, element); return; } final char f = element.charAt(0); if (StringUtils.containsAny(element, ':', '#')) { needQuote = true; } else { for (final char c : CANT_BE_FIRST) { if (c == f) { needQuote = true; break; } } } if (needQuote) { writeQuoted(writer, element); return; } if (StringUtils.isNumeric(element)) { writeQuoted(writer, element); } else { writer.append(StringUtils.replace(element, "\n", "\\n")); } break; } } }
From source file:org.efaps.db.search.value.QStringValue.java
/** * {@inheritDoc}// w ww . j av a 2s . c om * */ @Override public QStringValue prepare(final AbstractTypeQuery _query, final AbstractQPart _part) throws EFapsException { if (_part instanceof AbstractQAttrCompare) { if (((AbstractQAttrCompare) _part).isIgnoreCase()) { this.value = this.value.toUpperCase(Context.getThreadContext().getLocale()); } if (_part instanceof QMatch) { this.value = Context.getDbType().prepare4Match(this.value); } if (_part instanceof QEqual && ((QEqual) _part).getAttribute().getAttribute() != null) { // check if the string is an status key and must be converted in // a long if (((QEqual) _part).getAttribute().getAttribute().getParent().isCheckStatus() && ((QEqual) _part).getAttribute().getAttribute().equals( ((QEqual) _part).getAttribute().getAttribute().getParent().getStatusAttribute())) { final Status status; if (StringUtils.isNumeric(this.value)) { status = Status.get(Long.valueOf(this.value)); } else { status = Status.find(((QEqual) _part).getAttribute().getAttribute().getLink().getUUID(), this.value); } if (status != null) { this.value = Long.valueOf(status.getId()).toString(); this.noEscape = true; } // check if the string is an oid and must be converted in a long } else if (((QEqual) _part).getAttribute().getAttribute().hasLink()) { final Instance insTmp = Instance.get(this.value); if (insTmp.isValid()) { this.value = Long.valueOf(insTmp.getId()).toString(); this.noEscape = true; } } } } return this; }
From source file:org.efaps.eql.JSONData.java
/** * @param _printStmt Statement the datalist will be created for * @return a DataList//from w w w.j ava2 s . c o m * @throws EFapsException on error */ @SuppressWarnings("checkstyle:illegalcatch") public static DataList getDataList(final IPrintStmt _printStmt) throws EFapsException { final DataList ret = new DataList(); if (_printStmt instanceof PrintStmt) { try { final PrintStmt printStmt = (PrintStmt) _printStmt; final Map<String, AbstractSelect> mapping = printStmt.getAlias2Selects(); for (final Map<String, Object> map : printStmt.getData()) { final ObjectData data = new ObjectData(); for (final Entry<String, AbstractSelect> entry : mapping.entrySet()) { final Object obj = map.get(entry.getKey()); data.getValues().add(getValue(entry.getKey(), obj)); } ret.add(data); } final Map<String, Boolean> sortMap = printStmt.getSortKey2desc(); if (!sortMap.isEmpty()) { final ComparatorChain<ObjectData> comparator = new ComparatorChain<>(); for (final Entry<String, Boolean> entry : sortMap.entrySet()) { AbstractValue<?> sortVal = null; if (StringUtils.isNumeric(entry.getKey())) { final int idx = Integer.parseInt(entry.getKey()); sortVal = ret.get(0).getValues().get(idx - 1); } else { for (final AbstractValue<?> val : ret.get(0).getValues()) { if (val.getKey().equals(entry.getKey())) { sortVal = val; break; } } } comparator.addComparator(new ObjectDataComparator(sortVal, !entry.getValue())); } Collections.sort(ret, comparator); } LOG.debug("Generated DataList: {}", ret); } catch (final Exception e) { if (e instanceof EFapsException) { throw (EFapsException) e; } else { throw new EFapsException("Could not create JSONData", e); } } } return ret; }
From source file:org.efaps.esjp.admin.common.systemconfiguration.SystemConf_Base.java
/** * Update field4 key.//from w w w. j a va 2 s . c om * * @param _parameter the _parameter * @return the return * @throws EFapsException on error */ public Return updateFields4Key(final Parameter _parameter) throws EFapsException { final boolean isLink = "true".equalsIgnoreCase(getProperty(_parameter, "SysConfLink")); final PrintQuery print = new PrintQuery(_parameter.getCallInstance()); final SelectBuilder sel; if (_parameter.getCallInstance().getType().isCIType(CIAdminCommon.SystemConfiguration)) { sel = SelectBuilder.get().attribute(CIAdminCommon.SystemConfiguration.UUID); } else { sel = SelectBuilder.get().linkto(CIAdminCommon.SystemConfigurationAttribute.AbstractLink) .attribute(CIAdminCommon.SystemConfiguration.UUID); } print.addSelect(sel); print.execute(); final String uuid = print.getSelect(sel); final String key = _parameter.getParameterValue("key"); ISysConfAttribute attr = isLink ? SysConfResourceConfig.getResourceConfig().getLink(uuid, key) : SysConfResourceConfig.getResourceConfig().getAttribute(uuid, key); if (attr == null && StringUtils.isNumeric(key.substring(key.length() - 2, key.length()))) { attr = isLink ? SysConfResourceConfig.getResourceConfig().getLink(uuid, key.substring(0, key.length() - 2)) : SysConfResourceConfig.getResourceConfig().getAttribute(uuid, key.substring(0, key.length() - 2)); } final Map<String, Object> map = new HashMap<>(); final String fieldName = _parameter.getParameters().containsKey("value") ? "value" : "value4edit"; final CharSequence node; if (attr == null) { node = StringEscapeUtils.escapeEcmaScript( new PropertiesSysConfAttribute().getHtml(_parameter, null, fieldName).toString()); } else { node = StringEscapeUtils.escapeEcmaScript(attr.getHtml(_parameter, null, fieldName).toString()); if (attr instanceof AbstractSysConfAttribute_Base) { map.put("description", StringEscapeUtils .escapeEcmaScript(((AbstractSysConfAttribute_Base<?, ?>) attr).getDescription())); } } final Return ret = new Return(); final List<Map<String, Object>> values = new ArrayList<>(); values.add(map); final StringBuilder js = new StringBuilder() .append("require(['dojo/query', 'dojo/dom-construct'], function (query, domConstruct) {") .append("var first = true;").append("query('[name=value],[tag=rem]').forEach(function (node) {") .append("if (first) {").append("first = false;").append("var newNode = '").append(node).append("';") .append("domConstruct.place(newNode, node, 'replace');").append("} else {") .append("domConstruct.destroy(node);").append("}").append("});").append("});"); map.put("eFapsFieldUpdateJS", js.toString()); ret.put(ReturnValues.VALUES, values); return ret; }