Java Code Examples for javax.xml.parsers.DocumentBuilderFactory#setIgnoringComments()

The following examples show how to use javax.xml.parsers.DocumentBuilderFactory#setIgnoringComments() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Ensures the namespace declared by {@link ClusteringCacheManagerServiceConfigurationParser} and its
 * schema are the same.
 */
@Test
public void testSchema() throws Exception {
  final ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser();
  final StreamSource schemaSource = (StreamSource) parser.getXmlSchema();

  final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setIgnoringComments(true);
  factory.setIgnoringElementContentWhitespace(true);

  final DocumentBuilder domBuilder = factory.newDocumentBuilder();
  final Element schema = domBuilder.parse(schemaSource.getInputStream()).getDocumentElement();
  final Attr targetNamespaceAttr = schema.getAttributeNode("targetNamespace");
  assertThat(targetNamespaceAttr, is(not(nullValue())));
  assertThat(targetNamespaceAttr.getValue(), is(parser.getNamespace().toString()));
}
 
Example 2
/**
 * Initializes the pool with a new set of configuration options.
 * 
 * @throws XMLParserException thrown if there is a problem initialzing the pool
 */
protected synchronized void initializePool() throws XMLParserException {
    if (!dirtyBuilderConfiguration) {
        // in case the pool was initialized by some other thread
        return;
    }

    DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
    setAttributes(newFactory, builderAttributes);
    setFeatures(newFactory, builderFeatures);
    newFactory.setCoalescing(coalescing);
    newFactory.setExpandEntityReferences(expandEntityReferences);
    newFactory.setIgnoringComments(ignoreComments);
    newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
    newFactory.setNamespaceAware(namespaceAware);
    newFactory.setSchema(schema);
    newFactory.setValidating(dtdValidating);
    newFactory.setXIncludeAware(xincludeAware);

    poolVersion++;
    dirtyBuilderConfiguration = false;
    builderFactory = newFactory;
    builderPool.clear();
}
 
Example 3
public GlueSettingsParser() throws ResourceParseException {
	try {
		setTypeMappings();
		setStyleMappings();
		DocumentBuilderFactory factory = DocumentBuilderFactory
				.newInstance();
		factory.setIgnoringElementContentWhitespace(true);
		factory.setIgnoringComments(true);
		root = factory.newDocumentBuilder()
				.parse(AjLatexMath.getAssetManager().open(RESOURCE_NAME))
				.getDocumentElement();
		parseGlueTypes();
	} catch (Exception e) { // JDOMException or IOException
		throw new XMLResourceParseException(RESOURCE_NAME, e);
	}
}
 
Example 4
private static Document loadPrefsDoc(InputStream in)
    throws SAXException, IOException
{
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setValidating(true);
    dbf.setCoalescing(true);
    dbf.setIgnoringComments(true);
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setEntityResolver(new Resolver());
        db.setErrorHandler(new EH());
        return db.parse(new InputSource(in));
    } catch (ParserConfigurationException e) {
        throw new AssertionError(e);
    }
}
 
Example 5
@Override
protected DocumentBuilder initialValue() {
    final DocumentBuilderFactory factory =
            DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);

    // Configure the factory to ignore comments
    factory.setIgnoringComments(true);
    DocumentBuilder builder = null;
    try {
        builder = factory.newDocumentBuilder();
        final EntityResolver resolver = new IgnoringEntityResolver();
        boolean resolveEntities =
            Boolean.getBoolean("org.jvoicexml.xml.resolveEntities");
        if (!resolveEntities) {
            builder.setEntityResolver(resolver);
        }
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return builder;
}
 
Example 6
public PredefinedTeXFormulaParser(InputStream file, String type) throws ResourceParseException {
    try {
        this.type = type;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setIgnoringElementContentWhitespace(true);
        factory.setIgnoringComments(true);
        root = factory.newDocumentBuilder().parse(file).getDocumentElement();
    } catch (Exception e) { // JDOMException or IOException
        throw new XMLResourceParseException("", e);
    }
}
 
