Java Code Examples for org.xml.sax.ContentHandler

The following are top voted examples for showing how to use org.xml.sax.ContentHandler. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: fluentxml4j   File: AbstractSAXFilter.java   View source code 6 votes vote down vote up
@Override
public void setResult(Result result) throws IllegalArgumentException
{
	SAXResult saxResult = toSAXResult(result);

	ContentHandler handler = saxResult.getHandler();
	this.nextContentHandler = handler;
	if (handler instanceof LexicalHandler)
	{
		this.nextLexicalHandler = (LexicalHandler) handler;
	}
	if (handler instanceof DTDHandler)
	{
		this.nextDtdHandler = (DTDHandler) handler;
	}

}
 
Example 2
Project: Equella   File: PdfExtracter.java   View source code 6 votes vote down vote up
@Override
public void extractText(String mimeType, InputStream input, StringBuilder outputText, int maxSize)
	throws IOException
{
	WriteOutContentHandler wrapped = new WriteOutContentHandler(maxSize);
	ContentHandler handler = new BodyContentHandler(wrapped);
	try
	{
		Metadata meta = new Metadata();
		Parser parser = new AutoDetectParser(new TikaConfig(getClass().getClassLoader()));
		parser.parse(input, handler, meta, new ParseContext());

		appendText(handler, outputText, maxSize);
	}
	catch( Exception t )
	{
		if( wrapped.isWriteLimitReached(t) )
		{
			// keep going
			LOGGER.debug("PDF size limit reached.  Indexing truncated text");
			appendText(handler, outputText, maxSize);
			return;
		}
		throw Throwables.propagate(t);
	}
}
 
Example 3
Project: OpenJSharp   File: DOMForestParser.java   View source code 6 votes vote down vote up
public void parse(
    InputSource source,
    ContentHandler contentHandler,
    ErrorHandler errorHandler,
    EntityResolver entityResolver )
    throws SAXException, IOException {

    String systemId = source.getSystemId();
    Document dom = forest.get(systemId);

    if(dom==null) {
        // if no DOM tree is built for it,
        // let the fall back parser parse the original document.
        //
        // for example, XSOM parses datatypes.xsd (XML Schema part 2)
        // but this will never be built into the forest.
        fallbackParser.parse( source, contentHandler, errorHandler, entityResolver );
        return;
    }

    scanner.scan( dom, contentHandler );
}
 
Example 4
Project: morf   File: XmlDataSetConsumer.java   View source code 6 votes vote down vote up
/**
 * Serialise the meta data for a table.
 *
 * @param table The meta data to serialise.
 * @param contentHandler Content handler to receive the meta data xml.
 * @throws SAXException Propagates from SAX API calls.
 */
private void outputTableMetaData(Table table, ContentHandler contentHandler) throws SAXException {
  AttributesImpl tableAttributes = new AttributesImpl();
  tableAttributes.addAttribute(XmlDataSetNode.URI, XmlDataSetNode.NAME_ATTRIBUTE, XmlDataSetNode.NAME_ATTRIBUTE,
    XmlDataSetNode.STRING_TYPE, table.getName());
  contentHandler.startElement(XmlDataSetNode.URI, XmlDataSetNode.METADATA_NODE, XmlDataSetNode.METADATA_NODE, tableAttributes);

  for (Column column : table.columns()) {
    emptyElement(contentHandler, XmlDataSetNode.COLUMN_NODE, buildColumnAttributes(column));
  }

  // we need to sort the indexes by name to ensure consistency, since indexes don't have an explicit "sequence" in databases.
  List<Index> indexes = new ArrayList<>(table.indexes());
  Collections.sort(indexes, new Comparator<Index>() {
    @Override
    public int compare(Index o1, Index o2) {
      return o1.getName().compareTo(o2.getName());
    }
  });

  for (Index index : indexes) {
    emptyElement(contentHandler, XmlDataSetNode.INDEX_NODE, buildIndexAttributes(index));
  }

  contentHandler.endElement(XmlDataSetNode.URI, XmlDataSetNode.METADATA_NODE, XmlDataSetNode.METADATA_NODE);
}
 
Example 5
Project: OpenJSharp   File: FuncNormalizeSpace.java   View source code 6 votes vote down vote up
/**
 * Execute an expression in the XPath runtime context, and return the
 * result of the expression.
 *
 *
 * @param xctxt The XPath runtime context.
 *
 * @return The result of the expression in the form of a <code>XObject</code>.
 *
 * @throws javax.xml.transform.TransformerException if a runtime exception
 *         occurs.
 */
