Пример #1
0
 private boolean isEqual(ProcessingInstruction e1, ProcessingInstruction e2) {
   String t1 = e1.getTarget();
   String t2 = e2.getTarget();
   if (!Util.isEqual(t1, t2)) return false;
   t1 = e1.getData();
   t2 = e2.getData();
   return Util.isEqual(t1, t2);
 }
 private XMLEvent handleProcessingInstruction(ProcessingInstruction pi, XMLEventFactory xef) {
   // remove all PIs since they may be copyrighted or freaky weird in other ways
   // unless its a css PI in which case we create a new one
   if (pi.getTarget().equals("xml-stylesheet") && pi.getData().toLowerCase().contains("css")) {
     return xef.createProcessingInstruction(
         "xml-stylesheet", "type=\"text/css\" href=\"dummy.css\"");
   }
   return null;
 }
Пример #3
0
 public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
   XMLEvent currentEvent = input.peek();
   if (currentEvent != null) {
     int eventType = currentEvent.getEventType();
     if (eventType != XMLStreamConstants.START_DOCUMENT
         && eventType != XMLStreamConstants.START_ELEMENT) {
       throw new XMLStreamException();
     }
     fLocationWrapper.setLocation(currentEvent.getLocation());
     fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
     loop:
     while (input.hasNext()) {
       currentEvent = input.nextEvent();
       eventType = currentEvent.getEventType();
       switch (eventType) {
         case XMLStreamConstants.START_ELEMENT:
           ++fDepth;
           StartElement start = currentEvent.asStartElement();
           fillQName(fElementQName, start.getName());
           fLocationWrapper.setLocation(start.getLocation());
           fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
           fillXMLAttributes(start);
           fillDeclaredPrefixes(start);
           addNamespaceDeclarations();
           fNamespaceContext.pushContext();
           fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
           break;
         case XMLStreamConstants.END_ELEMENT:
           EndElement end = currentEvent.asEndElement();
           fillQName(fElementQName, end.getName());
           fillDeclaredPrefixes(end);
           fLocationWrapper.setLocation(end.getLocation());
           fSchemaDOMParser.endElement(fElementQName, null);
           fNamespaceContext.popContext();
           --fDepth;
           if (fDepth <= 0) {
             break loop;
           }
           break;
         case XMLStreamConstants.CHARACTERS:
           sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
           break;
         case XMLStreamConstants.SPACE:
           sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
           break;
         case XMLStreamConstants.CDATA:
           fSchemaDOMParser.startCDATA(null);
           sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
           fSchemaDOMParser.endCDATA(null);
           break;
         case XMLStreamConstants.PROCESSING_INSTRUCTION:
           ProcessingInstruction pi = (ProcessingInstruction) currentEvent;
           fillProcessingInstruction(pi.getData());
           fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
           break;
         case XMLStreamConstants.DTD:
           /* There shouldn't be a DTD in the schema */
           break;
         case XMLStreamConstants.ENTITY_REFERENCE:
           /* Not needed for schemas */
           break;
         case XMLStreamConstants.COMMENT:
           /* No point in sending comments */
           break;
         case XMLStreamConstants.START_DOCUMENT:
           fDepth++;
           /* We automatically call startDocument before the loop */
           break;
         case XMLStreamConstants.END_DOCUMENT:
           /* We automatically call endDocument after the loop */
           break;
       }
     }
     fLocationWrapper.setLocation(null);
     fNamespaceContext.setNamespaceContext(null);
     fSchemaDOMParser.endDocument(null);
   }
 }