Example 7
public TeXSymbolParser(InputStream file, String name)
		throws ResourceParseException {
	try {
		DocumentBuilderFactory factory = DocumentBuilderFactory
				.newInstance();
		factory.setIgnoringElementContentWhitespace(true);
		factory.setIgnoringComments(true);
		root = factory.newDocumentBuilder().parse(file)
				.getDocumentElement();
		// set possible valid symbol type mappings
		setTypeMappings();
	} catch (Exception e) { // JDOMException or IOException
		throw new XMLResourceParseException(name, e);
	}
}
 
Example 8
public Node getReplyRoot(String xmlReply)
{
    Document doc;
    InputSource is = new InputSource(new StringReader(xmlReply));
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    factory.setIgnoringComments(true);
    DocumentBuilder docBuilder;
    try
    {
        docBuilder = factory.newDocumentBuilder();
        doc = docBuilder.parse(is);
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return null;
    }

    Node root = doc.getDocumentElement();
    if (!root.getNodeName().equals("replies"))
    {
        PacketSamurai.getUserInterface().log("LogRepository: Error: malformed reply: root node should be called 'replies'.");
        return null;
    }
    return root;
}
 
Example 9
public PredefinedTeXFormulaParser(InputStream file, String type)
		throws ResourceParseException, IOException {
	try {
		this.type = type;
		DocumentBuilderFactory factory = DocumentBuilderFactory
				.newInstance();
		factory.setIgnoringElementContentWhitespace(true);
		factory.setIgnoringComments(true);
		root = factory.newDocumentBuilder().parse(file)
				.getDocumentElement();
	} catch (Exception e) { // JDOMException or IOException
		throw new XMLResourceParseException("", e);
	}
	file.close();
}
 
Example 10
Source Project: geowave   File: GeoWaveRasterConfig.java    License: Apache License 2.0 5 votes vote down vote up
private static Map<String, String> getParamsFromURL(final URL xmlURL)
    throws IOException, ParserConfigurationException, SAXException {
  try (final InputStream in = xmlURL.openStream()) {
    final InputSource input = new InputSource(xmlURL.toString());

    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setIgnoringComments(true);

    dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

    // HP Fortify "XML External Entity Injection" fix.
    // These lines are the recommended fix for
    // protecting a Java DocumentBuilderFactory from XXE.
    final String DISALLOW_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl";
    dbf.setFeature(DISALLOW_DOCTYPE_DECL, true);

    final DocumentBuilder db = dbf.newDocumentBuilder();

    // db.setEntityResolver(new ConfigEntityResolver(xmlURL));
    final Document dom = db.parse(input);
    in.close();

    final NodeList children = dom.getChildNodes().item(0).getChildNodes();
    final Map<String, String> configParams = new HashMap<>();
    for (int i = 0; i < children.getLength(); i++) {
      final Node child = children.item(i);
      configParams.put(child.getNodeName(), child.getTextContent());
    }
    return configParams;
  }
}
 
Example 11
Source Project: ph-commons   File: MicroHelperTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertToMicroNode () throws SAXException, IOException, ParserConfigurationException
{
  final String sXML = "<?xml version='1.0'?>" +
                      "<!DOCTYPE root [ <!ENTITY sc \"sc.exe\"> <!ELEMENT root (child, child2)> <!ELEMENT child (#PCDATA)> <!ELEMENT child2 (#PCDATA)> ]>" +
                      "<root attr='value'>" +
                      "<![CDATA[hihi]]>" +
                      "text" +
                      "&sc;" +
                      "<child xmlns='http://myns' a='b' />" +
                      "<child2 />" +
                      "<!-- comment -->" +
                      "<?stylesheet x y z?>" +
                      "</root>";
  final DocumentBuilderFactory aDBF = XMLFactory.createDefaultDocumentBuilderFactory ();
  aDBF.setCoalescing (false);
  aDBF.setIgnoringComments (false);
  final Document doc = aDBF.newDocumentBuilder ().parse (new StringInputStream (sXML, StandardCharsets.ISO_8859_1));
  assertNotNull (doc);
  final IMicroNode aNode = MicroHelper.convertToMicroNode (doc);
  assertNotNull (aNode);
  try
  {
    MicroHelper.convertToMicroNode (null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example 12
Source Project: anno4j   File: DocumentFragmentMarshall.java    License: Apache License 2.0 5 votes vote down vote up
public static DocumentBuilderFactory newDocumentBuilderFactory() {
	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setValidating(false);
	factory.setNamespaceAware(true);
	factory.setIgnoringComments(false);
	factory.setIgnoringElementContentWhitespace(false);
	return factory;
}
 
Example 13
public TeXFormulaSettingsParser(InputStream file, String name) throws ResourceParseException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setIgnoringElementContentWhitespace(true);
        factory.setIgnoringComments(true);
        root = factory.newDocumentBuilder().parse(file).getDocumentElement();
    } catch (Exception e) { // JDOMException or IOException
        throw new XMLResourceParseException(name, e);
    }
}
 
Example 14
/**
 * Generates the resource files
 */
public void generate() throws IOException, ParserConfigurationException {
    File pkgFolder = getFolderPath();
    if (!pkgFolder.isDirectory()) {
        if (!pkgFolder.mkdirs()) {
            throw new RuntimeException("Failed to create " + pkgFolder.getAbsolutePath());
        }
    }

    File resFile = new File(pkgFolder, RES_VALUE_FILENAME_XML);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(false);
    factory.setIgnoringComments(true);
    DocumentBuilder builder;

    builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();

    Node rootNode = document.createElement(TAG_RESOURCES);
    document.appendChild(rootNode);

    rootNode.appendChild(document.createTextNode("\n"));
    rootNode.appendChild(document.createComment("Automatically generated file. DO NOT MODIFY"));
    rootNode.appendChild(document.createTextNode("\n\n"));

    for (Object item : mItems) {
        if (item instanceof ClassField) {
            ClassField field = (ClassField)item;

            ResourceType type = ResourceType.getEnum(field.getType());
            boolean hasResourceTag = (type != null && RESOURCES_WITH_TAGS.contains(type));

            Node itemNode = document.createElement(hasResourceTag ? field.getType() : TAG_ITEM);
            Attr nameAttr = document.createAttribute(ATTR_NAME);

            nameAttr.setValue(field.getName());
            itemNode.getAttributes().setNamedItem(nameAttr);

            if (!hasResourceTag) {
                Attr typeAttr = document.createAttribute(ATTR_TYPE);
                typeAttr.setValue(field.getType());
                itemNode.getAttributes().setNamedItem(typeAttr);
            }

            if (type == ResourceType.STRING) {
                Attr translatable = document.createAttribute(ATTR_TRANSLATABLE);
                translatable.setValue(VALUE_FALSE);
                itemNode.getAttributes().setNamedItem(translatable);
            }

            if (!field.getValue().isEmpty()) {
                itemNode.appendChild(document.createTextNode(field.getValue()));
            }

            rootNode.appendChild(itemNode);
        } else if (item instanceof String) {
            rootNode.appendChild(document.createTextNode("\n"));
            rootNode.appendChild(document.createComment((String) item));
            rootNode.appendChild(document.createTextNode("\n"));
        }
    }

    String content;
    try {
        content = XmlPrettyPrinter.prettyPrint(document, true);
    } catch (Throwable t) {
        content = XmlUtils.toXml(document);
    }

    Files.write(content, resFile, Charsets.UTF_8);
}
 
Example 15
Source Project: ranger   File: XMLUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void loadConfig(InputStream input, Map<Object, Object> properties) {
	try {
		DocumentBuilderFactory xmlDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
		xmlDocumentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
		xmlDocumentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
               	xmlDocumentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
		xmlDocumentBuilderFactory.setIgnoringComments(true);
		xmlDocumentBuilderFactory.setNamespaceAware(true);

		DocumentBuilder xmlDocumentBuilder = xmlDocumentBuilderFactory.newDocumentBuilder();
		Document xmlDocument = xmlDocumentBuilder.parse(input);
		xmlDocument.getDocumentElement().normalize();

		NodeList nList = xmlDocument.getElementsByTagName(XMLCONFIG_PROPERTY_TAGNAME);

		for (int temp = 0; temp < nList.getLength(); temp++) {

			Node nNode = nList.item(temp);

			if (nNode.getNodeType() == Node.ELEMENT_NODE) {

				Element eElement = (Element) nNode;

				String propertyName = "";
				String propertyValue = "";
				if (eElement.getElementsByTagName(XMLCONFIG_NAME_TAGNAME).item(0) != null) {
					propertyName = eElement.getElementsByTagName(XMLCONFIG_NAME_TAGNAME)
							.item(0).getTextContent().trim();
				}
				if (eElement.getElementsByTagName(XMLCONFIG_VALUE_TAGNAME).item(0) != null) {
					propertyValue = eElement.getElementsByTagName(XMLCONFIG_VALUE_TAGNAME)
							.item(0).getTextContent().trim();
				}

				if (properties.get(propertyName) != null) {
					properties.remove(propertyName);
				}

				properties.put(propertyName, propertyValue);

			}
		}

	} catch (Exception e) {
		LOG.error("Error loading : ", e);
	}
}
 
Example 16
Source Project: steady   File: WSS4JFaultCodeTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test for WSS4JInInterceptor when it receives a message with no security header. 
 */
@Test
public void testNoSecurity() throws Exception {
    Document doc = readDocument("wsse-request-clean.xml");

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);
    
    SOAPMessage saajMsg = MessageFactory.newInstance().createMessage();
    SOAPPart part = saajMsg.getSOAPPart();
    part.setContent(new DOMSource(doc));
    saajMsg.saveChanges();

    msg.setContent(SOAPMessage.class, saajMsg);
    doc = part;
    
    byte[] docbytes = getMessageBytes(doc);
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    dbf.setValidating(false);
    dbf.setIgnoringComments(false);
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setNamespaceAware(true);

    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setEntityResolver(new NullResolver());
    doc = StaxUtils.read(db, reader, false);

    WSS4JInInterceptor inHandler = new WSS4JInInterceptor();

    SoapMessage inmsg = new SoapMessage(new MessageImpl());
    ex.setInMessage(inmsg);
    inmsg.setContent(SOAPMessage.class, saajMsg);

    inHandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
    inHandler.setProperty(WSHandlerConstants.DEC_PROP_FILE, "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    try {
        inHandler.handleMessage(inmsg);
        fail("Expected failure on an message with no security header");
    } catch (SoapFault fault) {
        assertTrue(fault.getReason().startsWith(
            "An error was discovered processing the <wsse:Security> header"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "InvalidSecurity");
        assertTrue(fault.getFaultCode().equals(faultCode));
    }
}
 
Example 17
Source Project: steady   File: WSS4JFaultCodeTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Test that an action mismatch gets mapped to a proper fault code 
 */
@Test
public void testActionMismatch() throws Exception {
    Document doc = readDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);
    
    SOAPMessage saajMsg = MessageFactory.newInstance().createMessage();
    SOAPPart part = saajMsg.getSOAPPart();
    part.setContent(new DOMSource(doc));
    saajMsg.saveChanges();

    msg.setContent(SOAPMessage.class, saajMsg);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);

    handler.handleMessage(msg);

    doc = part;
    
    assertValid("//wsse:Security", doc);

    byte[] docbytes = getMessageBytes(doc);
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    dbf.setValidating(false);
    dbf.setIgnoringComments(false);
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setNamespaceAware(true);

    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setEntityResolver(new NullResolver());
    doc = StaxUtils.read(db, reader, false);

    WSS4JInInterceptor inHandler = new WSS4JInInterceptor();

    SoapMessage inmsg = new SoapMessage(new MessageImpl());
    ex.setInMessage(inmsg);
    inmsg.setContent(SOAPMessage.class, saajMsg);

    inHandler.setProperty(WSHandlerConstants.ACTION, 
        WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.USERNAME_TOKEN);
    inHandler.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());

    try {
        inHandler.handleMessage(inmsg);
        fail("Expected failure on an action mismatch");
    } catch (SoapFault fault) {
        assertTrue(fault.getReason().startsWith(
            "An error was discovered processing the <wsse:Security> header"));
        QName faultCode = new QName(WSConstants.WSSE_NS, "InvalidSecurity");
        assertTrue(fault.getFaultCode().equals(faultCode));
    }
}
 
