List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:edu.cornell.kfs.fp.batch.service.impl.AdvanceDepositServiceImpl.java
public boolean loadFile(String fileName, PhysicalFlatFileInformation physicalFlatFileInformation) { boolean valid = true; byte[] fileByteContent = safelyLoadFileBytes(fileName); if (LOG.isInfoEnabled()) { LOG.info("Attempting to parse the file "); }//from w ww . j a v a 2 s. co m Object parsedObject; try { parsedObject = batchInputFileService.parse(batchInputFileType, fileByteContent); } catch (org.kuali.kfs.sys.exception.ParseException e) { LOG.error("Error parsing batch file: " + e.getMessage()); FlatFileInformation fileInformation = new FlatFileInformation(); fileInformation.addFileInfoMessage("Unable to process file" + StringUtils.substringAfterLast(fileName, "\\") + "." + e.getMessage()); physicalFlatFileInformation.getFlatFileInfomationList().add(fileInformation); return false; } if (parsedObject != null) { valid = validate(parsedObject); copyAllMessage(parsedObject, physicalFlatFileInformation); if (valid) { loadAchIncomeTransactions(parsedObject); } } return valid; }
From source file:edu.ku.brc.specify.tools.schemalocale.FieldItemPanel.java
/** * @param item/*from w w w . j av a2 s .com*/ */ protected void fillFormatSwticherCBX(final DBTableChildIFace item) { formatSwitcherCombo.removeAllItems(); formatSwitcherCombo.addItem(SL_NONE); if (item instanceof DBRelationshipInfo) { if (((DBRelationshipInfo) item).getType() == DBRelationshipInfo.RelationshipType.ManyToOne) { formatSwitcherCombo.addItem(SL_PICKLIST); } } else { DBFieldInfo fi = (DBFieldInfo) item; if (fi != null) { if (fi.getDataClass() == String.class) { String ts = fi.getType(); String typeStr = ts.indexOf('.') > -1 ? StringUtils.substringAfterLast(fi.getType(), ".") : ts; if (StringUtils.isNotEmpty(typeStr)) { formatSwitcherCombo.addItem(SL_FORMAT); formatSwitcherCombo.addItem(SL_WEBLINK); formatSwitcherCombo.addItem(SL_PICKLIST); } } else if (fi.getDataClass() == Byte.class || fi.getDataClass() == Short.class || fi.getDataClass() == Integer.class) { formatSwitcherCombo.addItem(SL_PICKLIST); } } } formatSwitcherCombo.setEnabled( formatSwitcherCombo.getModel().getSize() > 1 && schemaType != SpLocaleContainer.WORKBENCH_SCHEMA); }
From source file:edu.arizona.kra.kim.impl.identity.PersonServiceImpl.java
/** * @see org.kuali.rice.kim.api.identity.PersonService#resolvePrincipalNamesToPrincipalIds(org.kuali.rice.krad.bo.BusinessObject, java.util.Map) *///from w w w.ja va 2 s.co m @SuppressWarnings("unchecked") @Override public Map<String, String> resolvePrincipalNamesToPrincipalIds(BusinessObject businessObject, Map<String, String> fieldValues) { if (fieldValues == null) { return null; } if (businessObject == null) { return fieldValues; } StringBuffer resolvedPrincipalIdPropertyName = new StringBuffer(); // save off all criteria which are not references to Person properties // leave person properties out so they can be resolved and replaced by this method Map<String, String> processedFieldValues = getNonPersonSearchCriteria(businessObject, fieldValues); for (String propertyName : fieldValues.keySet()) { if (!StringUtils.isBlank(fieldValues.get(propertyName)) // property has a value && isPersonProperty(businessObject, propertyName) // is a property on a Person object ) { // strip off the prefix on the property String personPropertyName = ObjectUtils.getNestedAttributePrimitive(propertyName); // special case - the user ID if (StringUtils.equals(KIMPropertyConstants.Person.PRINCIPAL_NAME, personPropertyName)) { @SuppressWarnings("rawtypes") Class targetBusinessObjectClass = null; BusinessObject targetBusinessObject = null; resolvedPrincipalIdPropertyName.setLength(0); // clear the buffer without requiring a new object allocation on each iteration // get the property name up until the ".principalName" // this should be a reference to the Person object attached to the BusinessObject String personReferenceObjectPropertyName = ObjectUtils.getNestedAttributePrefix(propertyName); // check if the person was nested within another BO under the master BO. If so, go up one more level // otherwise, use the passed in BO class as the target class if (ObjectUtils.isNestedAttribute(personReferenceObjectPropertyName)) { String targetBusinessObjectPropertyName = ObjectUtils .getNestedAttributePrefix(personReferenceObjectPropertyName); targetBusinessObject = (BusinessObject) ObjectUtils.getPropertyValue(businessObject, targetBusinessObjectPropertyName); if (targetBusinessObject != null) { targetBusinessObjectClass = targetBusinessObject.getClass(); resolvedPrincipalIdPropertyName.append(targetBusinessObjectPropertyName).append("."); } else { LOG.error("Could not find target property '" + propertyName + "' in class " + businessObject.getClass().getName() + ". Property value was null."); } } else { // not a nested Person property targetBusinessObjectClass = businessObject.getClass(); targetBusinessObject = businessObject; } if (targetBusinessObjectClass != null) { // use the relationship metadata in the KNS to determine the property on the // host business object to put back into the map now that the principal ID // (the value stored in application tables) has been resolved String propName = ObjectUtils .getNestedAttributePrimitive(personReferenceObjectPropertyName); DataObjectRelationship rel = getBusinessObjectMetaDataService() .getBusinessObjectRelationship(targetBusinessObject, propName); if (rel != null) { String sourcePrimitivePropertyName = rel .getParentAttributeForChildAttribute(KIMPropertyConstants.Person.PRINCIPAL_ID); resolvedPrincipalIdPropertyName.append(sourcePrimitivePropertyName); // get the principal - for translation of the principalName to principalId String principalName = fieldValues.get(propertyName); Principal principal = getIdentityService().getPrincipalByPrincipalName(principalName); if (principal != null) { processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), principal.getPrincipalId()); } else { processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), null); try { // if the principalName is bad, then we need to clear out the Person object // and base principalId property // so that their values are no longer accidentally used or re-populate // the object ObjectUtils.setObjectProperty(targetBusinessObject, resolvedPrincipalIdPropertyName.toString(), null); ObjectUtils.setObjectProperty(targetBusinessObject, propName, null); ObjectUtils.setObjectProperty(targetBusinessObject, propName + ".principalName", principalName); } catch (Exception ex) { LOG.error( "Unable to blank out the person object after finding that the person with the given principalName does not exist.", ex); } } } else { LOG.error("Missing relationship for " + propName + " on " + targetBusinessObjectClass.getName()); } } else { // no target BO class - the code below probably will not work processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), null); } } // if the property does not seem to match the definition of a Person property but it // does end in principalName then... // this is to handle the case where the user ID is on an ADD line - a case excluded from isPersonProperty() } else if (propertyName.endsWith("." + KIMPropertyConstants.Person.PRINCIPAL_NAME)) { // if we're adding to a collection and we've got the principalName; let's populate universalUser String principalName = fieldValues.get(propertyName); if (StringUtils.isNotEmpty(principalName)) { String containerPropertyName = propertyName; if (containerPropertyName.startsWith(KRADConstants.MAINTENANCE_ADD_PREFIX)) { containerPropertyName = StringUtils.substringAfter(propertyName, KRADConstants.MAINTENANCE_ADD_PREFIX); } // get the class of the object that is referenced by the property name // if this is not true then there's a principalName collection or primitive attribute // directly on the BO on the add line, so we just ignore that since something is wrong here if (ObjectUtils.isNestedAttribute(containerPropertyName)) { // the first part of the property is the collection name String collectionName = StringUtils.substringBefore(containerPropertyName, "."); // what is the class held by that collection? // JHK: I don't like this. This assumes that this method is only used by the maintenance // document service. If that will always be the case, this method should be moved over there. Class<? extends BusinessObject> collectionBusinessObjectClass = getMaintenanceDocumentDictionaryService() .getCollectionBusinessObjectClass(getMaintenanceDocumentDictionaryService() .getDocumentTypeName(businessObject.getClass()), collectionName); if (collectionBusinessObjectClass != null) { // we are adding to a collection; get the relationships for that object; // is there one for personUniversalIdentifier? List<DataObjectRelationship> relationships = getBusinessObjectMetaDataService() .getBusinessObjectRelationships(collectionBusinessObjectClass); // JHK: this seems like a hack - looking at all relationships for a BO does not guarantee that we get the right one // JHK: why not inspect the objects like above? Is it the property path problems because of the .add. portion? for (DataObjectRelationship rel : relationships) { String parentAttribute = rel.getParentAttributeForChildAttribute( KIMPropertyConstants.Person.PRINCIPAL_ID); if (parentAttribute == null) { continue; } // there is a relationship for personUserIdentifier; use that to find the universal user processedFieldValues.remove(propertyName); String fieldPrefix = StringUtils .substringBeforeLast(StringUtils.substringBeforeLast(propertyName, "." + KIMPropertyConstants.Person.PRINCIPAL_NAME), "."); String relatedPrincipalIdPropertyName = fieldPrefix + "." + parentAttribute; // KR-683 Special handling for extension objects if (EXTENSION.equals(StringUtils.substringAfterLast(fieldPrefix, ".")) && EXTENSION.equals(StringUtils.substringBefore(parentAttribute, "."))) { relatedPrincipalIdPropertyName = fieldPrefix + "." + StringUtils.substringAfter(parentAttribute, "."); } String currRelatedPersonPrincipalId = processedFieldValues .get(relatedPrincipalIdPropertyName); if (StringUtils.isBlank(currRelatedPersonPrincipalId)) { Principal principal = getIdentityService() .getPrincipalByPrincipalName(principalName); if (principal != null) { processedFieldValues.put(relatedPrincipalIdPropertyName, principal.getPrincipalId()); } else { processedFieldValues.put(relatedPrincipalIdPropertyName, null); } } } // relationship loop } else { if (LOG.isDebugEnabled()) { LOG.debug( "Unable to determine class for collection referenced as part of property: " + containerPropertyName + " on " + businessObject.getClass().getName()); } } } else { if (LOG.isDebugEnabled()) { LOG.debug("Non-nested property ending with 'principalName': " + containerPropertyName + " on " + businessObject.getClass().getName()); } } } } } return processedFieldValues; }
From source file:biz.netcentric.cq.tools.actool.authorizableutils.impl.AuthorizableCreatorServiceImpl.java
private void setAuthorizableProperties(Authorizable authorizable, ValueFactory vf, AuthorizableConfigBean principalConfigBean, Session session) throws RepositoryException { String profileContent = principalConfigBean.getProfileContent(); if (StringUtils.isNotBlank(profileContent)) { ContentHelper.importContent(session, authorizable.getPath() + "/profile", profileContent); }//from w ww .ja v a 2 s . c o m String preferencesContent = principalConfigBean.getPreferencesContent(); if (StringUtils.isNotBlank(preferencesContent)) { ContentHelper.importContent(session, authorizable.getPath() + "/preferences", preferencesContent); } String name = principalConfigBean.getPrincipalName(); if (StringUtils.isNotBlank(name)) { if (authorizable.isGroup()) { authorizable.setProperty("profile/givenName", vf.createValue(name)); } else { String givenName = StringUtils.substringBeforeLast(name, " "); String familyName = StringUtils.substringAfterLast(name, " "); authorizable.setProperty("profile/givenName", vf.createValue(givenName)); authorizable.setProperty("profile/familyName", vf.createValue(familyName)); } } String description = principalConfigBean.getDescription(); if (StringUtils.isNotBlank(description)) { authorizable.setProperty("profile/aboutMe", vf.createValue(description)); } }
From source file:com.oneops.inductor.AbstractOrderExecutor.java
protected String getShortenedClass(String className) { return StringUtils.substringAfterLast(className, ".").toLowerCase(); }
From source file:info.magnolia.importexport.DataTransporter.java
/** * The opposite of {@link #createExportPath(String)}. * I.e. given a path like this <code>.foo.bar..baz.test.....dir.baz....bar</code>, this method will produce <code>/foo/bar.baz/test../dir/baz..bar</code>. *///from w w w .j a v a 2s. c o m public static String revertExportPath(String exportPath) { if (".".equals(exportPath)) { return "/"; } //TODO I have a feeling there's a simpler way to achieve our goal. Matcher matcher = DOT_NAME_PATTERN.matcher(exportPath); StringBuilder reversed = new StringBuilder(exportPath.length()); while (matcher.find()) { String group = matcher.group(); int dotsNumber = StringUtils.countMatches(group, "."); if (dotsNumber == 1) { reversed.append(group.replaceFirst("\\.", "/")); } else { String dots = StringUtils.substringBeforeLast(group, ".").replace("..", "."); String name = StringUtils.substringAfterLast(group, "."); reversed.append(dots); //if number is odd, the last dot has to be replaced with a slash if (dotsNumber % 2 != 0) { reversed.append("/"); } reversed.append(name); } } return reversed.toString(); }
From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java
/** * /*from w w w. j a va 2s . co m*/ */ public void generate() { Rectangle rect = getPanel().getParent().getBounds(); System.out.println("MAIN[" + rect + "]"); if (rect.width == 0 || rect.height == 0) { return; } BufferedImage bufImage = new BufferedImage(rect.width, rect.height, (doPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB)); Graphics2D g2 = bufImage.createGraphics(); if (!doPNG) { g2.setColor(Color.WHITE); g2.fillRect(0, 0, rect.width, rect.height); } g2.setRenderingHints(createTextRenderingHints()); g2.setFont(tblTracker.getFont()); getPanel().getParent().paint(g2); g2.dispose(); Component stop = getPanel().getParent(); Point p = new Point(0, 0); calcLoc(p, getPanel().getMainTable(), stop); String name = StringUtils.substringAfterLast(getPanel().getMainTable().getClassName(), "."); DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByShortClassName(name); String fName = schemaDir.getAbsolutePath() + File.separator + name; try { String origName = fName; int i = 1; while (pngNameHash.contains(fName)) { fName = origName + i; } pngNameHash.add(fName); File html = new File(fName + ".html"); BufferedWriter output = new BufferedWriter(new FileWriter(html)); int index = mapTemplate.indexOf(contentTag); String subContent = mapTemplate.substring(0, index); output.write(StringUtils.replace(subContent, "<!-- Title -->", tblInfo.getTitle())); File imgFile = new File(fName + (doPNG ? ".png" : ".jpg")); output.write("<map name=\"schema\" id=\"schema\">\n"); Vector<ERDTable> nList = mainPanel.isRoot() ? tblTracker.getTreeAsList(mainPanel.getMainTable()) : getPanel().getRelTables(); for (ERDTable erdt : nList) { p = new Point(0, 0); calcLoc(p, erdt, stop); Dimension s = erdt.getSize(); String linkname = StringUtils.substringAfterLast(erdt.getClassName(), "."); output.write("<area shape=\"rect\" coords=\"" + p.x + "," + p.y + "," + (p.x + s.width) + "," + (p.y + s.height) + "\" href=\"" + linkname + ".html\"/>\n"); } output.write("</map>\n"); output.write("<img border=\"0\" usemap=\"#schema\" src=\"" + imgFile.getName() + "\"/>\n"); output.write(mapTemplate.substring(index + contentTag.length() + 1, mapTemplate.length())); output.close(); File oFile = new File(schemaDir + File.separator + imgFile.getName()); System.out.println(oFile.getAbsolutePath()); if (doPNG) { ImageIO.write(bufImage, "PNG", oFile); } else { writeJPEG(oFile, bufImage, 0.75f); } //ImageIO.write(bufImage, "JPG", new File(schemaDir + File.separator + imgFile.getName()+".jpg")); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e); e.printStackTrace(); } }
From source file:info.magnolia.module.admininterface.SaveHandlerImpl.java
/** * Returns the page. The page is created if not yet existing depending on the property create * @param hm//from www . j ava2s .c o m * @return the node * @throws RepositoryException * @throws AccessDeniedException * @throws PathNotFoundException */ protected Content getPageNode(HierarchyManager hm) throws RepositoryException, AccessDeniedException, PathNotFoundException { Content page = null; String path = this.getPath(); try { page = hm.getContent(path); } catch (RepositoryException e) { if (this.isCreate()) { String parentPath = StringUtils.substringBeforeLast(path, "/"); //$NON-NLS-1$ String label = StringUtils.substringAfterLast(path, "/"); //$NON-NLS-1$ if (StringUtils.isEmpty(parentPath)) { page = hm.getRoot(); } else { page = hm.getContent(parentPath); } page = page.createContent(label, this.getCreationItemType()); } else { log.error("Tried to save a not existing node with path {}. use create = true to force creation", //$NON-NLS-1$ path); } } return page; }
From source file:com.htmlhifive.tools.wizard.download.DownloadModule.java
/** * ZIP?.//from ww w .j ava 2 s. c o m * * @param libraryNode * @param perLibWork libWork * @param folder * @param monitor * @param logger . * @return ???????. * @throws IOException IO * @throws CoreException */ private boolean downloadZip(LibraryNode libraryNode, int perLibWork, IContainer folder, IProgressMonitor monitor, ResultStatus logger) throws IOException, CoreException { boolean result = true; boolean addStatus = false; ZipFile cachedZipFile = null; String cachedSite = null; Library library = libraryNode.getValue(); if (!library.getSite().isEmpty()) { int perSiteWork = Math.max(1, perLibWork / library.getSite().size()); for (Site site : library.getSite()) { String siteUrl = site.getUrl(); String path = H5IOUtils.getURLPath(siteUrl); if (path == null) { logger.log(Messages.SE0082, siteUrl); continue; } boolean setWorked = false; IContainer savedFolder = folder; if (site.getExtractPath() != null) { savedFolder = savedFolder.getFolder(Path.fromOSString(site.getExtractPath())); } // ?. IFile iFile = null; if (path.endsWith(".zip") || path.endsWith(".jar") || site.getFilePattern() != null) { // Zip // ?????????. if (!siteUrl.equals(cachedSite)) { cachedZipFile = download(monitor, perSiteWork, logger, null, siteUrl); setWorked = true; if (!lastDownloadStatus || cachedZipFile == null) { libraryNode.setInError(true); result = false; break; } cachedSite = siteUrl; } final ZipFile zipFile = cachedZipFile; // int perZipWork = Math.max(1, perSiteWork / zipFile.size()); // Zip. for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) { final ZipEntry zipEntry = e.nextElement(); if (site.getFilePattern() != null && !FilenameUtils.wildcardMatch(zipEntry.getName(), site.getFilePattern())) { // ???. continue; } IContainer savedFolder2 = savedFolder; String wildCardStr = StringUtils.defaultString(site.getFilePattern()); if (wildCardStr.contains("*") && wildCardStr.contains("/")) { // ??????. wildCardStr = StringUtils.substringBeforeLast(site.getFilePattern(), "/"); } String entryName = zipEntry.getName(); if (entryName.startsWith(wildCardStr + "/")) { entryName = entryName.substring(wildCardStr.length() + 1); } if (zipEntry.isDirectory()) { // zip?????. if (StringUtils.isNotEmpty(entryName)) { // ?. savedFolder2 = savedFolder2.getFolder(Path.fromOSString(entryName)); if (libraryNode.isAddable() && !savedFolder2.exists()) { logger.log(Messages.SE0091, savedFolder2.getFullPath()); H5IOUtils.createParentFolder(savedFolder2, null); logger.log(Messages.SE0092, savedFolder2.getFullPath()); } else if (libraryNode.getState() == LibraryState.REMOVE && savedFolder2.exists()) { // . logger.log(Messages.SE0095, savedFolder2.getFullPath()); H5IOUtils.createParentFolder(savedFolder2, null); logger.log(Messages.SE0096, savedFolder2.getFullPath()); } } } else { // zip. // ???. if (site.getReplaceFileName() != null) { iFile = savedFolder2.getFile(Path.fromOSString(site.getReplaceFileName())); } else { iFile = savedFolder2.getFile(Path.fromOSString(entryName)); } // ?. updateFile(monitor, 0, logger, iFile, new ZipFileContentsHandler(zipFile, zipEntry)); addStatus = true; } } if (savedFolder.exists() && savedFolder.members().length == 0) { // ????. savedFolder.delete(true, monitor); } } else { // ???. if (site.getReplaceFileName() != null) { iFile = savedFolder.getFile(Path.fromOSString(site.getReplaceFileName())); } else { // . iFile = savedFolder.getFile(Path.fromOSString(StringUtils.substringAfterLast(path, "/"))); } // . download(monitor, perSiteWork, logger, iFile, siteUrl); setWorked = true; if (!lastDownloadStatus) { // SE0101=ERROR,({0})??????URL={1}, File={2} logger.log(Messages.SE0101, iFile != null ? iFile.getFullPath().toString() : StringUtils.defaultString(site.getFilePattern()), site.getUrl(), site.getFilePattern()); libraryNode.setInError(true); } else { addStatus = true; } } // ?????. // . if (!addStatus) { // SE0099=ERROR,???????URL={1}, File={2} logger.log(Messages.SE0099, site.getUrl(), iFile != null ? iFile.getFullPath().toString() : StringUtils.defaultString(site.getFilePattern())); libraryNode.setInError(true); result = false; } // folder.refreshLocal(IResource.DEPTH_ZERO, null); // // SE0102=INFO,???? // logger.log(Messages.SE0102); // logger.log(Messages.SE0068, iFile.getFullPath()); if (!setWorked) { monitor.worked(perSiteWork); } } } else { monitor.worked(perLibWork); } return result; }
From source file:com.google.gdt.eclipse.designer.util.Utils.java
/** * @return the default name of HTML file for given module name. *///from w w w . ja v a 2s . c o m public static String getDefaultHTMLName(String moduleId) { return StringUtils.substringAfterLast(moduleId, ".") + ".html"; }