⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contenthandlerimpl.java

📁 xbrlapi的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    		    	} catch (XBRLException e) {
    		    		logger.warn("A problem occurred when stashing the schemaLocation URL: " + fields[i]);
			    	} catch (XMLBaseException e) {
			    		logger.warn("A problem occurred when getting the base URL so schemaLocation URLs were not stashed from: " + schemaLocations);
			    	}
    			}
    		}
    	}
    	
    	// Handle XLink fragments
    	try {

    		// First let the XLink handler know the depth of the element being processed in case it makes a fragment
    		getXLinkHandler().setDepth(getDepth());
    		getXLinkHandler().setState(getState());
    		
    		// Next pass control to the XLink processor so it can recognise and respond to XLink elements
    		getLoader().getXlinkProcessor().startElement(namespaceURI,lName,qName,attrs);
    		
    	} catch (XLinkException e) {
    		throw new SAXException("XLink processing of the start of an element failed.",e);
    	}

    	// Handle XML Schema fragments
    	try {
	    	Fragment schemaFragment = null;
	    	String fragmentID = null; // The ID attribute value for the fragment if it exists

	    	if (namespaceURI.equals(Constants.XMLSchemaNamespace)) {
	    		
	    		if (lName.equals("schema")) {
	    			schemaFragment = new SchemaImpl();

    				model = getXSModel();
	    			this.targetNamespace = attrs.getValue("targetNamespace");
	    			
	    		} else if (lName.equals("element")) {
	    			
	    			fragmentID = attrs.getValue("id");
	    			
	    			String elementName = attrs.getValue("name");
	    			
	    			if (model == null) {
	    			    throw new XBRLException("An XML Schema element was found outside of an XML Schema.");
	    			}

	    			if (this.targetNamespace == null) {
	    				throw new XBRLException("An XML Schema element was found where the targetNamespace was not initialised.");
	    			}

	    			// Find the XS model element declaration for the element that has been started - if one can be found
	    			XSElementDeclaration declaration = null;
	    			
	    			// Handle anonymous schemas first - these are the tough case
	    			if (this.targetNamespace.equals("")) {
	    				
	    				// Get the list of namespaces declared in the model
	    				XSNamespaceItemList nsItemList = model.getNamespaceItems();
	    				
	    				// For each namespace ...
	    				for (int i=0; i<nsItemList.getLength(); i++) {
	    					XSNamespaceItem nsItem = nsItemList.item(i);
	    					
	    					// Get a candidate element declaration if one exists
	    					XSElementDeclaration candidateDeclaration = nsItem.getElementDeclaration(elementName);
	    					if (candidateDeclaration != null) {
	    						
	    						// Get the URIs of the documents that were used to create elements in this namespace
	    						StringList locations = nsItem.getDocumentLocations();
	    						
	    						// Check to see if the current document URL is one of those documents and if so, the candidate could be good
	    						for (int j=0; j<locations.getLength(); j++) {
	    							String location = locations.item(j);
	    							if (location.equals(this.url.toString())) {
	    								// Throw an exception if we find two feasible candidate element declarations in the Schema model
	    	    						if (declaration != null) throw new XBRLException("Potentially ambiguous anonymous Schema problem.");
	    	    						declaration = candidateDeclaration;
	    							}
	    						}
	    					}
	    				}
	    				
	    				// TODO Handle anonymous schemas without throwing an exception.
	    				if (declaration == null) throw new XBRLException("An anonymous XML Schema was found that could not be handled.");
	    				
	    			// Handle the easy case where the schema specifies its target namespace
	    			} else if (elementName != null) {
	    					declaration = model.getElementDeclaration(elementName, this.targetNamespace);
	    			}
	    			
	    			// Determine what substitution groups the element is in - if any.
	    			boolean isItemConcept = false;
	    			boolean isTupleConcept = false;
	    			boolean isReferencePartDeclaration = false;
	    			if (declaration != null) {
	    				XSElementDeclaration sgDeclaration = declaration.getSubstitutionGroupAffiliation();
		    			while (sgDeclaration != null) {
		    				
		    				if (sgDeclaration.getNamespace().equals(Constants.XBRL21Namespace)) {
		    					if (sgDeclaration.getName().equals("item"))
		    						isItemConcept = true;
		    					else if (sgDeclaration.getName().equals("tuple"))
		    						isTupleConcept = true;
		    				}
		    				if (sgDeclaration.getNamespace().equals(Constants.XBRL21LinkNamespace)) {
		    					if (sgDeclaration.getName().equals("part"))
		    						isReferencePartDeclaration = true;
		    				}
		    				sgDeclaration = sgDeclaration.getSubstitutionGroupAffiliation();
		    			}
	    			}
	    			// TODO Decide if the element declarations need to keep track of their whole substitution group stack.
	    			
	    			// If the element has a periodType attribute it is an XBRL concept
	    			if (isItemConcept || isTupleConcept) {
	    				schemaFragment = new ConceptImpl();
	    				
	    			} else if (isReferencePartDeclaration) {
	    				schemaFragment = new ReferencePartDeclarationImpl();
	    			} else if (elementName != null) {
	    				schemaFragment = new ElementDeclarationImpl();
	    			}	    			
	    			
	    		}
	    		
	    		if (schemaFragment != null) {
		    		schemaFragment.setFragmentIndex(getLoader().getNextFragmentId());
	    			if (fragmentID != null) {
	    				schemaFragment.appendID(fragmentID);
	    				state.setId(fragmentID);
	    			}
	    			getLoader().addFragment(schemaFragment,depth,getState());
	    		}
	    	}
	    	
    	} catch (XBRLException e) {
    		throw new SAXException("The XML Schema fragment could not be processed.",e);
    	}
    	
    	// Handle XBRL fragments
    	Fragment xbrlFragment = null;
    	try {

	    	if (namespaceURI.equals(Constants.XBRL21Namespace)) {

	    		if (lName.equals("xbrl")) {
	    			xbrlFragment = new InstanceImpl();
	    			this.parsingAnXBRLInstance = true;
	    			this.canBeATuple = true;
	    		} else if (lName.equals("period")) {
	    			xbrlFragment = new PeriodImpl();
	    		} else if (lName.equals("entity")) {
	    			xbrlFragment = new EntityImpl();
	    		} else if (lName.equals("segment")) {
	    			xbrlFragment = new SegmentImpl();
	    		} else if (lName.equals("scenario")) {
	    			xbrlFragment = new ScenarioImpl();
	    		} else if (lName.equals("context")) {
	    			xbrlFragment = new ContextImpl();
	    			this.canBeATuple = false;
	    		} else if (lName.equals("unit")) {
	    			xbrlFragment = new UnitImpl();
	    			this.canBeATuple = false;
	    		}
	    		
	    		if (xbrlFragment != null) {
	    			xbrlFragment.setFragmentIndex(getLoader().getNextFragmentId());
	    			if (attrs.getValue("id") != null) {
	    				xbrlFragment.appendID(attrs.getValue("id"));
	    				state.setId(attrs.getValue("id"));
	    			}
	    			getLoader().addFragment(xbrlFragment,depth,getState());
	    		}
	    	}
		} catch (XBRLException e) {
			e.printStackTrace();
			throw new SAXException("The XBRL fragment could not be processed.",e);
		}

    	// Handle reference part fragments
    	Fragment referencePartFragment = null;
    	try {
    		
	    	if (parsingAReferenceResource) {
	    		referencePartFragment = new ReferencePartImpl();
	    	}

    		if (referencePartFragment != null) {
    			referencePartFragment.setFragmentIndex(getLoader().getNextFragmentId());
    			getLoader().addFragment(referencePartFragment,depth,getState());
    		}
    		
		} catch (XBRLException e) {
			throw new SAXException("The XBRL fragment could not be processed.",e);
		}
		
    	// Handle XBRL Link fragments
    	try {
	    	Fragment xbrlLinkFragment = null;
	    	if (namespaceURI.equals(Constants.XBRL21LinkNamespace)) {
	    		if (lName.equals("roleType")) {
	    			xbrlLinkFragment = new RoleTypeImpl();
	    		} else if (lName.equals("arcroleType")) {
	    			xbrlLinkFragment = new ArcroleTypeImpl();
	    		} else if (lName.equals("usedOn")) {
	    			xbrlLinkFragment = new UsedOnImpl();
	    		} else if (lName.equals("linkbase")) {
	    			xbrlLinkFragment = new LinkbaseImpl();
	    		} else if (lName.equals("documentation")) {
	    			xbrlLinkFragment = new XlinkDocumentationImpl();
	    		} else if (lName.equals("footnoteLink")) {
	    			// Fragment already created by XLink processor
	    			this.canBeATuple = false;
	    		} else if (lName.equals("schemaRef")) {
	    			// Fragment already created by XLink processor
	    			this.canBeATuple = false;
	    		} else if (lName.equals("linkbaseRef")) {
	    			// Fragment already created by XLink processor
	    			this.canBeATuple = false;
	    		} else if (lName.equals("roleRef")) {
	    			// Fragment already created by XLink processor
	    			this.canBeATuple = false;
	    		} else if (lName.equals("arcroleRef")) {
	    			// Fragment already created by XLink processor
	    			this.canBeATuple = false;
	    		} else if (lName.equals("reference")) {
	    			// Fragment already created by XLink processor
	    			this.parsingAReferenceResource = true;
	    		}
	    		
	    		if (xbrlLinkFragment != null) {
		    		xbrlLinkFragment.setFragmentIndex(getLoader().getNextFragmentId());
	    			if (attrs.getValue("id") != null) {
	    				xbrlLinkFragment.appendID(attrs.getValue("id"));
	    				state.setId(attrs.getValue("id"));
	    			}
	    			getLoader().addFragment(xbrlLinkFragment,depth,state); 			
	    		}
	    	}
		} catch (XBRLException e) {
			throw new SAXException("The XBRL Link fragment could not be processed.",e);
		}

    	// Handle XBRL facts
		if ((xbrlFragment == null) && (referencePartFragment == null) && this.parsingAnXBRLInstance) {
	    	try {
		    	Fragment factFragment = null;
		    	
		    	// First handle items
		    	String contextRef = attrs.getValue("contextRef");
		    	if (contextRef != null) {
			    	String unitRef = attrs.getValue("unitRef");
			    	if (unitRef != null) {
			    		// TODO Handle recognition of fraction numeric items - may require reading ahead in SAX - ouch
			    		factFragment = new SimpleNumericItemImpl();
			    	} else {
			    		factFragment = new NonNumericItemImpl();
			    	}
		    	}
		    	
		    	// Next handle XBRL instance tuples
		    	if ((factFragment == null) && this.canBeATuple) {
		    		factFragment = new TupleImpl();
		    	}
		    	
		    	if (factFragment != null) {
		    		factFragment.setFragmentIndex(getLoader().getNextFragmentId());
		    		if (attrs.getValue("id") != null) {
		    			factFragment.appendID(attrs.getValue("id"));
	    				state.setId(attrs.getValue("id"));
		    		}
		    		getLoader().addFragment(factFragment,depth,state);
		    	}

			} catch (XBRLException e) {
				throw new SAXException("The XBRL Link fragment could not be processed.",e);
			}
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -