/** * Internalize all {@code <jaxb:bindings>} customizations in the given forest. * * @return * if the SCD support is enabled, the return bindings need to be applied * after schema components are parsed. * If disabled, the returned binding set will be empty. * SCDs are only for XML Schema, and doesn't make any sense for other * schema languages. */ static SCDBasedBindingSet transform( DOMForest forest, boolean enableSCD, boolean disableSecureProcessing ) { return new Internalizer(forest, enableSCD, disableSecureProcessing).transform(); }
/** * Recursively visits sub-elements and declare all used namespaces. * TODO: the fact that we recognize all namespaces in the extension * is a bad design. */ private void declExtensionNamespace(Element decl, Element target) { // if this comes from external namespaces, add the namespace to // @extensionBindingPrefixes. if( !Const.JAXB_NSURI.equals(decl.getNamespaceURI()) ) declareExtensionNamespace( target, decl.getNamespaceURI() ); NodeList lst = decl.getChildNodes(); for( int i=0; i<lst.getLength(); i++ ) { Node n = lst.item(i); if( n instanceof Element ) declExtensionNamespace( (Element)n, target ); } }
private void reportError( Element errorSource, String formattedMsg ) { reportError( errorSource, formattedMsg, null ); }
move(item, targetNodes); } else if ("globalBindings".equals(localName)) { moveUnder(item,forest.getOneDocument().getDocumentElement()); } else { if (!(target instanceof Element)) { reportError(item, Messages.format(Messages.CONTEXT_NODE_IS_NOT_ELEMENT)); return; // abort reportError(item, Messages.format(Messages.ORPHANED_CUSTOMIZATION, item.getNodeName())); return; // abort moveUnder(item,(Element)target);
private SCDBasedBindingSet transform() { // either target nodes are conventional DOM nodes (as per spec), Map<Element,Node> targetNodes = new HashMap<Element,Node>(); // ... or it will be schema components by means of SCD (RI extension) SCDBasedBindingSet scd = new SCDBasedBindingSet(forest); // // identify target nodes for all <jaxb:bindings> // for (Element jaxbBindings : forest.outerMostBindings) { // initially, the inherited context is itself buildTargetNodeMap(jaxbBindings, jaxbBindings, null, targetNodes, scd); } // // then move them to their respective positions. // for (Element jaxbBindings : forest.outerMostBindings) { move(jaxbBindings, targetNodes); } return scd; }
Element realTarget = forest.logic.refineTarget(target); declExtensionNamespace( decl, target ); copyLocators( original, decl );
validate(bindings); // validate this node buildTargetNodeMap(value, forest.get(systemId).getDocumentElement(), inheritedSCD, result, scdResult); reportError( bindings, Messages.format(Messages.ERR_INCORRECT_SCHEMA_REFERENCE, schemaLocation, } catch (XPathExpressionException e) { if(required) { reportError( bindings, Messages.format(Messages.ERR_XPATH_EVAL,e.getMessage()), e ); return; // abort processing this <jaxb:bindings> reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NO_TARGET, nodeXPath) ); return; // abort reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TOO_MANY_TARGETS, nodeXPath,nlst.getLength()) ); Node rnode = nlst.item(0); if (!(rnode instanceof Element)) { reportError(bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NON_ELEMENT, nodeXPath)); return; // abort reportError(bindings, Messages.format(Messages.XPATH_EVAL_TO_NON_SCHEMA_ELEMENT,
buildTargetNodeMap(value, forest.get(systemId).getDocumentElement(), inheritedSCD, result, scdResult); reportError( bindings, Messages.format(Messages.ERR_INCORRECT_SCHEMA_REFERENCE, schemaLocation, } catch (XPathExpressionException e) { if(required) { reportError( bindings, Messages.format(Messages.ERR_XPATH_EVAL,e.getMessage()), e ); return; // abort processing this <jaxb:bindings> reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NO_TARGET, nodeXPath) ); return; // abort reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TOO_MANY_TARGETS, nodeXPath,nlst.getLength()) ); Node rnode = nlst.item(0); if (!(rnode instanceof Element)) { reportError(bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NON_ELEMENT, nodeXPath)); return; // abort reportError(bindings, Messages.format(Messages.XPATH_EVAL_TO_NON_SCHEMA_ELEMENT, nodeXPath, rnode.getNodeName()));
/** * Performs internalization. * * This method should be called only once, only after all the * schemas are parsed. * * @return * the returned bindings need to be applied after schema * components are built. */ public SCDBasedBindingSet transform(boolean enableSCD) { return Internalizer.transform(this,enableSCD); }
/** * Copies location information attached to the "src" node to the "dst" node. */ private void copyLocators( Element src, Element dst ) { forest.locatorTable.storeStartLocation( dst, forest.locatorTable.getStartLocation(src) ); forest.locatorTable.storeEndLocation( dst, forest.locatorTable.getEndLocation(src) ); // recursively process child elements Element[] srcChilds = DOMUtils.getChildElements(src); Element[] dstChilds = DOMUtils.getChildElements(dst); for( int i=0; i<srcChilds.length; i++ ) copyLocators( srcChilds[i], dstChilds[i] ); }
/** * Adds the specified namespace URI to the jaxb:extensionBindingPrefixes * attribute of the target document. */ private void declareExtensionNamespace( Element target, String nsUri ) { // look for the attribute Element root = target.getOwnerDocument().getDocumentElement(); Attr att = root.getAttributeNodeNS(Const.JAXB_NSURI,EXTENSION_PREFIXES); if( att==null ) { String jaxbPrefix = allocatePrefix(root,Const.JAXB_NSURI); // no such attribute. Create one. att = target.getOwnerDocument().createAttributeNS( Const.JAXB_NSURI,jaxbPrefix+':'+EXTENSION_PREFIXES); root.setAttributeNodeNS(att); } String prefix = allocatePrefix(root,nsUri); if( att.getValue().indexOf(prefix)==-1 ) // avoid redeclaring the same namespace twice. att.setValue( att.getValue()+' '+prefix); }
move(item, targetNodes); } else if ("globalBindings".equals(localName)) { moveUnder(item, forest.getOneDocument().getDocumentElement()); } else { if (!(target instanceof Element)) { reportError(item, Messages.format(Messages.CONTEXT_NODE_IS_NOT_ELEMENT)); return; // abort reportError(item, Messages.format(Messages.ORPHANED_CUSTOMIZATION, item.getNodeName())); return; // abort moveUnder(item, (Element) target);
private SCDBasedBindingSet transform() { // either target nodes are conventional DOM nodes (as per spec), Map<Element,List<Node>> targetNodes = new HashMap<Element,List<Node>>(); // ... or it will be schema components by means of SCD (RI extension) SCDBasedBindingSet scd = new SCDBasedBindingSet(forest); // // identify target nodes for all <jaxb:bindings> // for (Element jaxbBindings : forest.outerMostBindings) { // initially, the inherited context is itself buildTargetNodeMap(jaxbBindings, jaxbBindings, null, targetNodes, scd); } // // then move them to their respective positions. // for (Element jaxbBindings : forest.outerMostBindings) { move(jaxbBindings, targetNodes); } return scd; }
Element realTarget = forest.logic.refineTarget(target); declExtensionNamespace( decl, target ); copyLocators( original, decl );
validate(bindings); // validate this node reportError( bindings, Messages.format(Messages.ERR_INCORRECT_SCHEMA_REFERENCE, schemaLocation, nlst = (NodeList)xpath.evaluate(nodeXPath,target,XPathConstants.NODESET); } catch (XPathExpressionException e) { reportError( bindings, Messages.format(Messages.ERR_XPATH_EVAL,e.getMessage()), e ); return; // abort processing this <jaxb:bindings> reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NO_TARGET, nodeXPath) ); return; // abort reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TOO_MANY_TARGETS, nodeXPath,nlst.getLength()) ); return; // abort reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NON_ELEMENT, nodeXPath) ); return; // abort reportError( bindings, Messages.format(Messages.XPATH_EVAL_TO_NON_SCHEMA_ELEMENT, nodeXPath, rnode.getNodeName() ) ); reportError(bindings,
buildTargetNodeMap(value, forest.get(systemId).getDocumentElement(), inheritedSCD, result, scdResult); reportError( bindings, Messages.format(Messages.ERR_INCORRECT_SCHEMA_REFERENCE, schemaLocation, } catch (XPathExpressionException e) { if(required) { reportError( bindings, Messages.format(Messages.ERR_XPATH_EVAL,e.getMessage()), e ); return; // abort processing this <jaxb:bindings> reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NO_TARGET, nodeXPath) ); return; // abort reportError( bindings, Messages.format(Messages.NO_XPATH_EVAL_TOO_MANY_TARGETS, nodeXPath,nlst.getLength()) ); Node rnode = nlst.item(0); if (!(rnode instanceof Element)) { reportError(bindings, Messages.format(Messages.NO_XPATH_EVAL_TO_NON_ELEMENT, nodeXPath)); return; // abort reportError(bindings, Messages.format(Messages.XPATH_EVAL_TO_NON_SCHEMA_ELEMENT, nodeXPath, rnode.getNodeName()));
/** * Performs internalization. * * This method should be called only once, only after all the * schemas are parsed. * * @return * the returned bindings need to be applied after schema * components are built. */ public SCDBasedBindingSet transform(boolean enableSCD) { return Internalizer.transform(this, enableSCD, options.disableXmlSecurity); }
/** * Copies location information attached to the "src" node to the "dst" node. */ private void copyLocators( Element src, Element dst ) { forest.locatorTable.storeStartLocation( dst, forest.locatorTable.getStartLocation(src) ); forest.locatorTable.storeEndLocation( dst, forest.locatorTable.getEndLocation(src) ); // recursively process child elements Element[] srcChilds = DOMUtils.getChildElements(src); Element[] dstChilds = DOMUtils.getChildElements(dst); for( int i=0; i<srcChilds.length; i++ ) copyLocators( srcChilds[i], dstChilds[i] ); }
/** * Adds the specified namespace URI to the jaxb:extensionBindingPrefixes * attribute of the target document. */ private void declareExtensionNamespace( Element target, String nsUri ) { // look for the attribute Element root = target.getOwnerDocument().getDocumentElement(); Attr att = root.getAttributeNodeNS(Const.JAXB_NSURI,EXTENSION_PREFIXES); if( att==null ) { String jaxbPrefix = allocatePrefix(root,Const.JAXB_NSURI); // no such attribute. Create one. att = target.getOwnerDocument().createAttributeNS( Const.JAXB_NSURI,jaxbPrefix+':'+EXTENSION_PREFIXES); root.setAttributeNodeNS(att); } String prefix = allocatePrefix(root,nsUri); if( att.getValue().indexOf(prefix)==-1 ) // avoid redeclaring the same namespace twice. att.setValue( att.getValue()+' '+prefix); }
move(item, targetNodes); } else if ("globalBindings".equals(localName)) { NodeList elements = root.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema"); if ((elements == null) || (elements.getLength() < 1)) { reportError(item, Messages.format(Messages.ORPHANED_CUSTOMIZATION, item.getNodeName())); return; } else { moveUnder(item, (Element)elements.item(0)); moveUnder(item, root); reportError(item, Messages.format(Messages.CONTEXT_NODE_IS_NOT_ELEMENT)); return; // abort reportError(item, Messages.format(Messages.ORPHANED_CUSTOMIZATION, item.getNodeName())); return; // abort moveUnder(item, (Element) target);