public void executeCharsToContentHandler(XPathContext xctxt,
                                            ContentHandler handler)
  throws javax.xml.transform.TransformerException,
         org.xml.sax.SAXException
{
  if(Arg0IsNodesetExpr())
  {
    int node = getArg0AsNode(xctxt);
    if(DTM.NULL != node)
    {
      DTM dtm = xctxt.getDTM(node);
      dtm.dispatchCharactersEvents(node, handler, true);
    }
  }
  else
  {
    XObject obj = execute(xctxt);
    obj.dispatchCharactersEvents(handler);
  }
}
 
Example 6
Project: monarch   File: XmlGeneratorUtilsJUnitTest.java   View source code 6 votes vote down vote up
/**
 * Test method for {@link XmlGeneratorUtils#endElement(ContentHandler, String, String)}.
 */
@Test
public void testEndElementContentHandlerStringString() throws SAXException {
  final AtomicReference<String> uriRef = new AtomicReference<String>();
  final AtomicReference<String> localnameRef = new AtomicReference<String>();
  final AtomicReference<String> qNameRef = new AtomicReference<String>();

  final ContentHandler contentHandler = new MockContentHandler() {
    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
      uriRef.set(uri);
      localnameRef.set(localName);
      qNameRef.set(qName);
    }
  };

  XmlGeneratorUtils.endElement(contentHandler, "prefix", "localname");
  assertEquals("localname", localnameRef.get());
  assertEquals("prefix:localname", qNameRef.get());
  assertEquals(NULL_NS_URI, uriRef.get());
}
 
Example 7
Project: azeroth   File: XLSX2CSV.java   View source code 5 votes vote down vote up
/**
 * Parses and shows the content of one sheet using the specified styles and
 * shared-strings tables.
 *
 * @param styles
 * @param strings
 * @param sheetInputStream
 */
public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler,
                         InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException {
    DataFormatter formatter = new DataFormatter();
    InputSource sheetSource = new InputSource(sheetInputStream);
    try {
        XMLReader sheetParser = SAXHelper.newXMLReader();
        ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false);
        sheetParser.setContentHandler(handler);
        sheetParser.parse(sheetSource);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
    }
}
 
Example 8
Project: openjdk-jdk10   File: ValidatorHandlerTest.java   View source code 5 votes vote down vote up
@Test
public void testContentHandler() {
    ValidatorHandler validatorHandler = getValidatorHandler();
    assertNull(validatorHandler.getContentHandler(), "When ValidatorHandler is created, initially ContentHandler should not be set.");

    ContentHandler handler = new DefaultHandler();
    validatorHandler.setContentHandler(handler);
    assertSame(validatorHandler.getContentHandler(), handler);

    validatorHandler.setContentHandler(null);
    assertNull(validatorHandler.getContentHandler());

}
 
Example 9
Project: DirectLeaks-AntiReleak-Remover   File: Processor.java   View source code 5 votes vote down vote up
public final ContentHandler createContentHandler() {
    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    return new ASMContentHandler(cw) {
        @Override
        public void endDocument() throws SAXException {
            try {
                os.write(cw.toByteArray());
            } catch (IOException e) {
                throw new SAXException(e);
            }
        }
    };
}
 
Example 10
Project: openjdk-jdk10   File: ParserAdapterTest.java   View source code 5 votes vote down vote up
/**
 * Verifies parserAdapter.getContentHandler()
 */
@Test
public void contentHandler01() {
    ContentHandler contentHandler = new XMLFilterImpl();
    parserAdapter.setContentHandler(contentHandler);
    assertNotNull(parserAdapter.getContentHandler());
}
 
Example 11
Project: openjdk-jdk10   File: DOM2SAX.java   View source code 5 votes vote down vote up
public void setContentHandler(ContentHandler handler) throws
    NullPointerException
{
    _sax = handler;
    if (handler instanceof LexicalHandler) {
        _lex = (LexicalHandler)handler;
    }

    if (handler instanceof SAXImpl) {
        _saxImpl = (SAXImpl)handler;
    }
}
 