Example 18
@org.junit.Test
public void testSignatureConfirmationRequest() throws Exception {
    Document doc = readDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);
    
    SOAPMessage saajMsg = MessageFactory.newInstance().createMessage();
    SOAPPart part = saajMsg.getSOAPPart();
    part.setContent(new DOMSource(doc));
    saajMsg.saveChanges();

    msg.setContent(SOAPMessage.class, saajMsg);

    msg.put(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    msg.put(WSHandlerConstants.ENABLE_SIGNATURE_CONFIRMATION, "true");
    msg.put(WSHandlerConstants.SIG_PROP_FILE, "outsecurity.properties");
    msg.put(WSHandlerConstants.USER, "myalias");
    msg.put("password", "myAliasPassword");
    //
    // This is necessary to convince the WSS4JOutInterceptor that we're
    // functioning as a requestor
    //
    msg.put(org.apache.cxf.message.Message.REQUESTOR_ROLE, true);

    handler.handleMessage(msg);
    doc = part;
    
    assertValid("//wsse:Security", doc);
    assertValid("//wsse:Security/ds:Signature", doc);

    byte[] docbytes = getMessageBytes(doc);
    //
    // Save the signature for future confirmation
    //
    List<WSHandlerResult> sigv = CastUtils.cast((List<?>)msg.get(WSHandlerConstants.SEND_SIGV));
    assertNotNull(sigv);
    assertTrue(sigv.size() != 0);
    
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    dbf.setValidating(false);
    dbf.setIgnoringComments(false);
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setNamespaceAware(true);

    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setEntityResolver(new NullResolver());
    doc = StaxUtils.read(db, reader, false);

    WSS4JInInterceptor inHandler = new WSS4JInInterceptor();

    SoapMessage inmsg = new SoapMessage(new MessageImpl());
    ex.setInMessage(inmsg);
    inmsg.setContent(SOAPMessage.class, saajMsg);

    inHandler.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
    inHandler.setProperty(WSHandlerConstants.SIG_PROP_FILE, "insecurity.properties");
    inHandler.setProperty(WSHandlerConstants.ENABLE_SIGNATURE_CONFIRMATION, "true");

    inHandler.handleMessage(inmsg);
    
    //
    // Check that the inbound signature result was saved
    //
    WSSecurityEngineResult result = 
        (WSSecurityEngineResult) inmsg.get(WSS4JInInterceptor.SIGNATURE_RESULT);
    assertNotNull(result);
    
    List<WSHandlerResult> sigReceived = 
        CastUtils.cast((List<?>)inmsg.get(WSHandlerConstants.RECV_RESULTS));
    assertNotNull(sigReceived);
    assertTrue(sigReceived.size() != 0);
    
    testSignatureConfirmationResponse(sigv, sigReceived);
}
 
