@Override public Alias getAliasByName(String name) { Alias ret = aliases.get(name); if (ret == null) Log.get().warning("Warning: cannot resolve alias '" + name + "'"); return ret; }
public static void main(String[] args) { System.out.println(Log.LOG_DATETIME_FORMATTER.format(new Date())); System.out.println(Log.XSD_DATETIME_FORMATTER.format(new Date())); //Log.addHandler(new SystemOutHandler()); Log.get().severe("started"); Log.get().severe("finished"); } private static List<Handler> handlers = new ArrayList<>();
public void printStructure() { Log.get().finest(projlib + " -> " + this); children.forEach(c -> ((LibraryItem)c).printStructure()); }
public default Optional<Item> getChild(String name) { List<Item> items = getChildren().stream().filter(item -> name.equals(item.getName())).collect(Collectors.toList()); if (items.size() == 0) return Optional.empty(); if (items.size() > 1) { Log.get().info(items.toString()); } return Optional.of(items.get(0)); } public boolean isFolder();
public Path createItem(Item parent, String name, boolean isFolder) { Path newItemPath = (parent == null ? Paths.get("/") : parent.getPath()).resolve(name); Path relativePath = Paths.get(newItemPath.toString().substring(1)); // remove starting \ Path p = deploymentPath.resolve(relativePath); if (isFolder) { if (!p.toFile().mkdirs()) { //throw new RuntimeException("Could not create directory, directory already exists (" + p + ")"); } Log.get().info("new dir " + p); } else { try { if (!p.toFile().createNewFile()) { //throw new RuntimeException("Could not create file, file already exists (" + p + ")"); } Log.get().info("new file " + p); } catch (IOException e) { throw new RuntimeException("Could not create file (" + p + ")", e); } } return relativePath; } @Override
public void print(Path rootPath) { Path currentPath = rootPath.resolve(getName()); Log.get().finest(currentPath + " ~ " + alternatives.stream() .map(item -> item.getItemSource().getAbsolutePath()).collect(Collectors.toList())); Log.get().finest(getPath() + " ~ " + alternatives.stream() .map(item -> item.getItemSource().getAbsolutePath()).collect(Collectors.toList())); getChildren().forEach(child -> ((RepositoryItem) child).print(currentPath)); }
public static void print(GlobalVariables vars) { Log.get().finest(vars.getPath() + "\n" + vars.getAllVariables().toString().replaceAll("],", "]\n")); vars.getChildVariables().forEach(v -> print(v)); }
public void save() { if (isChanged()) { Path p = inMemoryChangesImpl.getDeployment().createItem(parent, getName(), isFolder); if (hasContent()) { try (FileOutputStream stream = new FileOutputStream(inMemoryChangesImpl.getDeployment().getAbsolutePath().resolve(p).toFile())) { stream.write(content); Log.get().info("File stored: " + p); } catch (IOException e) { throw new RuntimeException("Cannot save item (" + p + ")", e); } } //getChildren().forEach(item -> ((InMemoryChangesItem)item).save()); } } @Override
node.setCDataContent(((CDATASection)n).getData()); default: Log.get().warning("unknown type: " + n.getNodeType()); break;
public void modify() { if (!changed) { Log.get().info("modifying item: " + getPath()); name = originalItem.getName(); isFolder = originalItem.isFolder(); path = originalItem.getPath(); if (isFolder) { children.addAll(getChildren()); } //children = isFolder ? getChildren() : children; if (!isFolder) { try (InputStream stream = originalItem.getContent()) { content = IOUtils.toByteArray(stream); } catch (IOException e) { throw new RuntimeException("Cannot copy content from original item (path = " + path + ")", e); } } if (parent != null) parent.modify(); changed = true; } } @Override
public static void main(String[] args) throws FileNotFoundException { /*File wsdl = new File("T:\\source\\dev\\SBLCRM_WS_IO\\WSDL\\Siebel\\AccountManagement_UpsertBillingProfile_v2.1.wsdl"); InputStream is = new FileInputStream(wsdl); XmlBuilderFactory f = new XmlBuilderFactory(); NodeBuilder n = f.parseDocument(is); System.out.println(n);*/ XmlBuilderFactory f = new XmlBuilderFactory(); NodeBuilder x = f.createRootElement("test"); x. addChild("a"). addChild("aa").getParent(). addChild("aa").getParent(). getParent(). addChild("b"). addChild("bb"). addChild("bbb"); x.search(true, n -> { Log.get().info(n.getName()); return true; }).toArray(); Log.get().info(x.toString()); } }
public static void main(String[] args) { l.setLevel(Level.FINEST); Node n = new Node(); n.add("s").add("b").add("c"); BaseRecursiveIterator<Node> b = new BaseRecursiveIterator<Node>(new ChildrenAccessor<Node>() { @Override public Iterable<Node> getChildren(Node currentItem) { l.finest("getting children"); return currentItem.getNodes(); } }, new Predicate<Node>() { @Override public boolean test(Node t) { l.fine("exec " + t.getName()); return "x".equals(t.getName()); } }, true, n); b.next(); Log.get(); } }