List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:org.eclipse.wb.internal.core.xml.model.description.rules.CreatePropertiesPropertyDescriptorRule.java
private void addSingleProperty(ComponentDescription componentDescription, PropertyDescriptor propertyDescriptor) throws Exception { Method setMethod = propertyDescriptor.getWriteMethod(); if (setMethod == null) { return;/*from www. j a v a2s .c om*/ } if (!ReflectionUtils.isPublic(setMethod)) { return; } // prepare description parts String title = propertyDescriptor.getName(); String attribute = StringUtils.substringBeforeLast(StringUtils.uncapitalize(title), "("); Method getMethod = propertyDescriptor.getReadMethod(); Class<?> propertyType = resolvePropertyType(componentDescription, setMethod); // prepare property parts String id = setMethod.getName() + "(" + ReflectionUtils.getFullyQualifiedName(propertyType, false) + ")"; ExpressionAccessor accessor = new MethodExpressionAccessor(attribute, setMethod, getMethod); ExpressionConverter converter = DescriptionPropertiesHelper.getConverterForType(propertyType); PropertyEditor editor = DescriptionPropertiesHelper.getEditorForType(propertyType); // create property GenericPropertyDescription property = new GenericPropertyDescription(id, title, propertyType, accessor); property.setConverter(converter); property.setEditor(editor); // add property componentDescription.addProperty(property); }
From source file:org.eclipse.wb.internal.rcp.model.jface.FieldEditorLabelsConstantsPropertyEditor.java
/** * @return the error message or <code>null</code>. *//* www . j a va2 s . c om*/ private static String prepareLabelsFields(List<String> resultLabels, List<IField> resultFields, GenericProperty property, String text) throws Exception { IJavaProject javaProject; String topTypeName; { JavaInfo javaInfo = property.getJavaInfo(); javaProject = javaInfo.getEditor().getJavaProject(); TypeDeclaration typeDeclaration = JavaInfoUtils.getTypeDeclaration(javaInfo); topTypeName = AstNodeUtils.getFullyQualifiedName(typeDeclaration, false); } // prepare containers List<String> tmpLabels = Lists.newArrayList(); List<IField> tmpFields = Lists.newArrayList(); resultLabels.clear(); resultFields.clear(); // analyze each line String[] lines = StringUtils.split(text, Text.DELIMITER); for (String line : lines) { line = line.trim(); String[] words = StringUtils.split(line); if (words.length < 2) { return MessageFormat.format(ModelMessages.FieldEditorLabelsConstantsPropertyEditor_errLabelField, line); } // prepare "label" and "field" code int lastSpaceIndex = StringUtils.lastIndexOf(line, " "); String label = line.substring(0, lastSpaceIndex).trim(); String fieldCode = line.substring(lastSpaceIndex).trim(); // convert "fieldCode" into IField IField field; if (fieldCode.contains(".")) { String typeName = StringUtils.substringBeforeLast(fieldCode, "."); String fieldName = StringUtils.substringAfterLast(fieldCode, "."); field = CodeUtils.findField(javaProject, typeName, fieldName); } else { field = CodeUtils.findField(javaProject, topTypeName, fieldCode); } // we should have IField if (field == null) { return MessageFormat .format(ModelMessages.FieldEditorLabelsConstantsPropertyEditor_errInvalidFieldName, line); } // add label/field tmpLabels.add(label); tmpFields.add(field); } // OK resultLabels.addAll(tmpLabels); resultFields.addAll(tmpFields); return null; }
From source file:org.eclipse.wb.internal.xwt.model.property.editor.style.XwtStyleClassResolver.java
public String resolve(Property property, String className) { if (className.equals("org.eclipse.swt.SWT")) { return ""; }/*from w w w . j a v a2 s . co m*/ // String packageName = StringUtils.substringBeforeLast(className, "."); String namespace = getPackageNamespace(property, packageName); String shortClassName = StringUtils.substringAfterLast(className, "."); return "(" + namespace + ":" + shortClassName + ")."; }
From source file:org.eclipse.wb.internal.xwt.model.util.XwtTagResolver.java
/** * @return the existing namespace (may be empty {@link String}), or <code>null</code> if new * namespace should be added.// w w w . j ava 2s .com */ private String getNamespace(String className) { prepareNamespaces(); String packageName = StringUtils.substringBeforeLast(className, "."); boolean isNotImportedForms = className.equals("org.eclipse.ui.forms.widgets.ColumnLayout") || className.equals("org.eclipse.ui.forms.widgets.ColumnLayoutData") || className.equals("org.eclipse.ui.forms.widgets.TableWrapLayout") || className.equals("org.eclipse.ui.forms.widgets.TableWrapData"); boolean isStandardCustom = packageName.equals("org.eclipse.swt.custom"); boolean isForms = XwtParser.hasForms(m_context) && packageName.equals("org.eclipse.ui.forms.widgets") && !isNotImportedForms; // standard XWT if (packageName.equals("org.eclipse.swt.widgets") || isStandardCustom || packageName.equals("org.eclipse.swt.layout") || packageName.equals("org.eclipse.jface.viewers") || isForms) { String name = m_nameForURI.get("http://www.eclipse.org/xwt/presentation"); // if standard XWT namespace declared if (name != null) { return name; } // if no default namespace, then standard XWT is implied if (!m_names.contains("")) { return ""; } } // existing for this package String packageURI = "clr-namespace:" + packageName; return ensureName(packageURI, "p"); }
From source file:org.eclipse.wb.internal.xwt.parser.XwtParser.java
private XmlObjectInfo getParentObjectInfo(Element element) { XmlObjectInfo parent = null;/* www. ja va2 s . c o m*/ String path = element.getPath(); do { path = StringUtils.substringBeforeLast(path, "/"); parent = m_pathToModelMap.get(path); } while (parent == null && path.contains("/")); return parent; }
From source file:org.ednovo.gooru.application.converter.GooruImageUtil.java
public boolean resizeImageByDimensions(String srcFilePath, String targetFolderPath, String filenamePrefix, String dimensions, String resourceGooruOid, String sessionToken, String thumbnail) { try {//from w w w .ja v a 2 s. c o m logger.debug(" src : {} /= target : {}", srcFilePath, targetFolderPath); String[] imageDimensions = dimensions.split(","); if (filenamePrefix == null) { filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/"); if (filenamePrefix.contains(".")) { filenamePrefix = StringUtils.substringBeforeLast(filenamePrefix, "."); } } for (String dimension : imageDimensions) { String[] xy = dimension.split(X); int width = Integer.valueOf(xy[0]); int height = Integer.valueOf(xy[1]); resizeImageByDimensions(srcFilePath, width, height, targetFolderPath + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath)); } try { HttpClient client = new HttpClient(); HttpMethod method = new PutMethod("http://" + propertyMap.get(SERVER_PATH) + "/" + propertyMap.get(REST_END_POINT) + "/media/resource/thumbnail?sessionToken=" + sessionToken + "&resourceGooruOid=" + resourceGooruOid + "&thumbnail=" + thumbnail); client.executeMethod(method); } catch (Exception ex) { logger.error("something went wrong while making rest api call", ex); } return true; } catch (Exception ex) { logger.error("Multiple scaling of image failed for src : " + srcFilePath + " : ", ex); return false; } }
From source file:org.ednovo.gooru.application.util.GooruImageUtil.java
public static String getFileNamePrefix(String filePath) { if (filePath != null) { if (filePath.contains("/")) { filePath = StringUtils.substringAfterLast(filePath, "/"); }/* w w w . ja v a 2s . c o m*/ if (filePath.contains("?")) { filePath = StringUtils.substringBefore(filePath, "?"); } return StringUtils.substringBeforeLast(filePath, "."); } else { return null; } }
From source file:org.ednovo.gooru.converter.service.ConversionServiceImpl.java
private static String[] applyTemporaryFixForPath(String[] cmdArgs) { if (cmdArgs.length > 0) { String[] fileTypes = { ".jpeg", ".JPEG", ".jpg", ".JPG", ".png", ".PNG", ".gif", ".GIF" }; for (int argIndex = 0; argIndex < cmdArgs.length; argIndex++) { String part = cmdArgs[argIndex]; if (containsIgnoreCaseInArray(part, fileTypes)) { String filePath = null; String repoPath = StringUtils.substringBeforeLast(part, "/"); String remainingPart = StringUtils.substringAfter(part, "/"); for (String fileType : fileTypes) { filePath = StringUtils.substringAfter(remainingPart, fileType); if (!filePath.isEmpty()) { break; }/*w ww .j a v a 2 s . c om*/ } if (!filePath.isEmpty()) { if (!repoPath.isEmpty()) { filePath = repoPath + "/" + filePath; } cmdArgs[argIndex] = filePath; } } } } return cmdArgs; }
From source file:org.ednovo.gooru.converter.service.ConversionServiceImpl.java
public List<String> resizeImageByDimensions(String srcFilePath, String targetFolderPath, String filenamePrefix, String dimensions, String resourceGooruOid, String sessionToken, String thumbnail, String apiEndPoint) { String imagePath = null;//from w w w . j a v a 2 s .c om List<String> list = new ArrayList<String>(); try { logger.debug(" src : {} /= target : {}", srcFilePath, targetFolderPath); String[] imageDimensions = dimensions.split(","); if (filenamePrefix == null) { filenamePrefix = StringUtils.substringAfterLast(srcFilePath, "/"); if (filenamePrefix.contains(".")) { filenamePrefix = StringUtils.substringBeforeLast(filenamePrefix, "."); } } for (String dimension : imageDimensions) { String[] xy = dimension.split(X); int width = Integer.valueOf(xy[0]); int height = Integer.valueOf(xy[1]); imagePath = resizeImageByDimensions(srcFilePath, width, height, targetFolderPath + filenamePrefix + "-" + dimension + "." + getFileExtenstion(srcFilePath)); list.add(imagePath); } try { JSONObject json = new JSONObject(); json.put(RESOURCE_GOORU_OID, resourceGooruOid); json.put(THUMBNAIL, thumbnail); JSONObject jsonAlias = new JSONObject(); jsonAlias.put(MEDIA, json); String jsonString = jsonAlias.toString(); StringRequestEntity requestEntity = new StringRequestEntity(jsonString, APP_JSON, "UTF-8"); HttpClient client = new HttpClient(); PutMethod postmethod = new PutMethod( apiEndPoint + "/media/resource/thumbnail?sessionToken=" + sessionToken); postmethod.setRequestEntity(requestEntity); client.executeMethod(postmethod); } catch (Exception ex) { logger.error("rest api call failed!", ex.getMessage()); } } catch (Exception ex) { logger.error("Multiple scaling of image failed for src : " + srcFilePath + " : ", ex); } return list; }
From source file:org.ednovo.gooru.converter.service.ConversionServiceImpl.java
@Override public void convertDocumentToPdf(Conversion conversion) { JSONObject data;//from w ww. j a v a 2 s . com try { data = new JSONObject(new JSONSerializer().serialize(conversion)); data.put("eventName", "convert.docToPdf"); try { if (conversion != null) { OfficeManager officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager(); officeManager.start(); OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); converter.convert(new File(conversion.getSourceFilePath()), new File(conversion.getTargetFolderPath() + "/" + conversion.getFileName())); data.put("status", "completed"); convertPdfToImage(conversion.getTargetFolderPath() + "/" + conversion.getFileName(), conversion.getResourceGooruOid(), conversion.getAuthXml()); File file = new File(conversion.getSourceFilePath()); file.renameTo(new File(conversion.getTargetFolderPath() + "/" + StringUtils.substringBeforeLast(conversion.getFileName(), ".") + ".ppt")); officeManager.stop(); } } catch (Exception e) { data.put("status", "failed"); } new ClientResource(conversion.getApiEndPoint() + "v2/job/" + conversion.getJobUid() + "?sessionToken=" + conversion.getSessionToken()).put(data.toString()); } catch (JSONException jsonException) { logger.error("Failed to parse json : " + jsonException); } }