public <T extends Element> Document<T> getDocument() { Document<T> document = null; if (parent != null) { if (parent instanceof Element) { document = ((Element)parent).getDocument(); } else if (parent instanceof Document) { document = (Document<T>)parent; } } return document; }
public <T extends Element> Document<T> getDocument() { return internal.getDocument(); }
public <T extends Element> Document<T> getDocument() { return internal.getDocument(); }
@SuppressWarnings("unchecked") private String getCharsetFromBase(Base base) { if (base == null) return null; if (base instanceof Document) { return ((Document)base).getCharset(); } else if (base instanceof Element) { return getCharsetFromBase(((Element)base).getDocument()); } return null; }
/** * Attempt to guess the base direction using the charset encoding. This is a bit of a last resort approach */ @SuppressWarnings("unchecked") public static <T extends Element> Direction guessDirectionFromEncoding(T element, boolean ignoredir) { if (!ignoredir && hasDirection(element)) return getDirection(element); Document doc = element.getDocument(); if (doc == null) return Direction.UNSPECIFIED; return Bidi.guessDirectionFromEncoding(doc.getCharset()); }
public void writeTo(Base base, WritableByteChannel out, WriterOptions options) throws IOException { String charset = options.getCharset(); if (charset == null) { Document doc = null; if (base instanceof Document) doc = (Document)base; else if (base instanceof Element) { doc = ((Element)base).getDocument(); } charset = doc != null ? doc.getCharset() : null; } writeTo(base, Channels.newWriter(out, charset != null ? charset : "utf-8"), options); }
@SuppressWarnings("unchecked") public void writeTo(Base base, OutputStream out, WriterOptions options) throws IOException { out = getCompressedOutputStream(out, options); String charset = options.getCharset(); if (charset == null) { if (base instanceof Document) charset = ((Document)base).getCharset(); else if (base instanceof Element) { Document doc = ((Element)base).getDocument(); if (doc != null) charset = doc.getCharset(); } if (charset == null) charset = "UTF-8"; } else { Document doc = null; if (base instanceof Document) doc = (Document)base; else if (base instanceof Element) doc = ((Element)base).getDocument(); if (doc != null) doc.setCharset(charset); } base.writeTo(new OutputStreamWriter(out, charset)); finishCompressedOutputStream(out, options); if (options.getAutoClose()) out.close(); }
public void writeTo( Base base, WritableByteChannel out, WriterOptions options) throws IOException { String charset = options.getCharset(); if (charset == null) { Document doc = null; if (base instanceof Document) doc = (Document) base; else if (base instanceof Element) { doc = ((Element)base).getDocument(); } charset = doc != null ? doc.getCharset() : null; } writeTo( base, Channels.newWriter( out, charset != null ? charset : "utf-8"), options); }
} else if (base instanceof Element) { Element el = (Element)base; if (el.getDocument() != null) { MimeType mt = el.getDocument().getContentType(); type = (mt != null) ? mt.toString() : null;
} else if (base instanceof Element) { Element el = (Element)base; if (el.getDocument() != null) { MimeType mt = el.getDocument().getContentType(); type = (mt != null) ? mt.toString() : null;
/** * Return a document */ @SuppressWarnings("unchecked") public static ResponseContext returnBase(Base base, int status, Date lastModified) { log.debug(Localizer.get("RETURNING.DOCUMENT")); BaseResponseContext response = new BaseResponseContext(base); response.setStatus(status); if (lastModified != null) response.setLastModified(lastModified); // response.setContentType(MimeTypeHelper.getMimeType(base)); Document doc = base instanceof Document ? (Document)base : ((Element)base).getDocument(); if (doc.getEntityTag() != null) { response.setEntityTag(doc.getEntityTag()); } else if (doc.getLastModified() != null) { response.setLastModified(doc.getLastModified()); } return response; }
private Document<Element> signDocument(Abdera abdera, Document<Element> doc) throws SecurityException { AbderaSecurity security = new AbderaSecurity(abdera); if (signingKey == null || cert == null) return doc; // pass through Signature sig = security.getSignature(); SignatureOptions options = sig.getDefaultSignatureOptions(); options.setCertificate(cert); options.setSigningKey(signingKey); if (algorithm != null) options.setSigningAlgorithm(algorithm); Element element = doc.getRoot(); element = sig.sign(element, options); return element.getDocument(); }