if (!breadthFirst) { entering(node, currentLevel); if (maxLevel == -1 || currentLevel < maxLevel) { currentLevel++; PropertyIterator propIter = node.getProperties(); while (propIter.hasNext()) { propIter.nextProperty().accept(this); NodeIterator nodeIter = node.getNodes(); while (nodeIter.hasNext()) { nodeIter.nextNode().accept(this); leaving(node, currentLevel); } else { entering(node, currentLevel); leaving(node, currentLevel); PropertyIterator propIter = node.getProperties(); while (propIter.hasNext()) { nextQueue.addLast(propIter.nextProperty()); NodeIterator nodeIter = node.getNodes(); while (nodeIter.hasNext()) { nextQueue.addLast(nodeIter.nextNode()); e.accept(this);
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Node; public class RemoveComments { public static void main(String... args) { String h = "<html><head></head><body>" + "<div><!-- foo --><p>bar<!-- baz --></div><!--qux--></body></html>"; Document doc = Jsoup.parse(h); removeComments(doc); System.out.println(doc.html); } private static void removeComments(Node node) { for (int i = 0; i < node.childNodes().size();) { Node child = node.childNode(i); if (child.nodeName().equals("#comment")) child.remove(); else { removeComments(child); i++; } } } }
/** * Stores an attribute in this credentials instance. * * @param name a <code>String</code> specifying the name of the attribute * @param value the <code>Object</code> to be stored */ public void setAttribute(String name, Object value) { // name cannot be null if (name == null) { throw new IllegalArgumentException("name cannot be null"); } // null value is the same as removeAttribute() if (value == null) { removeAttribute(name); return; } synchronized (attributes) { attributes.put(name, value); } }
@Override public void runTest() throws Exception { Node node = session.getRootNode().getNode(ROOT_NODE_NAME); for (int i = 1; i < CHILD_COUNT; i++) { node.getNode("node" + i).setProperty("foo", "bar"); session.save(); node.getNode("node" + i).getProperty("foo").remove(); node.getNode("node0").setProperty("foo", i); session.save(); } }
private void makeRegularImage(Node node, String name, InputStream istream, String mimeType, Calendar lastModified) throws RepositoryException { if (!node.hasNode(name)) { Node child = node.addNode(name); child.setProperty(JcrConstants.JCR_DATA, node.getSession().getValueFactory().createBinary(istream)); child.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); child.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); } }
private void loadChildrenByPaths( Session session, Node parentNode ) throws Exception { NodeIterator nodeIterator = parentNode.getNodes(); while (nodeIterator.hasNext()) { Node childNode = nodeIterator.nextNode(); // this should load &cache the nodes (and their paths) session.getNode(childNode.getPath()); } }
private long getPasswordMaxAge() throws RepositoryException { Node securityNode = session.getRootNode().getNode(SECURITY_PATH); if (securityNode.hasProperty(HippoNodeType.HIPPO_PASSWORDMAXAGEDAYS)) { return (long) (securityNode.getProperty(HippoNodeType.HIPPO_PASSWORDMAXAGEDAYS).getDouble() * ONEDAYMS); } return -1l; }
private void testRead( Session session ) throws Exception { Node rootNode = session.getRootNode(); for (NodeIterator iter = rootNode.getNodes(); iter.hasNext();) { iter.nextNode(); } }
public LazyNodeWrapper(Node node) throws RepositoryException { this.workspace = node.getSession().getWorkspace().getName(); this.nodeIdentifier = node.getIdentifier(); this.node = node; }
private static boolean hasConfigurationProperties(final Session session) throws RepositoryException { final boolean oldConfigLocationExists = session.nodeExists(OLD_CODECS_CONFIGURATION_LOCATION); if (oldConfigLocationExists) { final Node node = session.getNode(OLD_CODECS_CONFIGURATION_LOCATION); return node.hasProperty(DISPLAY_CONFIGURATION_PARAMETER) || node.getProperties(NODE_CONFIGURATION_PARAMETER_PATTERN).getSize() > 0; } return false; }
protected String getPathToProperty() throws RepositoryException { String path = testRootNode.getPath() + "/" + jcrPrimaryType; if (superuser.nodeExists(path)) { throw new RepositoryException("Path " + path + " should point to property."); } return path; } }
public void call() throws RepositoryException { prop.setValue("modified"); testRootNode.getSession().save(); } }, Event.PROPERTY_CHANGED);
/** * Test if workspace-restoring a node works on checked-out node. */ @SuppressWarnings("deprecation") public void testWorkspaceRestoreOnCheckedOutNode() throws RepositoryException { if (!versionableNode.isCheckedOut()) { versionableNode.checkout(); } superuser.getWorkspace().restore(new Version[]{version}, true); }
/** * Test if workspace-restoring a node works on checked-in node. */ @SuppressWarnings("deprecation") public void testWorkspaceRestoreOnCheckedInNode() throws RepositoryException { if (versionableNode.isCheckedOut()) { versionableNode.checkin(); } superuser.getWorkspace().restore(new Version[]{version}, true); }
String str = "<paragraph>" + // "<link>XML</link>" + // " is a " + // "<strong>browser based XML editor</strong>" + // "editor allows users to edit XML data in an intuitive word processor." + // "</paragraph>"; Document domDoc = null; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes()); domDoc = docBuilder.parse(bis); } catch (Exception e) { e.printStackTrace(); } DocumentTraversal traversal = (DocumentTraversal) domDoc; NodeIterator iterator = traversal.createNodeIterator(domDoc.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true); for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) { String tagname = ((Element) n).getTagName(); System.out.println(tagname + "=" + getFirstLevelTextContent(n)); }
String getXPath(Node node) { Node parent = node.getParent(); if (parent == null) { return "/" + node.getTagName(); } return getXPath(parent) + "/" + "[@id='" + node.getAttribute("id") + "']"; }
for (Node n: chartBackground.getParent().getChildrenUnmodifiable()) { if (n != chartBackground && n != xAxis && n != yAxis) { n.setMouseTransparent(true); chartBackground.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { cursorCoords.setVisible(true); chartBackground.setOnMouseMoved(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { cursorCoords.setText( chartBackground.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { cursorCoords.setVisible(false);
table.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.isPrimaryButtonDown() && event.getClickCount() == 2) { Node node = ((Node) event.getTarget()).getParent(); TableRow row; if (node instanceof TableRow) { row = (TableRow) node; } else { // clicking on text part row = (TableRow) node.getParent(); } System.out.println(row.getItem()); } } });