org.xembly.Directive Java Examples
The following examples show how to use
org.xembly.Directive.
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: TkMistakes.java From jpeek with MIT License | 6 votes |
@Override public Response act(final Request req) { return new RsPage( req, "mistakes", () -> new IterableOf<>( new XeAppend( "worst", new XeDirectives( new Joined<>( new HeadOf<Iterable<Directive>>( // @checkstyle MagicNumber (1 line) 20, new Mistakes().worst() ) ) ) ) ) ); }
Example #2
Source File: XeMemory.java From takes with MIT License | 6 votes |
/** * Ctor. * @param node Node name */ public XeMemory(final CharSequence node) { super( new XeSource() { @Override public Iterable<Directive> toXembly() { return new Directives().add(node.toString()) .attr( "total", XeMemory.mbs(Runtime.getRuntime().totalMemory()) ) .attr( "free", XeMemory.mbs(Runtime.getRuntime().freeMemory()) ) .attr( "max", XeMemory.mbs(Runtime.getRuntime().maxMemory()) ); } } ); }
Example #3
Source File: XeMillis.java From takes with MIT License | 6 votes |
@Override public Iterable<Directive> toXembly() { final Directives dirs = new Directives(); if (this.finish) { dirs.xpath(this.name.toString()) .strict(1) .xset( String.format( "%d - number(text())", System.currentTimeMillis() ) ); } else { dirs.add(this.name.toString()) .set(Long.toString(System.currentTimeMillis())); } return dirs; }
Example #4
Source File: XeLink.java From takes with MIT License | 6 votes |
/** * Ctor. * @param rel Related * @param href HREF * @param type Content type */ public XeLink(final CharSequence rel, final CharSequence href, final CharSequence type) { super( new XeSource() { @Override public Iterable<Directive> toXembly() { return new Directives() .addIf("links") .add("link") .attr("rel", rel.toString()) .attr("href", href.toString()) .attr("type", type.toString()) .up() .up(); } } ); }
Example #5
Source File: XeLifetime.java From takes with MIT License | 6 votes |
/** * Ctor. * @param elm Element name */ public XeLifetime(final CharSequence elm) { super( new XeSource() { @Override public Iterable<Directive> toXembly() { return new Directives().attr( elm.toString(), Long.toString( System.currentTimeMillis() - XeLifetime.START ) ); } } ); }
Example #6
Source File: XeWhen.java From takes with MIT License | 6 votes |
/** * Ctor. * @param condition Condition * @param positive Xembly source when condition is positive * @param negative Xembly source when condition is negative * @since 1.5 */ @SuppressWarnings ( { "PMD.CallSuperInConstructor", "PMD.ConstructorOnlyInitializesOrCallOtherConstructors" } ) public XeWhen(final Scalar<Boolean> condition, final Scalar<XeSource> positive, final Scalar<XeSource> negative) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { final Iterable<Directive> dirs; if (condition.get()) { dirs = positive.get().toXembly(); } else { dirs = negative.get().toXembly(); } return dirs; } } ); }
Example #7
Source File: XeDate.java From takes with MIT License | 6 votes |
/** * Ctor. * @param attr Attribute name */ public XeDate(final CharSequence attr) { super( new XeSource() { @Override public Iterable<Directive> toXembly() { final DateFormat fmt = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH ); fmt.setTimeZone(TimeZone.getTimeZone("UTC")); return new Directives().attr( attr.toString(), fmt.format(new Date()) ); } } ); }
Example #8
Source File: XeSla.java From takes with MIT License | 6 votes |
/** * Ctor. * @param attr Attribute name */ public XeSla(final CharSequence attr) { super( new XeSource() { @Override public Iterable<Directive> toXembly() { return new Directives().attr( attr.toString(), String.format( "%.3f", ManagementFactory.getOperatingSystemMXBean() .getSystemLoadAverage() ) ); } } ); }
Example #9
Source File: XeLocalhost.java From takes with MIT License | 6 votes |
/** * Ctor. * @param attr Attribute name */ @SuppressWarnings ( { "PMD.CallSuperInConstructor", "PMD.ConstructorOnlyInitializesOrCallOtherConstructors" } ) public XeLocalhost(final CharSequence attr) { super( new XeSource() { @Override public Iterable<Directive> toXembly() { String addr; try { addr = InetAddress.getLocalHost().getHostAddress(); } catch (final UnknownHostException ex) { addr = ex.getClass().getCanonicalName(); } return new Directives().attr(attr.toString(), addr); } } ); }
Example #10
Source File: XeFlash.java From takes with MIT License | 6 votes |
@Override public Iterable<Directive> toXembly() throws IOException { final Iterator<String> cookies = new RqCookies.Base(this.req).cookie(this.cookie).iterator(); final Directives dirs = new Directives(); if (cookies.hasNext()) { final Matcher matcher = XeFlash.PTN.matcher(cookies.next()); if (matcher.find()) { dirs.add("flash") .add("message").set( URLDecoder.decode( matcher.group(1), Charset.defaultCharset().name() ) ).up() .add("level").set(matcher.group(2)); } } return dirs; }
Example #11
Source File: XeIdentity.java From takes with MIT License | 6 votes |
/** * Ctor. * @param req Request */ public XeIdentity(final Request req) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { final Identity identity = new RqAuth(req).identity(); final Directives dirs = new Directives(); if (!identity.equals(Identity.ANONYMOUS)) { dirs.add("identity") .add("urn").set(identity.urn()).up(); for (final Map.Entry<String, String> prop : identity.properties().entrySet()) { dirs.add(prop.getKey()).set(prop.getValue()).up(); } } return dirs; } } ); }
Example #12
Source File: XmlTypeDef.java From eo with MIT License | 6 votes |
@Override @SuppressWarnings("PMD.AvoidDuplicateLiterals") public Iterator<Directive> iterator() { final Directives dir = new Directives().add("type") .attr("name", this.name); dir.add("super"); for (final String type : this.spr) { dir.add("type").attr("name", type).up(); } dir.up(); dir.add("methods"); for (final Method method : this.methods) { dir.append(method.xml()); } dir.up(); return dir.up().iterator(); }
Example #13
Source File: XmlMethodDef.java From eo with MIT License | 6 votes |
@Override @SuppressWarnings("PMD.AvoidDuplicateLiterals") public Iterator<Directive> iterator() { final Directives dir = new Directives() .add("method") .attr("name", this.name) .add("type") .attr("name", this.type) .up(); dir.add("params"); for (final Parameter param : this.params) { dir.append(param.xml()); } dir.up(); return dir.up().iterator(); }
Example #14
Source File: Results.java From jpeek with MIT License | 6 votes |
/** * Recent artifacts.. * @return List of them */ public Iterable<Iterable<Directive>> recent() { return new Mapped<>( item -> { final String[] parts = item.get("artifact").getS().split(":"); return new Directives() .add("repo") .add("group").set(parts[0]).up() .add("artifact").set(parts[1]).up() .up(); }, this.table.frame() .where("good", "true") .through( new QueryValve() .withScanIndexForward(false) .withIndexName("recent") .withConsistentRead(false) // @checkstyle MagicNumber (1 line) .withLimit(25) .withAttributesToGet("artifact") ) ); }
Example #15
Source File: Header.java From jpeek with MIT License | 6 votes |
@Override public Iterator<Directive> iterator() { try { return new Directives() .attr( "date", ZonedDateTime.now().format( DateTimeFormatter.ISO_INSTANT ) ) .attr("version", new Version().value()) .iterator(); } catch (final IOException ex) { throw new IllegalStateException(ex); } }
Example #16
Source File: RsXemblyTest.java From takes with MIT License | 5 votes |
/** * RsXembly can build XML response. * @throws IOException If some problem inside */ @Test public void buildsXmlResponse() throws IOException { MatcherAssert.assertThat( IOUtils.toString( new RsXembly( new XeStylesheet("/a.xsl"), new XeAppend( "root", new XeMillis(false), new XeSource() { @Override public Iterable<Directive> toXembly() { return new Directives().add("hey"); } }, new XeMillis(true) ) ).body(), StandardCharsets.UTF_8 ), XhtmlMatchers.hasXPaths( "/root/hey", "/root/millis", "/processing-instruction('xml-stylesheet')[contains(.,'/a')]" ) ); }
Example #17
Source File: XeAppend.java From takes with MIT License | 5 votes |
/** * Ctor. * @param target Name of XML element * @param src Source * @since 0.13 */ public XeAppend(final CharSequence target, final Iterable<XeSource> src) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { return new Directives().add(target.toString()).append( new XeChain(src).toXembly() ); } } ); }
Example #18
Source File: XeDirectives.java From takes with MIT License | 5 votes |
/** * Transform strings to directives. * @param texts Texts * @return Directives */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static Iterable<Directive> transform(final Iterable<String> texts) { final Collection<Directive> list = new LinkedList<>(); for (final String text : texts) { try { for (final Directive dir : new Directives(text)) { list.add(dir); } } catch (final SyntaxException ex) { throw new IllegalStateException(ex); } } return list; }
Example #19
Source File: XeAppend.java From takes with MIT License | 5 votes |
/** * Ctor. * @param target Name of XML element * @param src Source * @since 1.4 */ public XeAppend(final CharSequence target, final Scalar<XeSource> src) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { return new Directives().add(target.toString()).append( src.get().toXembly() ); } } ); }
Example #20
Source File: XeDirectives.java From takes with MIT License | 5 votes |
/** * Ctor. * @param dirs Directives */ public XeDirectives(final Iterable<Directive> dirs) { this( new Scalar<Iterable<Directive>>() { @Override public Iterable<Directive> get() { return dirs; } } ); }
Example #21
Source File: XeLinkHome.java From takes with MIT License | 5 votes |
/** * Ctor. * @param req Request */ public XeLinkHome(final Request req) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { return new XeLink( "home", new RqHref.Smart(new RqHref.Base(req)).home() ).toXembly(); } } ); }
Example #22
Source File: XeLinkSelf.java From takes with MIT License | 5 votes |
/** * Ctor. * @param req Request */ public XeLinkSelf(final Request req) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { return new XeLink( "self", new RqHref.Base(req).href() ).toXembly(); } } ); }
Example #23
Source File: Mistakes.java From jpeek with MIT License | 5 votes |
/** * Worst metrics. * @return List of them * @throws IOException If fails */ public Iterable<Iterable<Directive>> worst() throws IOException { return new Mapped<>( item -> new Directives() .add("metric") .attr("id", item.get("metric").getS()) .add("pos").set(item.get("pos").getN()).up() .add("neg").set(item.get("neg").getN()).up() .add("psum").set(new DyNum(item, "psum").doubleValue()).up() .add("pavg").set(new DyNum(item, "pavg").doubleValue()).up() .add("nsum").set(new DyNum(item, "nsum").doubleValue()).up() .add("navg").set(new DyNum(item, "navg").doubleValue()).up() .add("avg").set(new DyNum(item, "avg").doubleValue()).up() .add("champions").set(item.get("champions").getN()).up() .add("artifact").set(item.get("artifact").getS()).up() .add("mean").set(new DyNum(item, "mean").doubleValue()).up() .add("sigma").set(new DyNum(item, "sigma").doubleValue()).up() .up(), this.table.frame() .where("version", new Version().value()) .through( new QueryValve() .withScanIndexForward(false) .withIndexName("mistakes") .withConsistentRead(false) // @checkstyle MagicNumber (1 line) .withLimit(20) .withSelect(Select.ALL_ATTRIBUTES) ) ); }
Example #24
Source File: TypesOf.java From jpeek with MIT License | 5 votes |
@Override public Iterator<Directive> iterator() { new SignatureReader(this.singature).accept(this); final Directives dirs = new Directives().add("args"); for (final String type : this.types) { dirs.add("arg").set("?").attr("type", type).up(); } dirs.up().add("return").set(this.rtype.get()).up(); return dirs.iterator(); }
Example #25
Source File: Index.java From jpeek with MIT License | 5 votes |
@Override public Iterator<Directive> iterator() { return new Directives() .add("index") .attr("artifact", "unknown") .append(new Header()) .append( () -> new Directives() .attr( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ) .attr( "xsi:noNamespaceSchemaLocation", "xsd/index.xsd" ) .iterator() ) .append( new Joined<>( new Mapped<>( Index::metric, new Filtered<>( path -> path.getFileName().toString().matches( "^[A-Z].+\\.xml$" ), new Directory(this.output) ) ) ) ) .iterator(); }
Example #26
Source File: Object.java From eo with MIT License | 5 votes |
@Override @SuppressWarnings("PMD.AvoidDuplicateLiterals") public Iterable<Directive> xml() { final Directives dir = new Directives() .add("object") .attr("name", this.name); dir.add("types"); for (final String type : this.types) { dir.add("type").attr("name", type).up(); } dir.up(); dir.append(this.body.xml()); return dir.up(); }
Example #27
Source File: XeChain.java From takes with MIT License | 5 votes |
/** * Ctor. * @param items Sources * @since 1.5 */ public XeChain(final Scalar<Iterable<XeSource>> items) { super( new XeSource() { @Override public Iterable<Directive> toXembly() throws IOException { final Directives dirs = new Directives(); for (final XeSource src : items.get()) { dirs.push().append(src.toXembly()).pop(); } return dirs; } } ); }
Example #28
Source File: XmlParam.java From eo with MIT License | 5 votes |
@Override @SuppressWarnings("PMD.AvoidDuplicateLiterals") public Iterator<Directive> iterator() { return new Directives() .add("param") .add("name").set(this.name).up() .add("type").attr("name", this.type).up() .up().iterator(); }
Example #29
Source File: Items.java From takes with MIT License | 5 votes |
@Override @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public Iterable<Directive> toXembly() throws IOException { final Collection<XeSource> items = new LinkedList<>(); final File[] files = this.home.listFiles(); if (files != null) { for (final File file : files) { items.add(new Item(file)); } } return new Directives().add("files").append( new XeChain(items).toXembly() ); }
Example #30
Source File: Item.java From takes with MIT License | 5 votes |
@Override public Iterable<Directive> toXembly() { final String name = this.file.getName(); return new Directives().add("file") .add("name").set(name).up() .add("size").set(Long.toString(this.file.length())); }