List of usage examples for org.apache.commons.lang StringUtils difference
public static String difference(String str1, String str2)
Compares two Strings, and returns the portion where they differ.
From source file:org.betaconceptframework.astroboa.engine.jcr.util.JcrNodeUtils.java
public static String getYearMonthDayPathForContentObjectNode(Node contentObjectNode) throws RepositoryException { if (contentObjectNode == null || contentObjectNode.getParent() == null) { return ""; }//from www. j a va2s.co m //In releases prior to 3 (2.x.x) content object nodes were stored //under path contentTypeFolder/year/month/day //where as from release 3 and onwards content object nodes are stored under path //contentTypeFolder/year/month/day/hour/minute //This method takes under consideration both structures for compatibility reasons //Find content object type folder Node contentObjectTypeFolderNode = contentObjectNode.getParent(); //Try to find contentObjectTypeFolder node while (contentObjectTypeFolderNode != null && !contentObjectTypeFolderNode.isNodeType(CmsBuiltInItem.GenericContentTypeFolder.getJcrName())) { contentObjectTypeFolderNode = contentObjectTypeFolderNode.getParent(); } if (contentObjectTypeFolderNode == null) { return ""; } String contentObjectNodeParentPath = contentObjectNode.getParent().getPath(); String contentObjectTypeFolderPath = contentObjectTypeFolderNode.getPath(); String path = StringUtils.difference(contentObjectTypeFolderPath + "/", contentObjectNodeParentPath); logger.debug("CO Parent Path {} \n Type Folder Path {}\n Difference {}", new Object[] { contentObjectNodeParentPath, contentObjectTypeFolderPath, path }); //Path has either the format year/month/day or year/month/day/hour/minute int count = StringUtils.countMatches(path, "/"); if (count == 2) { return path; } else { //Must return the first two path = StringUtils.substringBeforeLast(path, "/"); return StringUtils.substringBeforeLast(path, "/"); } }
From source file:org.dspace.app.xmlui.aspect.submission.submit.DescribeStep.java
private void fill(java.util.List<Field> fields, java.util.List<String> values, boolean addInstances, ComplexDefinition definition, String fieldName) throws WingException { //fill the form for (int i = 0; i < fields.size(); i++) { Field field = fields.get(i); String value = values.get(i); if (addInstances) { Instance instance = field.addInstance(); //XXX: Branching on type if (field instanceof Select) { instance.setOptionSelected(value); } else { instance.setValue(value); }//from w ww.ja v a 2 s.c o m } else { //currently with error only field.setValue(value); String inputName = StringUtils.difference(fieldName + "_", field.getName()); String regex = definition.getInput(inputName).get("regexp"); if (!DCInput.isAllowedValue(value, regex)) { //attach the regex error to the right field field.addError(String.format( "The field doesn't match the required regular expression (format) \"%s\"", regex)); } } } }
From source file:org.jlibrary.client.ui.repository.RepositoryHelper.java
/** * Creates a resource node/*from w w w.jav a2s . co m*/ * * @param resourcePath Path to the resource file * @param documentPath Path to the document file. It can be <code>null</code> * if the document it has been already created * @param monitor Progress monitor to track resource addition * @param repository Repository * @param parent Parent node for the resource * * @return ResourceNode Created resource node * * @throws RepositoryException If the resources can't be created * @throws SecurityException If the user doesn't have permissions to do this operation */ private static ResourceNode createResourceFromFile(String resourcePath, String documentPath, IProgressMonitor monitor, Repository repository, Node parent) throws RepositoryException, SecurityException { Ticket ticket = repository.getTicket(); ServerProfile profile = repository.getServerProfile(); RepositoryService service = JLibraryServiceFactory.getInstance(profile).getRepositoryService(); File resourceFile = new File(resourcePath); try { if ((documentPath != null) && !documentPath.equals("")) { String filteredResourcePath = StringUtils.replace(resourcePath, "\\", "/"); filteredResourcePath = filteredResourcePath.substring(0, filteredResourcePath.lastIndexOf("/")); String filteredDocumentPath = StringUtils.replace(documentPath, "\\", "/"); filteredDocumentPath = filteredDocumentPath.substring(0, filteredDocumentPath.lastIndexOf("/")); String subpath = StringUtils.difference(filteredDocumentPath, filteredResourcePath); // Remove the .. references if (subpath.length() > 0) { // subpath. We must create the directories String[] dirs = StringUtils.split(subpath, "/"); for (int i = 0; i < dirs.length; i++) { String dirname = dirs[i]; if (dirname.equals(".")) { continue; } if (dirname.equals("..")) { if (parent.getParent() != null) { parent = EntityRegistry.getInstance().getNode(parent.getParent(), parent.getRepository()); } continue; } // Look if the directory already exists boolean found = false; Iterator it = parent.getNodes().iterator(); while (it.hasNext()) { Node node = (Node) it.next(); if (!node.isDirectory()) continue; if (node.getName().equalsIgnoreCase(dirname)) { //catched parent = node; found = true; } } if (!found) { Node newParent = service.createDirectory(ticket, dirname, Messages.getMessage("autogenerated_description"), parent.getId()); EntityRegistry.getInstance().addNode(newParent); parent.getNodes().add(newParent); parent = newParent; } } } } String resourceName = resourceFile.getName(); // Check if the resource already exists. We will look on the // resources added for this document Iterator it = addedResources.iterator(); while (it.hasNext()) { ResourceNode node = (ResourceNode) it.next(); if (node.getName().equals(resourceName)) { if (node.getParent().equals(parent.getId())) { // Resource already exists return node; } } } // Check if the resource already exists. We will look now on the // resources added to other documents it = parent.getNodes().iterator(); while (it.hasNext()) { Node node = (Node) it.next(); if (!node.isResource()) continue; ResourceNode resourceNode = (ResourceNode) node; if (resourceNode.getName().equals(resourceName)) { return resourceNode; } } // It's a file. Create it monitor.subTask( Messages.getAndParseValue("new_document_wizard_add_resource", "%1", resourceFile.getName())); monitor.internalWorked(1); ResourceNodeProperties resourceProperties = new ResourceNodeProperties(); resourceProperties.addProperty(ResourceNodeProperties.RESOURCE_NAME, resourceName); resourceProperties.addProperty(ResourceNodeProperties.RESOURCE_TYPECODE, Types.getTypeForFile(resourcePath)); resourceProperties.addProperty(ResourceNodeProperties.RESOURCE_CONTENT, IOUtils.toByteArray(new FileInputStream(resourceFile))); resourceProperties.addProperty(ResourceNodeProperties.RESOURCE_PARENT_ID, parent.getId()); resourceProperties.addProperty(ResourceNodeProperties.RESOURCE_PATH, FileUtils.buildPath((Directory) parent, resourceName)); resourceProperties.addProperty(ResourceNodeProperties.RESOURCE_DESCRIPTION, Messages.getMessage("autogenerated_description")); ResourceNode resource = service.createResource(ticket, resourceProperties); return resource; } catch (InvalidPropertyTypeException ipte) { logger.error(ipte.getMessage(), ipte); throw new RepositoryException(ipte); } catch (PropertyNotFoundException pnfe) { logger.error(pnfe.getMessage(), pnfe); throw new RepositoryException(pnfe); } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); throw new RepositoryException(ioe); } }
From source file:org.jlibrary.core.jcr.JCRAdapter.java
public static Directory internalCreateDirectory(javax.jcr.Node node, String parentId, String repositoryId, JCRCreationContext context, String memberId, boolean lazy) throws RepositoryException { Directory directory = new Directory(); if (node.isNodeType(JCRConstants.JCR_REFERENCEABLE)) { directory.setId(node.getUUID()); } else {//from w w w. j ava 2 s . c o m if (node.hasProperty(JCRConstants.JCR_UUID)) { directory.setId(node.getProperty(JCRConstants.JCR_UUID).getValue().getString()); } else { directory.setId("temp://" + UUIDGenerator.generate(directory)); } } if (node.hasProperty(JLibraryConstants.JLIBRARY_NAME)) { directory.setName(node.getProperty(JLibraryConstants.JLIBRARY_NAME).getValue().getString()); } else { directory.setName(node.getName()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_DESCRIPTION)) { directory.setDescription( node.getProperty(JLibraryConstants.JLIBRARY_DESCRIPTION).getValue().getString()); } else { directory.setDescription(node.getName()); } directory.setParent(parentId); if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATED)) { Calendar date = node.getProperty(JLibraryConstants.JLIBRARY_CREATED).getDate(); directory.setDate(date.getTime()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATOR)) { directory.setCreator(node.getProperty(JLibraryConstants.JLIBRARY_CREATOR).getString()); } else { directory.setCreator(User.ADMIN_CODE); } if (node.hasProperty(JLibraryConstants.JLIBRARY_IMPORTANCE)) { directory.setImportance( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_IMPORTANCE).getLong())); } else { directory.setImportance(org.jlibrary.core.entities.Node.IMPORTANCE_MEDIUM); } if (node.hasProperty(JLibraryConstants.JLIBRARY_TYPECODE)) { directory.setTypecode( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_TYPECODE).getLong())); } else { directory.setTypecode(Types.FOLDER); } if (node.hasProperty(JLibraryConstants.JLIBRARY_POSITION)) { directory.setPosition( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_POSITION).getLong())); } if (node.hasProperty(JLibraryConstants.JLIBRARY_PATH)) { /* directory.setPath(node.getProperty( JLibraryConstants.JLIBRARY_PATH). getString()); */ String path = StringUtils.difference("/" + JLibraryConstants.JLIBRARY_ROOT, node.getPath()); if (path.equals("")) { path = "/"; } directory.setPath(path); } directory.setJCRPath(node.getPath()); directory.setNodes(new HashSet()); directory.setRepository(repositoryId); directory.setSize(new BigDecimal(0)); directory.setRestrictions(obtainRestrictions(node)); if (node.hasNodes()) { directory.setHasChildren(Boolean.TRUE); } if (!lazy) { NodeIterator it = node.getNodes(); while (it.hasNext()) { Node child = (Node) it.next(); if (!JCRUtils.isActive(child)) { continue; } try { if ((memberId != null) && !JCRSecurityService.canRead(child, memberId)) { continue; } } catch (SecurityException se) { logger.error(se.getMessage(), se); continue; } if (child.isNodeType(JLibraryConstants.RESOURCE_MIXIN)) { directory.getNodes().add(createResource(child, directory.getId(), repositoryId)); } else if (child.isNodeType(JLibraryConstants.DIRECTORY_MIXIN)) { directory.getNodes().add(internalCreateDirectory(child, directory.getId(), repositoryId, context, memberId, lazy)); } else if (child.isNodeType(JLibraryConstants.DOCUMENT_MIXIN)) { directory.getNodes() .add(internalCreateDocument(child, directory.getId(), repositoryId, context)); } } } return directory; }
From source file:org.jlibrary.core.jcr.JCRAdapter.java
public static ResourceNode createResource(javax.jcr.Node node, String parentId, String repositoryId) throws RepositoryException { ResourceNode resource = new ResourceNode(); if (node.isNodeType(JCRConstants.JCR_REFERENCEABLE)) { resource.setId(node.getUUID());// ww w .j a v a 2s. c o m } else { resource.setId(node.getProperty(JCRConstants.JCR_UUID).getValue().getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_NAME)) { resource.setName(node.getProperty(JLibraryConstants.JLIBRARY_NAME).getValue().getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_DESCRIPTION)) { resource.setDescription( node.getProperty(JLibraryConstants.JLIBRARY_DESCRIPTION).getValue().getString()); } resource.setJCRPath(node.getPath()); resource.setParent(parentId); if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATED)) { Calendar date = node.getProperty(JLibraryConstants.JLIBRARY_CREATED).getDate(); resource.setDate(date.getTime()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATOR)) { resource.setCreator(node.getProperty(JLibraryConstants.JLIBRARY_CREATOR).getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_IMPORTANCE)) { resource.setImportance( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_IMPORTANCE).getLong())); } if (node.hasProperty(JLibraryConstants.JLIBRARY_TYPECODE)) { resource.setTypecode( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_TYPECODE).getLong())); } if (node.hasProperty(JLibraryConstants.JLIBRARY_PATH)) { /* resource.setPath(node.getProperty( JLibraryConstants.JLIBRARY_PATH). getString()); */ String path = StringUtils.difference("/" + JLibraryConstants.JLIBRARY_ROOT, node.getPath()); resource.setPath(path); } if (node.hasProperty(JLibraryConstants.JLIBRARY_SIZE)) { resource.setSize(new BigDecimal(node.getProperty(JLibraryConstants.JLIBRARY_SIZE).getLong())); } resource.setNodes(new HashSet()); resource.setRepository(repositoryId); resource.setRestrictions(obtainRestrictions(node)); return resource; }
From source file:org.jlibrary.core.jcr.JCRAdapter.java
public static Document internalCreateDocument(javax.jcr.Node node, String parentId, String repositoryId, JCRCreationContext context) throws RepositoryException { Document document = (Document) context.getNode(node.getUUID()); if (document != null) { return document; }/*www .java 2 s . c o m*/ // Not already generated document = new Document(); DocumentMetaData metadata = new DocumentMetaData(); document.setMetaData(metadata); if (node.isNodeType(JCRConstants.JCR_REFERENCEABLE)) { document.setId(node.getUUID()); } else { document.setId(node.getProperty(JCRConstants.JCR_UUID).getValue().getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_NAME)) { document.setName(node.getProperty(JLibraryConstants.JLIBRARY_NAME).getValue().getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_DESCRIPTION)) { document.setDescription( node.getProperty(JLibraryConstants.JLIBRARY_DESCRIPTION).getValue().getString()); } document.setJCRPath(node.getPath()); document.setParent(parentId); if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATED)) { Calendar date = node.getProperty(JLibraryConstants.JLIBRARY_CREATED).getDate(); document.setDate(date.getTime()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATOR)) { document.setCreator(node.getProperty(JLibraryConstants.JLIBRARY_CREATOR).getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_IMPORTANCE)) { document.setImportance( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_IMPORTANCE).getLong())); } if (node.hasProperty(JLibraryConstants.JLIBRARY_TYPECODE)) { document.setTypecode( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_TYPECODE).getLong())); } if (node.hasProperty(JLibraryConstants.JLIBRARY_PATH)) { /* document.setPath(node.getProperty( JLibraryConstants.JLIBRARY_PATH). getString()); */ String path = StringUtils.difference("/" + JLibraryConstants.JLIBRARY_ROOT, node.getPath()); document.setPath(path); } if (node.hasProperty(JLibraryConstants.JLIBRARY_POSITION)) { document.setPosition( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_POSITION).getLong())); } if (node.hasProperty(JLibraryConstants.JLIBRARY_TITLE)) { metadata.setTitle(node.getProperty(JLibraryConstants.JLIBRARY_TITLE).getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_DOCUMENT_URL)) { metadata.setUrl(node.getProperty(JLibraryConstants.JLIBRARY_DOCUMENT_URL).getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_AUTHOR)) { String authorUUID = node.getProperty(JLibraryConstants.JLIBRARY_AUTHOR).getNode().getUUID(); javax.jcr.Node authorNode = node.getSession().getNodeByUUID(authorUUID); metadata.setAuthor(createAuthor(authorNode)); } else { metadata.setAuthor(Author.UNKNOWN); } if (node.hasProperty(JLibraryConstants.JLIBRARY_KEYWORDS)) { metadata.setKeywords(node.getProperty(JLibraryConstants.JLIBRARY_KEYWORDS).getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_LANGUAGE)) { metadata.setLanguage(node.getProperty(JLibraryConstants.JLIBRARY_LANGUAGE).getString()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_CREATION_DATE)) { Calendar date = node.getProperty(JLibraryConstants.JLIBRARY_CREATION_DATE).getDate(); metadata.setDate(date.getTime()); } if (node.hasProperty(JLibraryConstants.JLIBRARY_SIZE)) { document.setSize(new BigDecimal(node.getProperty(JLibraryConstants.JLIBRARY_SIZE).getLong())); } if (node.isLocked()) { Session session = node.getSession(); if (node.getLock().getLockOwner().equals(session.getUserID())) { try { String lockToken = node.getProperty(JCRConstants.JCR_LOCK_TOKEN).getString(); session.addLockToken(lockToken); } catch (Throwable t) { logger.error(t.getMessage(), t); } } document.setLock(createLock(node.getLock())); } document.setNodes(new HashSet()); document.setRepository(repositoryId); document.setRestrictions(obtainRestrictions(node)); // Handle resources HashSet resources = new HashSet(); if (node.hasProperty(JLibraryConstants.JLIBRARY_RESOURCES)) { javax.jcr.Property resourcesProperty = node.getProperty(JLibraryConstants.JLIBRARY_RESOURCES); Session session = node.getSession(); Value[] values = resourcesProperty.getValues(); for (int i = 0; i < values.length; i++) { String uuid = values[i].getString(); javax.jcr.Node resourceNode = session.getNodeByUUID(uuid); String resourceParentId = resourceNode.getParent().getUUID(); resources.add(createResource(resourceNode, resourceParentId, repositoryId)); } } document.setResourceNodes(resources); // Handle notes HashSet notes = new HashSet(); NodeIterator iterator = node.getNodes(); while (iterator.hasNext()) { javax.jcr.Node child = (javax.jcr.Node) iterator.next(); if (!JCRUtils.isActive(child)) { continue; } if (child.isNodeType(JLibraryConstants.NOTE_MIXIN)) { Note note = createNote(child, document); notes.add(note); } } document.setNotes(notes); // Handle versions if (node.hasNode(JCRConstants.JCR_BASE_VERSION)) { Version[] predecessors = node.getBaseVersion().getPredecessors(); if (predecessors.length > 0 && predecessors[0].getPredecessors().length > 0) { document.setLastVersionId(predecessors[0].getUUID()); } else { document.setLastVersionId(node.getUUID()); } } else { document.setLastVersionId(node.getUUID()); } context.addNode(document); try { processCustomProperties(node, document); } catch (Exception e) { logger.error(e.getMessage(), e); } // Process relations. This depends on context stored data, so it must // be done as late as possible processRelations(node, document, repositoryId, context); return document; }
From source file:org.jlibrary.core.jcr.JCRSearchService.java
private SearchResult search(Ticket ticket, javax.jcr.Session session, String strQuery, int init, int end) throws SearchException { Set results = new TreeSet(); SearchResult result = new SearchResult(); result.setItems(results);//from www .j av a2 s. com result.setInit(init); result.setEnd(end); try { Workspace workspace = session.getWorkspace(); QueryManager queryManager = workspace.getQueryManager(); javax.jcr.Node rootNode = JCRUtils.getRootNode(session); String rootPath = rootNode.getPath(); String statement = "/jcr:root" + rootPath + strQuery; javax.jcr.query.Query query = queryManager.createQuery(statement, javax.jcr.query.Query.XPATH); QueryResult queryResult = query.execute(); result.setSize(queryResult.getNodes().getSize()); RowIterator it = queryResult.getRows(); NodeIterator nodeIterator = queryResult.getNodes(); if (init != NO_PAGING) { it.skip(init); nodeIterator.skip(init); } while (it.hasNext()) { if (init != NO_PAGING && end != NO_PAGING) { if (init > end) { break; } init++; } javax.jcr.query.Row row = (javax.jcr.query.Row) it.nextRow(); String textExcerpt = ""; try { Value excerpt = row.getValue("rep:excerpt(.)"); textExcerpt = excerpt.getString(); } catch (Exception e) { logger.warn("Exception getting excerpt: " + e.getMessage()); } javax.jcr.Node node = (javax.jcr.Node) nodeIterator.nextNode(); if (node.isNodeType("nt:frozenNode")) continue; if (node.isNodeType(JLibraryConstants.CONTENT_MIXIN)) { node = node.getParent(); } try { if (!JCRSecurityService.canRead(node, ticket.getUser().getId())) { continue; } } catch (SecurityException se) { logger.error(se.getMessage(), se); continue; } double score = row.getValue(JCRConstants.JCR_SCORE).getDouble(); SearchHit sh = new SearchHit(); sh.setRepository(ticket.getRepositoryId()); sh.setId(node.getUUID()); sh.setName(node.getProperty(JLibraryConstants.JLIBRARY_NAME).getString()); String path = StringUtils.difference("/" + JLibraryConstants.JLIBRARY_ROOT, node.getPath()); sh.setPath(path); sh.setImportance( new Integer((int) node.getProperty(JLibraryConstants.JLIBRARY_IMPORTANCE).getLong())); sh.setExcerpt(textExcerpt); sh.setScore(score / 1000); results.add(sh); } //TODO: Allow for plugabble search algorithms results = searchAlgorithm.filterSearchResults(results); } catch (InvalidQueryException iqe) { logger.error(iqe.getMessage()); return result; } catch (javax.jcr.RepositoryException e) { logger.error(e.getMessage(), e); throw new SearchException(e); } return result; }
From source file:org.jlibrary.web.servlet.JLibraryContentLoaderServlet.java
private void processContent(HttpServletRequest req, HttpServletResponse resp) { try {//from www . j ava2s. c o m resp.setCharacterEncoding("ISO-8859-1"); req.setCharacterEncoding("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } String appURL = req.getContextPath(); String uri = req.getRequestURI(); String path = StringUtils.difference(appURL + "/repositories", uri); if (path.equals("") || path.equals("/")) { // call to /repositories try { Ticket ticket = TicketService.getTicketService().getSystemTicket(); List repoInfo = repositoryService.findAllRepositoriesInfo(ticket); Iterator it = repoInfo.iterator(); List<RepositoryInfo> repositories = new ArrayList<RepositoryInfo>(); while (it.hasNext()) { RepositoryInfo info = (RepositoryInfo) it.next(); if (info.getName().equals("system") || info.getName().equals("default")) { continue; } repositories.add(info); } RequestDispatcher rd = getServletContext().getRequestDispatcher("/repositories.jsp"); req.setAttribute("repositories", repositories); rd.forward(req, resp); return; } catch (Exception e) { logger.error(e.getMessage(), e); //TODO: mandar a una pgina de error esttica } } String[] pathElements = StringUtils.split(path, "/"); String repositoryName = getRepositoryName(req); Ticket ticket = TicketService.getTicketService().getTicket(req, repositoryName); Repository repository = null; try { repository = loadRepository(repositoryName, ticket); if (pathElements.length > 1) { if (pathElements[1].equals("categories")) { String categoryPath = StringUtils .difference(appURL + "/repositories/" + repositoryName + "/categories", uri); Category category = findCategory(repository, pathElements); if (category == null) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); resp.flushBuffer(); } else { String output = exportCategory(req, resp, ticket, repository, category); resp.getOutputStream().write(output.getBytes()); resp.flushBuffer(); } return; } } Node node = null; String nodePath = StringUtils.difference(appURL + "/repositories/" + repositoryName, uri); if (pathElements.length == 1) { node = repository.getRoot(); } else { node = findNode(ticket, repositoryService, nodePath); } if (node == null) { logger.debug("Node could not be found"); } else { req.setAttribute("node", node); /* resp.setDateHeader("Last-Modified", node.getDate().getTime()); resp.setDateHeader("Age", 86400); // cache a day */ if (node.isDocument()) { Document document = (Document) node; byte[] output; if ("true".equals(req.getParameter("download"))) { output = repositoryService.loadDocumentContent(document.getId(), ticket); if (document.isImage()) { resp.setContentType( Types.getMimeTypeForExtension(FileUtils.getExtension(document.getPath()))); } else { resp.setContentType("application/octet-stream"); } } else { output = exportDocument(req, ticket, repository, node).getBytes(); } resp.getOutputStream().write(output); resp.flushBuffer(); } else if (node.isDirectory()) { // Search for a root document (index.html) String output = exportDirectory(req, resp, ticket, repository, node); resp.getOutputStream().write(output.getBytes()); resp.flushBuffer(); } else if (node.isResource()) { exportResouce(req, resp, repositoryService, ticket, node); } } } catch (NodeNotFoundException nnfe) { logErrorAndForward(req, resp, repositoryName, nnfe, "The requested page could not be found."); } catch (SecurityException se) { logErrorAndForward(req, resp, repositoryName, se, "You do not have enough rights for accessing to the requested page."); } catch (Exception e) { //TODO:mandar a pgina de error esttica e.printStackTrace(); } }
From source file:org.jlibrary.web.servlet.JLibraryServlet.java
/** * Returns the repository name for a given request. The repository name can be * infered from the request URL/* w w w. j a v a 2 s . c o m*/ * * @param request HTTP Request * * @return String repository name */ protected String getRepositoryName(HttpServletRequest request) { String appURL = request.getContextPath(); String uri = request.getRequestURI(); String path = StringUtils.difference(appURL + "/repositories", uri); String[] pathElements = StringUtils.split(path, "/"); String repositoryName = pathElements[0]; return repositoryName; }
From source file:org.mule.devkit.apt.model.AnnotationProcessorIdentifiable.java
@Override public boolean hasJavaDocTag(String tagName) { String comment = elements.getDocComment(innerElement); if (StringUtils.isBlank(comment)) { return false; }/* ww w. j a v a2 s . c o m*/ StringTokenizer st = new StringTokenizer(comment.trim(), "\n\r"); while (st.hasMoreTokens()) { String nextToken = st.nextToken().trim(); if (nextToken.startsWith("@" + tagName)) { String tagContent = StringUtils.difference("@" + tagName, nextToken); return !StringUtils.isBlank(tagContent); } if (nextToken.startsWith("{@" + tagName)) { return true; } } return false; }