org.jdom.Parent Java Examples

The following examples show how to use org.jdom.Parent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SequencerModel.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Method to determine if the navigation file has changed since it was last imported. If so then we need to check for old <items> and remove them from the document
 * 
 * @param items
 */
protected void removeOldNodes(final String[] items) {
    final Vector v = new Vector();
    final List itemList = getDocument().getRootElement().getChildren(ITEM_NODE);
    if (itemList != null && !itemList.isEmpty()) {
        final Iterator itemListElement = itemList.iterator();
        while (itemListElement.hasNext()) {
            final Element anItem = (Element) itemListElement.next();
            if (!doesItemExist(anItem.getAttributeValue(ITEM_IDENTIFIER), items)) {
                // mark this node - (can't delete at the same time as looping
                // otherwise get concurrent access errors)
                v.add(anItem);
            }
        }
        final Iterator itemsToRemove = v.iterator();
        while (itemsToRemove.hasNext()) {
            final Element anItemToDelete = (Element) itemsToRemove.next();
            final Parent parent = anItemToDelete.getParent();
            if (parent != null) {
                log.warn("item no longer exists so remove " + anItemToDelete.getAttributeValue(ITEM_IDENTIFIER), null);
                parent.removeContent(anItemToDelete);
            }
        }
    }
    v.clear();
}
 
Example #2
Source File: SequencerModel.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Method to determine if the navigation file has changed since it was last imported. If so then we need to check for old <items> and remove them from the document
 * 
 * @param items
 */
protected void removeOldNodes(final String[] items) {
    final Vector v = new Vector();
    final List itemList = getDocument().getRootElement().getChildren(ITEM_NODE);
    if (itemList != null && !itemList.isEmpty()) {
        final Iterator itemListElement = itemList.iterator();
        while (itemListElement.hasNext()) {
            final Element anItem = (Element) itemListElement.next();
            if (!doesItemExist(anItem.getAttributeValue(ITEM_IDENTIFIER), items)) {
                // mark this node - (can't delete at the same time as looping
                // otherwise get concurrent access errors)
                v.add(anItem);
            }
        }
        final Iterator itemsToRemove = v.iterator();
        while (itemsToRemove.hasNext()) {
            final Element anItemToDelete = (Element) itemsToRemove.next();
            final Parent parent = anItemToDelete.getParent();
            if (parent != null) {
                log.warn("item no longer exists so remove " + anItemToDelete.getAttributeValue(ITEM_IDENTIFIER), null);
                parent.removeContent(anItemToDelete);
            }
        }
    }
    v.clear();
}
 
Example #3
Source File: DescendantIterator.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Iterator for the descendants of the supplied object.
 *
 * @param parent document or element whose descendants will be iterated
 */
DescendantIterator(Parent parent) {
    if (parent == null) {
        throw new IllegalArgumentException("parent parameter was null");
    }
    this.iterator = parent.getContent().iterator();
}
 
Example #4
Source File: StorageUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isEmpty(@Nullable Parent element) {
  if (element == null) {
    return true;
  }
  else if (element instanceof Element) {
    return JDOMUtil.isEmpty((Element)element);
  }
  else {
    Document document = (Document)element;
    return !document.hasRootElement() || JDOMUtil.isEmpty(document.getRootElement());
  }
}
 
Example #5
Source File: StorageUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void sendContent(@Nonnull StreamProvider provider, @Nonnull String fileSpec, @Nonnull Parent element, @Nonnull RoamingType type) {
  if (!provider.isApplicable(fileSpec, type)) {
    return;
  }

  try {
    doSendContent(provider, fileSpec, element, type);
  }
  catch (IOException e) {
    LOG.warn(e);
  }
}
 
Example #6
Source File: ToolsProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Parent writeScheme(@Nonnull final ToolsGroup<T> scheme) throws WriteExternalException {
  Element groupElement = new Element(TOOL_SET);
  if (scheme.getName() != null) {
    groupElement.setAttribute(ATTRIBUTE_NAME, scheme.getName());
  }

  for (T tool : scheme.getElements()) {
    saveTool(tool, groupElement);
  }

  return groupElement;
}
 
Example #7
Source File: StorageUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static byte[] writeToBytes(@Nonnull Parent element, @Nonnull String lineSeparator) throws IOException {
  UnsyncByteArrayOutputStream out = new UnsyncByteArrayOutputStream(256);
  JDOMUtil.writeParent(element, out, lineSeparator);
  return out.toByteArray();
}
 
Example #8
Source File: StorageUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static byte[] elementToBytes(@Nonnull Parent element, boolean useSystemLineSeparator) throws IOException {
  return writeToBytes(element, useSystemLineSeparator ? SystemProperties.getLineSeparator() : "\n");
}
 
Example #9
Source File: StorageUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * You must call {@link StreamProvider#isApplicable(String, com.intellij.openapi.components.RoamingType)} before
 */
public static void doSendContent(@Nonnull StreamProvider provider, @Nonnull String fileSpec, @Nonnull Parent element, @Nonnull RoamingType type) throws IOException {
  // we should use standard line-separator (\n) - stream provider can share file content on any OS
  byte[] content = elementToBytes(element, false);
  provider.saveContent(fileSpec, content, type);
}
 
Example #10
Source File: ImmutableText.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected Text setParent(Parent parent) {
  throw ImmutableElement.immutableError(this);
  //return null; // to be able to add this to the other element
}
 
Example #11
Source File: ShelveChangesManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public ShelveChangesManager(Project project, ProjectPathMacroManager projectPathMacroManager, SchemesManagerFactory schemesManagerFactory, ChangeListManager changeListManager) {
  myProject = project;
  myPathMacroSubstitutor = projectPathMacroManager.createTrackingSubstitutor();
  myBus = project.getMessageBus();
  mySchemeManager = schemesManagerFactory.createSchemesManager(SHELVE_MANAGER_DIR_PATH, new BaseSchemeProcessor<ShelvedChangeList>() {
    @Nullable
    @Override
    public ShelvedChangeList readScheme(@Nonnull Element element, boolean duringLoad) throws InvalidDataException {
      return readOneShelvedChangeList(element);
    }

    @Nonnull
    @Override
    public Parent writeScheme(@Nonnull ShelvedChangeList scheme) throws WriteExternalException {
      Element child = new Element(ELEMENT_CHANGELIST);
      scheme.writeExternal(child);
      myPathMacroSubstitutor.collapsePaths(child);
      return child;
    }
  }, RoamingType.PER_USER);

  myCleaningFuture = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      cleanSystemUnshelvedOlderOneWeek();
    }
  }, 1, 1, TimeUnit.DAYS);
  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      stopCleanScheduler();
    }
  });

  File shelfDirectory = mySchemeManager.getRootDirectory();
  myFileProcessor = new CompoundShelfFileProcessor(shelfDirectory);
  // do not try to ignore when new project created,
  // because it may lead to predefined ignore creation conflict; see ConvertExcludedToIgnoredTest etc
  if (shelfDirectory.exists()) {
    changeListManager.addDirectoryToIgnoreImplicitly(shelfDirectory.getAbsolutePath());
  }
}
 
Example #12
Source File: SchemeProcessor.java    From consulo with Apache License 2.0 votes vote down vote up
Parent writeScheme(@Nonnull T scheme) throws WriteExternalException;