public String pasteNode(String pathOrigin, String pathSelected, int pasteType, int action) throws ExchangeException, RepositoryException { boolean move = false; if (action == Tree.ACTION_MOVE) { move = true; } String label = StringUtils.substringAfterLast(pathOrigin, "/"); // $NON-NLS-1$ String slash = "/"; // $NON-NLS-1$ if (pathSelected.equals("/")) { // $NON-NLS-1$ slash = StringUtils.EMPTY; } String destination = pathSelected + slash + label; if (pasteType == Tree.PASTETYPE_SUB && action != Tree.ACTION_COPY && destination.equals(pathOrigin)) { // drag node to parent node: move to last position pasteType = Tree.PASTETYPE_LAST; } if (pasteType == Tree.PASTETYPE_SUB) { destination = pathSelected + slash + label; Content touchedContent = this.copyMoveNode(pathOrigin, destination, move); if (touchedContent == null) { return StringUtils.EMPTY; } return touchedContent.getHandle(); } else if (pasteType == Tree.PASTETYPE_LAST) { // LAST only available for sorting inside the same directory try { Content touchedContent = getHierarchyManager().getContent(pathOrigin); return touchedContent.getHandle(); } catch (RepositoryException re) { return StringUtils.EMPTY; } } else { try { // PASTETYPE_ABOVE | PASTETYPE_BELOW String nameSelected = StringUtils.substringAfterLast(pathSelected, "/"); // $NON-NLS-1$ String nameOrigin = StringUtils.substringAfterLast(pathOrigin, "/"); // $NON-NLS-1$ Content tomove = getHierarchyManager().getContent(pathOrigin); Content selected = getHierarchyManager().getContent(pathSelected); if (tomove.getParent().getUUID().equals(selected.getParent().getUUID())) { tomove.getParent().orderBefore(nameOrigin, nameSelected); tomove.getParent().save(); } else { String newOrigin = selected.getParent().getHandle() + "/" + nameOrigin; getHierarchyManager().moveTo(pathOrigin, newOrigin); Content newNode = getHierarchyManager().getContent(newOrigin); if (pasteType == Tree.PASTETYPE_ABOVE) { newNode.getParent().orderBefore(nameOrigin, nameSelected); } } return tomove.getHandle(); } catch (RepositoryException re) { re.printStackTrace(); log.error("Problem when pasting node", re); return StringUtils.EMPTY; } } }
/** * Creates the specified permission if it does not exist yet. Also creates all intermediate * permission nodes if not present yet. The {@link Session#save()} is not called by this method; * it is the responsibility of the caller. * * @param path the path of the permission to get/create * @param session current JCR session * @return the permission node * @throws RepositoryException in case of an error */ public static JCRNodeWrapper getOrCreatePermission(String path, JCRSessionWrapper session) throws RepositoryException { if (path == null || !path.startsWith("/permissions/")) { throw new IllegalArgumentException("Illegal value for the permission path: " + path); } String basePath = StringUtils.substringBeforeLast(path, "/"); String name = StringUtils.substringAfterLast(path, "/"); JCRNodeWrapper permission = null; JCRNodeWrapper base = null; try { base = session.getNode(basePath); } catch (PathNotFoundException e) { base = getOrCreatePermission(basePath, session); } if (!base.hasNode(name)) { session.checkout(base); permission = base.addNode(name, "jnt:permission"); logger.info("Added permission node {}", permission.getPath()); } else { permission = base.getNode(name); } return permission; }
private boolean propertyStartsWithFieldMarkerPrefix(PropertyValue pv, String fieldMarkerPrefix) { String propertyName = pv.getName().indexOf(PATH_SEPARATOR) > -1 ? StringUtils.substringAfterLast(pv.getName(), ".") : pv.getName(); return propertyName.startsWith(fieldMarkerPrefix); }
private String getTokenFromMessage(Message msg) throws IOException, MessagingException { String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString(); // TODO better token extraction // this is going to get the wrong string if the first part is not // text/plain and the url isn't the last character in the email return StringUtils.substringAfterLast(body, "token="); }
private File prepareTargetFileName( final File file, final SignaturePackaging signaturePackaging, final String signatureLevel) { final File parentDir = file.getParentFile(); final String originalName = StringUtils.substringBeforeLast(file.getName(), "."); final String originalExtension = "." + StringUtils.substringAfterLast(file.getName(), "."); final String level = signatureLevel.toUpperCase(); if (((SignaturePackaging.ENVELOPING == signaturePackaging) || (SignaturePackaging.DETACHED == signaturePackaging)) && level.startsWith("XADES")) { final String form = "xades"; final String levelOnly = DSSUtils.replaceStrStr(level, "XADES-", "").toLowerCase(); final String packaging = signaturePackaging.name().toLowerCase(); return new File( parentDir, originalName + "-" + form + "-" + packaging + "-" + levelOnly + ".xml"); } if (level.startsWith("CADES") && !originalExtension.toLowerCase().equals(".p7m")) { return new File(parentDir, originalName + originalExtension + ".p7m"); } if (level.startsWith("ASIC_S")) { return new File(parentDir, originalName + originalExtension + ".asics"); } if (level.startsWith("ASIC_E")) { return new File(parentDir, originalName + originalExtension + ".asice"); } return new File(parentDir, originalName + "-signed" + originalExtension); }
/** * Saves a value edited directly inside the tree. This can also be a lable * * @return name of the view */ public String saveValue() { String saveName = this.getRequest().getParameter("saveName"); // $NON-NLS-1$ Tree tree = getTree(); // value to save is a node data's value (config admin) boolean isNodeDataValue = "true" .equals(this.getRequest().getParameter("isNodeDataValue")); // $NON-NLS-1$ //$NON-NLS-2$ // value to save is a node data's type (config admin) boolean isNodeDataType = "true" .equals(this.getRequest().getParameter("isNodeDataType")); // $NON-NLS-1$ //$NON-NLS-2$ String value = StringUtils.defaultString(this.getRequest().getParameter("saveValue")); // $NON-NLS-1$ displayValue = StringUtils.EMPTY; // value to save is a content's meta information boolean isMeta = "true".equals(this.getRequest().getParameter("isMeta")); // $NON-NLS-1$ //$NON-NLS-2$ // value to save is a label (name of page, content node or node data) boolean isLabel = "true".equals(this.getRequest().getParameter("isLabel")); // $NON-NLS-1$ //$NON-NLS-2$ if (isNodeDataValue || isNodeDataType) { tree.setPath(StringUtils.substringBeforeLast(path, "/")); // $NON-NLS-1$ saveName = StringUtils.substringAfterLast(path, "/"); // $NON-NLS-1$ } else { // "/modules/templating/Templates/x" tree.setPath(path); } if (isLabel) { displayValue = rename(value); } else if (isNodeDataType) { int type = Integer.valueOf(value).intValue(); synchronized (ExclusiveWrite.getInstance()) { displayValue = tree.saveNodeDataType(saveName, type); } } else { synchronized (ExclusiveWrite.getInstance()) { displayValue = tree.saveNodeData(saveName, value, isMeta); } } // if there was a displayValue passed show it instead of the written value displayValue = StringUtils.defaultString( this.getRequest().getParameter("displayValue"), value); // $NON-NLS-1$ // @todo should be handled in a better way but, at the moment, this is better than nothing if (path.startsWith("/subscribers/")) { // $NON-NLS-1$ Subscriber.reload(); } else if (path.startsWith("/server/MIMEMapping")) { // $NON-NLS-1$ MIMEMapping.reload(); } return VIEW_VALUE; }
//////////////////////////////////////////////////////////////////////////// // // XMLObjectResolveTag // //////////////////////////////////////////////////////////////////////////// private void resolveTag(XmlObjectInfo object, Class<?> clazz, String[] namespace, String[] tag) throws Exception { if (tag[0] == null && UiBinderDescriptionProcessor.isUiBinder(object)) { String className = clazz.getName(); namespace[0] = getNamespace(className); tag[0] = StringUtils.substringAfterLast(className, "."); } }
public String getLocalName() { String localPart = StringUtils.substringAfterLast(getNodeName(), ":"); if (localPart == null) { return nodeName; } else { return localPart; } }
// 模拟创建一个process protected Long initProcess() { String path = zookeeper.create(processPath + "/", new byte[0], CreateMode.PERSISTENT_SEQUENTIAL); // 创建为顺序的节点 String processNode = StringUtils.substringAfterLast(path, "/"); return StagePathUtils.getProcessId(processNode); // 添加到当前的process列表 }
private String determinePrefix() { StackTraceElement[] stackTrace = new RuntimeException().getStackTrace(); for (StackTraceElement element : stackTrace) { if (element.getClassName().endsWith("Test") || element.getClassName().endsWith("Spec")) { return StringUtils.substringAfterLast(element.getClassName(), ".") + "/unknown-test"; } } return "unknown-test-class"; }
@Override protected List<Tome> parseTomes(Document htmlDocument, Serie parent) { Date today = new Date(); List<Tome> tomes = new LinkedList<>(); Elements divChapters = htmlDocument.select("div.detail_list"); if (!divChapters.isEmpty()) { Elements spansLeft = divChapters.first().select("span.left"); if (!spansLeft.isEmpty()) { for (Element span : spansLeft) { Elements tomeNumberElements = span.select("span.mr6"); final String tomeNumberString = StringUtils.substringAfter(tomeNumberElements.first().text(), "Vol "); int tomeNumber = 0; if (tomeNumberString != null && !tomeNumberString.isEmpty()) { Integer.parseInt(tomeNumberString); } Tome foundTome = null; for (Tome tome : tomes) { if (tomeNumber == tome.getNumber()) { foundTome = tome; break; } } if (foundTome == null) { Tome tome = new Tome(); tome.setNumber(tomeNumber); tome.setName("Tome " + tomeNumber); tome.setMustBeSaved(true); tome.setValidityDate(today); tome.setSerie(parent); tomes.add(tome); foundTome = tome; } Element link = span.select("a").first(); Chapter chapter = new Chapter(); chapter.setMustBeSaved(true); chapter.setUrl(link.attr("href")); String chapterNumberToParse = link.text(); String tempNumber = StringUtils.substringAfterLast(chapterNumberToParse, " "); chapter.setNumber(Float.parseFloat(tempNumber)); chapter.setName(span.text()); chapter.setTome(foundTome); foundTome.addChapter(chapter); } } } parent.setValidityDate(today); return tomes; }
public static String convertToSquidKeyFormat(JavaFile file) { String key = file.getKey(); if (file.getParent() == null || file.getParent().isDefault()) { key = StringUtils.substringAfterLast(file.getKey(), "."); } else { key = StringUtils.replace(key, ".", "/"); } return key + ".java"; }
/* (non-Javadoc) * @see com.hangum.tadpole.rdb.core.editors.objects.table.scripts.RDBDDLScript#getProcedureScript(com.hangum.tadpole.dao.mysql.ProcedureFunctionDAO) */ @Override public String getProcedureScript(ProcedureFunctionDAO procedureDAO) throws Exception { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); Map srcList = (HashMap) client.queryForObject("getProcedureScript", procedureDAO.getName()); String strSource = "" + srcList.get("Create Procedure"); strSource = StringUtils.substringAfterLast(strSource, "PROCEDURE"); return "CREATE PROCEDURE " + strSource; }
/** * This method extracts a port number from the serial number of a device. It assumes that the * device name is of format [xxxx-nnnn] where nnnn is the port number. * * @param device The device to extract the port number from. * @return Returns the port number of the device */ private int extractPortFromDevice(IDevice device) { String portStr = StringUtils.substringAfterLast(device.getSerialNumber(), "-"); if (StringUtils.isNotBlank(portStr) && StringUtils.isNumeric(portStr)) { return Integer.parseInt(portStr); } // If the port is not available then return -1 return -1; }
private IResDescriptor getResDescriptor(String filename) { // 全名优先 // 应该先检查文件全名,再检查扩展名 IResDescriptor desc = ARESResRegistry.getInstance().getResDescriptor(filename); if (desc == null) { String ext = StringUtils.substringAfterLast(filename, "."); desc = ARESResRegistry.getInstance().getResDescriptor(ext); } return desc; }
/* (non-Javadoc) * @see uk.ac.ox.oucs.oxam.logic.PaperFileService#deposit(uk.ac.ox.oucs.oxam.logic.PaperFile, uk.ac.ox.oucs.oxam.logic.Callback) */ public void deposit(PaperFile paperFile, InputStream in) { PaperFileImpl impl = castToImpl(paperFile); String path = impl.getPath(); ContentResourceEdit resource = null; try { try { contentHostingService.checkResource(path); resource = contentHostingService.editResource(path); // Ignore PermissionException, IdUnusedException, TypeException // As they are too serious to continue. } catch (IdUnusedException iue) { // Will attempt to create containing folders. resource = contentHostingService.addResource(path); // Like the basename function. String filename = StringUtils.substringAfterLast(path, "/"); ResourceProperties props = resource.getPropertiesEdit(); props.addProperty(ResourceProperties.PROP_DISPLAY_NAME, filename); resource.setContentType(mimeTypes.getContentType(filename)); } resource.setContent(in); contentHostingService.commitResource(resource, NotificationService.NOTI_NONE); LOG.debug("Sucessfully copied file to: " + path); } catch (OverQuotaException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ServerOverloadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PermissionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InUseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TypeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IdUsedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IdInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InconsistentException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // Close the stream here as this is where it's created. if (resource.isActiveEdit()) { contentHostingService.cancelResource(resource); } } }
@Override public int getJobTrackerPort() throws UnsupportedOperationException { String address = conf.get("yarn.resourcemanager.address"); address = StringUtils.substringAfterLast(address, ":"); if (StringUtils.isBlank(address)) { throw new IllegalArgumentException("Invalid YARN resource manager port."); } return Integer.parseInt(address); }
/** * Return the EBO fieldValue entries explicitly for the given eboPropertyName. (I.e., any * properties with the given property name as a prefix. * * @param eboPropertyName the externalizable business object property name to retrieve * @param fieldValues map of lookup criteria return map of lookup criteria for the given * eboPropertyName */ public static Map<String, String> getExternalizableBusinessObjectFieldValues( String eboPropertyName, Map<String, String> fieldValues) { Map<String, String> eboFieldValues = new HashMap<String, String>(); for (String key : fieldValues.keySet()) { if (key.startsWith(eboPropertyName + ".")) { eboFieldValues.put(StringUtils.substringAfterLast(key, "."), fieldValues.get(key)); } } return eboFieldValues; }
/* (non-Javadoc) * @see com.hangum.tadpole.rdb.core.editors.objects.table.scripts.RDBDDLScript#getTriggerScript(com.hangum.tadpole.dao.mysql.TriggerDAO) */ @Override public String getTriggerScript(TriggerDAO triggerDAO) throws Exception { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); StringBuilder result = new StringBuilder(""); Map srcList = (HashMap) client.queryForObject("getTriggerScript", triggerDAO.getTrigger()); String strSource = "" + srcList.get("SQL Original Statement"); strSource = StringUtils.substringAfterLast(strSource, "TRIGGER"); return "CREATE TRIGGER " + strSource; }
/* (non-Javadoc) * @see com.hangum.tadpole.rdb.core.editors.objects.table.scripts.RDBDDLScript#getViewScript(java.lang.String) */ @Override public String getViewScript(String strName) throws Exception { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); StringBuilder result = new StringBuilder(""); Map srcList = (HashMap) client.queryForObject("getViewScript", strName); String strSource = "" + srcList.get("Create View"); strSource = StringUtils.substringAfterLast(strSource, "VIEW"); return "CREATE VIEW " + strSource; }
/* (non-Javadoc) * @see com.hangum.tadpole.rdb.core.editors.objects.table.scripts.RDBDDLScript#getFunctionScript(com.hangum.tadpole.dao.mysql.ProcedureFunctionDAO) */ @Override public String getFunctionScript(ProcedureFunctionDAO functionDAO) throws Exception { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); StringBuilder result = new StringBuilder(""); Map srcList = (HashMap) client.queryForObject("getFunctionScript", functionDAO.getName()); String strSource = "" + srcList.get("Create Function"); strSource = StringUtils.substringAfterLast(strSource, "FUNCTION"); return "CREATE FUNCTION " + strSource; }
public String getSafeName() { String safeName = getName(); if (getComponent() != null && getComponent().isAlloyComponent()) { safeName = ReservedAttributeUtil.getSafeName(this); } if (safeName.indexOf(StringPool.COLON) > -1) { safeName = StringUtils.substringAfterLast(safeName, StringPool.COLON); } return safeName; }
/** * AS 7 has few aliases for the distributed login modules. This methods translates them from AS 5. */ private static String deriveLoginModuleName(String as5moduleName) { String type = StringUtils.substringAfterLast(as5moduleName, "."); switch (type) { case "ClientLoginModule": return "Client"; case "BaseCertLoginModule": return "Certificate"; case "CertRolesLoginModule": return "CertificateRoles"; case "DatabaseServerLoginModule": return "Database"; case "DatabaseCertLoginModule": return "DatabaseCertificate"; case "IdentityLoginModule": return "Identity"; case "LdapLoginModule": return "Ldap"; case "LdapExtLoginModule": return "LdapExtended"; case "RoleMappingLoginModule": return "RoleMapping"; case "RunAsLoginModule": return "RunAs"; case "SimpleServerLoginModule": return "Simple"; case "ConfiguredIdentityLoginModule": return "ConfiguredIdentity"; case "SecureIdentityLoginModule": return "SecureIdentity"; case "PropertiesUsersLoginModule": return "PropertiesUsers"; case "SimpleUsersLoginModule": return "SimpleUsers"; case "LdapUsersLoginModule": return "LdapUsers"; case "Krb5loginModule": return "Kerberos"; case "SPNEGOLoginModule": return "SPNEGOUsers"; case "AdvancedLdapLoginModule": return "AdvancedLdap"; case "AdvancedADLoginModule": return "AdvancedADldap"; case "UsersRolesLoginModule": return "UsersRoles"; default: return as5moduleName; } }
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fileName = ""; try { fileName = StringUtils.substringAfterLast(request.getRequestURI(), "/"); File file = new File(imageDirectory + fileName); if (!file.exists()) { file = new File(imageTempDirectory + fileName); } if (!file.exists()) { fileName = request.getParameter("fileName"); // report file delivery validates the filename against the username // of the user in session for security purposes. ReportUser user = (ReportUser) request.getSession().getAttribute(ORStatics.REPORT_USER); if (user == null || fileName.indexOf(user.getName()) < 0) { String message = "Not Authorized..."; response.getOutputStream().write(message.getBytes()); return; } file = new File(reportGenerationDirectory + fileName); } String contentType = ORUtil.getContentType(fileName); response.setContentType(contentType); if (contentType != ReportEngineOutput.CONTENT_TYPE_HTML) { response.setHeader( "Content-disposition", "inline; filename=" + StringUtils.deleteWhitespace(fileName)); } byte[] content = FileUtils.readFileToByteArray(file); response.setContentLength(content.length); ServletOutputStream ouputStream = response.getOutputStream(); ouputStream.write(content, 0, content.length); ouputStream.flush(); ouputStream.close(); } catch (Exception e) { log.warn(e); String message = "Error Loading File..."; response.getOutputStream().write(message.getBytes()); } }
/** Logs the event type and some information about the associated sponsor */ protected void logEvent() { if (LOG.isDebugEnabled()) { StringBuilder logMessage = new StringBuilder(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); if (getSponsorToBecomeAwardTransferringSponsor() == null) { logMessage.append("null Award Transferring Sponsor"); } else { logMessage.append(getSponsorToBecomeAwardTransferringSponsor().toString()); } LOG.debug(logMessage); } }
@Override protected void logEvent() { StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); // vary logging detail as needed if (this.actionBean == null) { logMessage.append("null actionBean"); } else { logMessage.append(actionBean.toString()); } getLOGHook().debug(logMessage); }
/** Logs the event type and some information about the associated item */ private void logEvent() { StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); // vary logging detail as needed if (item == null) { logMessage.append("null item"); } else { logMessage.append(" item# "); logMessage.append(item.getItemIdentifier()); } LOG.debug(logMessage); }
protected void updatePath( PathTrackingReader reader, Path path, Path currentPath, XstreamPathValueTracker pathValueTracker) { if (doBasicPathsMatch(path, currentPath)) { if (path.toString().contains("@")) { String attributeName = StringUtils.substringAfterLast(path.toString(), "@"); pathValueTracker.add(path, reader.getAttribute(attributeName)); } else { pathValueTracker.add(path, reader.getValue()); } } }
private Class<?> getPropertyTypeForPath(String propertyName) { Class<?> type = bean.getPropertyType(propertyName); if (type == null) { // type not available via BeanWrapper - this happens with e.g. empty list indexes - so // find type by examining GrailsDomainClass Object target = bean.getWrappedInstance(); String path = propertyName.replaceAll("\\[.+?\\]", ""); if (path.indexOf(PATH_SEPARATOR) > -1) { // transform x.y.z into value of x.y and path z target = bean.getPropertyValue(StringUtils.substringBeforeLast(propertyName, ".")); path = StringUtils.substringAfterLast(path, "."); } type = getReferencedTypeForCollection(path, target); } return type; }
/** * Creates the specified role if it does not exist yet. The {@link Session#save()} is not called * by this method; it is the responsibility of the caller. * * @param path the path of the role to get/create * @param session current JCR session * @return the role node * @throws RepositoryException in case of an error */ public static JCRNodeWrapper getOrCreateRole(String path, JCRSessionWrapper session) throws RepositoryException { if (path == null || !path.startsWith("/roles/")) { throw new IllegalArgumentException("Illegal value for the role path: " + path); } String name = StringUtils.substringAfterLast(path, "/"); JCRNodeWrapper role = null; JCRNodeWrapper base = session.getNode("/roles"); if (!base.hasNode(name)) { session.checkout(base); role = base.addNode(name, "jnt:role"); logger.info("Added role node {}", role.getPath()); } else { role = base.getNode(name); } return role; }