throws IOException { XmlBlob cumulative = new XmlBlob(); Collection<XmlNamespace> namespaces = cumulative.getNamespaces(); cumulative.setLang(xmlBlob.getLang()); cumulative.setBase(xmlBlob.getBase()); namespaces.addAll(xmlBlob.getNamespaces()); w.write(xmlBlob.getBlob()); cumulative.setBlob(w.toString()); return cumulative;
/** * Reverses {@link #generateCumulativeXmlBlob(ExtensionProfile)}. This * operation overwrites the current contents of this extension point. */ public void parseCumulativeXmlBlob(XmlBlob blob, ExtensionProfile extProfile, Class<? extends ExtensionPoint> extendedClass) throws IOException, ParseException { this.xmlBlob = new XmlBlob(); nonRepeatingExtensionMap.clear(); repeatingExtensionMap.clear(); // Prepare a fake XML document from the blob. StringWriter sw = new StringWriter(); XmlWriter w = new XmlWriter(sw); XmlBlob.startElement(w, null, "CUMULATIVE_BLOB", blob, null, null); XmlBlob.endElement(w, null, "CUMULATIVE_BLOB", blob); // Now parse it. StringReader sr = new StringReader(sw.toString()); XmlParser parser = new XmlParser(); parser.parse(sr, new CumulativeBlobHandler(extProfile, extendedClass), "", "CUMULATIVE_BLOB"); }
curHandler.xmlBlob.setBlob(blob.toString()); curHandler.xmlBlob.setFullText( curHandler.fullTextIndexWriter.toString());
/** * Generates XML in the Atom format. * * @param w * output writer * * @param elementName * Atom element name * * @throws IOException */ @Override public void generateAtom(XmlWriter w, String elementName) throws IOException { ArrayList<XmlWriter.Attribute> attrs = new ArrayList<XmlWriter.Attribute>(2); attrs.add(new XmlWriter.Attribute("type", "xhtml")); if (lang != null) { attrs.add(new XmlWriter.Attribute("xml:lang", lang)); } XmlBlob.startElement(w, Namespaces.atomNs, elementName, xhtml, attrs, null); XmlBlob.endElement(w, Namespaces.atomNs, elementName, xhtml); }
String lang = xml.getLang(); String base = xml.getBase(); List<XmlNamespace> blobNamespaces = xml.getNamespaces(); int additionalNsSize = (additionalNs == null ? 0 : additionalNs.size());
/** @return the XHTML contents of this text construct */ public XmlBlob getXhtml() { if (xhtml == null) { xhtml = new XmlBlob(); // init on demand } return xhtml; } /** Specifies the XHTML contents of this text construct. */
private void setPublicState(VideoEntry entry) throws Exception { YouTubeMediaGroup mediaGroup = entry.getMediaGroup(); if (mediaGroup.isPrivate()) { System.out.println("Video is private"); mediaGroup.setPrivate(false); } XmlBlob entryBlob = entry.getXmlBlob(); entryBlob.setBlob("<yt:accessControl action='list' permission='allowed'/>"); entry.setXmlBlob(entryBlob); entry.update(); }
/** Ensures that the namespace from the QName is stored with the blob. */ private void ensureBlobNamespace(ElementHandler handler, String qName) { // Get the namespace. NamespaceDecl nsDecl = null; String alias = qName.substring(0, Math.max(0, qName.indexOf(":"))); if (alias.equals("xml")) { // "xml:" doesn't need a declaration. return; } Stack<NamespaceDecl> mapping = namespaceMap.get(alias); if (mapping != null) { nsDecl = mapping.peek(); } // The namespace might be null for a namespace-less element. assert alias.length() == 0 || nsDecl != null : "Namespace alias '" + alias + "' should be mapped in 'namespaceMap'."; // Make sure the namespace is described within the blob if it was // originally declared externally to it if (nsDecl != null && !nsDecl.inBlob && nsDecl.ns != null && !handler.blobNamespaces.contains(alias)) { handler.blobNamespaces.add(alias); handler.xmlBlob.getNamespaces().add( new XmlNamespace(alias, nsDecl.ns.getUri())); } }
String lang = xmlBlob.getLang(); if (lang != null) { w.simpleElement(Namespaces.rssNs, "language", null, lang);
@Override public Content parseContent(Element element) { checkNotNull(element); String href = element.getAttribute("href"); if (href.equals("")) { StringBuilder builder = new StringBuilder(); NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node child = nodeList.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { builder.append(xmlElementOf((Element) child)); } else if (child.getNodeType() == Node.TEXT_NODE) { builder.append(child.getNodeValue()); } } XmlBlob xmlBlob = new XmlBlob(); xmlBlob.setBlob(builder.toString()); TextContent content = new TextContent(); content.setContent(new XhtmlTextConstruct(xmlBlob)); return content; } OutOfLineContent content = new OutOfLineContent(); content.setUri(href); return content; }
String lang = xml.getLang(); String base = xml.getBase(); List<XmlNamespace> blobNamespaces = xml.getNamespaces(); int additionalNsSize = (additionalNs == null ? 0 : additionalNs.size());
/** @return the XHTML contents of this text construct */ public XmlBlob getXhtml() { if (xhtml == null) { xhtml = new XmlBlob(); // init on demand } return xhtml; } /** Specifies the XHTML contents of this text construct. */
/** * Generates XML in the Atom format. * * @param w * output writer * * @param elementName * Atom element name * * @throws IOException */ @Override public void generateAtom(XmlWriter w, String elementName) throws IOException { ArrayList<XmlWriter.Attribute> attrs = new ArrayList<XmlWriter.Attribute>(2); attrs.add(new XmlWriter.Attribute("type", "xhtml")); if (lang != null) { attrs.add(new XmlWriter.Attribute("xml:lang", lang)); } XmlBlob.startElement(w, Namespaces.atomNs, elementName, xhtml, attrs, null); XmlBlob.endElement(w, Namespaces.atomNs, elementName, xhtml); }
private void setUnlistedState(VideoEntry entry) throws Exception { YouTubeMediaGroup mediaGroup = entry.getMediaGroup(); if (mediaGroup.isPrivate()) { System.out.println("Video is private"); mediaGroup.setPrivate(false); } XmlBlob xmlBlob = entry.getXmlBlob(); xmlBlob.setBlob("<yt:accessControl action='list' permission='denied'/>"); entry.setXmlBlob(xmlBlob); entry.update(); }
/** Ensures that the namespace from the QName is stored with the blob. */ private void ensureBlobNamespace(ElementHandler handler, String qName) { // Get the namespace. NamespaceDecl nsDecl = null; String alias = qName.substring(0, Math.max(0, qName.indexOf(":"))); if (alias.equals("xml")) { // "xml:" doesn't need a declaration. return; } Stack<NamespaceDecl> mapping = namespaceMap.get(alias); if (mapping != null) { nsDecl = mapping.peek(); } // The namespace might be null for a namespace-less element. assert alias.length() == 0 || nsDecl != null : "Namespace alias '" + alias + "' should be mapped in 'namespaceMap'."; // Make sure the namespace is described within the blob if it was // originally declared externally to it if (nsDecl != null && !nsDecl.inBlob && nsDecl.ns != null && !handler.blobNamespaces.contains(alias)) { handler.blobNamespaces.add(alias); handler.xmlBlob.getNamespaces().add( new XmlNamespace(alias, nsDecl.ns.getUri())); } }