Example 19
Source Project: steady   File: SamlTokenTest.java    License: Apache License 2.0 4 votes vote down vote up
private SoapMessage makeInvocation(
    Map<String, Object> outProperties,
    List<String> xpaths,
    Map<String, Object> inProperties,
    Map<String, String> inMessageProperties
) throws Exception {
    Document doc = readDocument("wsse-request-clean.xml");

    WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
    PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();

    SoapMessage msg = new SoapMessage(new MessageImpl());
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(msg);

    SOAPMessage saajMsg = MessageFactory.newInstance().createMessage();
    SOAPPart part = saajMsg.getSOAPPart();
    part.setContent(new DOMSource(doc));
    saajMsg.saveChanges();

    msg.setContent(SOAPMessage.class, saajMsg);

    for (String key : outProperties.keySet()) {
        msg.put(key, outProperties.get(key));
    }

    handler.handleMessage(msg);

    doc = part;

    for (String xpath : xpaths) {
        assertValid(xpath, doc);
    }

    byte[] docbytes = getMessageBytes(doc);
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    dbf.setValidating(false);
    dbf.setIgnoringComments(false);
    dbf.setIgnoringElementContentWhitespace(true);
    dbf.setNamespaceAware(true);

    DocumentBuilder db = dbf.newDocumentBuilder();
    db.setEntityResolver(new NullResolver());
    doc = StaxUtils.read(db, reader, false);

    WSS4JInInterceptor inHandler = new WSS4JInInterceptor(inProperties);

    SoapMessage inmsg = new SoapMessage(new MessageImpl());
    inmsg.put(SecurityConstants.SAML_ROLE_ATTRIBUTENAME, "role");
    for (String inMessageProperty : inMessageProperties.keySet()) {
        inmsg.put(inMessageProperty, inMessageProperties.get(inMessageProperty));
    }
    ex.setInMessage(inmsg);
    inmsg.setContent(SOAPMessage.class, saajMsg);

    inHandler.handleMessage(inmsg);

    return inmsg;
}
 
