List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:org.locationtech.udig.project.ui.internal.actions.Delete.java
protected final void doDelete(ProjectElement element, boolean deleteFiles, int returncode) { if (returncode != Window.CANCEL) { for (UDIGEditorInputDescriptor desc : ApplicationGIS.getEditorInputs(element)) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = page.findEditor(desc.createInput(element)); if (editor != null) page.closeEditor(editor, false); }//from w w w . j a va 2 s . com List<ProjectElement> elements = element.getElements(ProjectElement.class); for (ProjectElement projectElement : elements) { doDelete(projectElement, deleteFiles, returncode); } Project projectInternal = element.getProjectInternal(); if (projectInternal != null) projectInternal.getElementsInternal().remove(element); else { Project project = findProject(element); if (project != null) project.getElementsInternal().remove(element); } Resource resource = element.eResource(); if (resource != null) { resource.getContents().remove(element); resource.unload(); } if (deleteFiles) { try { if (resource == null) { return; } URI resourceUri = resource.getURI(); String path = resourceUri.toFileString(); resource.unload(); if (resourceUri.hasAuthority()) { path = StringUtils.removeStart(path, "//"); } /* int lastIndexOf = path.lastIndexOf('/'); if (lastIndexOf == -1) lastIndexOf = path.length(); path = path.substring(0, lastIndexOf); */ final File file = new File(path); deleteFile(file); } catch (Exception e) { ProjectUIPlugin.log("Error deleting project element file", e); //$NON-NLS-1$ } } } }
From source file:org.locationtech.udig.tools.internal.CursorPosition.java
/** * transforms a String value to a Coordinate considering Locale setting and the supplied crs. * //from ww w .j a va 2s . c om * @param value * @param crs * @return */ public static Coordinate parse(String value, CoordinateReferenceSystem crs) { char decimalSeparator = DecimalFormatSymbols.getInstance(Locale.getDefault()).getDecimalSeparator(); String modifiedvalue = value.trim(); boolean latlong = false; String upperCase = modifiedvalue.toUpperCase(); String tmp = modifiedvalue; modifiedvalue = stripCode(modifiedvalue, upperCase); if (tmp.length() != modifiedvalue.length()) latlong = true; modifiedvalue = StringUtils.removeStart(modifiedvalue.trim(), "("); modifiedvalue = StringUtils.removeStart(modifiedvalue.trim(), "["); modifiedvalue = StringUtils.removeEnd(modifiedvalue.trim(), ")"); modifiedvalue = StringUtils.removeEnd(modifiedvalue.trim(), "]"); String[] components = StringUtils.split(modifiedvalue, decimalSeparator == ',' ? " " : ","); //$NON-NLS-1$ if (components.length == 1) { components = StringUtils.split(modifiedvalue, " "); //$NON-NLS-1$ } if (components.length == 1) { components = StringUtils.split(modifiedvalue, ","); } if (components.length <= 1) { return null; } try { components[0] = StringUtils.stripEnd(components[0].trim(), ", "); double arg1 = components[0].contains(".") ? Double.parseDouble(components[0]) : NumberFormat.getInstance().parse(components[0]).doubleValue(); components[1] = StringUtils.stripEnd(components[1].trim(), ", "); double arg0 = components[1].contains(".") ? Double.parseDouble(components[1]) : NumberFormat.getInstance().parse(components[1]).doubleValue(); Coordinate coord = new Coordinate(arg1, arg0); if (latlong && crs != null) { try { JTS.transform(coord, coord, CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs, true)); } catch (Exception e) { ToolsPlugin.log(Messages.CursorPosition_transformError, e); } } return coord; } catch (NumberFormatException e) { return null; } catch (ParseException e1) { return null; } catch (Exception e1) { return null; } }
From source file:org.metaabm.ide.JavaAgentImporter.java
protected IStatus run(IProgressMonitor monitor) { if (path != null) { URI uri = URI.createFileURI(path); JavaResourceFactoryImpl resourceFactory = new JavaResourceFactoryImpl(); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("java", resourceFactory); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("packages", new JavaPackageResourceFactoryImpl()); ResourceSet resourceSet = new ResourceSetImpl(); Resource resource = resourceSet.getResource(uri, true); JCompilationUnit javaSource = (JCompilationUnit) resource.getEObject("/"); JClass publicClass = javaSource.getTypes().get(0); monitor.beginTask("Importing from: " + new Path(path).lastSegment(), publicClass.getAllMethods().size()); importAsSName(agent, publicClass); for (JMethod method : publicClass.getAllMethods()) { if (method.getReturnType() != null && method.getVisibility() == JVisibility.PUBLIC_LITERAL) { String propertyName = method.getName(); if (propertyName.startsWith("get") || propertyName.startsWith("is")) { if (method.getParameters().size() == 0 && supportedTypes.get(method.getReturnType().getName()) != null) { SAttribute attr = MetaABMFactory.eINSTANCE.createSAttribute(); if (propertyName.startsWith("get")) { propertyName = StringUtils.removeStart(propertyName, "get"); } else { propertyName = StringUtils.removeStart(propertyName, "is"); }// w w w.j a v a 2 s.c om propertyName = StringUtils.uncapitalize(propertyName); method.setName(propertyName); agent.getAttributes().add(attr); importAsSName(attr, method); attr.setSType(supportedTypes.get(method.getReturnType().getName())); } } else if (!propertyName.startsWith("set") && method.getReturnType().getName().equals("void")) { ARule rule = MetaABMActFactory.eINSTANCE.createARule(); ((AGroup) agent.getRootActivity()).getMembers().add(rule); importAsSName(rule, method); rule.setSelected(rule); rule.setAgent(agent); if (agent.getOwner() != null && agent.getOwner().getProjections().size() > 0) { rule.setSpace(agent.getOwner().getProjections().get(0)); } } } monitor.worked(1); } return Status.OK_STATUS; } else { return Status.CANCEL_STATUS; } }
From source file:org.mule.modules.box.BoxConnector.java
/** * Returns the item information for a given path. * * {@sample.xml ../../../doc/box-connector.xml.sample box:get-item-by-path} * * @param resourcePath//from w w w . ja va 2 s . co m * the resource to retrieve from Box * @return an instance of {@link org.mule.modules.box.model.Item} with that * about the found item. {@code null} if the item is not found * @throws Exception if case of error */ @Processor @OAuthProtected @OAuthInvalidateAccessTokenOn(exception = BoxTokenExpiredException.class) public Item getItemByPath(String resourcePath) throws Exception { String parentId = "0"; String[] itemNames = StringUtils.removeStart(resourcePath, "/").split("/"); Item boxItem = null; for (int i = 0; i < itemNames.length; i++) { boxItem = this.getFolderItem(parentId, itemNames[i]); if (boxItem == null) { return null; } parentId = boxItem.getId(); } return boxItem; }
From source file:org.mule.modules.box.BoxConnector.java
/** * Returns the folder information for a given path * * {@sample.xml ../../../doc/box-connector.xml.sample * box:get-folder-by-path}/* w ww . j av a2 s .c om*/ * * @param resourcePath * the resource to retrieve from Box * @param getAllAttributes * option to retrieve all folder attributes or just the default ones * * @return an instance of {@link org.mule.modules.box.model.Folder} with * that about the found Folder. {@code null} if the folder is not * found * @throws Exception if case of error */ @Processor @OAuthProtected @OAuthInvalidateAccessTokenOn(exception = BoxTokenExpiredException.class) public Folder getFolderByPath(String resourcePath, @Optional @Default("false") boolean getAllAttributes) throws Exception { String parentId = "0"; String[] itemNames = StringUtils.removeStart(resourcePath, "/").split("/"); for (int i = 0; i < itemNames.length; i++) { if (StringUtils.isBlank(itemNames[i])) { continue; } Item boxItem = this.getFolderItem(parentId, itemNames[i]); if (boxItem == null) { return null; } parentId = boxItem.getId(); } return this.getFolder(parentId, getAllAttributes); }
From source file:org.onehippo.cms7.essentials.components.rest.BaseRestResource.java
private Node getScopeForContext(final RestContext context) throws RepositoryException { Node scopeNode;/*from w w w . ja v a 2s . c o m*/ final HttpServletRequest request = context.getRequest(); if (context.getScope() == null) { scopeNode = getScope(request); } else { if (context.isAbsolutePath()) { final Node rootNode = context.getRequestContext().getSession().getRootNode(); scopeNode = rootNode.getNode(StringUtils.removeStart(context.getScope(), "/")); } else { scopeNode = getScope(request, context.getScope()); } } return scopeNode; }
From source file:org.onehippo.forge.channelmanager.pagesupport.channel.event.DocumentCopyingPageCopyEventListener.java
/** * Resolves target document absolute path under {@code targetContentBaseNode}, * corresponding to the {@code sourceDocumentPath} under {@code sourceContentBaseNode}. * @param sourceContentBaseNode source content base folder node * @param targetContentBaseNode target content base folder node * @param sourceDocumentPath source document relative path * @return corresponding target document absolute path * @throws RepositoryException if any repository exception occurs */// ww w .ja v a 2s .c o m private String resolveTargetDocumentAbsPath(final Node sourceContentBaseNode, final Node targetContentBaseNode, final String sourceDocumentPath) throws RepositoryException { Node sourceDocumentHandleNode = sourceContentBaseNode.getNode(sourceDocumentPath); Node sourceFolderNode = sourceDocumentHandleNode.getParent(); Node targetFolderNode = findTargetTranslatedFolderNode(targetContentBaseNode, sourceFolderNode); if (targetFolderNode != null) { return targetFolderNode.getPath() + "/" + sourceDocumentHandleNode.getName(); } Stack<String> targetFolderNameStack = new Stack<>(); targetFolderNameStack.push(sourceFolderNode.getName()); sourceFolderNode = sourceFolderNode.getParent(); while (!sourceFolderNode.isSame(sourceContentBaseNode)) { targetFolderNode = findTargetTranslatedFolderNode(targetContentBaseNode, sourceFolderNode); if (targetFolderNode != null) { String folderPath = StringUtils.removeStart(targetFolderNode.getPath(), targetContentBaseNode.getPath() + "/"); targetFolderNameStack.push(folderPath); break; } else { targetFolderNameStack.push(sourceFolderNode.getName()); } sourceFolderNode = sourceFolderNode.getParent(); } return targetContentBaseNode.getPath() + "/" + StringUtils.join(popAllToList(targetFolderNameStack), "/") + "/" + sourceDocumentHandleNode.getName(); }
From source file:org.onehippo.forge.cmisreplication.CmisDocumentsReplicator.java
private void updateCmisDocumentsToHippoRepository() throws RepositoryException, IOException { Session session = null;/*ww w . j a v a 2 s . c o m*/ try { session = createSession(); OperationContext operationContext = session.createOperationContext(); operationContext.setMaxItemsPerPage(cmisRepoConfig.getMaxItemsPerPage()); CmisObject seed; if (StringUtils.isBlank(cmisRepoConfig.getRootPath())) { seed = session.getRootFolder(operationContext); } else { seed = session.getObjectByPath(cmisRepoConfig.getRootPath(), operationContext); } List<String> documentIds = new LinkedList<String>(); fillAllDocumentIdsFromCMISRepository(seed, documentIds); log.debug("Found {} numnber of documents", documentIds.size()); for (String documentId : documentIds) { Document document = null; try { document = (Document) session.getObject(documentId); } catch (CmisObjectNotFoundException ignore) { } if (document == null) { continue; } String remoteDocument = StringUtils.removeStart( StringUtils.substringBeforeLast(document.getPaths().get(0), "/"), cmisRepoConfig.getRootPath()); // Remove the first start remoteDocument = StringUtils.removeStart(remoteDocument, "/"); // Encode the name of the document String encodedAssetName = Codecs.encodeNode(document.getName()); String assetFolderPath = hippoRepoConfig.getRootPath(); String assetPath; // No folder if (StringUtils.isEmpty(remoteDocument)) { assetPath = assetFolderPath + "/" + encodedAssetName; } else { assetPath = assetFolderPath + "/" + remoteDocument + "/" + encodedAssetName; } AssetMetadata metadata = AssetUtils.getAssetMetadata(jcrSession, assetPath); long documentLastModified = document.getLastModificationDate().getTimeInMillis(); if (metadata == null || documentLastModified > metadata.getLastModified()) { Node assetFolderNode = AssetUtils.createAssetFolders(jcrSession, assetFolderPath); CmisDocumentBinary binary = new CmisDocumentBinary(document); AssetUtils.updateAsset(jcrSession, assetFolderNode, encodedAssetName, document, binary, cmisRepoConfig.getMetadataIdsToSync()); binary.dispose(); log.info("Updated asset on {}", assetPath); } } } finally { if (session != null) { try { session.clear(); } catch (Exception ignore) { } } } }
From source file:org.onehippo.forge.cmisreplication.util.AssetUtils.java
public static AssetMetadata getAssetMetadata(Session session, String path) throws RepositoryException { if (!session.itemExists(path)) { return null; }/*w w w. j a va 2s . c om*/ AssetMetadata metadata = null; Node node = session.getRootNode().getNode(StringUtils.removeStart(path, "/")); if (node.isNodeType(CmisReplicationTypes.HIPPO_HANDLE)) { if (node.hasNode(node.getName())) { node = node.getNode(node.getName()); } else { return null; } } Node resourceChildNode = null; if (node.hasNode(CmisReplicationTypes.HIPPOGALLERY_ASSET)) { resourceChildNode = node.getNode(CmisReplicationTypes.HIPPOGALLERY_ASSET); } if (resourceChildNode != null) { metadata = new AssetMetadata(); metadata.setPath(path); if (resourceChildNode.hasProperty("jcr:mimeType")) { metadata.setMimeType(resourceChildNode.getProperty("jcr:mimeType").getString()); } if (resourceChildNode.hasProperty("jcr:lastModified")) { metadata.setLastModified(resourceChildNode.getProperty("jcr:lastModified").getLong()); } } return metadata; }
From source file:org.onehippo.forge.cmisreplication.util.AssetUtils.java
public static Node createAssetFolders(Session session, String assetFolderPath) throws RepositoryException { if (session.itemExists(assetFolderPath)) { return session.getRootNode().getNode(StringUtils.removeStart(assetFolderPath, "/")); }//from www.j a v a 2 s . co m if (StringUtils.isBlank(assetFolderPath)) { throw new IllegalArgumentException("Blank folder path: " + assetFolderPath); } String[] folderComponents = StringUtils.split(assetFolderPath, "/"); Node curNode = session.getRootNode(); for (String folderComponent : folderComponents) { if (!StringUtils.isEmpty(folderComponent)) { if (curNode.hasNode(folderComponent)) { curNode = curNode.getNode(folderComponent); } else { curNode = createAssetFolder(session, curNode, folderComponent); } } } return curNode; }