Example 12
Project: fastAOP   File: Processor.java   View source code 5 votes vote down vote up
private void processEntry(final ZipInputStream zis, final ZipEntry ze,
        final ContentHandlerFactory handlerFactory) {
    ContentHandler handler = handlerFactory.createContentHandler();
    try {

        // if (CODE2ASM.equals(command)) { // read bytecode and process it
        // // with TraceClassVisitor
        // ClassReader cr = new ClassReader(readEntry(zis, ze));
        // cr.accept(new TraceClassVisitor(null, new PrintWriter(os)),
        // false);
        // }

        boolean singleInputDocument = inRepresentation == SINGLE_XML;
        if (inRepresentation == BYTECODE) { // read bytecode and process it
            // with handler
            ClassReader cr = new ClassReader(readEntry(zis, ze));
            cr.accept(new SAXClassAdapter(handler, singleInputDocument), 0);

        } else { // read XML and process it with handler
            XMLReader reader = XMLReaderFactory.createXMLReader();
            reader.setContentHandler(handler);
            reader.parse(new InputSource(
                    singleInputDocument ? (InputStream) new ProtectedInputStream(
                            zis) : new ByteArrayInputStream(readEntry(zis,
                            ze))));

        }
    } catch (Exception ex) {
        update(ze.getName(), 0);
        update(ex, 0);
    }
}
 
Example 13
Project: alfresco-repository   File: ViewXMLExporter.java   View source code 5 votes vote down vote up
/**
 * Construct
 * 
 * @param namespaceService  namespace service
 * @param nodeService  node service
 * @param contentHandler  content handler
 */
ViewXMLExporter(NamespaceService namespaceService, NodeService nodeService, SearchService searchService,
        DictionaryService dictionaryService, PermissionService permissionService, ContentHandler contentHandler)
{
    this.namespaceService = namespaceService;
    this.nodeService = nodeService;
    this.searchService = searchService;
    this.dictionaryService = dictionaryService;
    this.permissionService = permissionService;
    this.contentHandler = contentHandler;
    
    VIEW_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, VIEW_LOCALNAME, namespaceService);
    VALUE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUE_LOCALNAME, namespaceService);
    VALUES_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, VALUES_LOCALNAME, namespaceService);
    CHILDNAME_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, CHILDNAME_LOCALNAME, namespaceService);
    ASPECTS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ASPECTS_LOCALNAME, namespaceService);
    PROPERTIES_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, PROPERTIES_LOCALNAME, namespaceService);
    ASSOCIATIONS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ASSOCIATIONS_LOCALNAME, namespaceService);
    DATATYPE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, DATATYPE_LOCALNAME, namespaceService);
    ISNULL_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ISNULL_LOCALNAME, namespaceService);
    METADATA_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, METADATA_LOCALNAME, namespaceService);
    EXPORTEDBY_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDBY_LOCALNAME, namespaceService);
    EXPORTEDDATE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTEDDATE_LOCALNAME, namespaceService);
    EXPORTERVERSION_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTERVERSION_LOCALNAME, namespaceService);
    EXPORTOF_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, namespaceService);
    ACL_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ACL_LOCALNAME, namespaceService);
    ACE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ACE_LOCALNAME, namespaceService);
    ACCESS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, ACCESS_LOCALNAME, namespaceService);
    AUTHORITY_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, AUTHORITY_LOCALNAME, namespaceService);
    PERMISSION_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, PERMISSION_LOCALNAME, namespaceService);
    INHERITPERMISSIONS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, INHERITPERMISSIONS_LOCALNAME, namespaceService);
    REFERENCE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, REFERENCE_LOCALNAME, namespaceService);
    PATHREF_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, PATHREF_LOCALNAME, namespaceService);
    NODEREF_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, NODEREF_LOCALNAME, namespaceService);
    LOCALE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, LOCALE_LOCALNAME, namespaceService);
    MLVALUE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, MLVALUE_LOCALNAME, namespaceService);

}
 
Example 14
Project: openjdk-jdk10   File: Bridge.java   View source code 5 votes vote down vote up
/**
 * @since 2.0.2
 */
public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
    Marshaller m = context.marshallerPool.take();
    m.setAttachmentMarshaller(am);
    marshal(m,object,contentHandler);
    m.setAttachmentMarshaller(null);
    context.marshallerPool.recycle(m);
}
 
Example 15
Project: alfresco-repository   File: TikaOfficeDetectParser.java   View source code 5 votes vote down vote up
/**
 * @deprecated This method will be removed in Apache Tika 1.0.
 */
public void parse(InputStream stream,
      ContentHandler handler, Metadata metadata)
      throws IOException, SAXException, TikaException 
{
   parse(stream, handler, metadata, new ParseContext());
}
 
