/** * writeLink Write both data link or group link depending on the given path. * * @param pnSrcPath path of node targeted by the link * @param prRelPath path of node wearing the link * @throws NexusException */ protected void writeLink(PathNexus pnSrcPath, PathNexus prRelPath) throws NexusException { PathData pdDestNode; // Check the source node is well designed if (pnSrcPath.isRelative()) throw new NexusException("Path is invalid: the targeted path must be absolute!"); // Ensure the wearing node is a DataItem if (prRelPath.getDataItemName() == null) { PathGroup pgDest = new PathGroup(prRelPath.clone()); pdDestNode = new PathData(pgDest, generateDataName((PathGroup) pgDest, DataItem_LINK)); } else pdDestNode = (PathData) prRelPath; // Check the link is valid // PathNexus pnTgtPath = checkRelativeLinkTarget(prRelPath, pdDestNode); // Open path to get the corresponding NXlink openPath(pnSrcPath); NXlink nlLink = getNXlink(); // Create the source path if needed and open it createPath(pdDestNode, true); // Write the link getNexusFile().makenamedlink(pdDestNode.getDataItemName(), nlLink); // Update node list buffer NexusNode nnNode = pdDestNode.getCurrentNode(); pushNodeInBuffer(nnNode.getNodeName(), nnNode.getClassName()); }
/** @return the number of days displayed (0 or greater) */ public int getNumberDaysDisplayed() { if (isCanonical()) { return new Long(CommonDateOperations.approximateDifference(getEndDate(), getStartDate())) .intValue(); } return pathData.getEndDateIndex() - pathData.getStartDateIndex(); }
@Test public void processPathWithQuotasByMultipleStorageTypesContent() throws Exception { Path path = new Path("mockfs:/test"); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); PathData pathData = new PathData(path.toString(), conf); PrintStream out = mock(PrintStream.class); Count count = new Count(); count.out = out; LinkedList<String> options = new LinkedList<String>(); options.add("-q"); options.add("-t"); options.add("SSD,DISK"); options.add("dummy"); count.processOptions(options); count.processPath(pathData); String withStorageType = BYTES + StorageType.SSD.toString() + " " + StorageType.DISK.toString() + " " + pathData.toString(); verify(out).println(withStorageType); verifyNoMoreInteractions(out); }
/** * Returns a device independent representation of the receiver. * * @return the PathData for the receiver * @exception SWTException * <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed * </ul> * * @see PathData */ public PathData getPathData() { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); int count = handle.elementCount(); int pointCount = 0, typeCount = 0; byte[] types = new byte[count]; float[] pointArray = new float[count * 6]; int points = OS.malloc(3 * NSPoint.sizeof); if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES); NSPoint pt = new NSPoint(); for (int i = 0; i < count; i++) { int element = handle.elementAtIndex_associatedPoints_(i, points); switch (element) { case OS.NSMoveToBezierPathElement: types[typeCount++] = SWT.PATH_MOVE_TO; OS.memmove(pt, points, NSPoint.sizeof); pointArray[pointCount++] = (int) pt.x; pointArray[pointCount++] = (int) pt.y; break; case OS.NSLineToBezierPathElement: types[typeCount++] = SWT.PATH_LINE_TO; OS.memmove(pt, points, NSPoint.sizeof); pointArray[pointCount++] = (int) pt.x; pointArray[pointCount++] = (int) pt.y; break; case OS.NSCurveToBezierPathElement: types[typeCount++] = SWT.PATH_CUBIC_TO; OS.memmove(pt, points, NSPoint.sizeof); pointArray[pointCount++] = (int) pt.x; pointArray[pointCount++] = (int) pt.y; OS.memmove(pt, points + NSPoint.sizeof, NSPoint.sizeof); pointArray[pointCount++] = (int) pt.x; pointArray[pointCount++] = (int) pt.y; OS.memmove(pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof); pointArray[pointCount++] = (int) pt.x; pointArray[pointCount++] = (int) pt.y; break; case OS.NSClosePathBezierPathElement: types[typeCount++] = SWT.PATH_CLOSE; break; } } OS.free(points); if (pointCount != pointArray.length) { float[] temp = new float[pointCount]; System.arraycopy(pointArray, 0, temp, 0, pointCount); pointArray = temp; } PathData data = new PathData(); data.types = types; data.points = pointArray; return data; }
public static void Initialize(final Context _startContext, BootstrapDelegate delegate) throws Exception { Bootstrap.delegate = delegate; if (Bootstrap.initialized) { delegate.onBootstrapInitialised(); return; } Bootstrap.initialized = true; AppData.currentContext = _startContext; AppData.current_activity = (Activity) _startContext; creerProgressDialog(); boolean copyFiles = false; if (!PathData.IsAppDirectoryExists()) { copyFiles = true; } /* * do mkdirs, to set pathFiles architecture */ PathData.Initialize(); try { boolean b = new File(PathData.ROOT_PATH + "" + ".nomedia").createNewFile(); if (!b && !new File(PathData.ROOT_PATH + "" + ".nomedia").exists()) { System.out.println("pb creer nomedia"); } } catch (Exception e) { } boolean langueChanged = checkLanguageChanged(); copierFichiers(copyFiles, langueChanged); }
/** * @param requestPath * @return */ static PathData extractPathData(String requestPath) { PathData pathData = new PathData(); String[] tokens = requestPath.split(URL_PATH_SEPARATOR); // shareId is always the first token pathData.setShareKey(tokens[0]); String datePhraseCandidate = ""; if (tokens.length == 4) { datePhraseCandidate = tokens[1]; pathData.setEventId(tokens[2]); pathData.setRecurrenceId(tokens[3]); } else if (tokens.length == 3) { // 2nd token could be either date range or uid Matcher matcher = DR_PATTERN.matcher(tokens[1]); if (matcher.matches()) { datePhraseCandidate = tokens[1]; pathData.setEventId(tokens[2]); } else { pathData.setEventId(tokens[1]); pathData.setRecurrenceId(tokens[2]); } } else if (tokens.length == 2) { // 2nd token could be either date range or uid Matcher matcher = DR_PATTERN.matcher(tokens[1]); if (matcher.matches()) { // looks like a date range datePhraseCandidate = tokens[1]; // no eventId } else { // doesn't match dr pattern, treat as eventId pathData.setEventId(tokens[1]); } } // send the datePhraseCandidate and the PathData object processDatePhrase(datePhraseCandidate, pathData); return pathData; }
/** * checkLinkTarget open the target file and check if pointed data is a DataItem. Returns a string * array of two elements. The first is the attribute to distinguish if a DataItem or nxgroup is * pointed, the seconds is the full sibling path (completed by missing class or names). * * @param prTgtPath pointed node by the link * @param paSrcPath path of the starting node for the relative link * @return the corresponding absolute path if found, else return null */ protected PathNexus checkRelativeLinkTarget(PathNexus prTgtPath, PathData paSrcPath) { PathNexus pnTarget = null; if (paSrcPath.isRelative()) return null; // Construct an absolute path using the source and the target if (!prTgtPath.isRelative()) pnTarget = prTgtPath; // Try to open the requested absolute path try { if (pnTarget == null) { PathRelative prRelTgtPath = new PathRelative(prTgtPath); pnTarget = prRelTgtPath.generateAbsolutePath((PathNexus) paSrcPath); } openPath(pnTarget); pnTarget = getCurrentPath().clone(); closeAll(); return pnTarget; } catch (NexusException ne) { return null; } }
/** * Mutates the {@link PathData} argument, calling {@link PathData#setStartDate(Date)} and {@link * PathData#setEndDate(Date)} as appropriate. * * @param datePhraseCandidate * @param pathData */ static void processDatePhrase(final String datePhraseCandidate, final PathData pathData) { Calendar start = Calendar.getInstance(); start.set(Calendar.HOUR_OF_DAY, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); // one to represent the end of the day // use clone to ensure that start and end are the same date (DD-MM-YYYY) Calendar end = (Calendar) start.clone(); end.set(Calendar.HOUR_OF_DAY, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.set(Calendar.MILLISECOND, 0); if (StringUtils.isBlank(datePhraseCandidate)) { // short circuit and return default pathData.setDatePhrase(DEFAULT_DATE_PHRASE); pathData.setStartDate(start.getTime()); pathData.setEndDate(end.getTime()); return; } int startDays = 0; int endDays = 0; Matcher matcher = DR_PATTERN.matcher(datePhraseCandidate); if (matcher.matches()) { try { // group 1 tests for presence of "-" before first digit String firstDash = matcher.group(1); // group 2 is the first digit (corresponds with startDate) startDays = Integer.parseInt(matcher.group(2)); if (MINUS.equals(firstDash)) { // minus exists, negate startDays startDays = 0 - startDays; } // group 3 tests for presence of "-" before second digit String secondDash = matcher.group(3); // group 4 is the first digit (corresponds with startDate) endDays = Integer.parseInt(matcher.group(4)); if (MINUS.equals(secondDash)) { // minus exists, negate endDays endDays = 0 - endDays; } // lastly test if we are spanning more than MAX_RANGE // if yes, then set endDays to startDays + MAX. if (endDays - startDays > MAX_RANGE) { int newEndDays = startDays + MAX_RANGE; LOG.debug( "endDays (" + endDays + ") - startDays (" + startDays + ") is greater than maxRange, resetting endDays to " + newEndDays); endDays = newEndDays; } if (LOG.isDebugEnabled()) { LOG.debug("found dr: " + startDays + ", " + endDays); } } catch (NumberFormatException e) { startDays = 0; endDays = 0; LOG.warn("caught NumberFormatException, resetting to dr(0,0)", e); } } pathData.setStartDateIndex(startDays); pathData.setEndDateIndex(endDays); // roll start back specified days start.add(Calendar.DATE, startDays); // roll end forward specified days end.add(Calendar.DATE, endDays); // overwrite datePhrase pathData.setDatePhrase(constructDatePhrase(startDays, endDays)); pathData.setStartDate(start.getTime()); pathData.setEndDate(end.getTime()); }
/** @return */ public String getPrevDatePhrase() { return constructDatePhrase(pathData.getStartDateIndex() - 1, pathData.getEndDateIndex() - 1); }
/** @return */ public String getNextDatePhrase() { return constructDatePhrase(pathData.getStartDateIndex() + 1, pathData.getEndDateIndex() + 1); }