Example 20
private final void load()
{
	if (Config.DEBUG)
   		System.out.print("Parsing ...");
       try
       {
           DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
           factory.setValidating(false);
           factory.setIgnoringComments(true);

           File file = new File(Config.DATAPACK_ROOT+"/data/xml/cursedWeapons.xml");
           if (!file.exists())
           {
       		if (Config.DEBUG)
           		System.out.println("NO FILE");
           	return;
           }

           Document doc = factory.newDocumentBuilder().parse(file);

           for (Node n=doc.getFirstChild(); n != null; n = n.getNextSibling())
           {
               if ("list".equalsIgnoreCase(n.getNodeName()))
               {
                   for (Node d=n.getFirstChild(); d != null; d = d.getNextSibling())
                   {
                       if ("item".equalsIgnoreCase(d.getNodeName()))
                       {
                   		NamedNodeMap attrs = d.getAttributes();
                       	int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
                       	int skillId = Integer.parseInt(attrs.getNamedItem("skillId").getNodeValue());
                       	String name = attrs.getNamedItem("name").getNodeValue();

                       	CursedWeapon cw = new CursedWeapon(id, skillId, name);

                       	int val;
                           for (Node cd=d.getFirstChild(); cd != null; cd = cd.getNextSibling())
                           {
                               if ("dropRate".equalsIgnoreCase(cd.getNodeName()))
                               {
                           		attrs = cd.getAttributes();
                           		val = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
                           		cw.setDropRate(val);
                               }
                               else if ("duration".equalsIgnoreCase(cd.getNodeName()))
                               {
                           		attrs = cd.getAttributes();
                           		val = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
                           		cw.setDuration(val);
                               }
                               else if ("durationLost".equalsIgnoreCase(cd.getNodeName()))
                               {
                           		attrs = cd.getAttributes();
                           		val = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
                           		cw.setDurationLost(val);
                               }
                               else if ("disapearChance".equalsIgnoreCase(cd.getNodeName()))
                               {
                           		attrs = cd.getAttributes();
                           		val = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
                           		cw.setDisapearChance(val);
                               }
                               else if ("stageKills".equalsIgnoreCase(cd.getNodeName()))
                               {
                           		attrs = cd.getAttributes();
                           		val = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
                           		cw.setStageKills(val);
                               }
                           }
                           _cursedWeapons.put(id, cw);
                       }
                   }
               }
           }

       	if (Config.DEBUG)
       		System.out.println("OK");
       }
       catch (Exception e)
       {
           _log.log(Level.SEVERE, "Error parsing cursed weapons file.", e);

           if (Config.DEBUG)
       		System.out.println("ERROR");
           return ;
       }
}