Example 16
Project: OpenJSharp   File: NamespaceMappings.java   View source code 5 votes vote down vote up
/**
 * Pop, or undeclare all namespace definitions that are currently
 * declared at the given element depth, or deepter.
 * @param elemDepth the element depth for which mappings declared at this
 * depth or deeper will no longer be valid
 * @param saxHandler The ContentHandler to notify of any endPrefixMapping()
 * calls.  This parameter can be null.
 */
void popNamespaces(int elemDepth, ContentHandler saxHandler)
{
    while (true)
    {
        if (m_nodeStack.isEmpty())
            return;
        MappingRecord map = (MappingRecord)(m_nodeStack.peek());
        int depth = map.m_declarationDepth;
        if (depth < elemDepth)
            return;
        /* the depth of the declared mapping is elemDepth or deeper
         * so get rid of it
         */

        map = (MappingRecord) m_nodeStack.pop();
        final String prefix = map.m_prefix;
        popNamespace(prefix);
        if (saxHandler != null)
        {
            try
            {
                saxHandler.endPrefixMapping(prefix);
            }
            catch (SAXException e)
            {
                // not much we can do if they aren't willing to listen
            }
        }

    }
}
 
Example 17
Project: hadoop   File: FSEditLogOp.java   View source code 5 votes vote down vote up
@Override
protected void toXml(ContentHandler contentHandler) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "SRC", src);
  XMLUtils.addSaxString(contentHandler, "NSQUOTA",
      Long.toString(nsQuota));
  XMLUtils.addSaxString(contentHandler, "DSQUOTA",
      Long.toString(dsQuota));
}
 
Example 18
Project: OpenJSharp   File: TreeWalker.java   View source code 5 votes vote down vote up
/**
 * Constructor.
 * @param   contentHandler The implemention of the
 * contentHandler operation (toXMLString, digest, ...)
 */
public TreeWalker(ContentHandler contentHandler, DOMHelper dh)
{
  this.m_contentHandler = contentHandler;
  m_contentHandler.setDocumentLocator(m_locator);
  try {
     // Bug see Bugzilla  26741
    m_locator.setSystemId(SecuritySupport.getSystemProperty("user.dir") + File.separator + "dummy.xsl");
  }
  catch (SecurityException se){// user.dir not accessible from applet
  }
  m_dh = dh;
}
 
Example 19
Project: openjdk-jdk10   File: TagInfoset.java   View source code 5 votes vote down vote up
/**
 * Writes the end element event.
 */
public void writeEnd(ContentHandler contentHandler) throws SAXException{
    contentHandler.endElement(fixNull(nsUri),localName,getQName());
    for( int i=ns.length-2; i>=0; i-=2 ) {
        contentHandler.endPrefixMapping(fixNull(ns[i]));
    }
}
 
Example 20
Project: OpenJSharp   File: ToSAXHandler.java   View source code 5 votes vote down vote up
public ToSAXHandler(
    ContentHandler hdlr,
    LexicalHandler lex,
    String encoding)
{
    setContentHandler(hdlr);
    setLexHandler(lex);
    setEncoding(encoding);
}
 
Example 21
Project: hadoop   File: FSEditLogOp.java   View source code 5 votes vote down vote up
@Override
protected void toXml(ContentHandler contentHandler) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "LENGTH",
      Integer.toString(length));
  XMLUtils.addSaxString(contentHandler, "INODEID",
      Long.toString(inodeId));
  XMLUtils.addSaxString(contentHandler, "PATH", path);
  XMLUtils.addSaxString(contentHandler, "REPLICATION",
      Short.valueOf(replication).toString());
  XMLUtils.addSaxString(contentHandler, "MTIME",
      Long.toString(mtime));
  XMLUtils.addSaxString(contentHandler, "ATIME",
      Long.toString(atime));
  XMLUtils.addSaxString(contentHandler, "BLOCKSIZE",
      Long.toString(blockSize));
  XMLUtils.addSaxString(contentHandler, "CLIENT_NAME", clientName);
  XMLUtils.addSaxString(contentHandler, "CLIENT_MACHINE", clientMachine);
  XMLUtils.addSaxString(contentHandler, "OVERWRITE", 
      Boolean.toString(overwrite));
  for (Block b : blocks) {
    FSEditLogOp.blockToXml(contentHandler, b);
  }
  FSEditLogOp.permissionStatusToXml(contentHandler, permissions);
  if (this.opCode == OP_ADD) {
    if (aclEntries != null) {
      appendAclEntriesToXml(contentHandler, aclEntries);
    }
    appendRpcIdsToXml(contentHandler, rpcClientId, rpcCallId);
  }
}
 
