String tableId = (String) target.getValue(elContext); Exporter exporter = ExporterFactory.getExporterForType(exportAs); UIComponent component = event.getComponent().findComponent(tableId); if(component == null) { throw new FacesException("Cannot find component \"" + tableId + "\" in view."); } if(!(component instanceof DataTable)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable."); } DataTable table = (DataTable) component; exporter.export(context, table, outputFileName, isPageOnly, isSelectionOnly, encodingType, preProcessor, postProcessor);
/** * Exports the given node by preparing the export and calling the * abstract {@link #exportNode(String, String, Node)} method to give * control of the export format to a subclass. * <p> * This method should be called only once for an exporter instance. * * @param node node to be exported * @throws SAXException if a SAX error occurs * @throws RepositoryException if a repository error occurs */ public void export(Node node) throws RepositoryException, SAXException { handler.startDocument(); String[] prefixes = session.getNamespacePrefixes(); for (int i = 0; i < prefixes.length; i++) { if (prefixes[i].length() > 0 && !prefixes[i].equals("xml") ) { addNamespace(prefixes[i], session.getNamespaceURI(prefixes[i])); } } exportNode(node); handler.endDocument(); }
/** * Utility method for processing the named property from the given * map of properties. If the property exists, it is removed from the * given map and passed to {@link #exportProperty(Property)}. * The property is ignored if it does not exist. * * @param properties map of properties * @param name property name * @throws RepositoryException if a repository error occurs * @throws SAXException if a SAX error occurs */ private void exportProperty(Map properties, String name) throws RepositoryException, SAXException { Property property = (Property) properties.remove(name); if (property != null) { exportProperty(name, property); } }
/** * Adds the given namespace to the export. A unique prefix based on * the given prefix hint is mapped to the given namespace URI. If the * namespace is already mapped, then the existing prefix is returned. * * @param hint prefix hint * @param uri namespace URI * @return registered prefix */ protected String addNamespace(String hint, String uri) { String prefix = getPrefix(uri); if (prefix == null) { prefix = getUniquePrefix(hint); ((Map) stack.getFirst()).put(uri, prefix); } return prefix; }
exportProperty( NamespaceHelper.JCR, "primaryType", factory.createValue( helper.getJcrName("nt:share"), PropertyType.NAME)); exportProperty( NamespaceHelper.JCR, "uuid", factory.createValue(node.getUUID())); } else { SortedMap properties = getProperties(node); exportProperty(properties, helper.getJcrName("jcr:primaryType")); exportProperty(properties, helper.getJcrName("jcr:mixinTypes")); exportProperty(properties, helper.getJcrName("jcr:uuid")); Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); exportProperty(name, (Property) entry.getValue());
/** * Adds the given attribute to be included in the next element. * * @param uri namespace URI of the attribute * @param local local name of the attribute * @param value attribute value * @throws RepositoryException if a repository error occurs */ protected void addAttribute(String uri, String local, String value) throws RepositoryException { attributes.addAttribute( uri, local, getXMLName(uri, local), "CDATA", value); }
/** * Called by {@link #exportNode(String, String, Node)} to recursively * call {@link #exportNode(String, String, Node)} for each child node. * Does nothing if this exporter is not recursive. * * @param node parent node * @throws RepositoryException if a repository error occurs * @throws SAXException if a SAX error occurs */ protected void exportNodes(Node node) throws RepositoryException, SAXException { if (recurse && !share) { NodeIterator iterator = node.getNodes(); while (iterator.hasNext()) { Node child = iterator.nextNode(); exportNode(child); } } }
/** * Adds the given namespace to the export. A unique prefix based on * the given prefix hint is mapped to the given namespace URI. If the * namespace is already mapped, then the existing prefix is returned. * * @param hint prefix hint * @param uri namespace URI * @return registered prefix */ protected String addNamespace(String hint, String uri) { String prefix = getPrefix(uri); if (prefix == null) { prefix = getUniquePrefix(hint); ((Map) stack.getFirst()).put(uri, prefix); } return prefix; }
exportProperty( NamespaceHelper.JCR, "primaryType", factory.createValue( helper.getJcrName("nt:share"), PropertyType.NAME)); exportProperty( NamespaceHelper.JCR, "uuid", factory.createValue(node.getUUID())); } else { SortedMap properties = getProperties(node); exportProperty(properties, helper.getJcrName("jcr:primaryType")); exportProperty(properties, helper.getJcrName("jcr:mixinTypes")); exportProperty(properties, helper.getJcrName("jcr:uuid")); Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); exportProperty(name, (Property) entry.getValue());
/** * Adds the given attribute to be included in the next element. * * @param uri namespace URI of the attribute * @param local local name of the attribute * @param value attribute value * @throws RepositoryException if a repository error occurs */ protected void addAttribute(String uri, String local, String value) throws RepositoryException { attributes.addAttribute( uri, local, getXMLName(uri, local), "CDATA", value); }
/** * Called by {@link #exportNode(String, String, Node)} to recursively * call {@link #exportNode(String, String, Node)} for each child node. * Does nothing if this exporter is not recursive. * * @param node parent node * @throws RepositoryException if a repository error occurs * @throws SAXException if a SAX error occurs */ protected void exportNodes(Node node) throws RepositoryException, SAXException { if (recurse && !share) { NodeIterator iterator = node.getNodes(); while (iterator.hasNext()) { Node child = iterator.nextNode(); exportNode(child); } } }
private void export(String path, Exporter exporter) throws PathNotFoundException, SAXException, RepositoryException { Item item = getItem(path); if (item.isNode()) { exporter.export((Node) item); } else { throw new PathNotFoundException("XML export is not defined for properties: " + path); } }
/** * Adds the given namespace to the export. A unique prefix based on * the given prefix hint is mapped to the given namespace URI. If the * namespace is already mapped, then the existing prefix is returned. * * @param hint prefix hint * @param uri namespace URI * @return registered prefix */ protected String addNamespace(String hint, String uri) { String prefix = getPrefix(uri); if (prefix == null) { prefix = getUniquePrefix(hint); ((Map) stack.getFirst()).put(uri, prefix); } return prefix; }
/** * Exports the given node by preparing the export and calling the * abstract {@link #exportNode(String, String, Node)} method to give * control of the export format to a subclass. * <p> * This method should be called only once for an exporter instance. * * @param node node to be exported * @throws SAXException if a SAX error occurs * @throws RepositoryException if a repository error occurs */ public void export(Node node) throws RepositoryException, SAXException { handler.startDocument(); String[] prefixes = session.getNamespacePrefixes(); for (int i = 0; i < prefixes.length; i++) { if (prefixes[i].length() > 0 && !prefixes[i].equals("xml") ) { addNamespace(prefixes[i], session.getNamespaceURI(prefixes[i])); } } exportNode(node); handler.endDocument(); }
exportProperty( NamespaceHelper.JCR, "primaryType", factory.createValue( helper.getJcrName("nt:share"), PropertyType.NAME)); exportProperty( NamespaceHelper.JCR, "uuid", factory.createValue(node.getUUID())); } else { SortedMap properties = getProperties(node); exportProperty(properties, helper.getJcrName("jcr:primaryType")); exportProperty(properties, helper.getJcrName("jcr:mixinTypes")); exportProperty(properties, helper.getJcrName("jcr:uuid")); Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); exportProperty(name, (Property) entry.getValue());
/** * Adds the given attribute to be included in the next element. * * @param uri namespace URI of the attribute * @param local local name of the attribute * @param value attribute value * @throws RepositoryException if a repository error occurs */ protected void addAttribute(String uri, String local, String value) throws RepositoryException { attributes.addAttribute( uri, local, getXMLName(uri, local), "CDATA", value); }
/** * Called by {@link #exportNode(String, String, Node)} to recursively * call {@link #exportNode(String, String, Node)} for each child node. * Does nothing if this exporter is not recursive. * * @param node parent node * @throws RepositoryException if a repository error occurs * @throws SAXException if a SAX error occurs */ protected void exportNodes(Node node) throws RepositoryException, SAXException { if (recurse && !share) { NodeIterator iterator = node.getNodes(); while (iterator.hasNext()) { Node child = iterator.nextNode(); exportNode(child); } } }
/** * Utility method for processing the named property from the given * map of properties. If the property exists, it is removed from the * given map and passed to {@link #exportProperty(Property)}. * The property is ignored if it does not exist. * * @param properties map of properties * @param name property name * @throws RepositoryException if a repository error occurs * @throws SAXException if a SAX error occurs */ private void exportProperty(Map properties, String name) throws RepositoryException, SAXException { Property property = (Property) properties.remove(name); if (property != null) { exportProperty(name, property); } }
/** * Exports content at the given path using the given exporter. * * @param path of the node to be exported * @param exporter document or system view exporter * @throws SAXException if the SAX event handler failed * @throws RepositoryException if another error occurs */ private synchronized void export(String path, Exporter exporter) throws PathNotFoundException, SAXException, RepositoryException { Item item = getItem(path); if (item.isNode()) { exporter.export((Node) item); } else { throw new PathNotFoundException( "XML export is not defined for properties: " + path); } }
/** * Returns a prefixed XML name for the given namespace URI and local * name. If a prefix mapping for the namespace URI is not yet available, * it is created based on the namespace mappings of the current JCR * session. * * @param uri namespace URI * @param local local name * @return prefixed XML name * @throws RepositoryException if a JCR namespace mapping is not available */ protected String getXMLName(String uri, String local) throws RepositoryException { if (uri.length() == 0) { return local; } else { String prefix = getPrefix(uri); if (prefix == null) { prefix = getUniquePrefix(session.getNamespacePrefix(uri)); ((Map) stack.getFirst()).put(uri, prefix); } return prefix + ":" + local; } }