Example 22
Project: morf   File: XmlDataSetConsumer.java   View source code 5 votes vote down vote up
/**
 * @param outputStream The output
 * @return A content handler
 * @throws IOException When there's an XML error
 */
private ContentHandler createContentHandler(OutputStream outputStream) throws IOException {
  Properties outputProperties = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
  outputProperties.setProperty("indent", "yes");
  outputProperties.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, "2");
  outputProperties.setProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR, "\n");
  Serializer serializer = SerializerFactory.getSerializer(outputProperties);
  serializer.setOutputStream(outputStream);
  return serializer.asContentHandler();
}
 
Example 23
Project: OpenJSharp   File: ForkingFilter.java   View source code 5 votes vote down vote up
/**
 * Starts the event forking.
 */
public void startForking(String uri, String localName, String qName, Attributes atts, ContentHandler side) throws SAXException {
    if(this.side!=null)     throw new IllegalStateException();  // can't fork to two handlers

    this.side = side;
    depth = 1;
    side.setDocumentLocator(loc);
    side.startDocument();
    for( int i=0; i<namespaces.size(); i+=2 )
        side.startPrefixMapping(namespaces.get(i),namespaces.get(i+1));
    side.startElement(uri,localName,qName,atts);
}
 
Example 24
Project: OpenJSharp   File: FaultDetailHeader.java   View source code 5 votes vote down vote up
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException {
    String nsUri = av.nsUri;
    String ln = av.faultDetailTag.getLocalPart();

    h.startPrefixMapping("",nsUri);
    h.startElement(nsUri,ln,ln,EMPTY_ATTS);
    h.startElement(nsUri,wrapper,wrapper,EMPTY_ATTS);
    h.characters(problemValue.toCharArray(),0,problemValue.length());
    h.endElement(nsUri,wrapper,wrapper);
    h.endElement(nsUri,ln,ln);
}
 
Example 25
Project: hadoop   File: FSEditLogOp.java   View source code 5 votes vote down vote up
@Override
protected void toXml(ContentHandler contentHandler) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "LENGTH",
      Integer.toString(length));
  XMLUtils.addSaxString(contentHandler, "PATH", path);
  XMLUtils.addSaxString(contentHandler, "MTIME",
      Long.toString(mtime));
  XMLUtils.addSaxString(contentHandler, "ATIME",
      Long.toString(atime));
}
 
Example 26
Project: openjdk-jdk10   File: ForkContentHandler.java   View source code 5 votes vote down vote up
/**
 * Creates ForkContentHandlers so that the specified handlers
 * will receive SAX events in the order of the array.
 */
public static ContentHandler create( ContentHandler[] handlers ) {
        if(handlers.length==0)
                throw new IllegalArgumentException();

        ContentHandler result = handlers[0];
        for( int i=1; i<handlers.length; i++ )
                result = new ForkContentHandler( result, handlers[i] );
        return result;
}
 
Example 27
Project: monarch   File: MockCacheExtensionXmlGenerator.java   View source code 5 votes vote down vote up
@Override
public void generate(CacheXmlGenerator cacheXmlGenerator) throws SAXException {
  final ContentHandler handler = cacheXmlGenerator.getContentHandler();

  try {
    handler.startPrefixMapping(PREFIX, NAMESPACE);

    final AttributesImpl atts = new AttributesImpl();
    addAttribute(atts, ATTRIBUTE_VALUE, extension.getValue());
    emptyElement(handler, PREFIX, ELEMENT_CACHE, atts);
  } finally {
    handler.endPrefixMapping("mock");
  }
}
 
Example 28
Project: OpenJSharp   File: SAAJMessage.java   View source code 5 votes vote down vote up
/**
 * Collects the ns declarations and starts the prefix mapping, consequently the associated endPrefixMapping needs to be called.
 * @param contentHandler
 * @param attrs
 * @param excludePrefix , this is to excldue the global prefix mapping "S" used at the start
 * @throws SAXException
 */
private void startPrefixMapping(ContentHandler contentHandler, NamedNodeMap attrs, String excludePrefix) throws SAXException {
    if(attrs == null)
        return;
    for(int i=0; i < attrs.getLength();i++) {
        Attr a = (Attr)attrs.item(i);
        //check if attr is ns declaration
        if("xmlns".equals(a.getPrefix()) || "xmlns".equals(a.getLocalName())) {
            if(!fixNull(a.getPrefix()).equals(excludePrefix)) {
                contentHandler.startPrefixMapping(fixNull(a.getPrefix()), a.getNamespaceURI());
            }
        }
    }
}
 
Example 29
Project: OpenJSharp   File: StAXStream2SAX.java   View source code 5 votes vote down vote up
public void setContentHandler(ContentHandler handler) throws
    NullPointerException
{
    _sax = handler;
    if (handler instanceof LexicalHandler) {
        _lex = (LexicalHandler) handler;
    }

    if (handler instanceof SAXImpl) {
        _saxImpl = (SAXImpl)handler;
    }
}
 
Example 30
Project: openjdk-jdk10   File: DOMScanner.java   View source code 5 votes vote down vote up
/**
 * Parses a subtree starting from the element e and
 * reports SAX2 events to the specified handler.
 *
 * @deprecated in JAXB 2.0
 *      Use {@link #scan(Element)}
 */
public void parse( Element e, ContentHandler handler ) throws SAXException {
    // it might be better to set receiver at the constructor.
    receiver = handler;

    setCurrentLocation( e );
    receiver.startDocument();

    receiver.setDocumentLocator(locator);
    visit(e);

    setCurrentLocation( e );
    receiver.endDocument();
}
 
Example 31
Project: OpenJSharp   File: OldBridge.java   View source code 5 votes vote down vote up
/**
 * @since 2.0.2
 */
public final void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
    Marshaller m = context.marshallerPool.take();
    m.setAttachmentMarshaller(am);
    marshal(m,object,contentHandler);
    m.setAttachmentMarshaller(null);
    context.marshallerPool.recycle(m);
}
 
Example 32
Project: which-food-uptec-cli   File: App.java   View source code 5 votes vote down vote up
private static String parse(final InputStream input) throws TikaException, SAXException, IOException {
    final Parser parser = new PDFParser();
    final ContentHandler handler = new BodyContentHandler();
    final Metadata metadata = new Metadata();
    final ParseContext parseContext = new ParseContext();

    parser.parse(input, handler, metadata, parseContext);

    return handler.toString();
}
 
Example 33
Project: hadoop   File: FSEditLogOp.java   View source code 5 votes vote down vote up
@Override
protected void toXml(ContentHandler contentHandler) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "LENGTH",
      Integer.toString(length));
  XMLUtils.addSaxString(contentHandler, "SRC", src);
  XMLUtils.addSaxString(contentHandler, "DST", dst);
  XMLUtils.addSaxString(contentHandler, "TIMESTAMP",
      Long.toString(timestamp));
  appendRpcIdsToXml(contentHandler, rpcClientId, rpcCallId);
}
 
Example 34
Project: openjdk-jdk10   File: JAXPValidatorComponent.java   View source code 4 votes vote down vote up
public ContentHandler getContentHandler() {
    return fContentHandler;
}
 
Example 35
Project: OpenJSharp   File: EmptySerializer.java   View source code 4 votes vote down vote up
/**
 * @see SerializationHandler#setContentHandler(org.xml.sax.ContentHandler)
 */
public void setContentHandler(ContentHandler ch)
{
    aMethodIsCalled();
}
 
Example 36
Project: DirectLeaks-AntiReleak-Remover   File: SAXAdapter.java   View source code 4 votes vote down vote up
protected ContentHandler getContentHandler() {
    return h;
}
 
Example 37
Project: openjdk-jdk10   File: ToSAXHandler.java   View source code 4 votes vote down vote up
public ToSAXHandler(ContentHandler handler, String encoding) {
    setContentHandler(handler);
    setEncoding(encoding);
}
 
Example 38
Project: OpenJSharp   File: BridgeImpl.java   View source code 4 votes vote down vote up
public void marshal(Marshaller _m, T t, ContentHandler contentHandler) throws JAXBException {
    MarshallerImpl m = (MarshallerImpl)_m;
    m.write(tagName,bi,t,new SAXOutput(contentHandler),null);
}
 
Example 39
Project: monarch   File: CacheXmlGenerator.java   View source code 4 votes vote down vote up
public ContentHandler getContentHandler() {
  return this.handler;
}
 
Example 40
Project: openjdk-jdk10   File: EmptySerializer.java   View source code 4 votes vote down vote up
/**
 * @see SerializationHandler#setContentHandler(org.xml.sax.ContentHandler)
 */
public void setContentHandler(ContentHandler ch) {
    aMethodIsCalled();
}